6 import os,sys,subprocess,datetime,copy,math,array,shutil,ROOT,re,string
8 from subprocess
import call
9 from array
import array
11 __author__ =
"John Anders & Jack Lindon"
12 __doc__ =
"""Script to add Sherpa Systematic Weight branches to existing file."""
17 print "Adding Z--> nunu to the dictionary"
18 print "\tRange 0-70:",
19 for i
in range(361444, 361447):
23 print "\n\tRange 70-140:",
24 for i
in range(361447, 361450):
28 print "\n\tRange 140-280:",
29 for i
in range(361450, 361453):
34 print "\n\tRange 280-500:",
35 for i
in range(361453, 361456):
39 print "\n\tRange 500-700:",
40 for i
in range(361456, 361459):
44 print "\n\tRange 700-1000:",
45 for i
in range(361459, 361462):
49 print "\n\tRange 1000-2000:",
50 for i
in range(361462, 361465):
54 print "\n\tRange 2000-ECMS:",
55 for i
in range(361465, 361468):
61 print "\nAdding Z--> ee to the dictionary"
62 print "\tRange 0-70:",
63 for i
in range(361372, 361375):
67 print "\n\tRange 70-140:",
68 for i
in range(361375, 361378):
72 print "\n\tRange 140-280:",
73 for i
in range(361378, 361381):
78 print "\n\tRange 280-500:",
79 for i
in range(361381, 361384):
83 print "\n\tRange 500-700:",
84 for i
in range(361384, 361387):
88 print "\n\tRange 700-1000:",
89 for i
in range(361387, 361390):
93 print "\n\tRange 1000-2000:",
94 for i
in range(361390, 361393):
98 print "\n\tRange 2000-ECMS:",
99 for i
in range(361393, 361396):
105 print "\nAdding Z--> mumu to the dictionary"
106 print "\tRange 0-70:",
107 for i
in range(361396, 361399):
111 print "\n\tRange 70-140:",
112 for i
in range(361399, 361402):
116 print "\n\tRange 140-280:",
117 for i
in range(361402, 361405):
122 print "\n\tRange 280-500:",
123 for i
in range(361405, 361408):
127 print "\n\tRange 500-700:",
128 for i
in range(361408, 361411):
132 print "\n\tRange 700-1000:",
133 for i
in range(361411, 361414):
137 print "\n\tRange 1000-2000:",
138 for i
in range(361414, 361417):
142 print "\n\tRange 2000-ECMS:",
143 for i
in range(361417, 361420):
148 print "\nAdding Z--> tautau to the dictionary"
149 print "\tRange 0-70:",
150 for i
in range(361420, 361423):
154 print "\n\tRange 70-140:",
155 for i
in range(361423, 361426):
159 print "\n\tRange 140-280:",
160 for i
in range(361426, 361429):
165 print "\n\tRange 280-500:",
166 for i
in range(361429, 361432):
170 print "\n\tRange 500-700:",
171 for i
in range(361432, 361435):
175 print "\n\tRange 700-1000:",
176 for i
in range(361435, 361438):
180 print "\n\tRange 1000-2000:",
181 for i
in range(361438, 361441):
185 print "\n\tRange 2000-ECMS:",
186 for i
in range(361441, 361444):
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):
198 print "\n\tRange 70-140:",
199 for i
in range(361303, 361306):
203 print "\n\tRange 140-280:",
204 for i
in range(361306, 361309):
209 print "\n\tRange 280-500:",
210 for i
in range(361309, 361312):
214 print "\n\tRange 500-700:",
215 for i
in range(361312, 361315):
219 print "\n\tRange 700-1000:",
220 for i
in range(361315, 361318):
224 print "\n\tRange 1000-2000:",
225 for i
in range(361318, 361321):
229 print "\n\tRange 2000-ECMS:",
230 for i
in range(361321, 361324):
235 print "\nAdding W--> munu to the dictionary"
236 print "\tRange 0-70:",
237 for i
in range(361324, 361327):
241 print "\n\tRange 70-140:",
242 for i
in range(361327, 361330):
246 print "\n\tRange 140-280:",
247 for i
in range(361330, 361333):
252 print "\n\tRange 280-500:",
253 for i
in range(361333, 361336):
257 print "\n\tRange 500-700:",
258 for i
in range(361336, 361339):
262 print "\n\tRange 700-1000:",
263 for i
in range(361339, 361342):
267 print "\n\tRange 1000-2000:",
268 for i
in range(361342, 361345):
272 print "\n\tRange 2000-ECMS:",
273 for i
in range(361345, 361348):
278 print "\nAdding W--> taunu to the dictionary"
279 print "\tRange 0-70:",
280 for i
in range(361348, 361351):
284 print "\n\tRange 70-140:",
285 for i
in range(361351, 361354):
289 print "\n\tRange 140-280:",
290 for i
in range(361354, 361357):
295 print "\n\tRange 280-500:",
296 for i
in range(361357, 361360):
300 print "\n\tRange 500-700:",
301 for i
in range(361360, 361363):
305 print "\n\tRange 700-1000:",
306 for i
in range(361363, 361366):
310 print "\n\tRange 1000-2000:",
311 for i
in range(361366, 361369):
315 print "\n\tRange 2000-ECMS:",
316 for i
in range(361369, 361372):
321 print "\nAdding the Sherpa 2.2 nominal to the dictionary"
324 print "Adding Z--> nunu to the dictionary"
325 print "\tRange 0-70:",
326 for i
in range(363412, 363415):
330 print "\n\tRange 70-140:",
331 for i
in range(363415, 363418):
335 print "\n\tRange 140-280:",
336 for i
in range(363418, 363421):
341 print "\n\tRange 280-500:",
342 for i
in range(363421, 363424):
346 print "\n\tRange 500-700:",
347 for i
in range(363424, 363427):
351 print "\n\tRange 700-1000:",
352 for i
in range(363427, 363430):
356 print "\n\tRange 1000-2000:",
357 for i
in range(363430, 363433):
361 print "\n\tRange 2000-ECMS:",
362 for i
in range(363433, 363436):
368 print "\nAdding Z--> ee to the dictionary"
369 print "\tRange 0-70:",
370 for i
in range(363388, 363391):
374 print "\n\tRange 70-140:",
375 for i
in range(363391, 363394):
379 print "\n\tRange 140-280:",
380 for i
in range(363394, 363397):
385 print "\n\tRange 280-500:",
386 for i
in range(363397, 363400):
390 print "\n\tRange 500-700:",
391 for i
in range(363400, 363403):
395 print "\n\tRange 700-1000:",
396 for i
in range(363403, 363406):
400 print "\n\tRange 1000-2000:",
401 for i
in range(363406, 363409):
405 print "\n\tRange 2000-ECMS:",
406 for i
in range(363409, 363412):
412 print "\nAdding Z--> mumu to the dictionary"
413 print "\tRange 0-70:",
414 for i
in range(363364, 363367):
418 print "\n\tRange 70-140:",
419 for i
in range(363367, 363370):
423 print "\n\tRange 140-280:",
424 for i
in range(363370, 363373):
429 print "\n\tRange 280-500:",
430 for i
in range(363373, 363376):
434 print "\n\tRange 500-700:",
435 for i
in range(363376, 363379):
439 print "\n\tRange 700-1000:",
440 for i
in range(363379, 363382):
444 print "\n\tRange 1000-2000:",
445 for i
in range(363382, 363385):
449 print "\n\tRange 2000-ECMS:",
450 for i
in range(363385, 363388):
455 print "\nAdding Z--> tautau to the dictionary"
456 print "\tRange 0-70:",
457 for i
in range(363099, 363102):
461 print "\n\tRange 70-140:",
462 for i
in range(363102, 363105):
466 print "\n\tRange 140-280:",
467 for i
in range(363105, 363108):
472 print "\n\tRange 280-500:",
473 for i
in range(363108, 363111):
477 print "\n\tRange 500-700:",
478 for i
in range(363111, 363114):
482 print "\n\tRange 700-1000:",
483 for i
in range(363114, 363117):
487 print "\n\tRange 1000-2000:",
488 for i
in range(363117, 363120):
492 print "\n\tRange 2000-ECMS:",
493 for i
in range(363120, 363123):
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):
507 print "\n\tRange 70-140:",
508 for i
in range(363463, 363466):
512 print "\n\tRange 140-280:",
513 for i
in range(363466, 363469):
518 print "\n\tRange 280-500:",
519 for i
in range(363469, 363472):
523 print "\n\tRange 500-700:",
524 for i
in range(363472, 363475):
528 print "\n\tRange 700-1000:",
529 for i
in range(363475, 363478):
533 print "\n\tRange 1000-2000:",
534 for i
in range(363478, 363481):
538 print "\n\tRange 2000-ECMS:",
539 for i
in range(363481, 363484):
544 print "\nAdding W--> munu to the dictionary"
545 print "\tRange 0-70:",
546 for i
in range(363436, 363439):
550 print "\n\tRange 70-140:",
551 for i
in range(363439, 363442):
555 print "\n\tRange 140-280:",
556 for i
in range(363442, 363445):
561 print "\n\tRange 280-500:",
562 for i
in range(363445, 363448):
566 print "\n\tRange 500-700:",
567 for i
in range(363448, 363451):
571 print "\n\tRange 700-1000:",
572 for i
in range(363451, 363454):
576 print "\n\tRange 1000-2000:",
577 for i
in range(363454, 363457):
581 print "\n\tRange 2000-ECMS:",
582 for i
in range(363447, 363460):
587 print "\nAdding W--> taunu to the dictionary"
588 print "\tRange 0-70:",
589 for i
in range(363331, 363334):
593 print "\n\tRange 70-140:",
594 for i
in range(363334, 363337):
598 print "\n\tRange 140-280:",
599 for i
in range(363337, 363340):
604 print "\n\tRange 280-500:",
605 for i
in range(363340, 363343):
609 print "\n\tRange 500-700:",
610 for i
in range(363343, 363346):
614 print "\n\tRange 700-1000:",
615 for i
in range(363346, 363349):
619 print "\n\tRange 1000-2000:",
620 for i
in range(363349, 363352):
624 print "\n\tRange 2000-ECMS:",
625 for i
in range(363352, 363355):
632 print "\nAdding the Sherpa 2.2.1 nominal to the dictionary"
635 print "Adding Z--> nunu to the dictionary"
636 print "\tRange 0-70:",
637 for i
in range(364142, 364145):
641 print "\n\tRange 70-140:",
642 for i
in range(364145, 364148):
646 print "\n\tRange 140-280:",
647 for i
in range(364148, 364151):
652 print "\n\tRange 280-500:",
653 for i
in range(364151, 364154):
657 print "\n\tRange 500-1000:",
662 print "\n\tRange 1000-ECMS:",
669 print "\nAdding Z--> ee to the dictionary"
670 print "\tRange 0-70:",
671 for i
in range(364114, 364117):
675 print "\n\tRange 70-140:",
676 for i
in range(364117, 364120):
680 print "\n\tRange 140-280:",
681 for i
in range(364120, 364123):
686 print "\n\tRange 280-500:",
687 for i
in range(364123, 364126):
691 print "\n\tRange 500-1000:",
692 dictionary[364126] = 5
693 dictionary[364218] = 5
696 print "\n\tRange 1000-ECMS:",
697 dictionary[364127] = 7
698 dictionary[364219] = 7
703 print "\nAdding Z--> mumu to the dictionary"
704 print "\tRange 0-70:",
705 for i
in range(364100, 364103):
709 print "\n\tRange 70-140:",
710 for i
in range(364103, 364106):
714 print "\n\tRange 140-280:",
715 for i
in range(364106, 364109):
720 print "\n\tRange 280-500:",
721 for i
in range(364109, 364112):
725 print "\n\tRange 500-1000:",
726 dictionary[364112] = 5
727 dictionary[364216] = 5
730 print "\n\tRange 1000-ECMS:",
731 dictionary[364113] = 7
732 dictionary[364217] = 7
736 print "\nAdding Z--> tautau to the dictionary"
737 print "\tRange 0-70:",
738 for i
in range(364128, 364131):
742 print "\n\tRange 70-140:",
743 for i
in range(364131, 364134):
747 print "\n\tRange 140-280:",
748 for i
in range(364134, 364137):
753 print "\n\tRange 280-500:",
754 for i
in range(364137, 364140):
758 print "\n\tRange 500-1000:",
759 dictionary[364140] = 5
760 dictionary[364220] = 5
763 print "\n\tRange 1000-ECMS:",
764 dictionary[364141] = 7
765 dictionary[364221] = 7
770 print "\nAdding Z--> nunu (2019 PTV filtered samples) to the dictionary"
772 print "\tRange 70-100:",
773 for i
in [366010,366019,366028]:
777 print "\n\tRange 100-140:",
778 for i
in [366011,366012,366013,366020,366021,366022,366029,366030,366031]:
782 print "\n\tRange 140-280:",
783 for i
in [366014,366015,366016,366023,366024,366025,366032,366033,366034]:
787 print "\n\tRange 280-500:",
788 for i
in [366017,366026,366035]:
792 print "\n\tRange 500-1000:",
797 print "\n\tRange 1000-ECMS:",
804 print "\nAdding W--> enu to the dictionary"
805 print "\tRange 0-70:",
806 for i
in range(364170, 364173):
810 print "\n\tRange 70-140:",
811 for i
in range(364173, 364176):
815 print "\n\tRange 140-280:",
816 for i
in range(364176, 364179):
821 print "\n\tRange 280-500:",
822 for i
in range(364179, 364182):
826 print "\n\tRange 500-1000:",
827 dictionary[364182] = 5
828 dictionary[364226] = 5
831 print "\n\tRange 1000-ECMS:",
832 dictionary[364183] = 7
833 dictionary[364227] = 7
838 print "\nAdding W--> munu to the dictionary"
839 print "\tRange 0-70:",
840 for i
in range(364156, 364159):
844 print "\n\tRange 70-140:",
845 for i
in range(364159, 364162):
849 print "\n\tRange 140-280:",
850 for i
in range(364162, 364165):
855 print "\n\tRange 280-500:",
856 for i
in range(364165, 364168):
860 print "\n\tRange 500-1000:",
861 dictionary[364168] = 5
862 dictionary[364224] = 5
865 print "\n\tRange 1000-ECMS:",
866 dictionary[364169] = 7
867 dictionary[364225] = 7
871 print "\nAdding W--> taunu to the dictionary"
872 print "\tRange 0-70:",
873 for i
in range(364184, 364187):
877 print "\n\tRange 70-140:",
878 for i
in range(364187, 364190):
882 print "\n\tRange 140-280:",
883 for i
in range(364190, 364193):
888 print "\n\tRange 280-500:",
889 for i
in range(364193, 364196):
893 print "\n\tRange 500-1000:",
894 dictionary[364196] = 5
895 dictionary[364228] = 5
898 print "\n\tRange 1000-ECMS:",
899 dictionary[364197] = 7
900 dictionary[364229] = 7
908 def main(infile, weightsFile, treename, attr_mcID, attr_nTruthJets):
909 print "Creating MCID, ZpT mapping"
913 print "Loading histograms with weights"
918 g = ROOT.TFile(weightsFile)
919 systList = [
"ckkw15",
"ckkw30",
"fac025",
"fac4",
"renorm025",
"renorm4",
"qsf025",
"qsf4"]
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)
930 f = ROOT.TFile(infile,
"update")
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.])
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")
955 print "Adding Weights"
956 nEvts = T.GetEntries()
958 for iEvt
in range(nEvts):
961 print '\x1b[2K\r',
"Current Event being Processed is: {0:15d}".
format(iEvt),
966 MCID = getattr(T, attr_mcID)
967 nTruthJets = getattr(T, attr_nTruthJets)
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)
983 decayType =
"dilepton"
986 (361444 <= MCID <= 361467)
or
987 (363412 <= MCID <= 363435)
or
988 (364142 <= MCID <= 364155)
or
989 (366010 <= MCID <= 366035)
or
990 (364222 <= MCID <= 364223)
992 decayType =
"nolepton"
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)
1006 decayType =
"onelepton"
1012 ZpTBin = ZpTMapping.get(MCID)
1013 TruthJetBin = nTruthJets+1
1014 if nTruthJets >= 11:
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)
1056 print '\x1b[2K\r',
"Missing entry for MCID={0}, nTruthJets={1}".
format(MCID, nTruthJets)
1063 renorm025branch.Fill()
1064 renorm4branch.Fill()
1068 print '\x1b[2K\r',
"All entries processed"
1071 print "Done with {0:s}/{1:s}.".
format(infile, treename)
1074 if __name__ ==
'__main__':
1081 parser = argparse.ArgumentParser(description=__doc__, usage=
'\033[93m%(prog)s\033[0m file.root [options]',
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=
'')
1089 args = parser.parse_args()
1091 main(args.file, args.weights, args.treename, args.mcID, args.nTruthJets)