-
Notifications
You must be signed in to change notification settings - Fork 1
/
analysis_sample_combiner.py
454 lines (365 loc) · 17 KB
/
analysis_sample_combiner.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
# -*- coding: utf-8 -*-
"""
analysis_sample_combiner.py
Combines analyzed samples from the output of the analysis scripts.
Ricardo Barrué (LIP/IST/CERN-ATLAS), 3/8/2023
"""
from __future__ import absolute_import, division, print_function, unicode_literals
from email.policy import default
import logging
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
import os, shutil, sys
import argparse as ap
from madminer.core import MadMiner
from madminer.lhe import LHEReader
from madminer.sampling import combine_and_shuffle
# MadMiner output
logging.basicConfig(
format='%(asctime)-5.5s %(name)-20.20s %(levelname)-7.7s %(message)s',
datefmt='%H:%M',
level=logging.INFO
)
# Output of all other modules (e.g. matplotlib)
for key in logging.Logger.manager.loggerDict:
if "madminer" not in key:
logging.getLogger(key).setLevel(logging.WARNING)
if __name__ == "__main__":
parser = ap.ArgumentParser(description='Combines and shuffles different samples, depending on the purposes.',formatter_class=ap.ArgumentDefaultsHelpFormatter)
parser.add_argument('--main_dir',help='folder where to keep everything for MadMiner WH studies, on which we store Madgraph samples and all .h5 files (setup, analyzed events, ...)',required=True)
parser.add_argument('--do_signal',help='analyze/combine signal samples', action='store_true',default=False)
parser.add_argument('--do_backgrounds',help='combine background samples', action='store_true',default=False)
parser.add_argument('--observable_set',help="using full (including unobservable degrees of freedom) or met (only observable degrees of freedom) observable set",required=True,choices=['full','met'])
parser.add_argument('--combine_individual',help='combine samples for each of the charge+flavor combination separately (should be done once before all other combination possibilities)',action='store_true',default=False)
parser.add_argument('--combine_flavors',help='combine muon and electron events for each charges separately', action='store_true',default=False)
parser.add_argument('--combine_charges',help='combine w+ and w- events for each flavor separately', action='store_true',default=False)
parser.add_argument('--combine_all',help='combine all charges + flavors', action='store_true',default=False)
parser.add_argument('--combine_BSM',help='combine samples generated at the BSM benchmarks with those generated at the SM point', action='store_true',default=False)
args=parser.parse_args()
if not (args.do_signal or args.do_backgrounds):
sys.exit('asking to process events but not asking for either signal or background ! Exiting...')
if not args.combine_individual and (args.combine_flavors or args.combine_charges or args.combine_all):
logging.warning('not asking to combine samples for each of the charge+flavor combination separately, but asking to make a combination of samples from different charges or flavors. watch out for possible crash from missing samples')
if args.combine_flavors and args.combine_charges:
if not args.combine_all:
logging.warning('asked to combine samples in flavor and in charge separately but combine_all=False, won\'t create single WH sample')
full_proc_dir=f'{args.main_dir}/{args.observable_set}/'
if args.combine_individual:
#### mu+ vm
if args.do_signal:
# generated SM samples
os.symlink(f'{full_proc_dir}/signal/wph_mu_smeftsim_SM_lhe.h5'.format(),f'{full_proc_dir}/wph_mu_signalOnly_SMonly_noSysts_lhe.h5'.format())
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/signal/wph_mu_smeftsim_SM_lhe.h5',
f'{full_proc_dir}/signal/wph_mu_smeftsim_BSM_lhe.h5'],
f'{full_proc_dir}/wph_mu_signalOnly_noSysts_lhe.h5'
)
if args.do_backgrounds:
combine_and_shuffle([
f'{full_proc_dir}/background/tpb_mu_background_lhe.h5',
f'{full_proc_dir}/background/tt_mupjj_background_lhe.h5',
f'{full_proc_dir}/background/wpbb_mu_background_lhe.h5'],
f'{full_proc_dir}/wph_mu_backgroundOnly_noSysts_lhe.h5'
)
if args.do_signal and args.do_backgrounds:
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/signal/wph_mu_smeftsim_SM_lhe.h5',
f'{full_proc_dir}/wph_mu_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wph_mu_withBackgrounds_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wph_mu_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wph_mu_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wph_mu_withBackgrounds_noSysts_lhe.h5'
)
#### e+ ve
if args.do_signal:
# generated SM samples
os.symlink(f'{full_proc_dir}/signal/wph_e_smeftsim_SM_lhe.h5',f'{full_proc_dir}/wph_e_signalOnly_SMonly_noSysts_lhe.h5')
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/signal/wph_e_smeftsim_SM_lhe.h5',
f'{full_proc_dir}/signal/wph_e_smeftsim_BSM_lhe.h5'],
f'{full_proc_dir}/wph_e_signalOnly_noSysts_lhe.h5'
)
if args.do_backgrounds:
combine_and_shuffle([
f'{full_proc_dir}/background/tpb_e_background_lhe.h5',
f'{full_proc_dir}/background/tt_epjj_background_lhe.h5',
f'{full_proc_dir}/background/wpbb_e_background_lhe.h5'],
f'{full_proc_dir}/wph_e_backgroundOnly_noSysts_lhe.h5'
)
if args.do_signal and args.do_backgrounds:
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/signal/wph_e_smeftsim_SM_lhe.h5',
f'{full_proc_dir}/wph_e_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wph_e_withBackgrounds_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wph_e_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wph_e_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wph_e_withBackgrounds_noSysts_lhe.h5'
)
##### mu- vm~
if args.do_signal:
# generated SM samples
os.symlink(f'{full_proc_dir}/signal/wmh_mu_smeftsim_SM_lhe.h5',f'{full_proc_dir}/wmh_mu_signalOnly_SMonly_noSysts_lhe.h5')
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/signal/wmh_mu_smeftsim_SM_lhe.h5',
f'{full_proc_dir}/signal/wmh_mu_smeftsim_BSM_lhe.h5'],
f'{full_proc_dir}/wmh_mu_signalOnly_noSysts_lhe.h5'
)
if args.do_backgrounds:
combine_and_shuffle([
f'{full_proc_dir}/background/tmb_mu_background_lhe.h5',
f'{full_proc_dir}/background/tt_mumjj_background_lhe.h5',
f'{full_proc_dir}/background/wmbb_mu_background_lhe.h5'],
f'{full_proc_dir}/wmh_mu_backgroundOnly_noSysts_lhe.h5'
)
if args.do_signal and args.do_backgrounds:
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/signal/wmh_mu_smeftsim_SM_lhe.h5',
f'{full_proc_dir}/wmh_mu_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wmh_mu_withBackgrounds_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wmh_mu_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_mu_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wmh_mu_withBackgrounds_noSysts_lhe.h5'
)
#### e- ve~
if args.do_signal:
# generated SM samples
os.symlink(f'{full_proc_dir}/signal/wmh_e_smeftsim_SM_lhe.h5',f'{full_proc_dir}/wmh_e_signalOnly_SMonly_noSysts_lhe.h5')
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/signal/wmh_e_smeftsim_SM_lhe.h5',
f'{full_proc_dir}/signal/wmh_e_smeftsim_BSM_lhe.h5'],
f'{full_proc_dir}/wmh_e_signalOnly_noSysts_lhe.h5'
)
if args.do_backgrounds:
combine_and_shuffle([
f'{full_proc_dir}/background/tmb_e_background_lhe.h5',
f'{full_proc_dir}/background/tt_emjj_background_lhe.h5',
f'{full_proc_dir}/background/wmbb_e_background_lhe.h5'],
f'{full_proc_dir}/wmh_e_backgroundOnly_noSysts_lhe.h5'
)
if args.do_signal and args.do_backgrounds:
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/signal/wmh_e_smeftsim_SM_lhe.h5',
f'{full_proc_dir}/wmh_e_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wmh_e_withBackgrounds_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wmh_e_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_e_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wmh_e_withBackgrounds_noSysts_lhe.h5'
)
logging.info('finished standard sample combination for training of ML methods, will now start the combinations used for plotting')
# combining electron and muon channels for each of the charges separately
if args.combine_flavors:
if args.do_signal:
#### w+
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/wph_e_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wph_mu_signalOnly_SMonly_noSysts_lhe.h5'],
f'{full_proc_dir}/wph_signalOnly_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wph_e_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wph_mu_signalOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wph_signalOnly_noSysts_lhe.h5'
)
#### w-
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/wmh_e_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_mu_signalOnly_SMonly_noSysts_lhe.h5'],
f'{full_proc_dir}/wmh_signalOnly_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wmh_e_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_mu_signalOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wmh_signalOnly_noSysts_lhe.h5'
)
if args.do_backgrounds:
#### w+
combine_and_shuffle([
f'{full_proc_dir}/wph_e_backgroundOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wph_mu_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wph_backgroundOnly_noSysts_lhe.h5'
)
#### w-
combine_and_shuffle([
f'{full_proc_dir}/wmh_e_backgroundOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_mu_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wmh_backgroundOnly_noSysts_lhe.h5'
)
if args.do_signal and args.do_backgrounds:
#### w+
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/wph_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wph_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wph_withBackgrounds_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wph_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wph_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wph_withBackgrounds_noSysts_lhe.h5'
)
#### w-
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/wmh_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wmh_withBackgrounds_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wmh_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wmh_withBackgrounds_noSysts_lhe.h5'
)
# combining positive and negative charge channels for each of the flavors separately
if args.combine_charges:
if args.do_signal:
#### e
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/wph_e_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_e_signalOnly_SMonly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_e_signalOnly_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wph_e_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_e_signalOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_e_signalOnly_noSysts_lhe.h5'
)
#### mu
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/wph_mu_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_mu_signalOnly_SMonly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_mu_signalOnly_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wph_mu_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_mu_signalOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_mu_signalOnly_noSysts_lhe.h5'
)
if args.do_backgrounds:
#### e
combine_and_shuffle([
f'{full_proc_dir}/wph_e_backgroundOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_e_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_e_backgroundOnly_noSysts_lhe.h5'
)
#### mu
combine_and_shuffle([
f'{full_proc_dir}/wph_mu_backgroundOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_mu_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_mu_backgroundOnly_noSysts_lhe.h5'
)
if args.do_signal and args.do_backgrounds:
#### e
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/wh_e_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wh_e_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_e_withBackgrounds_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wh_e_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wh_e_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_e_withBackgrounds_noSysts_lhe.h5'
)
#### mu
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/wh_mu_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wh_mu_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_mu_withBackgrounds_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wh_mu_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wh_mu_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_mu_withBackgrounds_noSysts_lhe.h5'
)
# combining positive and negative charge channels and all the flavors
if args.combine_all:
if args.do_signal:
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/wph_e_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_e_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wph_mu_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_mu_signalOnly_SMonly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_signalOnly_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wph_e_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_e_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wph_mu_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_mu_signalOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_signalOnly_noSysts_lhe.h5'
)
if args.do_backgrounds:
combine_and_shuffle([
f'{full_proc_dir}/wph_e_backgroundOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_e_backgroundOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wph_mu_backgroundOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wmh_mu_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_backgroundOnly_noSysts_lhe.h5'
)
if args.do_signal and args.do_backgrounds:
# generated SM samples
combine_and_shuffle([
f'{full_proc_dir}/wh_signalOnly_SMonly_noSysts_lhe.h5',
f'{full_proc_dir}/wh_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_withBackgrounds_SMonly_noSysts_lhe.h5'
)
# generated SM samples + generated BSM samples
if args.combine_BSM:
combine_and_shuffle([
f'{full_proc_dir}/wh_signalOnly_noSysts_lhe.h5',
f'{full_proc_dir}/wh_backgroundOnly_noSysts_lhe.h5'],
f'{full_proc_dir}/wh_withBackgrounds_noSysts_lhe.h5'
)