9 from __future__
import print_function
17 input_file_name =
'/afs/cern.ch/user/j/juhofer/WORK/validation/data/QSP_on/valid1.410000.PowhegPythiaEvtGen_P2012_ttbar_hdamp172p5_nonallhad.merge.NTUP_PHYSVAL.e4993_s3641_r12287_p4360_p3821_tid24086162_00/NTUP_PHYSVAL.24086162._000001.pool.root.1'
20 production_process =
'ttbar'
24 jet_collections = [
'AntiKt2PV0TrackJets',
27 'AntiKt4PV0TrackJets',
28 'AntiKtVR30Rmax4Rmin02TrackJets']
32 if production_process
not in [
'ttbar',
'Zprime']:
33 print(
"Typo in the given production process: ", production_process,
". Exiting.")
37 'IP3D_b_matched_weight ',
38 'IP3D_b_matched_weight_trackCuts ',
39 'IP3D_b_50_matched_pt ',
40 'IP3D_b_70_matched_pt ',
41 'IP3D_b_80_matched_pt ',
42 'IP3D_c_matched_weight ',
43 'IP3D_c_matched_weight_trackCuts ',
44 'IP3D_c_50_matched_pt ',
45 'IP3D_c_70_matched_pt ',
46 'IP3D_c_80_matched_pt ',
47 'IP3D_tau_matched_weight ',
48 'IP3D_tau_matched_weight_trackCuts ',
49 'IP3D_tau_50_matched_pt ',
50 'IP3D_tau_70_matched_pt ',
51 'IP3D_tau_80_matched_pt ',
52 'IP3D_u_matched_weight ',
53 'IP3D_u_matched_weight_trackCuts ',
54 'IP3D_u_50_matched_pt ',
55 'IP3D_u_70_matched_pt ',
56 'IP3D_u_80_matched_pt ',
57 'IP2D_b_matched_weight ',
58 'IP2D_b_matched_weight_trackCuts ',
59 'IP2D_b_50_matched_pt ',
60 'IP2D_b_70_matched_pt ',
61 'IP2D_b_80_matched_pt ',
62 'IP2D_c_matched_weight ',
63 'IP2D_c_matched_weight_trackCuts ',
64 'IP2D_c_50_matched_pt ',
65 'IP2D_c_70_matched_pt ',
66 'IP2D_c_80_matched_pt ',
67 'IP2D_tau_matched_weight ',
68 'IP2D_tau_matched_weight_trackCuts ',
69 'IP2D_tau_50_matched_pt ',
70 'IP2D_tau_70_matched_pt ',
71 'IP2D_tau_80_matched_pt ',
72 'IP2D_u_matched_weight ',
73 'IP2D_u_matched_weight_trackCuts ',
74 'IP2D_u_50_matched_pt ',
75 'IP2D_u_70_matched_pt ',
76 'IP2D_u_80_matched_pt ',
77 'SV1_b_matched_weight ',
78 'SV1_b_matched_weight_trackCuts ',
79 'SV1_b_40_matched_pt ',
80 'SV1_b_50_matched_pt ',
81 'SV1_b_60_matched_pt ',
82 'SV1_c_matched_weight ',
83 'SV1_c_matched_weight_trackCuts ',
84 'SV1_c_40_matched_pt ',
85 'SV1_c_50_matched_pt ',
86 'SV1_c_60_matched_pt ',
87 'SV1_tau_matched_weight ',
88 'SV1_tau_matched_weight_trackCuts ',
89 'SV1_tau_40_matched_pt ',
90 'SV1_tau_50_matched_pt ',
91 'SV1_tau_60_matched_pt ',
92 'SV1_u_matched_weight ',
93 'SV1_u_matched_weight_trackCuts ',
94 'SV1_u_40_matched_pt ',
95 'SV1_u_50_matched_pt ',
96 'SV1_u_60_matched_pt ',
97 'JetFitter_b_matched_weight ',
98 'JetFitter_b_matched_weight_trackCuts ',
99 'JetFitter_b_50_matched_pt ',
100 'JetFitter_b_70_matched_pt ',
101 'JetFitter_b_80_matched_pt ',
102 'JetFitter_c_matched_weight ',
103 'JetFitter_c_matched_weight_trackCuts ',
104 'JetFitter_c_50_matched_pt ',
105 'JetFitter_c_70_matched_pt ',
106 'JetFitter_c_80_matched_pt ',
107 'JetFitter_tau_matched_weight ',
108 'JetFitter_tau_matched_weight_trackCuts ',
109 'JetFitter_tau_50_matched_pt ',
110 'JetFitter_tau_70_matched_pt ',
111 'JetFitter_tau_80_matched_pt ',
112 'JetFitter_u_matched_weight ',
113 'JetFitter_u_matched_weight_trackCuts ',
114 'JetFitter_u_50_matched_pt ',
115 'JetFitter_u_70_matched_pt ',
116 'JetFitter_u_80_matched_pt ',
138 'IP3DgradeOfTracks ',
139 'IP2DgradeOfTracks ',
140 'IP3D_valD0wrtPVofTracks ',
141 'IP3D_valZ0wrtPVofTracks ',
142 'IP3D_sigD0wrtPVofTracks ',
143 'IP3D_sigZ0wrtPVofTracks ',
144 'IP3D_weightBofTracks ',
145 'IP3D_weightUofTracks ',
146 'IP2D_weightBofTracks ',
147 'IP2D_weightUofTracks '
152 taggers = [
"_IP3D_",
"_SV1_",
"_JetFitter_"]
153 old_taggers = [
"_IP2D_"]
154 oneToOne_associations = {
155 '_truthLabel ':
'_jet_truthLabel ',
156 '_IP3Dpb ':
'_tagger_IP3D_pb ',
157 '_IP3Dpc ':
'_tagger_IP3D_pc ',
158 '_IP3Dpu ':
'_tagger_IP3D_pu ',
159 '_SV1pb ':
'_tagger_SV1_pb ',
160 '_SV1pc ':
'_tagger_SV1_pc ',
161 '_SV1pu ':
'_tagger_SV1_pu ',
162 '_NTracksIP3D ':
'_tagger_IP3D_NTracks_incl ',
163 '_NTracksIP2D ':
'_old_taggers_IP2D_NTracks_incl ',
164 '_NGTinSvx1 ':
'_tagger_SV1_nGoodTracks_incl ',
165 '_eta ':
'_jet_jet_eta ',
166 '_phi ':
'_jet_jet_phi ',
167 '_d0 ':
'_tracks_d0_b ',
168 '_z0 ':
'_tracks_z0_b ',
169 '_IP3DgradeOfTracks ':
'_tagger_IP3D_gradeOfTracks_incl ',
170 '_IP2DgradeOfTracks ':
'_old_taggers_IP2D_gradeOfTracks_incl ',
172 oneToOne_associations_ttbar = {
173 '_TruthBpt ':
'_jet_jet_pt_b_ttbar ',
174 '_TruthLpt ':
'_jet_jet_pt_l_ttbar ',
175 '_TruthCpt ':
'_jet_jet_pt_c_ttbar ',
176 '_e ':
'_jet_jet_e ',
177 '_pt ':
'_jet_jet_pt_ttbar ',
179 oneToOne_associations_Zprime = {
180 '_TruthBpt ':
'_jet_jet_pt_b_Zprime ',
181 '_TruthLpt ':
'_jet_jet_pt_l_Zprime ',
182 '_TruthCpt ':
'_jet_jet_pt_c_Zprime ',
183 '_e ':
'_jet_jet_e_Zprime ',
184 '_pt ':
'_jet_jet_pt_Zprime ',
187 name_associations = {}
194 new_name = new_name.replace(tag,
"_tagger" + tag)
196 for tag
in old_taggers:
198 new_name = new_name.replace(tag,
"_old_taggers" + tag)
200 if "_matched_pt" in new_name:
201 new_name = new_name.replace(
"_matched_pt",
"_matched_pt_" + production_process)
203 if "AntiKt4EMPFlowJets" in new_name:
204 new_name = new_name.replace(
"AntiKt4EMPFlowJets",
"AntiKt4EMPFlowJets_")
206 if "AntiKtVR30Rmax4Rmin02TrackJets" in new_name:
207 new_name = new_name.replace(
"AntiKtVR30Rmax4Rmin02TrackJets",
"AntiKtVR30Rmax4Rmin02TrackJets_")
209 for key
in oneToOne_associations:
211 new_name = new_name.replace(key, oneToOne_associations[key])
213 if production_process ==
'ttbar':
214 for key
in oneToOne_associations_ttbar:
216 new_name = new_name.replace(key, oneToOne_associations_ttbar[key])
218 if production_process ==
'Zprime':
219 for key
in oneToOne_associations_Zprime:
221 new_name = new_name.replace(key, oneToOne_associations_Zprime[key])
227 name = name.replace(
" ",
"")
228 new_name = new_name.replace(
" ",
"")
231 name_associations[name] = new_name
233 return name_associations
239 for jet_col
in jet_collections:
240 for var_name
in var_name_list:
241 if jet_col ==
"AntiKt4EMPFlowJets" or jet_col ==
"AntiKtVR30Rmax4Rmin02TrackJets":
242 name_list.append(
"BTag_" + jet_col + var_name)
244 name_list.append(
"BTag_" + jet_col +
"_" + var_name)
249 print(name_associations)
252 if input_file_name.endswith(
'.root'):
253 output_file_name = input_file_name[:-5] +
'_renamed.root'
254 elif input_file_name.endswith(
'.pool.root.1'):
255 output_file_name = input_file_name[:-12] +
'_renamed.pool.root.1'
257 print(
"Input file ending is not .root and not .pool.root.1, I can't handle the conversion to an output name.")
260 output_file = ROOT.TFile(output_file_name,
'RECREATE')
263 output_file.mkdir(
"BTag")
264 for jet_col
in jet_collections:
265 path =
"BTag/" + jet_col +
"/"
266 output_file.mkdir(path)
272 for jet_col
in jet_collections:
275 input_file = ROOT.TFile(input_file_name,
'READ')
277 if input_file.IsOpen():
280 path =
"BTag;1/" + jet_col +
";1/"
281 ROOT.gDirectory.cd(path)
284 print(
"\njust cd'ed into: " + path)
289 currentdir = ROOT.gDirectory.GetPath()
290 dirlist = input_file.Get(currentdir).GetListOfKeys()
293 print(
"\ndirlist\n", dirlist)
298 for subdir
in dirlist:
299 obj = subdir.ReadObj()
302 if obj.IsA().InheritsFrom(ROOT.TH1.Class())
and jet_col
in obj.GetName():
305 print(
"\nobj: ", obj)
306 print(
"'", obj.GetName(),
"'," )
309 if obj.GetName()
not in name_associations:
310 print(
"This name is not defined!!!", obj.GetName())
315 new_histo.SetName(name_associations[obj.GetName()])
316 histograms.append(new_histo)
319 output_file = ROOT.TFile(output_file_name,
'UPDATE')
321 if output_file.IsOpen():
323 ROOT.gDirectory.cd(path)
326 for histo
in histograms:
334 print(
"\n the output was written to:\n ", output_file_name)