|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +function JSON_to_workspace() { |
| 6 | + # 1: the analysis name |
| 7 | + # 2: the url of the JSON workspaces |
| 8 | + # 3: the background only workspace |
| 9 | + # 4: the signal workspace patch |
| 10 | + # 5: the patched background + signal workspace |
| 11 | + local ANALYSIS_NAME=$1 |
| 12 | + local HEPDATA_URL=$2 |
| 13 | + local BACKGROUND_ONLY=$3 |
| 14 | + local SIGNAL_PATCH=$4 |
| 15 | + local JSON_WORKSPACE=$5 |
| 16 | + |
| 17 | + if [[ ! -d "${ANALYSIS_NAME}" ]]; then |
| 18 | + mkdir "${ANALYSIS_NAME}" |
| 19 | + fi |
| 20 | + |
| 21 | + # Download from HEPData |
| 22 | + curl -sL -o "${ANALYSIS_NAME}/workspaces.tar.gz" "${HEPDATA_URL}" |
| 23 | + # Unpack tarball |
| 24 | + if [[ ! -d "${ANALYSIS_NAME}/workspaces" ]]; then |
| 25 | + mkdir "${ANALYSIS_NAME}/workspaces" |
| 26 | + fi |
| 27 | + tar xvzf "${ANALYSIS_NAME}/workspaces.tar.gz" -C "${ANALYSIS_NAME}/workspaces" |
| 28 | + |
| 29 | + # Create a full signal+background workspace |
| 30 | + jsonpatch \ |
| 31 | + "${ANALYSIS_NAME}/workspaces/${BACKGROUND_ONLY}" \ |
| 32 | + "${ANALYSIS_NAME}/workspaces/${SIGNAL_PATCH}" > \ |
| 33 | + "${ANALYSIS_NAME}/workspaces/${JSON_WORKSPACE}" |
| 34 | + |
| 35 | + # Convert to ROOT + XML |
| 36 | + if [[ ! -d "${ANALYSIS_NAME}/xml" ]]; then |
| 37 | + mkdir "${ANALYSIS_NAME}/xml" |
| 38 | + fi |
| 39 | + rm -rf "${ANALYSIS_NAME}/xml"/* |
| 40 | + pyhf json2xml \ |
| 41 | + --output-dir "${ANALYSIS_NAME}/xml" \ |
| 42 | + "${ANALYSIS_NAME}/workspaces/${JSON_WORKSPACE}" |
| 43 | + |
| 44 | + # Generate ROOT workspace |
| 45 | + hist2workspace "${ANALYSIS_NAME}/xml"/FitConfig.xml |
| 46 | +} |
| 47 | + |
| 48 | +function main() { |
| 49 | + # 1: the analysis name |
| 50 | + # 2: the url of the JSON workspaces |
| 51 | + # 3: the background only workspace |
| 52 | + # 4: the signal workspace patch |
| 53 | + # 5: the patched background + signal workspace |
| 54 | + local ANALYSIS_NAME=$1 |
| 55 | + local HEPDATA_URL=$2 |
| 56 | + local BACKGROUND_ONLY=$3 |
| 57 | + local SIGNAL_PATCH=$4 |
| 58 | + local JSON_WORKSPACE=$5 |
| 59 | + |
| 60 | + JSON_to_workspace "${ANALYSIS_NAME}" "${HEPDATA_URL}" "${BACKGROUND_ONLY}" "${SIGNAL_PATCH}" "${JSON_WORKSPACE}" |
| 61 | + |
| 62 | + # bash tests/test_suite.sh \ |
| 63 | + # "${ANALYSIS_NAME}/xml"/config/FitConfig_combined_NormalMeasurement_model.root \ |
| 64 | + # "${ANALYSIS_NAME}/workspaces/${JSON_WORKSPACE}" |
| 65 | +} |
| 66 | + |
| 67 | +main "$@" || exit 1 |
| 68 | + |
| 69 | +# main \ |
| 70 | +# sbottom \ |
| 71 | +# https://doi.org/10.17182/hepdata.89408.v1/r2 \ |
| 72 | +# RegionA/BkgOnly.json \ |
| 73 | +# RegionA/patch.sbottom_1300_205_60.json \ |
| 74 | +# RegionA/sbottom_1300_205_60.json |
0 commit comments