forked from sagittaeri/htt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultisig
More file actions
executable file
·76 lines (66 loc) · 2.79 KB
/
multisig
File metadata and controls
executable file
·76 lines (66 loc) · 2.79 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
76
#!/usr/bin/env python
from multiprocessing import Process
from rootpy.io import root_open
from statstools.jobs import run_pool
from statstools import get_significance_workspace
import pickle
import os
class SigProcess(Process):
def __init__(self, file, name, blind=True, profile='1', overwrite=False):
super(SigProcess, self).__init__()
self.file = file
self.name = name
self.blind = blind
self.profile = profile
self.overwrite = overwrite
def run(self):
if self.blind:
pickle_name = os.path.splitext(self.file)[0] + '.pickle'
else:
pickle_name = os.path.splitext(self.file)[0] + '_profiled_mu{0}_unblind.pickle'.format(self.profile)
if os.path.exists(pickle_name) and not self.overwrite:
# abort
return
# get the significance of the workspace
with root_open(self.file) as file:
ws = file[self.name]
if self.profile=='hat':
ws.fit()
poi = ws.obj('ModelConfig').GetParametersOfInterest().first()
mu_profile_value = poi.getVal()
else:
mu_profile_value = float(self.profile)
hist = get_significance_workspace(ws,
verbose=True,
blind=self.blind,
mu_profile_value=mu_profile_value)
sig = hist[2].value
# write the value into a pickle
with open(pickle_name, 'w') as pickle_file:
pickle.dump({self.name: sig}, pickle_file)
if __name__ == '__main__':
from rootpy.extern.argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('--jobs', type=int, default=-1)
parser.add_argument('--name', default='combined')
parser.add_argument('--overwrite', action='store_true', default=False)
parser.add_argument('--unblind', action='store_false', dest='blind', default=True)
parser.add_argument('--profile', choices=['0', '1', 'hat'], default='1')
parser.add_argument('files', nargs='+')
args = parser.parse_args()
# find all root files
root_files = []
for file in args.files:
if os.path.isdir(file):
# walk below this path
for dirpath, dirnames, filenames in os.walk(file):
for filename in filenames:
if filename.endswith('.root'):
root_files.append(os.path.join(dirpath, filename))
else:
root_files.append(file)
# define the workers
workers = [SigProcess(file, args.name, blind=args.blind, profile=args.profile, overwrite=args.overwrite)
for file in root_files]
# run the pool
run_pool(workers, n_jobs=args.jobs)