ATLAS Offline Software
AddZJetsWeights.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-,
3 
4 # Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
5 
6 import os,sys,subprocess,datetime,copy,math,array,shutil,ROOT,re,string
7 from ROOT import gROOT
8 from subprocess import call
9 from array import array
10 
11 __author__ = "John Anders & Jack Lindon"
12 __doc__ = """Script to add Sherpa Systematic Weight branches to existing file."""
13 def generateZpTMapping(dictionary):
14 
15  #Sherpa 2.1
16  # 0-70, bin 1, 70-140 bin 2 etc.
17  print "Adding Z--> nunu to the dictionary"
18  print "\tRange 0-70:",
19  for i in range(361444, 361447):
20  dictionary[i] = 1
21  print i,
22 
23  print "\n\tRange 70-140:",
24  for i in range(361447, 361450):
25  dictionary[i] = 2
26  print i,
27 
28  print "\n\tRange 140-280:",
29  for i in range(361450, 361453):
30  dictionary[i] = 3
31  print i,
32 
33 
34  print "\n\tRange 280-500:",
35  for i in range(361453, 361456):
36  dictionary[i] = 4
37  print i,
38 
39  print "\n\tRange 500-700:",
40  for i in range(361456, 361459):
41  dictionary[i] = 5
42  print i,
43 
44  print "\n\tRange 700-1000:",
45  for i in range(361459, 361462):
46  dictionary[i] = 6
47  print i,
48 
49  print "\n\tRange 1000-2000:",
50  for i in range(361462, 361465):
51  dictionary[i] = 7
52  print i,
53 
54  print "\n\tRange 2000-ECMS:",
55  for i in range(361465, 361468):
56  dictionary[i] = 8
57  print i,
58 
59 
60 
61  print "\nAdding Z--> ee to the dictionary"
62  print "\tRange 0-70:",
63  for i in range(361372, 361375):
64  dictionary[i] = 1
65  print i,
66 
67  print "\n\tRange 70-140:",
68  for i in range(361375, 361378):
69  dictionary[i] = 2
70  print i,
71 
72  print "\n\tRange 140-280:",
73  for i in range(361378, 361381):
74  dictionary[i] = 3
75  print i,
76 
77 
78  print "\n\tRange 280-500:",
79  for i in range(361381, 361384):
80  dictionary[i] = 4
81  print i,
82 
83  print "\n\tRange 500-700:",
84  for i in range(361384, 361387):
85  dictionary[i] = 5
86  print i,
87 
88  print "\n\tRange 700-1000:",
89  for i in range(361387, 361390):
90  dictionary[i] = 6
91  print i,
92 
93  print "\n\tRange 1000-2000:",
94  for i in range(361390, 361393):
95  dictionary[i] = 7
96  print i,
97 
98  print "\n\tRange 2000-ECMS:",
99  for i in range(361393, 361396):
100  dictionary[i] = 8
101  print i,
102 
103 
104 
105  print "\nAdding Z--> mumu to the dictionary"
106  print "\tRange 0-70:",
107  for i in range(361396, 361399):
108  dictionary[i] = 1
109  print i,
110 
111  print "\n\tRange 70-140:",
112  for i in range(361399, 361402):
113  dictionary[i] = 2
114  print i,
115 
116  print "\n\tRange 140-280:",
117  for i in range(361402, 361405):
118  dictionary[i] = 3
119  print i,
120 
121 
122  print "\n\tRange 280-500:",
123  for i in range(361405, 361408):
124  dictionary[i] = 4
125  print i,
126 
127  print "\n\tRange 500-700:",
128  for i in range(361408, 361411):
129  dictionary[i] = 5
130  print i,
131 
132  print "\n\tRange 700-1000:",
133  for i in range(361411, 361414):
134  dictionary[i] = 6
135  print i,
136 
137  print "\n\tRange 1000-2000:",
138  for i in range(361414, 361417):
139  dictionary[i] = 7
140  print i,
141 
142  print "\n\tRange 2000-ECMS:",
143  for i in range(361417, 361420):
144  dictionary[i] = 8
145  print i,
146 
147 
148  print "\nAdding Z--> tautau to the dictionary"
149  print "\tRange 0-70:",
150  for i in range(361420, 361423):
151  dictionary[i] = 1
152  print i,
153 
154  print "\n\tRange 70-140:",
155  for i in range(361423, 361426):
156  dictionary[i] = 2
157  print i,
158 
159  print "\n\tRange 140-280:",
160  for i in range(361426, 361429):
161  dictionary[i] = 3
162  print i,
163 
164 
165  print "\n\tRange 280-500:",
166  for i in range(361429, 361432):
167  dictionary[i] = 4
168  print i,
169 
170  print "\n\tRange 500-700:",
171  for i in range(361432, 361435):
172  dictionary[i] = 5
173  print i,
174 
175  print "\n\tRange 700-1000:",
176  for i in range(361435, 361438):
177  dictionary[i] = 6
178  print i,
179 
180  print "\n\tRange 1000-2000:",
181  for i in range(361438, 361441):
182  dictionary[i] = 7
183  print i,
184 
185  print "\n\tRange 2000-ECMS:",
186  for i in range(361441, 361444):
187  dictionary[i] = 8
188  print i,
189 
190 
191  print "\nAdding W+Jets MCIDs",
192  print "Adding W--> enu to the dictionary"
193  print "\tRange 0-70:",
194  for i in range(361300, 361303):
195  dictionary[i] = 1
196  print i,
197 
198  print "\n\tRange 70-140:",
199  for i in range(361303, 361306):
200  dictionary[i] = 2
201  print i,
202 
203  print "\n\tRange 140-280:",
204  for i in range(361306, 361309):
205  dictionary[i] = 3
206  print i,
207 
208 
209  print "\n\tRange 280-500:",
210  for i in range(361309, 361312):
211  dictionary[i] = 4
212  print i,
213 
214  print "\n\tRange 500-700:",
215  for i in range(361312, 361315):
216  dictionary[i] = 5
217  print i,
218 
219  print "\n\tRange 700-1000:",
220  for i in range(361315, 361318):
221  dictionary[i] = 6
222  print i,
223 
224  print "\n\tRange 1000-2000:",
225  for i in range(361318, 361321):
226  dictionary[i] = 7
227  print i,
228 
229  print "\n\tRange 2000-ECMS:",
230  for i in range(361321, 361324):
231  dictionary[i] = 8
232  print i,
233 
234 
235  print "\nAdding W--> munu to the dictionary"
236  print "\tRange 0-70:",
237  for i in range(361324, 361327):
238  dictionary[i] = 1
239  print i,
240 
241  print "\n\tRange 70-140:",
242  for i in range(361327, 361330):
243  dictionary[i] = 2
244  print i,
245 
246  print "\n\tRange 140-280:",
247  for i in range(361330, 361333):
248  dictionary[i] = 3
249  print i,
250 
251 
252  print "\n\tRange 280-500:",
253  for i in range(361333, 361336):
254  dictionary[i] = 4
255  print i,
256 
257  print "\n\tRange 500-700:",
258  for i in range(361336, 361339):
259  dictionary[i] = 5
260  print i,
261 
262  print "\n\tRange 700-1000:",
263  for i in range(361339, 361342):
264  dictionary[i] = 6
265  print i,
266 
267  print "\n\tRange 1000-2000:",
268  for i in range(361342, 361345):
269  dictionary[i] = 7
270  print i,
271 
272  print "\n\tRange 2000-ECMS:",
273  for i in range(361345, 361348):
274  dictionary[i] = 8
275  print i,
276 
277 
278  print "\nAdding W--> taunu to the dictionary"
279  print "\tRange 0-70:",
280  for i in range(361348, 361351):
281  dictionary[i] = 1
282  print i,
283 
284  print "\n\tRange 70-140:",
285  for i in range(361351, 361354):
286  dictionary[i] = 2
287  print i,
288 
289  print "\n\tRange 140-280:",
290  for i in range(361354, 361357):
291  dictionary[i] = 3
292  print i,
293 
294 
295  print "\n\tRange 280-500:",
296  for i in range(361357, 361360):
297  dictionary[i] = 4
298  print i,
299 
300  print "\n\tRange 500-700:",
301  for i in range(361360, 361363):
302  dictionary[i] = 5
303  print i,
304 
305  print "\n\tRange 700-1000:",
306  for i in range(361363, 361366):
307  dictionary[i] = 6
308  print i,
309 
310  print "\n\tRange 1000-2000:",
311  for i in range(361366, 361369):
312  dictionary[i] = 7
313  print i,
314 
315  print "\n\tRange 2000-ECMS:",
316  for i in range(361369, 361372):
317  dictionary[i] = 8
318  print i,
319 
320 
321  print "\nAdding the Sherpa 2.2 nominal to the dictionary"
322 
323  # 0-70, bin 1, 70-140 bin 2 etc.
324  print "Adding Z--> nunu to the dictionary"
325  print "\tRange 0-70:",
326  for i in range(363412, 363415):
327  dictionary[i] = 1
328  print i,
329 
330  print "\n\tRange 70-140:",
331  for i in range(363415, 363418):
332  dictionary[i] = 2
333  print i,
334 
335  print "\n\tRange 140-280:",
336  for i in range(363418, 363421):
337  dictionary[i] = 3
338  print i,
339 
340 
341  print "\n\tRange 280-500:",
342  for i in range(363421, 363424):
343  dictionary[i] = 4
344  print i,
345 
346  print "\n\tRange 500-700:",
347  for i in range(363424, 363427):
348  dictionary[i] = 5
349  print i,
350 
351  print "\n\tRange 700-1000:",
352  for i in range(363427, 363430):
353  dictionary[i] = 6
354  print i,
355 
356  print "\n\tRange 1000-2000:",
357  for i in range(363430, 363433):
358  dictionary[i] = 7
359  print i,
360 
361  print "\n\tRange 2000-ECMS:",
362  for i in range(363433, 363436):
363  dictionary[i] = 8
364  print i,
365 
366 
367 
368  print "\nAdding Z--> ee to the dictionary"
369  print "\tRange 0-70:",
370  for i in range(363388, 363391):
371  dictionary[i] = 1
372  print i,
373 
374  print "\n\tRange 70-140:",
375  for i in range(363391, 363394):
376  dictionary[i] = 2
377  print i,
378 
379  print "\n\tRange 140-280:",
380  for i in range(363394, 363397):
381  dictionary[i] = 3
382  print i,
383 
384 
385  print "\n\tRange 280-500:",
386  for i in range(363397, 363400):
387  dictionary[i] = 4
388  print i,
389 
390  print "\n\tRange 500-700:",
391  for i in range(363400, 363403):
392  dictionary[i] = 5
393  print i,
394 
395  print "\n\tRange 700-1000:",
396  for i in range(363403, 363406):
397  dictionary[i] = 6
398  print i,
399 
400  print "\n\tRange 1000-2000:",
401  for i in range(363406, 363409):
402  dictionary[i] = 7
403  print i,
404 
405  print "\n\tRange 2000-ECMS:",
406  for i in range(363409, 363412):
407  dictionary[i] = 8
408  print i,
409 
410 
411 
412  print "\nAdding Z--> mumu to the dictionary"
413  print "\tRange 0-70:",
414  for i in range(363364, 363367):
415  dictionary[i] = 1
416  print i,
417 
418  print "\n\tRange 70-140:",
419  for i in range(363367, 363370):
420  dictionary[i] = 2
421  print i,
422 
423  print "\n\tRange 140-280:",
424  for i in range(363370, 363373):
425  dictionary[i] = 3
426  print i,
427 
428 
429  print "\n\tRange 280-500:",
430  for i in range(363373, 363376):
431  dictionary[i] = 4
432  print i,
433 
434  print "\n\tRange 500-700:",
435  for i in range(363376, 363379):
436  dictionary[i] = 5
437  print i,
438 
439  print "\n\tRange 700-1000:",
440  for i in range(363379, 363382):
441  dictionary[i] = 6
442  print i,
443 
444  print "\n\tRange 1000-2000:",
445  for i in range(363382, 363385):
446  dictionary[i] = 7
447  print i,
448 
449  print "\n\tRange 2000-ECMS:",
450  for i in range(363385, 363388):
451  dictionary[i] = 8
452  print i,
453 
454 
455  print "\nAdding Z--> tautau to the dictionary"
456  print "\tRange 0-70:",
457  for i in range(363099, 363102):
458  dictionary[i] = 1
459  print i,
460 
461  print "\n\tRange 70-140:",
462  for i in range(363102, 363105):
463  dictionary[i] = 2
464  print i,
465 
466  print "\n\tRange 140-280:",
467  for i in range(363105, 363108):
468  dictionary[i] = 3
469  print i,
470 
471 
472  print "\n\tRange 280-500:",
473  for i in range(363108, 363111):
474  dictionary[i] = 4
475  print i,
476 
477  print "\n\tRange 500-700:",
478  for i in range(363111, 363114):
479  dictionary[i] = 5
480  print i,
481 
482  print "\n\tRange 700-1000:",
483  for i in range(363114, 363117):
484  dictionary[i] = 6
485  print i,
486 
487  print "\n\tRange 1000-2000:",
488  for i in range(363117, 363120):
489  dictionary[i] = 7
490  print i,
491 
492  print "\n\tRange 2000-ECMS:",
493  for i in range(363120, 363123):
494  dictionary[i] = 8
495  print i,
496 
497 
498 
499 
500  print "\nAdding W+Jets MCIDs for Sherpa 2.2"
501  print "Adding W--> enu to the dictionary"
502  print "\tRange 0-70:",
503  for i in range(363460, 363463):
504  dictionary[i] = 1
505  print i,
506 
507  print "\n\tRange 70-140:",
508  for i in range(363463, 363466):
509  dictionary[i] = 2
510  print i,
511 
512  print "\n\tRange 140-280:",
513  for i in range(363466, 363469):
514  dictionary[i] = 3
515  print i,
516 
517 
518  print "\n\tRange 280-500:",
519  for i in range(363469, 363472):
520  dictionary[i] = 4
521  print i,
522 
523  print "\n\tRange 500-700:",
524  for i in range(363472, 363475):
525  dictionary[i] = 5
526  print i,
527 
528  print "\n\tRange 700-1000:",
529  for i in range(363475, 363478):
530  dictionary[i] = 6
531  print i,
532 
533  print "\n\tRange 1000-2000:",
534  for i in range(363478, 363481):
535  dictionary[i] = 7
536  print i,
537 
538  print "\n\tRange 2000-ECMS:",
539  for i in range(363481, 363484):
540  dictionary[i] = 8
541  print i,
542 
543 
544  print "\nAdding W--> munu to the dictionary"
545  print "\tRange 0-70:",
546  for i in range(363436, 363439):
547  dictionary[i] = 1
548  print i,
549 
550  print "\n\tRange 70-140:",
551  for i in range(363439, 363442):
552  dictionary[i] = 2
553  print i,
554 
555  print "\n\tRange 140-280:",
556  for i in range(363442, 363445):
557  dictionary[i] = 3
558  print i,
559 
560 
561  print "\n\tRange 280-500:",
562  for i in range(363445, 363448):
563  dictionary[i] = 4
564  print i,
565 
566  print "\n\tRange 500-700:",
567  for i in range(363448, 363451):
568  dictionary[i] = 5
569  print i,
570 
571  print "\n\tRange 700-1000:",
572  for i in range(363451, 363454):
573  dictionary[i] = 6
574  print i,
575 
576  print "\n\tRange 1000-2000:",
577  for i in range(363454, 363457):
578  dictionary[i] = 7
579  print i,
580 
581  print "\n\tRange 2000-ECMS:",
582  for i in range(363447, 363460):
583  dictionary[i] = 8
584  print i,
585 
586 
587  print "\nAdding W--> taunu to the dictionary"
588  print "\tRange 0-70:",
589  for i in range(363331, 363334):
590  dictionary[i] = 1
591  print i,
592 
593  print "\n\tRange 70-140:",
594  for i in range(363334, 363337):
595  dictionary[i] = 2
596  print i,
597 
598  print "\n\tRange 140-280:",
599  for i in range(363337, 363340):
600  dictionary[i] = 3
601  print i,
602 
603 
604  print "\n\tRange 280-500:",
605  for i in range(363340, 363343):
606  dictionary[i] = 4
607  print i,
608 
609  print "\n\tRange 500-700:",
610  for i in range(363343, 363346):
611  dictionary[i] = 5
612  print i,
613 
614  print "\n\tRange 700-1000:",
615  for i in range(363346, 363349):
616  dictionary[i] = 6
617  print i,
618 
619  print "\n\tRange 1000-2000:",
620  for i in range(363349, 363352):
621  dictionary[i] = 7
622  print i,
623 
624  print "\n\tRange 2000-ECMS:",
625  for i in range(363352, 363355):
626  dictionary[i] = 8
627  print i,
628 
629 
630 
631 
632  print "\nAdding the Sherpa 2.2.1 nominal to the dictionary"
633 
634  # 0-70, bin 1, 70-140 bin 2 etc.
635  print "Adding Z--> nunu to the dictionary"
636  print "\tRange 0-70:",
637  for i in range(364142, 364145):
638  dictionary[i] = 1
639  print i,
640 
641  print "\n\tRange 70-140:",
642  for i in range(364145, 364148):
643  dictionary[i] = 2
644  print i,
645 
646  print "\n\tRange 140-280:",
647  for i in range(364148, 364151):
648  dictionary[i] = 3
649  print i,
650 
651 
652  print "\n\tRange 280-500:",
653  for i in range(364151, 364154):
654  dictionary[i] = 4
655  print i,
656 
657  print "\n\tRange 500-1000:",
658  for i in [364154]:
659  dictionary[i] = 5
660  print i,
661 
662  print "\n\tRange 1000-ECMS:",
663  for i in [364155]:
664  dictionary[i] = 7
665  print i,
666 
667 
668 
669  print "\nAdding Z--> ee to the dictionary"
670  print "\tRange 0-70:",
671  for i in range(364114, 364117):
672  dictionary[i] = 1
673  print i,
674 
675  print "\n\tRange 70-140:",
676  for i in range(364117, 364120):
677  dictionary[i] = 2
678  print i,
679 
680  print "\n\tRange 140-280:",
681  for i in range(364120, 364123):
682  dictionary[i] = 3
683  print i,
684 
685 
686  print "\n\tRange 280-500:",
687  for i in range(364123, 364126):
688  dictionary[i] = 4
689  print i,
690 
691  print "\n\tRange 500-1000:",
692  dictionary[364126] = 5
693  dictionary[364218] = 5
694  print i,
695 
696  print "\n\tRange 1000-ECMS:",
697  dictionary[364127] = 7
698  dictionary[364219] = 7
699  print i,
700 
701 
702 
703  print "\nAdding Z--> mumu to the dictionary"
704  print "\tRange 0-70:",
705  for i in range(364100, 364103):
706  dictionary[i] = 1
707  print i,
708 
709  print "\n\tRange 70-140:",
710  for i in range(364103, 364106):
711  dictionary[i] = 2
712  print i,
713 
714  print "\n\tRange 140-280:",
715  for i in range(364106, 364109):
716  dictionary[i] = 3
717  print i,
718 
719 
720  print "\n\tRange 280-500:",
721  for i in range(364109, 364112):
722  dictionary[i] = 4
723  print i,
724 
725  print "\n\tRange 500-1000:",
726  dictionary[364112] = 5
727  dictionary[364216] = 5
728  print i,
729 
730  print "\n\tRange 1000-ECMS:",
731  dictionary[364113] = 7
732  dictionary[364217] = 7
733  print i,
734 
735 
736  print "\nAdding Z--> tautau to the dictionary"
737  print "\tRange 0-70:",
738  for i in range(364128, 364131):
739  dictionary[i] = 1
740  print i,
741 
742  print "\n\tRange 70-140:",
743  for i in range(364131, 364134):
744  dictionary[i] = 2
745  print i,
746 
747  print "\n\tRange 140-280:",
748  for i in range(364134, 364137):
749  dictionary[i] = 3
750  print i,
751 
752 
753  print "\n\tRange 280-500:",
754  for i in range(364137, 364140):
755  dictionary[i] = 4
756  print i,
757 
758  print "\n\tRange 500-1000:",
759  dictionary[364140] = 5
760  dictionary[364220] = 5
761  print i,
762 
763  print "\n\tRange 1000-ECMS:",
764  dictionary[364141] = 7
765  dictionary[364221] = 7
766  print i,
767 
768 
769  #NEW ZNUNU
770  print "\nAdding Z--> nunu (2019 PTV filtered samples) to the dictionary"
771 
772  print "\tRange 70-100:",
773  for i in [366010,366019,366028]:
774  dictionary[i] = 2
775  print i,
776 
777  print "\n\tRange 100-140:",
778  for i in [366011,366012,366013,366020,366021,366022,366029,366030,366031]:
779  dictionary[i] = 2
780  print i,
781 
782  print "\n\tRange 140-280:",
783  for i in [366014,366015,366016,366023,366024,366025,366032,366033,366034]:
784  dictionary[i] = 3
785  print i,
786 
787  print "\n\tRange 280-500:",
788  for i in [366017,366026,366035]:
789  dictionary[i] = 4
790  print i,
791 
792  print "\n\tRange 500-1000:",
793  for i in [364222]:
794  dictionary[i] = 5
795  print i,
796 
797  print "\n\tRange 1000-ECMS:",
798  for i in [364223]:
799  dictionary[i] = 7
800  print i,
801  # clear from previous print
802  print ""
803 
804  print "\nAdding W--> enu to the dictionary"
805  print "\tRange 0-70:",
806  for i in range(364170, 364173):
807  dictionary[i] = 1
808  print i,
809 
810  print "\n\tRange 70-140:",
811  for i in range(364173, 364176):
812  dictionary[i] = 2
813  print i,
814 
815  print "\n\tRange 140-280:",
816  for i in range(364176, 364179):
817  dictionary[i] = 3
818  print i,
819 
820 
821  print "\n\tRange 280-500:",
822  for i in range(364179, 364182):
823  dictionary[i] = 4
824  print i,
825 
826  print "\n\tRange 500-1000:",
827  dictionary[364182] = 5
828  dictionary[364226] = 5
829  print i,
830 
831  print "\n\tRange 1000-ECMS:",
832  dictionary[364183] = 7
833  dictionary[364227] = 7
834  print i,
835 
836 
837 
838  print "\nAdding W--> munu to the dictionary"
839  print "\tRange 0-70:",
840  for i in range(364156, 364159):
841  dictionary[i] = 1
842  print i,
843 
844  print "\n\tRange 70-140:",
845  for i in range(364159, 364162):
846  dictionary[i] = 2
847  print i,
848 
849  print "\n\tRange 140-280:",
850  for i in range(364162, 364165):
851  dictionary[i] = 3
852  print i,
853 
854 
855  print "\n\tRange 280-500:",
856  for i in range(364165, 364168):
857  dictionary[i] = 4
858  print i,
859 
860  print "\n\tRange 500-1000:",
861  dictionary[364168] = 5
862  dictionary[364224] = 5
863  print i,
864 
865  print "\n\tRange 1000-ECMS:",
866  dictionary[364169] = 7
867  dictionary[364225] = 7
868  print i,
869 
870 
871  print "\nAdding W--> taunu to the dictionary"
872  print "\tRange 0-70:",
873  for i in range(364184, 364187):
874  dictionary[i] = 1
875  print i,
876 
877  print "\n\tRange 70-140:",
878  for i in range(364187, 364190):
879  dictionary[i] = 2
880  print i,
881 
882  print "\n\tRange 140-280:",
883  for i in range(364190, 364193):
884  dictionary[i] = 3
885  print i,
886 
887 
888  print "\n\tRange 280-500:",
889  for i in range(364193, 364196):
890  dictionary[i] = 4
891  print i,
892 
893  print "\n\tRange 500-1000:",
894  dictionary[364196] = 5
895  dictionary[364228] = 5
896  print i,
897 
898  print "\n\tRange 1000-ECMS:",
899  dictionary[364197] = 7
900  dictionary[364229] = 7
901  print i,
902  # clear from previous print
903  print ""
904 
905 
906  return dictionary
907 
908 def main(infile, weightsFile, treename, attr_mcID, attr_nTruthJets):
909  print "Creating MCID, ZpT mapping"
910  ZpTMapping = dict()
911  generateZpTMapping(ZpTMapping)
912 
913  print "Loading histograms with weights"
914  ZeeHistograms = []
915  ZnunuHistograms = []
916  WenuHistograms = []
917 
918  g = ROOT.TFile(weightsFile)
919  systList = ["ckkw15", "ckkw30", "fac025", "fac4", "renorm025", "renorm4", "qsf025", "qsf4"]
920 
921  for syst in systList:
922  h = ROOT.TH2F(g.Get("Zee"+syst))
923  ZeeHistograms.append(h)
924  h = ROOT.TH2F(g.Get("Znunu"+syst))
925  ZnunuHistograms.append(h)
926  h = ROOT.TH2F(g.Get("Wenu"+syst))
927  WenuHistograms.append(h)
928 
929  print "Loading File"
930  f = ROOT.TFile(infile,"update")
931 
932  print "Loading Tree"
933 
934  # empty arrays for adding branches
935  ckkw15 = array('f', [0.])
936  ckkw30 = array('f', [0.])
937  fac025 = array('f', [0.])
938  fac4 = array('f', [0.])
939  renorm025 = array('f', [0.])
940  renorm4 = array('f', [0.])
941  qsf025 = array('f', [0.])
942  qsf4 = array('f', [0.])
943 
944  # Add branches
945  T = f.Get(treename)
946  ckkw15branch = T.Branch("ckkw15_Weight", ckkw15,"ckkw15_Weight/F")
947  ckkw30branch = T.Branch("ckkw30_Weight", ckkw30,"ckkw30_Weight/F")
948  fac025branch = T.Branch("fac025_Weight", fac025,"fac025_Weight/F")
949  fac4branch = T.Branch("fac4_Weight", fac4,"fac4_Weight/F")
950  renorm025branch = T.Branch("renorm025_Weight", renorm025,"renorm025_Weight/F")
951  renorm4branch = T.Branch("renorm4_Weight", renorm4,"renorm4_Weight/F")
952  qsf025branch = T.Branch("qsf025_Weight", qsf025,"qsf025_Weight/F")
953  qsf4branch = T.Branch("qsf4_Weight", qsf4,"qsf4_Weight/F")
954 
955  print "Adding Weights"
956  nEvts = T.GetEntries()
957 
958  for iEvt in range(nEvts):
959 
960  if iEvt%1000 == 0:
961  print '\x1b[2K\r', "Current Event being Processed is: {0:15d}".format(iEvt),
962  sys.stdout.flush()
963 
964  T.GetEntry(iEvt)
965 
966  MCID = getattr(T, attr_mcID)
967  nTruthJets = getattr(T, attr_nTruthJets)
968 
969  decayType = "none"
970 
971  # Find the Decay type
972  if (
973  (361372 <= MCID <= 361443) or
974  (363102 <= MCID <= 363122) or
975  (363361 <= MCID <= 363363) or
976  (363364 <= MCID <= 363411) or
977  (364114 <= MCID <= 364127) or
978  (364100 <= MCID <= 364113) or
979  (364128 <= MCID <= 364141) or
980  (364216 <= MCID <= 364217) or
981  (364220 <= MCID <= 364221)
982  ):
983  decayType = "dilepton"
984 
985  elif (
986  (361444 <= MCID <= 361467) or
987  (363412 <= MCID <= 363435) or
988  (364142 <= MCID <= 364155) or
989  (366010 <= MCID <= 366035) or
990  (364222 <= MCID <= 364223)
991  ):
992  decayType = "nolepton"
993 
994  elif (
995  (361300 <= MCID <= 361371) or
996  (363331 <= MCID <= 363354) or
997  (363436 <= MCID <= 363459) or
998  (363460 <= MCID <= 363483) or
999  (364156 <= MCID <= 364169) or
1000  (364170 <= MCID <= 364183) or
1001  (364184 <= MCID <= 364197) or
1002  (364226 <= MCID <= 364227) or
1003  (364224 <= MCID <= 364225) or
1004  (364228 <= MCID <= 364229)
1005  ):
1006  decayType = "onelepton"
1007 
1008  else:
1009  decayType = "none"
1010 
1011  # find which ZpT bin we want
1012  ZpTBin = ZpTMapping.get(MCID)
1013  TruthJetBin = nTruthJets+1
1014  if nTruthJets >= 11:
1015  TruthJetBin = 12
1016  if ZpTBin == None:
1017  #this MCID isn't in the mapping, so skip and default to 1
1018  ckkw15[0] = 1
1019  ckkw30[0] = 1
1020  fac025[0] = 1
1021  fac4[0] = 1
1022  renorm025[0] = 1
1023  renorm4[0] = 1
1024  qsf025[0] = 1
1025  qsf4[0] = 1
1026 
1027  else:
1028  if decayType == "dilepton":
1029  ckkw15[0] = ZeeHistograms[0].GetBinContent(ZpTBin,TruthJetBin)
1030  ckkw30[0] = ZeeHistograms[1].GetBinContent(ZpTBin,TruthJetBin)
1031  fac025[0] = ZeeHistograms[2].GetBinContent(ZpTBin,TruthJetBin)
1032  fac4[0] = ZeeHistograms[3].GetBinContent(ZpTBin,TruthJetBin)
1033  renorm025[0] = ZeeHistograms[4].GetBinContent(ZpTBin,TruthJetBin)
1034  renorm4[0] = ZeeHistograms[5].GetBinContent(ZpTBin,TruthJetBin)
1035  qsf025[0] = ZeeHistograms[6].GetBinContent(ZpTBin,TruthJetBin)
1036  qsf4[0] = ZeeHistograms[7].GetBinContent(ZpTBin,TruthJetBin)
1037  elif decayType == "nolepton":
1038  ckkw15[0] = ZnunuHistograms[0].GetBinContent(ZpTBin,TruthJetBin)
1039  ckkw30[0] = ZnunuHistograms[1].GetBinContent(ZpTBin,TruthJetBin)
1040  fac025[0] = ZnunuHistograms[2].GetBinContent(ZpTBin,TruthJetBin)
1041  fac4[0] = ZnunuHistograms[3].GetBinContent(ZpTBin,TruthJetBin)
1042  renorm025[0] = ZnunuHistograms[4].GetBinContent(ZpTBin,TruthJetBin)
1043  renorm4[0] = ZnunuHistograms[5].GetBinContent(ZpTBin,TruthJetBin)
1044  qsf025[0] = ZnunuHistograms[6].GetBinContent(ZpTBin,TruthJetBin)
1045  qsf4[0] = ZnunuHistograms[7].GetBinContent(ZpTBin,TruthJetBin)
1046  elif decayType == "onelepton":
1047  ckkw15[0] = WenuHistograms[0].GetBinContent(ZpTBin,TruthJetBin)
1048  ckkw30[0] = WenuHistograms[1].GetBinContent(ZpTBin,TruthJetBin)
1049  fac025[0] = WenuHistograms[2].GetBinContent(ZpTBin,TruthJetBin)
1050  fac4[0] = WenuHistograms[3].GetBinContent(ZpTBin,TruthJetBin)
1051  renorm025[0] = WenuHistograms[4].GetBinContent(ZpTBin,TruthJetBin)
1052  renorm4[0] = WenuHistograms[5].GetBinContent(ZpTBin,TruthJetBin)
1053  qsf025[0] = WenuHistograms[6].GetBinContent(ZpTBin,TruthJetBin)
1054  qsf4[0] = WenuHistograms[7].GetBinContent(ZpTBin,TruthJetBin)
1055  else:
1056  print '\x1b[2K\r', "Missing entry for MCID={0}, nTruthJets={1}".format(MCID, nTruthJets)
1057  exit(1)
1058 
1059  ckkw15branch.Fill()
1060  ckkw30branch.Fill()
1061  fac025branch.Fill()
1062  fac4branch.Fill()
1063  renorm025branch.Fill()
1064  renorm4branch.Fill()
1065  qsf025branch.Fill()
1066  qsf4branch.Fill()
1067 
1068  print '\x1b[2K\r', "All entries processed"
1069  T.Write()
1070 
1071  print "Done with {0:s}/{1:s}.".format(infile, treename)
1072  f.Close()
1073 
1074 if __name__ == '__main__':
1075 
1076  import argparse
1077 
1078  class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter):
1079  pass
1080 
1081  parser = argparse.ArgumentParser(description=__doc__, usage='\033[93m%(prog)s\033[0m file.root [options]',
1082  formatter_class=lambda prog: CustomFormatter(prog, max_help_position=30))
1083  parser.add_argument('file', type=str, help='input ROOT tuple to reweight')
1084  parser.add_argument('--weights', type=str, required=False, help='Input weights file to use for reweighting', default='/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/dev/SUSYTools/Vjets_SysParameterization/VJetsWeights.root', metavar='')
1085  parser.add_argument('--treename', type=str, required=False, help='Name of tree', default='nominal', metavar='')
1086  parser.add_argument('--mcID', type=str, required=False, help='name of branch containing MC ID', default='mcID', metavar='')
1087  parser.add_argument('--nTruthJets', type=str, required=False, help='name of branch containing number of truth jets', default='nJets', metavar='')
1088 
1089  args = parser.parse_args()
1090 
1091  main(args.file, args.weights, args.treename, args.mcID, args.nTruthJets)
vtune_athena.format
format
Definition: vtune_athena.py:14
AddZJetsWeights.generateZpTMapping
def generateZpTMapping(dictionary)
Definition: AddZJetsWeights.py:13
AddZJetsWeights.main
def main(infile, weightsFile, treename, attr_mcID, attr_nTruthJets)
Definition: AddZJetsWeights.py:908
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
calibdata.exit
exit
Definition: calibdata.py:236
array
AddZJetsWeights.CustomFormatter
Definition: AddZJetsWeights.py:1078