forked from zctao/omnifoldTop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_unfold.py
More file actions
executable file
·75 lines (61 loc) · 2.25 KB
/
run_unfold.py
File metadata and controls
executable file
·75 lines (61 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
import os
import sys
import itertools
import util
from unfoldv2 import getArgsParser, unfold
# Usage
if len(sys.argv) != 2:
print("Usage: ./run_unfold.py <run_config.json>")
sys.exit(1)
fpath_run_config = sys.argv[1]
if not os.path.isfile(fpath_run_config):
print(f"ERROR: cannot find run config: {fpath_run_config}")
sys.exit(2)
run_cfgs = util.read_dict_from_json(fpath_run_config)
if not run_cfgs:
print(f"ERROR: failed to load run config from {fpath_run_config}")
sys.exit(3)
# run_cfgs could be a dictionary or a list of dictionaries
if not isinstance(run_cfgs, list):
run_cfgs = [run_cfgs]
# loop over the list of dict objects
for run_cfg_d in run_cfgs:
# If there is a entry: "skip": true, skip this one
if run_cfg_d.pop("skip", None):
continue
# get the default argument dictionary from getArgsParser
# -d and -s are the only two required arguments without defaults
data_samples = run_cfg_d["data"]
signal_samples = run_cfg_d["signal"]
default_args = getArgsParser(['-d']+data_samples+['-s']+signal_samples)
default_args = vars(default_args)
# Loop over run_cfg_d and replace the default argument values
scan_args = list()
for k, v in run_cfg_d.items():
if isinstance(v, dict):
# We are going to run unfolding with different values of this
# argument handle it later
scan_args.append(k)
elif k in default_args:
default_args[k] = v
else:
print(f"ERROR: {k} is not a known argument")
sys.exit(3)
# for arguments with labels and multiple values
labels = []
for k in scan_args:
assert(isinstance(run_cfg_d[k], dict))
labels.append( list(run_cfg_d[k].keys()) )
combinations = list(itertools.product(*labels))
# for each argument combination
for comb in combinations:
run_args = default_args.copy()
assert( len(comb) == len(scan_args) )
for k, l in zip(scan_args, comb):
run_args[k] = run_cfg_d[k][l]
# update output directory based on the labels
run_args['outputdir'] = os.path.join(run_args['outputdir'], *comb)
print("Run unfolding")
#print(run_args)
unfold(**run_args)