Skip to content

Instantly share code, notes, and snippets.

@matthewfeickert
Last active April 15, 2020 04:46
Show Gist options
  • Save matthewfeickert/f92f00755421b53494e07f1abff54dc3 to your computer and use it in GitHub Desktop.
Save matthewfeickert/f92f00755421b53494e07f1abff54dc3 to your computer and use it in GitHub Desktop.
Giordon CLs example
*.pdf
HistFactory/
validation.txt
.xml2json_output
roundtrip.json

CLs Example Debug

Source Files

spec.json taken form @kratsg's example Gist.

Run

bash run.sh

Debug Output

# pyhf cls spec.json

{
    "CLs_exp": [
        0.3779766122079999,
        0.5257773520036446,
        0.702130281843784,
        0.8695189282227754,
        0.9691693123561054
    ],
    "CLs_obs": 0.5932002295253658
}

# python run_cls.py HistFactory/config/FitConfig_combined_meas_model.root

# pyhf xml2json --basedir HistFactory --output-file roundtrip.json HistFactory/FitConfig.xml

# pyhf cls roundtrip.json

{
    "CLs_exp": [
        0.37796298099083625,
        0.5257645108789305,
        0.7021204342074518,
        0.8695137249328984,
        0.9691678471392434
    ],
    "CLs_obs": 0.5931943069940612
}

Looking visually at scan.pdf the observed CLs value at mu=1 seems to be below 0.6

default: run
all: clean run
run:
bash run.sh
clean:
rm -rf HistFactory
rm validation.txt scan.pdf roundtrip.json
#!/usr/bin/env bash
function generate {
if [[ ! -d HistFactory ]]; then
mkdir HistFactory
fi
cd HistFactory || return 1
pyhf json2xml ../spec.json
hist2workspace FitConfig.xml &> hist2workspace_log.txt
cd ..
}
function run_pyhf() {
# 1: The JSON spec
pyhf cls "$1"
}
function run_validation {
if [[ ! -f run_cls.py ]]; then
curl -sL https://raw.githubusercontent.com/scikit-hep/pyhf/master/validation/run_cls.py -o run_cls.py
fi
python run_cls.py HistFactory/config/FitConfig_combined_meas_model.root &> validation.txt
}
function xml_to_json {
pyhf xml2json --basedir HistFactory --output-file roundtrip.json HistFactory/FitConfig.xml &> .xml2json_output
}
function main() {
if [[ ! -d HistFactory ]]; then
generate
fi
printf "# pyhf cls spec.json\n\n"
run_pyhf spec.json
printf "\n# python run_cls.py HistFactory/config/FitConfig_combined_meas_model.root\n"
run_validation
printf "\n# pyhf xml2json --basedir HistFactory --output-file roundtrip.json HistFactory/FitConfig.xml\n"
xml_to_json
printf "\n# pyhf cls roundtrip.json\n\n"
run_pyhf roundtrip.json
}
main
{
"channels": [
{
"name": "channel1",
"samples": [
{
"data": [0.5781820670766233],
"modifiers": [
{"data": null, "name": "lumi", "type": "lumi"},
{"data": null, "name": "mu_Sig", "type": "normfactor"},
{"data": {"hi": 1.2150209298614274, "lo": 0.7849790701385726}, "name": "ucs_StopRHadron_1300_1000", "type": "normsys"}
],
"name": "StopRHadron_1300_1000"
},
{
"data": [1.88],
"modifiers": [
{"data": [0.2], "name": "staterror_channel1", "type": "staterror"}
],
"name": "Bkg"
}
]
}
],
"measurements": [
{
"config": {
"parameters": [{"auxdata": [1.0], "bounds": [[0.5, 1.5]], "inits": [1.0], "name": "lumi", "sigmas": [0.017]}],
"poi": "mu_Sig"
},
"name": "meas"
}
],
"observations": [{"data": [1], "name": "channel1"}],
"version": "1.0.0"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment