-
Notifications
You must be signed in to change notification settings - Fork 7
/
makecut.py
597 lines (541 loc) · 37.8 KB
/
makecut.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
import awkward as ak
from coffea import processor
#from coffea.nanoevents.methods import candidate
import hist
import uproot
#from coffea.nanoevents import NanoEventsFactory, BaseSchema
from coffea.nanoevents import BaseSchema
import boost_histogram as bh
import sys
sys.path.append("/cms/user/guojl/ME_test/CMSSW_10_6_26/src/HZZAnalysis/lib")
from setting import setting
##
class CutCoffeaProcessor(processor.ProcessorABC):
def __init__(self,):
pass
##
class CutAllCatCoffeaProcessor(processor.ProcessorABC):
r"""the coffea processor for make cut step"""
def __init__(self,config = None,year = None,fileset = None, option = None):
self.config = config
self.year = year
self.fileset = fileset
self.sumWeight = 0.0
self.nevents = 0.0
self.leptonic_cut_cats=['isEE','isMuMu','2lep']
self.regions = ['CR','SR','ALL','VR','SB','LSB','HSB']
self.AlphaRegion = ['VR','SB']
self.tags = ['btag','untag','vbftag','all']
self.massZZ_bins = setting().massZZ_bins
self.option = option # if option.lower() == 'masszz' then only cut on massZZ
#self.isData = isData
def getbininfo(self,varb):
'''
input: any varb exsited in config
output: bins informations associated with bins start stop name
'''
bins = self.config['bininfo'][varb][0]
start = self.config['bininfo'][varb][1]
stop = self.config['bininfo'][varb][2]
name = self.config['bininfo'][varb][3]
return bins, start, stop, name
def process(self, events):
####define paramters
dataset = events.metadata['dataset']
is_data =( dataset == 'Data')
if(not is_data):
#get sumWeight from rootfile
f = uproot.open(self.fileset[dataset][0])['sumWeights']
self.sumWeight = (f.to_boost()).sum()
f.close()
#get the number of events from rootfile
f = uproot.open(self.fileset[dataset][0])['nEvents']
self.nevents = (f.to_boost()).sum()
f.close()
lumi = self.config['lumi'][self.year]
xsec = self.config['samples_inf'][dataset][1]
h_out = {}
####Gen variable setup
varb = 'GEN_H1_mass'
bins, start, stop, name = self.getbininfo(varb)
h_out[varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out[varb].fill(events[varb])
#creat a histogram to store the number of events into the first bin
h_out['nevents'] = hist.Hist(hist.axis.Regular(1, 0, 1, name = 'nevents'))
h_out['nevents'].fill(0.5,weight=self.nevents)
####Leptonic cut apply and fill histo for each variable
if self.option == None: #if option is None, then apply all cuts for leptonic
h_out['lep'] = {}
for cat in self.leptonic_cut_cats:
selection = self.config['cut']['lep'][cat]
cut = ak.numexpr.evaluate(selection,events)
cut_event = events[cut]
h_out['lep'][cat] = {}
for varb in self.config['bininfo_lep'].keys():
if varb == 'mass2l2jet_allrange' or varb == 'mass2lj_allrange': continue
bins, start, stop, name = self.getbininfo(varb)
h_out['lep'][cat][varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out['lep'][cat][varb].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
####Resolved cut apply and fill histo for each variable
h_out['resolved']={}
for reg in self.regions:
h_out['resolved'][reg] = {}
for cat in self.leptonic_cut_cats:
h_out['resolved'][reg][cat] = {}
for tag in self.tags:
selection = self.config['cut']['resolved'][reg][cat][tag]
#print(selection)
cut = ak.numexpr.evaluate(selection,events)
cut_event = events[cut]
h_out['resolved'][reg][cat][tag] = {}
for varb in self.config['bininfo_resolved'].keys():
bins = self.config['bininfo_resolved'][varb][0]
start = self.config['bininfo_resolved'][varb][1]
stop = self.config['bininfo_resolved'][varb][2]
name = self.config['bininfo_resolved'][varb][3]
#if varb == 'mass2l2jet_allrange' or varb == 'mass2lj_allrange': continue
if varb=='mass2l2jet': #store massZZ related variables
h_out['resolved'][reg][cat][tag][f'{varb}_rebin'] = hist.Hist(self.massZZ_bins['resolved'])
h_out['resolved'][reg][cat][tag][f'{varb}_rebin'].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
#bin for signal fit template
h_out['resolved'][reg][cat][tag][f'{varb}_fit'] = hist.Hist(hist.axis.Regular(4000, 0, 4000, name = f'{varb}_fit'))
h_out['resolved'][reg][cat][tag][f'{varb}_fit'].fill(
cut_event[varb],
weight=ak.ones_like(cut_event.EventWeight)
)
#bin for all mass range template
h_out['resolved'][reg][cat][tag][f'{varb}_allrange'] = hist.Hist(hist.axis.Regular(80, 0, 4000, name = f'{varb}_allrange'))
h_out['resolved'][reg][cat][tag][f'{varb}_allrange'].fill(
cut_event[varb],
weight=ak.ones_like(cut_event.EventWeight),
)
#eventweight set to one for alpha ratio process
h_out['resolved'][reg][cat][tag][f'{varb}_rebin_raw'] = hist.Hist(self.massZZ_bins['resolved'])
h_out['resolved'][reg][cat][tag][f'{varb}_rebin_raw'].fill(
cut_event[varb],
weight=ak.ones_like(cut_event.EventWeight),
)
#2D template
h_out['resolved'][reg][cat][tag][f'{varb}_rebin_2d'] = hist.Hist(self.massZZ_bins['resolved'],hist.axis.Regular(50, 0, 1))
h_out['resolved'][reg][cat][tag][f'{varb}_rebin_2d'].fill(
cut_event[varb],
cut_event['KD_Zjj'],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
elif self.option == None: #store all variables only if option is None
h_out['resolved'][reg][cat][tag][varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out['resolved'][reg][cat][tag][varb].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
if self.option == None: #store split variables only if option is None
for varb in self.config['bininfo_resolved_split'].keys():
bins = self.config['bininfo_resolved_split'][varb][0]
start = self.config['bininfo_resolved_split'][varb][1]
stop = self.config['bininfo_resolved_split'][varb][2]
name = self.config['bininfo_resolved_split'][varb][3]
h_out['resolved'][reg][cat][tag][varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out['resolved'][reg][cat][tag][varb].fill(
cut_event[varb],
weight=ak.ones_like(cut_event.EventWeight),
)
####Resolved up cut apply and fill histo for each variable
h_out['resolved_up']={}
for reg in self.regions:
h_out['resolved_up'][reg] = {}
for cat in self.leptonic_cut_cats:
h_out['resolved_up'][reg][cat] = {}
for tag in self.tags:
selection = self.config['cut']['resolved_up'][reg][cat][tag]
cut = ak.numexpr.evaluate(selection,events)
cut_event = events[cut]
h_out['resolved_up'][reg][cat][tag] = {}
for varb in self.config['bininfo_resolvedup'].keys():
bins = self.config['bininfo_resolvedup'][varb][0]
start = self.config['bininfo_resolvedup'][varb][1]
stop = self.config['bininfo_resolvedup'][varb][2]
name = self.config['bininfo_resolvedup'][varb][3]
if varb=='mass2l2jet_up':
h_out['resolved_up'][reg][cat][tag][f'{varb}_rebin'] = hist.Hist(self.massZZ_bins['resolved'])
h_out['resolved_up'][reg][cat][tag][f'{varb}_rebin'].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
#eventweight set to one for alpha ratio process
h_out['resolved_up'][reg][cat][tag][f'{varb}_rebin_raw'] = hist.Hist(self.massZZ_bins['resolved'])
h_out['resolved_up'][reg][cat][tag][f'{varb}_rebin_raw'].fill(
cut_event[varb],
weight=ak.ones_like(cut_event.EventWeight),
)
#2D template
h_out['resolved_up'][reg][cat][tag][f'{varb}_rebin_2d'] = hist.Hist(self.massZZ_bins['resolved'],hist.axis.Regular(50, 0, 1))
h_out['resolved_up'][reg][cat][tag][f'{varb}_rebin_2d'].fill(
cut_event[varb],
cut_event['KD_Zjj_up'],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
elif self.option == None: #store all variables only if option is None
h_out['resolved_up'][reg][cat][tag][varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out['resolved_up'][reg][cat][tag][varb].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
####Resolved donw cut apply and fill histo for each variable
h_out['resolved_dn']={}
for reg in self.regions:
h_out['resolved_dn'][reg] = {}
for cat in self.leptonic_cut_cats:
h_out['resolved_dn'][reg][cat] = {}
for tag in self.tags:
selection = self.config['cut']['resolved_dn'][reg][cat][tag]
cut = ak.numexpr.evaluate(selection,events)
cut_event = events[cut]
h_out['resolved_dn'][reg][cat][tag] = {}
for varb in self.config['bininfo_resolveddn'].keys():
bins = self.config['bininfo_resolveddn'][varb][0]
start = self.config['bininfo_resolveddn'][varb][1]
stop = self.config['bininfo_resolveddn'][varb][2]
name = self.config['bininfo_resolveddn'][varb][3]
if varb=='mass2l2jet_dn':
h_out['resolved_dn'][reg][cat][tag][f'{varb}_rebin'] = hist.Hist(self.massZZ_bins['resolved'])
h_out['resolved_dn'][reg][cat][tag][f'{varb}_rebin'].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
#eventweight set to one for alpha ratio process
h_out['resolved_dn'][reg][cat][tag][f'{varb}_rebin_raw'] = hist.Hist(self.massZZ_bins['resolved'])
h_out['resolved_dn'][reg][cat][tag][f'{varb}_rebin_raw'].fill(
cut_event[varb],
weight=ak.ones_like(cut_event.EventWeight),
)
#2D template
h_out['resolved_dn'][reg][cat][tag][f'{varb}_rebin_2d'] = hist.Hist(self.massZZ_bins['resolved'],hist.axis.Regular(50, 0, 1))
h_out['resolved_dn'][reg][cat][tag][f'{varb}_rebin_2d'].fill(
cut_event[varb],
cut_event['KD_Zjj_dn'],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
elif self.option == None: #store all variables only if option is None
h_out['resolved_dn'][reg][cat][tag][varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out['resolved_dn'][reg][cat][tag][varb].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
####Merged cut apply and fill histo for each variable
#frist is no net cut merged cut
if self.option == None: #store all variables only if option is None
h_out['merged_notag']={}
for cat in self.leptonic_cut_cats:
selection = self.config['cut']['merged']['notag'][cat]
cut = ak.numexpr.evaluate(selection,events)
cut_event = events[cut]
h_out['merged_notag'][cat] = {}
for varb in self.config['bininfo_merged'].keys():
if varb == 'mass2l2jet_allrange' or varb == 'mass2lj_allrange': continue
bins = self.config['bininfo_merged'][varb][0]
start = self.config['bininfo_merged'][varb][1]
stop = self.config['bininfo_merged'][varb][2]
name = self.config['bininfo_merged'][varb][3]
h_out['merged_notag'][cat][varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out['merged_notag'][cat][varb].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
#second is merged with net cut
h_out['merged_tag']={}
for reg in self.regions:
h_out['merged_tag'][reg]={}
for cat in self.leptonic_cut_cats:
h_out['merged_tag'][reg][cat]={}
for tag in self.tags:
selection = self.config['cut']['merged']['net'][reg][cat][tag]
cut = ak.numexpr.evaluate(selection,events)
cut_event = events[cut]
h_out['merged_tag'][reg][cat][tag]={}
for varb in self.config['bininfo_merged'].keys():
if varb == 'mass2l2jet_allrange' or varb == 'mass2lj_allrange': continue
bins = self.config['bininfo_merged'][varb][0]
start = self.config['bininfo_merged'][varb][1]
stop = self.config['bininfo_merged'][varb][2]
name = self.config['bininfo_merged'][varb][3]
if varb=='mass2lj':
h_out['merged_tag'][reg][cat][tag][f'{varb}_rebin'] = hist.Hist(self.massZZ_bins['merged'])
h_out['merged_tag'][reg][cat][tag][f'{varb}_rebin'].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
h_out['merged_tag'][reg][cat][tag][f'{varb}_fit'] = hist.Hist(hist.axis.Regular(4000, 0, 4000, name = f'{varb}_fit'))
h_out['merged_tag'][reg][cat][tag][f'{varb}_fit'].fill(
cut_event[varb],
weight=ak.ones_like(cut_event.EventWeight),
)
h_out['merged_tag'][reg][cat][tag][f'{varb}_allrange'] = hist.Hist(hist.axis.Regular(80, 0, 4000, name = f'{varb}_allrange'))
h_out['merged_tag'][reg][cat][tag][f'{varb}_allrange'].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
#eventweight set to one for alpha ratio process
h_out['merged_tag'][reg][cat][tag][f'{varb}_rebin_raw'] = hist.Hist(self.massZZ_bins['merged'])
h_out['merged_tag'][reg][cat][tag][f'{varb}_rebin_raw'].fill(
cut_event[varb],
weight=ak.ones_like(cut_event.EventWeight),
)
#2D template
h_out['merged_tag'][reg][cat][tag][f'{varb}_rebin_2d'] = hist.Hist(self.massZZ_bins['merged'],hist.axis.Regular(50, 0, 1))
h_out['merged_tag'][reg][cat][tag][f'{varb}_rebin_2d'].fill(
cut_event[varb],
cut_event['KD_ZJ'],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
elif self.option == None: #store all variables only if option is None
h_out['merged_tag'][reg][cat][tag][varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out['merged_tag'][reg][cat][tag][varb].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if ((not is_data) and (varb!='GEN_H1_mass')) else \
ak.ones_like(cut_event.EventWeight),
)
if self.option == None: #store only split variables if option is None
for varb in self.config['bininfo_merged_split'].keys():
bins = self.config['bininfo_merged_split'][varb][0]
start = self.config['bininfo_merged_split'][varb][1]
stop = self.config['bininfo_merged_split'][varb][2]
name = self.config['bininfo_merged_split'][varb][3]
h_out['merged_tag'][reg][cat][tag][varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out['merged_tag'][reg][cat][tag][varb].fill(
cut_event[varb] if varb != 'ptmerged_raw' else cut_event['ptmerged'],
weight=ak.ones_like(cut_event.EventWeight),
)
#merged up with net cut
h_out['merged_tag_up']={}
for reg in self.regions:
h_out['merged_tag_up'][reg]={}
for cat in self.leptonic_cut_cats:
h_out['merged_tag_up'][reg][cat]={}
for tag in self.tags:
selection = self.config['cut']['merged']['net_up'][reg][cat][tag]
cut = ak.numexpr.evaluate(selection,events)
cut_event = events[cut]
h_out['merged_tag_up'][reg][cat][tag]={}
for varb in self.config['bininfo_mergedup'].keys():
bins = self.config['bininfo_mergedup'][varb][0]
start = self.config['bininfo_mergedup'][varb][1]
stop = self.config['bininfo_mergedup'][varb][2]
name = self.config['bininfo_mergedup'][varb][3]
if varb=='mass2lj_up':
h_out['merged_tag_up'][reg][cat][tag][f'{varb}_rebin'] = hist.Hist(self.massZZ_bins['merged'])
h_out['merged_tag_up'][reg][cat][tag][f'{varb}_rebin'].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
#eventweight set to one for alpha ratio process
h_out['merged_tag_up'][reg][cat][tag][f'{varb}_rebin_raw'] = hist.Hist(self.massZZ_bins['merged'])
h_out['merged_tag_up'][reg][cat][tag][f'{varb}_rebin_raw'].fill(
cut_event[varb],
weight=ak.ones_like(cut_event.EventWeight),
)
#2D template
h_out['merged_tag_up'][reg][cat][tag][f'{varb}_rebin_2d'] = hist.Hist(self.massZZ_bins['merged'],hist.axis.Regular(50, 0, 1))
h_out['merged_tag_up'][reg][cat][tag][f'{varb}_rebin_2d'].fill(
cut_event[varb],
cut_event['KD_ZJ_up'],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
elif self.option == None: #store all variables only if option is None
h_out['merged_tag_up'][reg][cat][tag][varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out['merged_tag_up'][reg][cat][tag][varb].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
#merged dn with net cut
h_out['merged_tag_dn']={}
for reg in self.regions:
h_out['merged_tag_dn'][reg]={}
for cat in self.leptonic_cut_cats:
h_out['merged_tag_dn'][reg][cat]={}
for tag in self.tags:
selection = self.config['cut']['merged']['net_dn'][reg][cat][tag]
cut = ak.numexpr.evaluate(selection,events)
cut_event = events[cut]
h_out['merged_tag_dn'][reg][cat][tag]={}
for varb in self.config['bininfo_mergeddn'].keys():
bins = self.config['bininfo_mergeddn'][varb][0]
start = self.config['bininfo_mergeddn'][varb][1]
stop = self.config['bininfo_mergeddn'][varb][2]
name = self.config['bininfo_mergeddn'][varb][3]
if varb=='mass2lj_dn':
h_out['merged_tag_dn'][reg][cat][tag][f'{varb}_rebin'] = hist.Hist(self.massZZ_bins['merged'])
h_out['merged_tag_dn'][reg][cat][tag][f'{varb}_rebin'].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
#eventweight set to one for alpha ratio process
h_out['merged_tag_dn'][reg][cat][tag][f'{varb}_rebin_raw'] = hist.Hist(self.massZZ_bins['merged'])
h_out['merged_tag_dn'][reg][cat][tag][f'{varb}_rebin_raw'].fill(
cut_event[varb],
weight=ak.ones_like(cut_event.EventWeight),
)
#2D template
h_out['merged_tag_dn'][reg][cat][tag][f'{varb}_rebin_2d'] = hist.Hist(self.massZZ_bins['merged'],hist.axis.Regular(50, 0, 1))
h_out['merged_tag_dn'][reg][cat][tag][f'{varb}_rebin_2d'].fill(
cut_event[varb],
cut_event['KD_ZJ_dn'],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
elif self.option == None: #store all variables only if option is None
h_out['merged_tag_dn'][reg][cat][tag][varb] = hist.Hist(hist.axis.Regular(bins=bins, start=start, stop=stop, name=name))
h_out['merged_tag_dn'][reg][cat][tag][varb].fill(
cut_event[varb],
weight=ak.numexpr.evaluate(f'EventWeight*{lumi}*1000*{xsec}/{self.sumWeight}',cut_event) if not is_data else \
ak.ones_like(cut_event.EventWeight),
)
return {
dataset: {
"entries": len(events),
"h_out": h_out,
}
}
def postprocess(self, accumulator):
pass
class CutUnit():
def __init__(self,year,varb = None) -> None:
self.processor = CutAllCatCoffeaProcessor
self.year = year
self.fileset = setting().fileset[self.year]
self.outstr = f"{self.year}_signal"
#self.outstr = f"{self.year}"
#print(self.fileset)
#self.option = 'masszz'
self.option = None
self.futures_run = processor.Runner(
executor = processor.FuturesExecutor(compression=None, workers=8),
schema=BaseSchema,
)
def run(self):
config = setting().config
out = self.futures_run(self.fileset,'passedEvents',processor_instance=self.processor(config,self.year,self.fileset,self.option))
leptonic_cut_cats=['isEE','isMuMu','2lep']
regions = ['CR','SR','ALL','LSB','HSB'] + ['VR','SB']
AlphaRegions = ['VR','SB']
tags = ['btag','untag','vbftag','all']
out_h_dir_name = 'h_out'
out_file_name = f"hist_{self.outstr}.root" if self.option == None else f"hist_{self.outstr}_{self.option}.root"
with uproot.recreate(out_file_name) as fw:
for sample in self.fileset.keys():
##Gen Variable
fw[f'{sample}/GEN_H1_mass'] = out[sample][out_h_dir_name]['GEN_H1_mass']
#number of events
fw[f'{sample}/nevents'] = out[sample][out_h_dir_name]['nevents']
##store Lep cut
if self.option == None:
for cat in leptonic_cut_cats:
for varb in config['bininfo'].keys():
if varb == 'mass2l2jet_allrange' or varb == 'mass2lj_allrange' or varb.find('_rebin')!=-1: continue
fw[f'{sample}/lep/{cat}/{varb}'] = out[sample][out_h_dir_name]['lep'][cat][varb]
##store resolved cut
for reg in regions:
for cat in leptonic_cut_cats:
for tag in tags:
for varb in config['bininfo_resolved'].keys():
if varb == 'mass2l2jet':
fw[f'{sample}/resolved/{reg}/{cat}/{tag}/{varb}_rebin'] = out[sample][out_h_dir_name]['resolved'][reg][cat][tag][f'{varb}_rebin']
fw[f'{sample}/resolved/{reg}/{cat}/{tag}/{varb}_rebin_2d'] = out[sample][out_h_dir_name]['resolved'][reg][cat][tag][f'{varb}_rebin_2d']
fw[f'{sample}/resolved/{reg}/{cat}/{tag}/{varb}_rebin_raw'] = out[sample][out_h_dir_name]['resolved'][reg][cat][tag][f'{varb}_rebin_raw']
fw[f'{sample}/resolved/{reg}/{cat}/{tag}/{varb}_fit'] = out[sample][out_h_dir_name]['resolved'][reg][cat][tag][f'{varb}_fit']
fw[f'{sample}/resolved/{reg}/{cat}/{tag}/{varb}_allrange'] = out[sample][out_h_dir_name]['resolved'][reg][cat][tag][f'{varb}_allrange']
elif self.option == None: #store all variables only if option is None
fw[f'{sample}/resolved/{reg}/{cat}/{tag}/{varb}'] = out[sample][out_h_dir_name]['resolved'][reg][cat][tag][varb]
if self.option == None: #store all variables only if option is None
for varb in config['bininfo_resolved_split'].keys():
fw[f'{sample}/resolved/{reg}/{cat}/{tag}/{varb}'] = out[sample][out_h_dir_name]['resolved'][reg][cat][tag][varb]
##store resolved_up cut
for reg in regions:
for cat in leptonic_cut_cats:
for tag in tags:
for varb in config['bininfo_resolvedup'].keys():
if varb == 'mass2l2jet_up':
fw[f'{sample}/resolved_up/{reg}/{cat}/{tag}/{varb}_rebin'] = out[sample][out_h_dir_name]['resolved_up'][reg][cat][tag][f'{varb}_rebin']
fw[f'{sample}/resolved_up/{reg}/{cat}/{tag}/{varb}_rebin_2d'] = out[sample][out_h_dir_name]['resolved_up'][reg][cat][tag][f'{varb}_rebin_2d']
fw[f'{sample}/resolved_up/{reg}/{cat}/{tag}/{varb}_rebin_raw'] = out[sample][out_h_dir_name]['resolved_up'][reg][cat][tag][f'{varb}_rebin_raw']
elif self.option == None: #store all variables only if option is None
fw[f'{sample}/resolved_up/{reg}/{cat}/{tag}/{varb}'] = out[sample][out_h_dir_name]['resolved_up'][reg][cat][tag][varb]
##store resolved_dn cut
for reg in regions:
for cat in leptonic_cut_cats:
for tag in tags:
for varb in config['bininfo_resolveddn'].keys():
if varb == 'mass2l2jet_dn':
fw[f'{sample}/resolved_dn/{reg}/{cat}/{tag}/{varb}_rebin'] = out[sample][out_h_dir_name]['resolved_dn'][reg][cat][tag][f'{varb}_rebin']
fw[f'{sample}/resolved_dn/{reg}/{cat}/{tag}/{varb}_rebin_2d'] = out[sample][out_h_dir_name]['resolved_dn'][reg][cat][tag][f'{varb}_rebin_2d']
fw[f'{sample}/resolved_dn/{reg}/{cat}/{tag}/{varb}_rebin_raw'] = out[sample][out_h_dir_name]['resolved_dn'][reg][cat][tag][f'{varb}_rebin_raw']
elif self.option == None: #store all variables only if option is None
fw[f'{sample}/resolved_dn/{reg}/{cat}/{tag}/{varb}'] = out[sample][out_h_dir_name]['resolved_dn'][reg][cat][tag][varb]
##store merged not net cut
if self.option == None:
for cat in leptonic_cut_cats:
for varb in config['bininfo_merged'].keys():
if varb == 'mass2l2jet_allrange' or varb == 'mass2lj_allrange': continue
fw[f'{sample}/merged_notag/{cat}/{varb}'] = out[sample][out_h_dir_name]['merged_notag'][cat][varb]
##store merged tag cut
for reg in regions:
for cat in leptonic_cut_cats:
for tag in tags:
for varb in config['bininfo_merged'].keys():
if varb == 'mass2l2jet_allrange' or varb == 'mass2lj_allrange': continue
if varb == 'mass2lj':
fw[f'{sample}/merged_tag/{reg}/{cat}/{tag}/{varb}_rebin'] = out[sample][out_h_dir_name]['merged_tag'][reg][cat][tag][f'{varb}_rebin']
fw[f'{sample}/merged_tag/{reg}/{cat}/{tag}/{varb}_rebin_2d'] = out[sample][out_h_dir_name]['merged_tag'][reg][cat][tag][f'{varb}_rebin_2d']
fw[f'{sample}/merged_tag/{reg}/{cat}/{tag}/{varb}_rebin_raw'] = out[sample][out_h_dir_name]['merged_tag'][reg][cat][tag][f'{varb}_rebin_raw']
fw[f'{sample}/merged_tag/{reg}/{cat}/{tag}/{varb}_fit'] = out[sample][out_h_dir_name]['merged_tag'][reg][cat][tag][f'{varb}_fit']
fw[f'{sample}/merged_tag/{reg}/{cat}/{tag}/{varb}_allrange'] = out[sample][out_h_dir_name]['merged_tag'][reg][cat][tag][f'{varb}_allrange']
elif self.option == None: #store all variables only if option is None
fw[f'{sample}/merged_tag/{reg}/{cat}/{tag}/{varb}'] = out[sample][out_h_dir_name]['merged_tag'][reg][cat][tag][varb]
if self.option == None: #store all variables only if option is None
for varb in config['bininfo_merged_split'].keys():
fw[f'{sample}/merged_tag/{reg}/{cat}/{tag}/{varb}'] = out[sample][out_h_dir_name]['merged_tag'][reg][cat][tag][varb]
##store merged up tag cut
for reg in regions:
for cat in leptonic_cut_cats:
for tag in tags:
for varb in config['bininfo_mergedup'].keys():
if varb == 'mass2lj_up':
fw[f'{sample}/merged_tag_up/{reg}/{cat}/{tag}/{varb}_rebin'] = out[sample][out_h_dir_name]['merged_tag_up'][reg][cat][tag][f'{varb}_rebin']
fw[f'{sample}/merged_tag_up/{reg}/{cat}/{tag}/{varb}_rebin_2d'] = out[sample][out_h_dir_name]['merged_tag_up'][reg][cat][tag][f'{varb}_rebin_2d']
fw[f'{sample}/merged_tag_up/{reg}/{cat}/{tag}/{varb}_rebin_raw'] = out[sample][out_h_dir_name]['merged_tag_up'][reg][cat][tag][f'{varb}_rebin_raw']
elif self.option == None: #store all variables only if option is None
fw[f'{sample}/merged_tag_up/{reg}/{cat}/{tag}/{varb}'] = out[sample][out_h_dir_name]['merged_tag_up'][reg][cat][tag][varb]
##store merged dn tag cut
for reg in regions:
for cat in leptonic_cut_cats:
for tag in tags:
for varb in config['bininfo_mergeddn'].keys():
if varb == 'mass2lj_dn':
fw[f'{sample}/merged_tag_dn/{reg}/{cat}/{tag}/{varb}_rebin'] = out[sample][out_h_dir_name]['merged_tag_dn'][reg][cat][tag][f'{varb}_rebin']
fw[f'{sample}/merged_tag_dn/{reg}/{cat}/{tag}/{varb}_rebin_2d'] = out[sample][out_h_dir_name]['merged_tag_dn'][reg][cat][tag][f'{varb}_rebin_2d']
fw[f'{sample}/merged_tag_dn/{reg}/{cat}/{tag}/{varb}_rebin_raw'] = out[sample][out_h_dir_name]['merged_tag_dn'][reg][cat][tag][f'{varb}_rebin_raw']
elif self.option == None: #store all variables only if option is None
fw[f'{sample}/merged_tag_dn/{reg}/{cat}/{tag}/{varb}'] = out[sample][out_h_dir_name]['merged_tag_dn'][reg][cat][tag][varb]