Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PrintTrkAnaSummary.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 
4 import sys, os, argparse, ROOT
5 import pandas as pd
6 
7 # Parsing arguments
8 commandName = os.path.basename( sys.argv[0] )
9 summaryDirDefault="InDetTrackPerfMonPlots/&TrkAnaName&/Offline/Tracks/"
10 parser = argparse.ArgumentParser( description = commandName+" options:" )
11 parser.add_argument( "-t", "--testFile", help="Path to input TEST file" )
12 parser.add_argument( "-r", "--refFile", default="", help="Path to input REFERENCE file" )
13 parser.add_argument( "-T", "--testLabel", default="TEST", help="Label for TEST" )
14 parser.add_argument( "-R", "--refLabel", default="REF", help="Label for REFERENCE" )
15 parser.add_argument( "-d", "--dirName", default=summaryDirDefault, help="Name of the TDirectory path with plots" )
16 parser.add_argument( "-a", "--analyses", default="TrkAnaEF", help="Comma-separeted list of track analyses to process" )
17 parser.add_argument( "-o", "--outName", default="TrkAnaSummary_&TrkAnaName&.html", help="Name of the output html files" )
18 MyArgs = parser.parse_args()
19 anaList = MyArgs.analyses.strip().split(',')
20 
21 if not MyArgs.testFile:
22  print( "ERROR: input test file not provided" )
23  sys.exit(1)
24 
25 def processFile( inFileName, dirName, label, data, index, updateIndex=True ):
26  sList = []
27  inFile = ROOT.TFile.Open( inFileName, "READ" )
28 
29 
30  hs = inFile.Get( dirName+"Multiplicities/summary" )
31  if hs:
32  for i in range( 1, hs.GetNbinsX()+1 ) :
33  if updateIndex : index.append( hs.GetXaxis().GetBinLabel(i) )
34  c = hs.GetBinContent(i)
35  e = hs.GetBinError(i)
36  sList.append( f"{c:.1f} +/- {e:.1f}" )
37 
38 
39  he = inFile.Get( dirName+"Efficiencies/eff_vs_truth_inclusive" )
40  if updateIndex : index.append( " " )
41  sList.append( " " )
42  if updateIndex : index.append( "Eff_vs_truth" )
43  if he:
44  c = 100*he.GetEfficiency(1)
45  eu = 100*he.GetEfficiencyErrorUp(1)
46  el = 100*he.GetEfficiencyErrorLow(1)
47  sList.append( f"{c:.2f} +{eu:.2f}/-{el:.2f} %" )
48  else : sList.append( "-" )
49 
50 
51  het = inFile.Get( dirName+"Efficiencies/Technical/eff_vs_truth_inclusive" )
52  if updateIndex : index.append( "Tech_eff_vs_truth" )
53  if het:
54  c = 100*het.GetEfficiency(1)
55  eu = 100*het.GetEfficiencyErrorUp(1)
56  el = 100*het.GetEfficiencyErrorLow(1)
57  sList.append( f"{c:.2f} +{eu:.2f}/-{el:.2f} %" )
58  else : sList.append( "-" )
59 
60 
61 
62  hrpt = inFile.Get( dirName+"Resolutions/resolution_pt_vs_truth_inclusive" )
63  if updateIndex : index.append( " " )
64  sList.append( " " )
65  if updateIndex : index.append( "Resolution_pT_vs_truth" )
66  if hrpt:
67  c = hrpt.GetBinContent(1)
68  e = hrpt.GetBinError(1)
69  sList.append( f"{c:.2f} +/- {e:.2f} GeV" )
70  else : sList.append( "-" )
71 
72 
73 
74  hrd0 = inFile.Get( dirName+"Resolutions/resolution_d0_vs_truth_inclusive" )
75  if updateIndex : index.append( "Resolution_d0_vs_truth" )
76  if hrd0:
77  c = hrd0.GetBinContent(1)
78  e = hrd0.GetBinError(1)
79  sList.append( f"{c:.2f} +/- {e:.2f} mm" )
80  else : sList.append( "-" )
81 
82 
83 
84  hrz0 = inFile.Get( dirName+"Resolutions/resolution_z0_vs_truth_inclusive" )
85  if updateIndex : index.append( "Resolution_z0_vs_truth" )
86  if hrz0:
87  c = hrz0.GetBinContent(1)
88  e = hrz0.GetBinError(1)
89  sList.append( f"{c:.2f} +/- {e:.2f} mm" )
90  else : sList.append( "-" )
91 
92 
93 
94  hf = inFile.Get( dirName+"FakeRates/fakerate_vs_offl_inclusive" )
95  if updateIndex : index.append( " " )
96  sList.append( " " )
97  if updateIndex : index.append( "FakeRate_vs_reco" )
98  if hf:
99  c = 100*hf.GetEfficiency(1)
100  eu = 100*hf.GetEfficiencyErrorUp(1)
101  el = 100*hf.GetEfficiencyErrorLow(1)
102  sList.append( f"{c:.2f} +{eu:.2f}/-{el:.2f} %" )
103  else : sList.append( "-" )
104 
105 
106 
107  hd = inFile.Get( dirName+"Duplicates/duplrate_vs_truth_inclusive" )
108  if updateIndex : index.append( "DuplicateRate_vs_truth" )
109  if hd:
110  c = 100*hd.GetEfficiency(1)
111  eu = 100*hd.GetEfficiencyErrorUp(1)
112  el = 100*hd.GetEfficiencyErrorLow(1)
113  sList.append( f"{c:.2f} +{eu:.2f}/-{el:.2f} %" )
114  else : sList.append( "-" )
115 
116 
117 
118  data.update( { label : sList } )
119  inFile.Close()
120 
121 
122 outFile = MyArgs.outName.replace( "_&TrkAnaName&", "" )
123 if os.path.isfile( outFile ) :
124  os.remove( outFile )
125 
126 
127 for anaName in anaList :
128 
129  data = {}
130  index = []
131  anaDirName = MyArgs.dirName.replace( "&TrkAnaName&", anaName )
132  anaOutName = MyArgs.outName.replace( "&TrkAnaName&", anaName )
133 
134 
135  processFile(
136  inFileName = MyArgs.testFile,
137  dirName = anaDirName,
138  label = MyArgs.testLabel,
139  data = data,
140  index = index
141  )
142 
143 
144  if MyArgs.refFile :
145  processFile(
146  inFileName = MyArgs.refFile,
147  dirName = anaDirName,
148  label = MyArgs.refLabel,
149  data = data,
150  index = index,
151  updateIndex=False
152  )
153 
154 
155  df = pd.DataFrame( data, index=index )
156  titleStr = f"Summary for TrackAnalysis = {anaName}:"
157  print( f"\n\n---------------\n{titleStr}" )
158  print( df )
159 
160 
161  with open( anaOutName, 'w' ) as f :
162  print( df.to_html(), file=f )
163 
164 
165  os.system( f"echo \"<br><b>{titleStr}</b><br>\" >> {outFile}" )
166  os.system( f"cat {anaOutName} >> {outFile}" )
167  os.remove( f"{anaOutName}" )
168 
169 sys.exit(0)
PrintTrkAnaSummary.processFile
def processFile(inFileName, dirName, label, data, index, updateIndex=True)
Definition: PrintTrkAnaSummary.py:25
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
Trk::open
@ open
Definition: BinningType.h:40
Trk::split
@ split
Definition: LayerMaterialProperties.h:38