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/TrkAnaEF/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( "-o", "--outName", default="TrkAnaSummary.html", help="Name of the output html file" )
17 MyArgs = parser.parse_args()
18 
19 if not MyArgs.testFile:
20  print( "ERROR: input test file not provided" )
21  sys.exit(1)
22 
23 data={}
24 index=[]
25 
26 def processFile( inFileName, dirName, label, data, index, updateIndex=True ):
27  sList = []
28  inFile = ROOT.TFile.Open( inFileName, "READ" )
29 
30 
31  hs = inFile.Get( dirName+"Multiplicities/summary" )
32  if hs:
33  for i in range( 1, hs.GetNbinsX()+1 ) :
34  if updateIndex : index.append( hs.GetXaxis().GetBinLabel(i) )
35  c = hs.GetBinContent(i)
36  e = hs.GetBinError(i)
37  sList.append( f"{c:.1f} +/- {e:.1f}" )
38 
39 
40  he = inFile.Get( dirName+"Efficiencies/eff_vs_truth_inclusive" )
41  if updateIndex : index.append( " " )
42  sList.append( " " )
43  if updateIndex : index.append( "Eff_vs_truth" )
44  if he:
45  c = 100*he.GetEfficiency(1)
46  eu = 100*he.GetEfficiencyErrorUp(1)
47  el = 100*he.GetEfficiencyErrorLow(1)
48  sList.append( f"{c:.2f} +{eu:.2f}/-{el:.2f} %" )
49  else : sList.append( "-" )
50 
51 
52  het = inFile.Get( dirName+"Efficiencies/Technical/eff_vs_truth_inclusive" )
53  if updateIndex : index.append( "Tech_eff_vs_truth" )
54  if het:
55  c = 100*het.GetEfficiency(1)
56  eu = 100*het.GetEfficiencyErrorUp(1)
57  el = 100*het.GetEfficiencyErrorLow(1)
58  sList.append( f"{c:.2f} +{eu:.2f}/-{el:.2f} %" )
59  else : sList.append( "-" )
60 
61 
62 
63  hrpt = inFile.Get( dirName+"Resolutions/resolution_pt_vs_truth_inclusive" )
64  if updateIndex : index.append( " " )
65  sList.append( " " )
66  if updateIndex : index.append( "Resolution_pT_vs_truth" )
67  if hrpt:
68  c = hrpt.GetBinContent(1)
69  e = hrpt.GetBinError(1)
70  sList.append( f"{c:.2f} +/- {e:.2f} GeV" )
71  else : sList.append( "-" )
72 
73 
74 
75  hrd0 = inFile.Get( dirName+"Resolutions/resolution_d0_vs_truth_inclusive" )
76  if updateIndex : index.append( "Resolution_d0_vs_truth" )
77  if hrd0:
78  c = hrd0.GetBinContent(1)
79  e = hrd0.GetBinError(1)
80  sList.append( f"{c:.2f} +/- {e:.2f} mm" )
81  else : sList.append( "-" )
82 
83 
84 
85  hrz0 = inFile.Get( dirName+"Resolutions/resolution_z0_vs_truth_inclusive" )
86  if updateIndex : index.append( "Resolution_z0_vs_truth" )
87  if hrz0:
88  c = hrz0.GetBinContent(1)
89  e = hrz0.GetBinError(1)
90  sList.append( f"{c:.2f} +/- {e:.2f} mm" )
91  else : sList.append( "-" )
92 
93 
94 
95  hf = inFile.Get( dirName+"FakeRates/fakerate_vs_offl_inclusive" )
96  if updateIndex : index.append( " " )
97  sList.append( " " )
98  if updateIndex : index.append( "FakeRate_vs_reco" )
99  if hf:
100  c = 100*hf.GetEfficiency(1)
101  eu = 100*hf.GetEfficiencyErrorUp(1)
102  el = 100*hf.GetEfficiencyErrorLow(1)
103  sList.append( f"{c:.2f} +{eu:.2f}/-{el:.2f} %" )
104  else : sList.append( "-" )
105 
106 
107 
108  hd = inFile.Get( dirName+"Duplicates/duplrate_vs_truth_inclusive" )
109  if updateIndex : index.append( "DuplicateRate_vs_truth" )
110  if hd:
111  c = 100*hd.GetEfficiency(1)
112  eu = 100*hd.GetEfficiencyErrorUp(1)
113  el = 100*hd.GetEfficiencyErrorLow(1)
114  sList.append( f"{c:.2f} +{eu:.2f}/-{el:.2f} %" )
115  else : sList.append( "-" )
116 
117 
118 
119  data.update( { label : sList } )
120  inFile.Close()
121 
122 
123 
125  inFileName = MyArgs.testFile,
126  dirName = MyArgs.dirName,
127  label = MyArgs.testLabel,
128  data = data,
129  index = index
130 )
131 
132 
133 if MyArgs.refFile :
134  processFile(
135  inFileName = MyArgs.refFile,
136  dirName = MyArgs.dirName,
137  label = MyArgs.refLabel,
138  data = data,
139  index = index,
140  updateIndex=False
141  )
142 
143 
144 df = pd.DataFrame( data, index=index )
145 print( df )
146 
147 
148 with open( MyArgs.outName, 'w' ) as f :
149  print( df.to_html(), file=f )
150 
151 sys.exit(0)
PrintTrkAnaSummary.processFile
def processFile(inFileName, dirName, label, data, index, updateIndex=True)
Definition: PrintTrkAnaSummary.py:26
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