-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_script.py
220 lines (205 loc) · 9.11 KB
/
gen_script.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
###this file is used to generate reweighting instructions
import ROOT, helpers
import config as CONF
import argparse, copy, glob, os, sys, time
temp_dic = {"j0_trk0_pt":"leadHCand_trk0_Pt",
"j0_trk1_pt":"leadHCand_trk1_Pt",
"j1_trk0_pt":"sublHCand_trk0_Pt",
"j1_trk1_pt":"sublHCand_trk1_Pt",
"j0_pt":"leadHCand_Pt_m",
"j1_pt":"sublHCand_Pt_m"}
#define functions
def options():
parser = argparse.ArgumentParser()
parser.add_argument("--plotter")
parser.add_argument("--inputdir", default=CONF.workdir)
parser.add_argument("--full", default=False) #4times more time
return parser.parse_args()
#currently reweighting all of them at once...may not be optimal...
def write_reweight(fname="TEST", reweight_dic={},
region_dic = [("2bs", "TwoTag_split_Sideband"), ("3b","ThreeTag_Sideband"), ("4b","FourTag_Sideband")], split=False, cond=False):
'''write reweight output '''
motherfolder="Moriond"
helpers.checkpath("script")
#building the inputdictionary
#creat an empty dictionary
#ready to dump file
f = open("script/" + fname + ".txt", "w")
#make sure over write everytime!
f.truncate()
f.write( "#reweighting script for hh4b analysis \n")
#iteration; Ntrk; parameter; inputfolder; parameterfile
for i in range(iteration):
f.write( "#iteration:" + str(i) + "\n")
#space is very important!!!!
for region, region_fname in region_dic:
for var, var_fname in reweight_dic.iteritems():
if split: #this is to reweight leading pT and trk pT seperately
if "j0_" in var and i%2 == 1: #for even skip j0_pt
continue
elif "j0_" not in var and i%2 != 1: #for odd, skip other
continue
# if "j0_pt" in var and i%4 > 1: #for even skip j0_pt
# continue
# elif "j0_pt" not in var and i%4 <= 1: #for odd, skip other
# continue
##notice this onlyputs condition on subl, lead reweighting; reweight lead's subl and subl's lead
#print region_fname, var_fname, ("lead_subl" in region_fname), ("lead" in var_fname)
if (("lead_lead" in region_fname) or ("lead_subl" in region_fname)):
if "lead" in var_fname:
continue
elif (("subl_lead" in region_fname) or ("subl_subl" in region_fname)):
if "subl" in var_fname:
continue
elif "lead" in region_fname:
if "lead" in var_fname:
continue
elif "subl" in region_fname:
if "subl" in var_fname:
continue
templine = ""
templine += str(i) + " " #iteration
templine += region + " " #Ntrk
templine += "event." + var + " " #parameter
templine += motherfolder + ("_" + fname + "_" + str(i-1) if i!= 0 else "") + " " #look for the original iteration
templine += "r" + str(i) + "_" + region_fname + "_" + var_fname + ".txt" + " " #parameterfile;
##add in condition; be very careful, this means the TinyNtuple has to be produced with the correct b-tagging MV2Cut
##also the definition of condition needs to agree with the PlotTinyTree region condition!!! STUPID but be very careful!!!
if cond:
if "2Trk_split_lead_Incl" in region_fname:
templine += "((event.j0_nb==1)and(event.j1_nb==0))" + " " #condition
if "2Trk_split_subl_Incl" in region_fname:
templine += "((event.j0_nb==0)and(event.j1_nb==1))" + " " #condition
# if "2Trk_split_lead_lead_Incl" in region_fname:
# templine += "((event.j0_nb==1)and(event.j1_nb==0)and(event.j0_trk0_Mv2>0.6455))" + " " #condition
# if "2Trk_split_subl_lead_Incl" in region_fname:
# templine += "((event.j0_nb==0)and(event.j1_nb==1)and(event.j1_trk0_Mv2>0.6455))" + " " #condition
# if "2Trk_split_lead_subl_Incl" in region_fname:
# templine += "((event.j0_nb==1)and(event.j1_nb==0)and(event.j0_trk0_Mv2<0.6455))" + " " #condition
# if "2Trk_split_subl_subl_Incl" in region_fname:
# templine += "((event.j0_nb==0)and(event.j1_nb==1)and(event.j1_trk0_Mv2<0.6455))" + " " #condition
if "3Trk_lead" in region_fname:
templine += "((event.j0_nb==2)and(event.j1_nb==0))" + " " #condition
if "3Trk_subl" in region_fname:
templine += "((event.j0_nb==0)and(event.j1_nb==2))" + " " #condition
if "4Trk_lead" in region_fname:
templine += "((event.j0_nb==2)and(event.j1_nb==0))" + " " #condition
if "4Trk_subl" in region_fname:
templine += "((event.j0_nb==0)and(event.j1_nb==2))" + " " #condition
templine += "\n"
print templine
f.write(templine)
#finish
f.close()
#do everything in one main?
def main():
global iteration
iteration = 10
# #next one; alltrk
# reweight_dic = {
# "j0_trk0_pt":"leadHCand_trk0_Pt",
# "j0_trk1_pt":"leadHCand_trk1_Pt",
# "j1_trk0_pt":"sublHCand_trk0_Pt",
# "j1_trk1_pt":"sublHCand_trk1_Pt",
# "j0_pt":"leadHCand_Pt_m",
# }
# write_reweight("j0pT-alltrk-fin", reweight_dic)
# #next one; leadtrk
# reweight_dic = {
# "j0_trk0_pt":"leadHCand_trk0_Pt",
# "j1_trk0_pt":"sublHCand_trk0_Pt",
# "j0_pt":"leadHCand_Pt_m",
# }
# write_reweight("j0pT-leadtrk-fin", reweight_dic)
#next one; leadtrk + dr
# reweight_dic = {
# "j0_trk0_pt":"leadHCand_trk0_Pt",
# "j0_trkdr":"leadHCand_trk_dr",
# "j1_trk0_pt":"sublHCand_trk0_Pt",
# "j1_trkdr":"sublHCand_trk_dr",
# "j0_pt":"leadHCand_Pt_m",
# }
# write_reweight("j0pT-leadtrk-trkdr-fin", reweight_dic)
# #next one; subltrk
# reweight_dic = {
# "j0_trk1_pt":"leadHCand_trk1_Pt",
# "j1_trk1_pt":"sublHCand_trk1_Pt",
# "j0_pt":"leadHCand_Pt_m",
# }
# write_reweight("j0pT-subltrk-fin", reweight_dic)
# #next one; trks_Pt
# reweight_dic = {
# "j0_trk0_pt":"trks_Pt",
# "j0_trk1_pt":"trks_Pt",
# "j1_trk0_pt":"trks_Pt",
# "j1_trk1_pt":"trks_Pt",
# "j0_pt":"leadHCand_Pt_m",
# }
# write_reweight("j0pT-trks-fin", reweight_dic)
reweight_dic = {
"j0_trk0_pt":"leadHCand_trk0_Pt",
"j0_trk1_pt":"leadHCand_trk1_Pt",
"j1_trk0_pt":"sublHCand_trk0_Pt",
"j1_trk1_pt":"sublHCand_trk1_Pt",
#"j0_pt":"leadHCand_Pt_m",
#"j1_pt":"sublHCand_Pt_m",
#"j0_eta":"leadHCand_Eta",
#"j1_eta":"sublHCand_Eta",
#"j0_trkdr":"leadHCand_trk_dr",
#"j1_trkdr":"sublHCand_trk_dr",
}
region_dic = [
("2bs","NoTag_2Trk_split_lead_Incl"),
("2bs", "NoTag_2Trk_split_subl_Incl"),
("3b", "NoTag_3Trk_lead_Incl"),
("3b", "NoTag_3Trk_subl_Incl"),
("4b", "NoTag_4Trk_lead_Incl"),
("4b", "NoTag_4Trk_subl_Incl"),
]
write_reweight("bkgtrk", reweight_dic, region_dic, cond=True)
# reweight_dic = {
# "j0_trk0_pt":"leadHCand_trk0_Pt",
# "j0_trk1_pt":"leadHCand_trk1_Pt",
# "j1_trk0_pt":"sublHCand_trk0_Pt",
# "j1_trk1_pt":"sublHCand_trk1_Pt",
# "j0_pt":"leadHCand_Pt_m",
# "j1_pt":"sublHCand_Pt_m",
# #"j0_eta":"leadHCand_Eta",
# #"j1_eta":"sublHCand_Eta",
# #"j0_trkdr":"leadHCand_trk_dr",
# #"j1_trkdr":"sublHCand_trk_dr",
# }
# region_dic = [
# ("2bs","NoTag_2Trk_split_lead_Sideband"),
# ("2bs", "NoTag_2Trk_split_subl_Sideband"),
# ("3b", "NoTag_3Trk_lead_Sideband"),
# ("3b", "NoTag_3Trk_subl_Sideband"),
# ("4b", "NoTag_4Trk_lead_Sideband"),
# ("4b", "NoTag_4Trk_subl_Sideband"),
# ]
# write_reweight("bkgsb", reweight_dic, region_dic, cond=True)
# reweight_dic = {
# "j0_trk0_pt":"leadHCand_trk0_Pt",
# "j0_trk1_pt":"leadHCand_trk1_Pt",
# "j1_trk0_pt":"sublHCand_trk0_Pt",
# "j1_trk1_pt":"sublHCand_trk1_Pt",
# "j0_pt":"leadHCand_Pt_m",
# "j1_pt":"sublHCand_Pt_m",
# #"j0_eta":"leadHCand_Eta",
# #"j1_eta":"sublHCand_Eta",
# }
# region_dic = [
# ("2bs","NoTag_2Trk_split_lead_lead_Incl"),
# ("2bs","NoTag_2Trk_split_subl_lead_Incl"),
# ("2bs","NoTag_2Trk_split_lead_subl_Incl"),
# ("2bs","NoTag_2Trk_split_subl_subl_Incl"),
# ("3b", "NoTag_3Trk_lead_Incl"),
# ("3b", "NoTag_3Trk_subl_Incl"),
# ("4b", "NoTag_4Trk_lead_Incl"),
# ("4b", "NoTag_4Trk_subl_Incl"),
# ]
# write_reweight("bkg_test", reweight_dic, region_dic, cond=True)
print "DONE"
### end
if __name__ == "__main__":
main()