195 Main function to be executed when starting the code.
199 print(
'No filename given' )
200 print(
'Usage: python '+argv[0]+
' physval_filename [doAverage]' )
204 if not os.path.exists( filename ):
205 print (
'File not found: ' + filename )
208 if len(argv) > 2
and argv[2] ==
'doAverage':
213 infile = ROOT.TFile.Open( filename,
'update' )
215 muonTypesEff = [
'All',
'Prompt',
'InFlight',
'NonIsolated' ]
216 muonTypesReco = [
'Prompt',
'InFlight',
'NonIsolated',
'Rest' ]
217 Variables = [
'pt',
'eta',
'phi',
'eta_phi',
'eta_pt' ]
220 'pt' :
'p_{T} [GeV]',
224 'eta_pt' :
'p_{T} [GeV]' }
228 for muType
in muonTypesEff:
229 if not infile.Get(
'Muons/' + muType ):
230 print(
'INFO TDirectory not found: Muons/' + muType )
233 AuthDir = infile.Get(
'Muons/{0}/matched'.
format( muType ) )
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 )
242 print(
'WARNING Directory not found: '+truthDirName )
245 print(
'WARNING Directory not found: '+matchDirName )
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 )
253 print(
'WARNING histogram not found: '+truthHistName )
256 print(
'WARNING histogram not found: '+matchHistName )
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 )
272 for muType
in muonTypesReco:
273 if not infile.Get(
'Muons/' + muType ):
274 print(
'INFO TDirectory not found: Muons/' + muType )
277 AuthDir = infile.Get(
'Muons/{0}/matched'.
format( muType ) )
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 )
286 print(
'INFO TDirectory not found: '+typedir )
289 print(
'INFO TDirectory not found: '+alldir )
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 )
297 print(
'WARNING plot not found: ' + typeplot )
300 print(
'WARNING plot not found: ' + allplot )
302 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, xtitle = muType +
' Muon ' + Xtitles[var], plottype =
'RecoFrac', doAverage = doAverage )
307 if not infile.Get(
'Muons/' + muType ):
308 print(
'INFO TDirectory not found: Muons/' + muType )
311 AuthDir = infile.Get(
'Muons/{0}/matched'.
format( muType ) )
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 )
320 print(
'INFO TDirectory not found: '+typedir )
323 print(
'INFO TDirectory not found: '+alldir )
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 )
331 print(
'WARNING plot not found: ' + typeplot )
334 print(
'WARNING plot not found: ' + allplot )
336 CreateRatioPlot( infile, typeRecoHist, allRecoHist, var, xtitle = muType +
' Muon ' + Xtitles[var], plottype =
'purity', doAverage = doAverage )
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 )
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:
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 )
364 for var
in Variables:
365 typeplot =
'Muons_{0}__kinematics_{1}'.
format( muType, var )
366 allplot = alldir.replace(
'/',
'_') +
'_{0}'.
format( var )
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 )