Skip to content

Commit

Permalink
Add JSON to workspace converter script
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfeickert committed Mar 15, 2020
1 parent ef09622 commit 6617919
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions scripts/JSON_to_workspace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

set -e

function JSON_to_workspace() {
# 1: the analysis name
# 2: the url of the JSON workspaces
# 3: the background only workspace
# 4: the signal workspace patch
# 5: the patched background + signal workspace
local ANALYSIS_NAME=$1
local HEPDATA_URL=$2
local BACKGROUND_ONLY=$3
local SIGNAL_PATCH=$4
local JSON_WORKSPACE=$5

if [[ ! -d "${ANALYSIS_NAME}" ]]; then
mkdir "${ANALYSIS_NAME}"
fi

# Download from HEPData
curl -sL -o "${ANALYSIS_NAME}/workspaces.tar.gz" "${HEPDATA_URL}"
# Unpack tarball
if [[ ! -d "${ANALYSIS_NAME}/workspaces" ]]; then
mkdir "${ANALYSIS_NAME}/workspaces"
fi
tar xvzf "${ANALYSIS_NAME}/workspaces.tar.gz" -C "${ANALYSIS_NAME}/workspaces"

# Create a full signal+background workspace
jsonpatch \
"${ANALYSIS_NAME}/workspaces/${BACKGROUND_ONLY}" \
"${ANALYSIS_NAME}/workspaces/${SIGNAL_PATCH}" > \
"${ANALYSIS_NAME}/workspaces/${JSON_WORKSPACE}"

# Convert to ROOT + XML
if [[ ! -d "${ANALYSIS_NAME}/xml" ]]; then
mkdir "${ANALYSIS_NAME}/xml"
fi
rm -rf "${ANALYSIS_NAME}/xml"/*
pyhf json2xml \
--output-dir "${ANALYSIS_NAME}/xml" \
"${ANALYSIS_NAME}/workspaces/${JSON_WORKSPACE}"

# Generate ROOT workspace
hist2workspace "${ANALYSIS_NAME}/xml"/FitConfig.xml
}

function main() {
# 1: the analysis name
# 2: the url of the JSON workspaces
# 3: the background only workspace
# 4: the signal workspace patch
# 5: the patched background + signal workspace
local ANALYSIS_NAME=$1
local HEPDATA_URL=$2
local BACKGROUND_ONLY=$3
local SIGNAL_PATCH=$4
local JSON_WORKSPACE=$5

JSON_to_workspace "${ANALYSIS_NAME}" "${HEPDATA_URL}" "${BACKGROUND_ONLY}" "${SIGNAL_PATCH}" "${JSON_WORKSPACE}"

# bash tests/test_suite.sh \
# "${ANALYSIS_NAME}/xml"/config/FitConfig_combined_NormalMeasurement_model.root \
# "${ANALYSIS_NAME}/workspaces/${JSON_WORKSPACE}"
}

main "$@" || exit 1

# main \
# sbottom \
# https://doi.org/10.17182/hepdata.89408.v1/r2 \
# RegionA/BkgOnly.json \
# RegionA/patch.sbottom_1300_205_60.json \
# RegionA/sbottom_1300_205_60.json

0 comments on commit 6617919

Please sign in to comment.