194 """
195 Main function to be executed when starting the code.
196 """
197
198 if len( argv ) < 2:
199 print(
'No filename given' )
200 print(
'Usage: python '+argv[0]+
' physval_filename [doAverage]' )
201 exit(1)
202
203 filename = argv[1]
204 if not os.path.exists( filename ):
205 print ( 'File not found: ' + filename )
206 exit(1)
207
208 if len(argv) > 2 and argv[2] == 'doAverage':
209 doAverage = True
210 else:
211 doAverage = False
212
213 infile = ROOT.TFile.Open( filename, 'update' )
214
215 muonTypesEff = [ 'All', 'Prompt', 'InFlight', 'NonIsolated' ]
216 muonTypesReco = [ 'Prompt', 'InFlight', 'NonIsolated', 'Rest' ]
217 Variables = [ 'pt', 'eta', 'phi', 'eta_phi', 'eta_pt' ]
218
219 Xtitles = {
220 'pt' : 'p_{T} [GeV]',
221 'eta' : '|#eta|',
222 'phi' : '#phi',
223 'eta_phi' : '#phi',
224 'eta_pt' : 'p_{T} [GeV]' }
225
226
227 Authors = []
228 for muType in muonTypesEff:
229 if not infile.Get( 'Muons/' + muType ):
230 print(
'INFO TDirectory not found: Muons/' + muType )
231 continue
232
233 AuthDir = infile.Get( 'Muons/{0}/matched'.format( muType ) )
234 if Authors == []:
235 Authors = [ i.GetName() for i in AuthDir.GetListOfKeys() if AuthDir.Get( i.GetName() ).InheritsFrom( 'TDirectory' ) ]
236 for author in Authors:
237 truthDirName = 'Muons/{0}/truth/all'.format( muType )
238 matchDirName = 'Muons/{0}/matched/{1}/kinematics'.format( muType, author )
239 truthDir = infile.GetDirectory( truthDirName )
240 matchDir = infile.GetDirectory( matchDirName )
241 if not truthDir:
242 print(
'WARNING Directory not found: '+truthDirName )
243 continue
244 if not matchDir:
245 print(
'WARNING Directory not found: '+matchDirName )
246 continue
247 for var in Variables:
248 truthHistName = truthDirName.replace('/','_') + '_' + var
249 truthHist = truthDir.Get( truthHistName )
250 matchHistName = matchDirName.replace('/','_') + '_' + var
251 matchHist = matchDir.Get( matchHistName )
252 if not truthHist:
253 print(
'WARNING histogram not found: '+truthHistName )
254 continue
255 if not matchHist:
256 print(
'WARNING histogram not found: '+matchHistName )
257 continue
258 CreateRatioPlot( infile, matchHist, truthHist, var, xtitle = muType+' Muon '+Xtitles[var], plottype = 'eff', doAverage = doAverage )
259 if var == 'eta_phi' or var == 'eta_pt':
260 CreateRatioPlot( infile, matchHist, truthHist, var, doProjY, 0, 2.5, muType+' Muon '+Xtitles[var], plottype = 'eff', doAverage = doAverage )
261 CreateRatioPlot( infile, matchHist, truthHist, var, doProjY, 0, 0.1, muType+' Muon '+Xtitles[var], plottype = 'eff', doAverage = doAverage )
262 CreateRatioPlot( infile, matchHist, truthHist, var, doProjY, 0.1, 1.05, muType+' Muon '+Xtitles[var], plottype = 'eff', doAverage = doAverage )
263 CreateRatioPlot( infile, matchHist, truthHist, var, doProjY, 1.05, 2.0, muType+' Muon '+Xtitles[var], plottype = 'eff', doAverage = doAverage )
264 CreateRatioPlot( infile, matchHist, truthHist, var, doProjY, 2.0, 2.5, muType+' Muon '+Xtitles[var], plottype = 'eff', doAverage = doAverage )
265 CreateRatioPlot( infile, matchHist, truthHist, var, doProjY, 2.5, 2.7, muType+' Muon '+Xtitles[var], plottype = 'eff', doAverage = doAverage )
266 if var == 'eta_pt' and author == 'CaloTag' :
267 CreateRatioPlot( infile, matchHist, truthHist, var, doProjX, 10, 1000, muType+' Muon '+Xtitles['eta'], plottype = 'eff', doAverage = doAverage )
268 CreateRatioPlot( infile, matchHist, truthHist, var, doProjX, 15, 1000, muType+' Muon '+Xtitles['eta'], plottype = 'eff', doAverage = doAverage )
269 CreateRatioPlot( infile, matchHist, truthHist, var, doProjX, 20, 1000, muType+' Muon '+Xtitles['eta'], plottype = 'eff', doAverage = doAverage )
270 CreateRatioPlot( infile, matchHist, truthHist, var, doProjX, 25, 1000, muType+' Muon '+Xtitles['eta'], plottype = 'eff', doAverage = doAverage )
271
272 for muType in muonTypesReco:
273 if not infile.Get( 'Muons/' + muType ):
274 print(
'INFO TDirectory not found: Muons/' + muType )
275 continue
276
277 AuthDir = infile.Get( 'Muons/{0}/matched'.format( muType ) )
278 if Authors == []:
279 Authors = [ i.GetName() for i in AuthDir.GetListOfKeys() if AuthDir.Get( i.GetName() ).InheritsFrom( 'TDirectory' ) ]
280 for author in Authors:
281 typedir = 'Muons/{0}/reco/{1}/kinematics'.format( muType, author )
282 alldir = 'Muons/All/reco/{0}/kinematics'.format( author )
283 typeRecoDir = infile.Get( typedir )
284 allRecoDir = infile.Get( alldir )
285 if not typeRecoDir:
286 print(
'INFO TDirectory not found: '+typedir )
287 continue
288 if not allRecoDir:
289 print(
'INFO TDirectory not found: '+alldir )
290 continue
291 for var in Variables:
292 typeplot = typedir.replace('/','_') + '_' + var
293 allplot = alldir.replace('/','_') + '_' + var
294 typeRecoHist = typeRecoDir.Get( typeplot )
295 allRecoHist = allRecoDir.Get( allplot )
296 if not typeRecoHist:
297 print(
'WARNING plot not found: ' + typeplot )
298 continue
299 if not allRecoHist:
300 print(
'WARNING plot not found: ' + allplot )
301 continue
302 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, xtitle = muType + ' Muon ' + Xtitles[var], plottype = 'RecoFrac', doAverage = doAverage )
303
304
305
306 muType = 'All'
307 if not infile.Get( 'Muons/' + muType ):
308 print(
'INFO TDirectory not found: Muons/' + muType )
309 else:
310
311 AuthDir = infile.Get( 'Muons/{0}/matched'.format( muType ) )
312 if Authors == []:
313 Authors = [ i.GetName() for i in AuthDir.GetListOfKeys() if AuthDir.Get( i.GetName() ).InheritsFrom( 'TDirectory' ) ]
314 for author in Authors:
315 typedir = 'Muons/{0}/matched/{1}/kinematicsReco'.format( muType, author )
316 alldir = 'Muons/{0}/reco/{1}/kinematics'.format( muType, author )
317 typeRecoDir = infile.Get( typedir )
318 allRecoDir = infile.Get( alldir )
319 if not typeRecoDir:
320 print(
'INFO TDirectory not found: '+typedir )
321 continue
322 if not allRecoDir:
323 print(
'INFO TDirectory not found: '+alldir )
324 continue
325 for var in Variables:
326 typeplot = typedir.replace('/','_') + '_' + var
327 allplot = alldir.replace('/','_') + '_' + var
328 typeRecoHist = typeRecoDir.Get( typeplot )
329 allRecoHist = allRecoDir.Get( allplot )
330 if not typeRecoHist:
331 print(
'WARNING plot not found: ' + typeplot )
332 continue
333 if not allRecoHist:
334 print(
'WARNING plot not found: ' + allplot )
335 continue
336 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, xtitle = muType + ' Muon ' + Xtitles[var], plottype = 'purity', doAverage = doAverage )
337 if var == 'eta_pt':
338 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjX, 4, 500, muType+' Muon '+Xtitles['pt'], plottype = 'purity', doAverage = doAverage )
339 if var == 'eta_pt' and author == 'CaloTag' :
340 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjX, 10, 500, muType+' Muon '+Xtitles['pt'], plottype = 'purity', doAverage = doAverage )
341 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjX, 15, 500, muType+' Muon '+Xtitles['pt'], plottype = 'purity', doAverage = doAverage )
342 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjX, 20, 500, muType+' Muon '+Xtitles['pt'], plottype = 'purity', doAverage = doAverage )
343 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjX, 25, 500, muType+' Muon '+Xtitles['pt'], plottype = 'purity', doAverage = doAverage )
344 if (var == 'eta_phi' or var == 'eta_pt') and author is not 'CaloTag' :
345 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjY, 0, 0.1, muType+' Muon '+Xtitles[var], plottype = 'purity', doAverage = doAverage )
346 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjY, 0.1, 1.05, muType+' Muon '+Xtitles[var], plottype = 'purity', doAverage = doAverage )
347 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjY, 1.05, 2.0, muType+' Muon '+Xtitles[var], plottype = 'purity', doAverage = doAverage )
348 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjY, 2.0, 2.5, muType+' Muon '+Xtitles[var], plottype = 'purity', doAverage = doAverage )
349 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjY, 0, 2.5, muType+' Muon '+Xtitles[var], plottype = 'purity', doAverage = doAverage )
350 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, doProjY, 2.5, 2.7, muType+' Muon '+Xtitles[var], plottype = 'purity', doAverage = doAverage )
351
352
353 muType = 'UnmatchedRecoMuons'
354 typedir = 'Muons/{0}/kinematics'.format( muType )
355 allnames = [ i for i in Authors if i == 'AllMuons' or i == 'AllAuthors' ]
356 if len(allnames) == 0:
357 return
358 alldir = 'Muons/All/reco/{0}/kinematics'.format( allnames[0] )
359 if not infile.GetDirectory( typedir ):
360 print(
'INFO directory not found: ' + typedir )
361 elif not infile.GetDirectory( alldir ):
362 print(
'INFO directory not found: ' + alldir )
363 else:
364 for var in Variables:
365 typeplot = 'Muons_{0}__kinematics_{1}'.format( muType, var )
366 allplot = alldir.replace('/','_') + '_{0}'.format( var )
367
368 typeRecoHist = infile.GetDirectory( typedir ).
Get( typeplot )
369 allRecoHist = infile.GetDirectory( alldir ).
Get( allplot )
370 if typeRecoHist and allRecoHist:
371 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, xtitle = 'Unmatched Reco Muon '+Xtitles[var], plottype = 'RecoFrac', doAverage = doAverage )
372 infile.Close()
373
374
375
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...