-
Notifications
You must be signed in to change notification settings - Fork 5
/
projections_scans.py
314 lines (255 loc) · 11.8 KB
/
projections_scans.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/usr/bin/env python
"""
Thomas Klijnsma
"""
#____________________________________________________________________
# Imports
import logging
import os, sys, re, copy
from OptionHandler import flag_as_option
import differentials
import differentialutils
import LatestBinning
import LatestPaths
lumiscale300 = 8.356546
lumiscale3000 = 83.56546
lumiscale6000 = 2. * lumiscale3000
#____________________________________________________________________
scenario1 = differentials.core.AttrDict()
scenario1.hgg = 'projections/workspaces_Jun28/ws_pth_smH_hgg.root'
scenario1.hzz = 'projections/workspaces_Jun28/ws_pth_smH_hzz.root'
scenario1.hbb = 'projections/workspaces_Jun28/ws_pth_smH_hbb.root'
scenario1.combWithHbb = 'projections/workspaces_Jun28/ws_pth_smH_combWithHbb.root'
scenario1.hbb_postfit_300ifb = 'out/postfits_Jul03/higgsCombine_POSTFIT_ASIMOV_ws_pth_smH_hbb.MultiDimFit.mH125.root'
scenario2 = differentials.core.AttrDict()
scenario2.hgg = 'projections/workspaces_Jul17/ws_pth_smH_hgg_s2.root'
scenario2.hzz = 'projections/workspaces_Jul17/ws_pth_smH_hzz_s2.root'
scenario2.hbb = 'projections/workspaces_Jul17/ws_pth_smH_hbb_s2.root'
scenario2.combWithHbb = 'projections/workspaces_Jul17/ws_pth_smH_combWithHbb_s2.root'
@flag_as_option
def projection_pth_smH_scan(args):
args = differentialutils.force_asimov(args)
decay_channel = differentialutils.get_decay_channel_tag(args)
wsdict = scenario2 if args.scenario2 else scenario1
ws = wsdict[decay_channel]
logging.warning('Running for 6000 fb-1 !!!!')
config = differential_config(args, ws, 'pth_smH', lumiscale=lumiscale6000)
config.nPoints = 70
def tight_ranges(config):
"""Very manual tight r_ ranges based on Hgg scan results"""
for POI in config.POIs:
if 'GT600' in POI:
config.set_parameter_range(POI, 0.64, 1.4)
else:
config.set_parameter_range(POI, 0.875, 1.14)
verbosity = 1
if args.hbb:
set_hbb_parameter_ranges(args, config)
# config.saveNuisances.extend([
# 'CMS_PU', 'CMS_res_j', 'CMS_scale_j', 'bbeff', 'eleveto', 'hqq125GenpT2failcat1mcstat', 'hqq125GenpT2passcat1mcstat', 'hqq125GenpT3failcat1mcstat', 'hqq125GenpT3failcat2mcstat', 'hqq125GenpT3passcat1mcstat', 'hqq125GenpT3passcat2mcstat', 'hqq125GenpT4failcat1mcstat', 'hqq125GenpT4failcat2mcstat', 'hqq125GenpT4passcat1mcstat', 'hqq125GenpT4passcat2mcstat', 'hqq125failmuonCRmcstat', 'hqq125pt', 'hqq125ptShape', 'lumi_13TeV_2016', 'muid', 'muiso', 'mutrigger', 'muveto', 'qcdfailmuonCRmcstat', 'qcdpassmuonCRmcstat', 'scale', 'scalept', 'smear', 'stqqfailmuonCRmcstat', 'stqqpassmuonCRmcstat', 'tqqfailcat1mcstat', 'tqqfailcat2mcstat', 'tqqfailmuonCRmcstat', 'tqqpasscat1mcstat', 'tqqpasscat2mcstat', 'tqqpassmuonCRmcstat', 'trigger', 'veff', 'vvqqfailmuonCRmcstat', 'wlnufailmuonCRmcstat', 'wlnupassmuonCRmcstat', 'wqqfailcat1mcstat', 'wqqfailcat2mcstat', 'wqqpasscat1mcstat', 'wqqpasscat2mcstat', 'wznormEW', 'xhqq125GenpT1failcat1mcstat', 'xhqq125GenpT1failcat2mcstat', 'xhqq125GenpT1passcat1mcstat', 'xhqq125GenpT1passcat2mcstat', 'xhqq125GenpT2failcat1mcstat', 'xhqq125GenpT2failcat2mcstat', 'xhqq125GenpT2passcat1mcstat', 'xhqq125GenpT2passcat2mcstat', 'xhqq125GenpT3failcat1mcstat', 'xhqq125GenpT3failcat2mcstat', 'xhqq125GenpT3passcat1mcstat', 'xhqq125GenpT3passcat2mcstat', 'xhqq125GenpT4failcat1mcstat', 'xhqq125GenpT4failcat2mcstat', 'xhqq125GenpT4passcat1mcstat', 'xhqq125GenpT4passcat2mcstat', 'xhqq125failmuonCRmcstat', 'xhqq125passmuonCRmcstat', 'zllfailmuonCRmcstat', 'znormEW', 'znormQ', 'zqqfailcat1mcstat', 'zqqfailcat2mcstat', 'zqqfailmuonCRmcstat', 'zqqpasscat1mcstat', 'zqqpasscat2mcstat', 'tqqfailcat1norm', 'tqqfailcat2norm', 'tqqfailmuonCRnorm', 'tqqpasscat1norm', 'tqqpasscat2norm', 'tqqpassmuonCRnorm', 'tqqnormSF', 'tqqeffSF', 'lumiscale'
# ])
# verbosity = 3
if args.hgg:
tight_ranges(config)
if args.combWithHbb:
set_hbb_parameter_ranges(args, config)
tight_ranges(config)
if args.hbb or args.hzz:
scan_directly(args, config, verbosity)
else:
postfit_and_scan(args, config)
@flag_as_option
def projection_pth_smH_scan_GT200(args):
args = differentialutils.force_asimov(args)
decay_channel = differentialutils.get_decay_channel_tag(args)
d = differentials.core.AttrDict()
d.s1 = differentials.core.AttrDict()
d.s2 = differentials.core.AttrDict()
d.s1.hgg = 'projections/workspaces_Oct24/ws_pth_smH_hgg_GT200_s1.root'
d.s2.hgg = 'projections/workspaces_Oct24/ws_pth_smH_hgg_GT200_s2.root'
ws = (d.s2 if args.scenario2 else d.s1)[decay_channel]
config = differential_config(args, ws, 'pth_smH', lumiscale=lumiscale3000)
def tight_ranges(config):
"""Very manual tight r_ ranges based on Hgg scan results"""
for POI in config.POIs:
if 'GT600' in POI:
config.set_parameter_range(POI, 0.64, 1.4)
else:
config.set_parameter_range(POI, 0.875, 1.14)
if args.hbb:
set_hbb_parameter_ranges(args, config)
if args.hgg:
tight_ranges(config)
if args.combWithHbb:
set_hbb_parameter_ranges(args, config)
tight_ranges(config)
# Overwrite to do only the scan for 1 POI
config.POIs = [ 'r_smH_PTH_GT200' ]
config.subDirectory += '_GT200only'
if args.hbb or args.hzz:
scan_directly(args, config, verbosity=1)
else:
postfit_and_scan(args, config)
@flag_as_option
def projection_pth_smH_scan_one_bin_locally(args):
decay_channel = 'combWithHbb'
args = differentialutils.set_one_decay_channel(args, decay_channel, asimov=True)
ws = workspaces[decay_channel]
config = differential_config(args, ws, 'pth_smH')
POI = 'r_smH_PTH_0_15'
left = 0.9
right = 1.1
n_points = 8
config.onBatch = False
config.POIs = [POI]
config.set_parameter_range(POI, left, right)
scan_directly(args, config, verbosity=1)
@flag_as_option
def projection_postfit_hbb_300ifb(args):
decay_channel = 'hbb'
args = differentialutils.set_one_decay_channel(args, decay_channel, asimov=True)
ws = scenario1[decay_channel]
config = differential_config(args, ws, 'pth_smH', lumiscale=lumiscale300)
only_postfit(args, config)
def get_ranges_from_hbb_postfit_300ifb(args):
w = differentials.core.get_ws(scenario1.hbb_postfit_300ifb)
w.loadSnapshot('MultiDimFit')
keys = [
'qcdeff',
'r0p1',
'r1p0',
'r1p1',
'r2p0',
'r2p1',
'r3p0',
'r3p1',
]
out = {}
for key in keys:
out[key] = w.var(key).getVal()
return out
def set_hbb_parameter_ranges(args, config):
bestfit = get_ranges_from_hbb_postfit_300ifb(args)
for key, value in bestfit.iteritems():
config.set_parameter(key, value)
config.set_parameter_range(key, 0.9*value, 1.1*value)
def differential_config(args, ws, obs_name, lumiscale=1.):
# base_config = combine.CombineConfig(args)
base_config = differentials.combine.combine.CombineConfig(args)
base_config.onBatch = True
base_config.queue = 'short.q'
base_config.asimov = True if args.asimov else False
base_config.decay_channel = differentialutils.get_decay_channel_tag(args)
if args.hbb or args.combWithHbb:
base_config.minimizer_settings = [
'--cminDefaultMinimizerType Minuit2',
'--cminDefaultMinimizerAlgo migrad',
'--minimizerStrategy 2',
'--minimizerTolerance 0.001',
'--robustFit 1',
'--minimizerAlgoForMinos Minuit2,Migrad',
]
base_config.datacard = ws
base_config.subDirectory = 'out/ScanProjection_{0}_{1}_{2}'.format(
differentials.core.datestr(),
obs_name,
base_config.decay_channel
)
# Scale lumi
base_config.freezeNuisances.append('lumiscale')
base_config.hardPhysicsModelParameters.append('lumiscale={0}'.format(lumiscale))
if args.hbb or args.combWithHbb:
# Freeze mcstat nuisances
logging.info('Freezing mcstat systematics')
base_config.extraOptions.append('--freezeNuisanceGroups mcstat')
if lumiscale == 1.:
base_config.subDirectory += '_36ifb'
elif lumiscale == lumiscale300:
base_config.subDirectory += '_300ifb'
elif lumiscale == lumiscale3000:
base_config.subDirectory += '_3000ifb'
elif lumiscale == lumiscale6000:
base_config.subDirectory += '_6000ifb'
if args.statonly:
base_config.subDirectory += '_statonly'
if args.scenario2:
base_config.subDirectory += '_scenario2'
POIs = differentials.core.list_POIs(ws)
if args.hbb: POIs.pop(0)
base_config.POIs = POIs
base_config.PhysicsModelParameters = [ '{0}=1.0'.format(p) for p in POIs ]
if args.hbb or args.combWithHbb:
logging.warning(
'For hbb: qcdeff and r*p* parameters are given ranges! '
'Should decide on (freezing) behaviour during postfit/scan'
)
base_config.PhysicsModelParameterRanges.extend([
'qcdeff=0.001,8.0',
'r1p0=0.1,8.0',
'r2p0=0.1,8.0',
'r3p0=0.1,8.0',
'r0p1=0.1,8.0',
'r1p1=0.1,8.0',
'r2p1=0.1,8.0',
'r3p1=0.1,8.0',
])
base_config.nPoints = 55
# base_config.nPoints = 20
base_config.nPointsPerJob = 5
if args.hzz or args.hbb:
base_config.nPoints = 90
base_config.nPointsPerJob = base_config.nPoints
if args.combWithHbb:
base_config.nPointsPerJob = 1
# Ranges
default_p3000 = differentials.core.AttrDict()
default_p3000.hzz = [ 0.7, 1.3 ]
default_p3000.hgg = [ 0.7, 1.3 ]
default_p3000.hbb = [ 0.3, 1.7 ]
default_p3000.combWithHbb = [ 0.5, 1.5 ]
default_ranges = default_p3000
for POI in POIs:
ranges = default_ranges[base_config.decay_channel][:]
if args.hzz and 'GT200' in POI:
ranges = [ 0.3, 1.7 ]
if (args.hgg) and ('GT600' in POI or '350_600' in POI):
ranges = [ 0.4, 1.6 ]
# if args.combWithHbb and ('GT600' in POI or '350_600' in POI):
# ranges = [ 0.6, 1.4 ]
base_config.set_parameter_range(POI, ranges[0], ranges[1])
return base_config
def differential_configs_for_scanning(args, original_base_config):
base_config = copy.deepcopy(original_base_config)
if args.statonly:
base_config.freezeNuisances.append('rgx{.*}')
# Overwrite get_name function to include the POI name
def new_get_name(self):
return 'bPOI_{0}_ePOI_{1}'.format(self.POIs[0], os.path.basename(self.datacard).replace('.root',''))
base_config.get_name = new_get_name.__get__(base_config, type(base_config))
configs_per_POI = []
for POI in base_config.POIs:
config = copy.deepcopy(base_config)
config.POIs = [POI]
config.set_verbosity(-1)
configs_per_POI.append(config)
return configs_per_POI
def postfit_and_scan(args, postfit_config):
# Make sure no previous run directory is overwritten
postfit_config.make_unique_directory()
postfit = differentials.combine.combine.CombinePostfit(postfit_config)
postfit.run()
postfit_ws = postfit.get_output()
scan_configs = differential_configs_for_scanning(args, postfit_config)
for config in scan_configs:
scan = differentials.combine.combine.CombineScanFromPostFit(config)
scan.run(postfit_ws)
def scan_directly(args, base_config, verbosity=1):
base_config.make_unique_directory()
scan_configs = differential_configs_for_scanning(args, base_config)
for config in scan_configs:
config.set_verbosity(verbosity)
scan = differentials.combine.combine.CombineScan(config)
scan.run()
def only_postfit(args, config):
postfit = differentials.combine.combine.CombineOnlyPostfit(config)
postfit.run()