4 import sys, os, argparse, ROOT
7 from uncertainties
import ufloat
as rd
10 commandName = os.path.basename( sys.argv[0] )
11 summaryDirDefault=
"InDetTrackPerfMonPlots/&TrkAnaName&/Offline/Tracks/"
12 parser = argparse.ArgumentParser( description = commandName+
" options:" )
13 parser.add_argument(
"-t",
"--testFile", help=
"Path to input TEST file" )
14 parser.add_argument(
"-r",
"--refFile", default=
"", help=
"Path to input REFERENCE file" )
15 parser.add_argument(
"-T",
"--testLabel", default=
"TEST", help=
"Label for TEST" )
16 parser.add_argument(
"-R",
"--refLabel", default=
"REF", help=
"Label for REFERENCE" )
17 parser.add_argument(
"-d",
"--dirName", default=summaryDirDefault, help=
"Name of the TDirectory path with plots" )
18 parser.add_argument(
"-a",
"--analyses", default=
"TrkAnaEF", help=
"Comma-separeted list of track analyses to process" )
19 parser.add_argument(
"-o",
"--outName", default=
"TrkAnaSummary_&TrkAnaName&.html", help=
"Name of the output html files" )
20 MyArgs = parser.parse_args()
21 anaList = MyArgs.analyses.strip().
split(
',')
23 if not MyArgs.testFile:
24 print(
"ERROR: input test file not provided" )
29 res =
str( rd( c, e ) )
30 return res.replace(
'+/-',
' \u00b1 ' ).
replace(
'(',
'( ' ).
replace(
')',
' )' )
32 def processFile( inFileName, dirName, label, data, dataDict, index, updateIndex=True, printMultiplicity=True ):
33 if updateIndex: index.clear()
36 inFile = ROOT.TFile.Open( inFileName,
"READ" )
40 hs = inFile.Get( dirName+
"Multiplicities/summary" )
41 for i
in range( 1, 8 ) :
43 if updateIndex : index.append( hs.GetXaxis().GetBinLabel(i) )
44 c = hs.GetBinContent(i)
46 sList.append( f
"{c:.0f} \u00b1 {e:.0f}" )
47 sDict.update( {
"mult_"+
str(i) : [ c, e ] } )
49 if updateIndex : index.append(
" ")
53 he = inFile.Get( dirName+
"Efficiencies/eff_vs_truth_inclusive" )
54 if updateIndex : index.append(
" " )
56 if updateIndex : index.append(
"Eff_vs_truth" )
58 c = 100*he.GetEfficiency(1)
59 eu = 100*he.GetEfficiencyErrorUp(1)
60 el = 100*he.GetEfficiencyErrorLow(1)
62 sList.append( f
"{fround( c, e )} %" )
63 sDict.update( {
"eff" : [ c, e ] } )
64 else : sList.append(
"-" )
67 het = inFile.Get( dirName+
"Efficiencies/Technical/eff_vs_truth_inclusive" )
68 if updateIndex : index.append(
"Tech_eff_vs_truth" )
70 c = 100*het.GetEfficiency(1)
71 eu = 100*het.GetEfficiencyErrorUp(1)
72 el = 100*het.GetEfficiencyErrorLow(1)
74 sList.append( f
"{fround( c, e )} %" )
75 sDict.update( {
"tech_eff" : [ c, e ] } )
76 else : sList.append(
"-" )
80 hrpt = inFile.Get( dirName+
"Resolutions/resolution_pt_vs_truth_inclusive" )
81 if updateIndex : index.append(
" " )
83 if updateIndex : index.append(
"Resolution_pT_vs_truth" )
85 c = hrpt.GetBinContent(1)
86 e = hrpt.GetBinError(1)
87 sList.append( f
"{fround( c, e )} GeV" )
88 sDict.update( {
"res_pt" : [ c, e ] } )
89 else : sList.append(
"-" )
93 hrd0 = inFile.Get( dirName+
"Resolutions/resolution_d0_vs_truth_inclusive" )
94 if updateIndex : index.append(
"Resolution_d0_vs_truth" )
96 c = hrd0.GetBinContent(1)
97 e = hrd0.GetBinError(1)
98 sList.append( f
"{fround( c, e )} \u03BCm" )
99 sDict.update( {
"res_d0" : [ c, e ] } )
100 else : sList.append(
"-" )
104 hrz0 = inFile.Get( dirName+
"Resolutions/resolution_z0_vs_truth_inclusive" )
105 if updateIndex : index.append(
"Resolution_z0_vs_truth" )
107 c = hrz0.GetBinContent(1)
108 e = hrz0.GetBinError(1)
109 sList.append( f
"{fround( c, e )} \u03BCm" )
110 sDict.update( {
"res_z0" : [ c, e ] } )
111 else : sList.append(
"-" )
115 hf = inFile.Get( dirName+
"FakeRates/fakerate_vs_offl_inclusive" )
116 if updateIndex : index.append(
" " )
118 if updateIndex : index.append(
"FakeRate_vs_reco" )
120 c = 100*hf.GetEfficiency(1)
121 eu = 100*hf.GetEfficiencyErrorUp(1)
122 el = 100*hf.GetEfficiencyErrorLow(1)
123 e =
max( [ eu, el ] )
124 sList.append( f
"{fround( c, e )} %" )
125 sDict.update( {
"fake" : [ c, e ] } )
126 else : sList.append(
"-" )
130 hd = inFile.Get( dirName+
"Duplicates/duplrate_vs_truth_inclusive" )
131 if updateIndex : index.append(
"DuplicateRate_vs_truth" )
133 c = 100*hd.GetEfficiency(1)
134 eu = 100*hd.GetEfficiencyErrorUp(1)
135 el = 100*hd.GetEfficiencyErrorLow(1)
136 e =
max( [ eu, el ] )
137 sList.append( f
"{fround( c, e )} %" )
138 sDict.update( {
"dupl" : [ c, e ] } )
139 else : sList.append(
"-" )
143 data.update( { label : sList } )
144 dataDict.update( { label : sDict } )
152 ce = math.sqrt( ( ae / b )**2 + ( a * be / b**2 )**2 )
159 if printMultiplicity:
160 for i
in range( 1, 8 ) :
161 if "mult_"+
str(i)
in dataDict[ltest]
and "mult_"+
str(i)
in dataDict[lref] :
162 c, e =
getRatio( dataDict[ltest][
"mult_"+
str(i)][0],
163 dataDict[ltest][
"mult_"+
str(i)][1],
164 dataDict[lref][
"mult_"+
str(i)][0],
165 dataDict[lref][
"mult_"+
str(i)][1] )
166 sList.append( f
"{fround( c, e )}" )
172 if "eff" in dataDict[ltest]
and "eff" in dataDict[lref] :
173 c, e =
getRatio( dataDict[ltest][
"eff"][0],
174 dataDict[ltest][
"eff"][1],
175 dataDict[lref][
"eff"][0],
176 dataDict[lref][
"eff"][1] )
179 sList.append( f
"{fround( c, e )} %" )
180 else : sList.append(
"-" )
183 if "tech_eff" in dataDict[ltest]
and "tech_eff" in dataDict[lref] :
184 c, e =
getRatio( dataDict[ltest][
"tech_eff"][0],
185 dataDict[ltest][
"tech_eff"][1],
186 dataDict[lref][
"tech_eff"][0],
187 dataDict[lref][
"tech_eff"][1] )
190 sList.append( f
"{fround( c, e )} %" )
191 else : sList.append(
"-" )
196 if "res_pt" in dataDict[ltest]
and "res_pt" in dataDict[lref] :
197 c, e =
getRatio( dataDict[ltest][
"res_pt"][0],
198 dataDict[ltest][
"res_pt"][1],
199 dataDict[lref][
"res_pt"][0],
200 dataDict[lref][
"res_pt"][1] )
201 sList.append( f
"{fround( c, e )}" )
202 else : sList.append(
"-" )
206 if "res_d0" in dataDict[ltest]
and "res_d0" in dataDict[lref] :
207 c, e =
getRatio( dataDict[ltest][
"res_d0"][0],
208 dataDict[ltest][
"res_d0"][1],
209 dataDict[lref][
"res_d0"][0],
210 dataDict[lref][
"res_d0"][1] )
211 sList.append( f
"{fround( c, e )}" )
212 else : sList.append(
"-" )
216 if "res_z0" in dataDict[ltest]
and "res_z0" in dataDict[lref] :
217 c, e =
getRatio( dataDict[ltest][
"res_z0"][0],
218 dataDict[ltest][
"res_z0"][1],
219 dataDict[lref][
"res_z0"][0],
220 dataDict[lref][
"res_z0"][1] )
221 sList.append( f
"{fround( c, e )}" )
222 else : sList.append(
"-" )
227 if "fake" in dataDict[ltest]
and "fake" in dataDict[lref] :
228 c, e =
getRatio( dataDict[ltest][
"fake"][0],
229 dataDict[ltest][
"fake"][1],
230 dataDict[lref][
"fake"][0],
231 dataDict[lref][
"fake"][1] )
232 sList.append( f
"{fround( c, e )}" )
233 else : sList.append(
"-" )
237 if "dupl" in dataDict[ltest]
and "dupl" in dataDict[lref] :
238 c, e =
getRatio( dataDict[ltest][
"dupl"][0],
239 dataDict[ltest][
"dupl"][1],
240 dataDict[lref][
"dupl"][0],
241 dataDict[lref][
"dupl"][1] )
242 sList.append( f
"{fround( c, e )}" )
243 else : sList.append(
"-" )
247 data.update( { ltest +
" / " + lref : sList } )
250 outFile = MyArgs.outName.replace(
"_&TrkAnaName&",
"" )
251 if os.path.isfile( outFile ) :
255 for anaName
in anaList :
260 anaDirName = MyArgs.dirName.replace(
"&TrkAnaName&", anaName )
261 anaOutName = MyArgs.outName.replace(
"&TrkAnaName&", anaName )
263 testFile = ROOT.TFile.Open( MyArgs.testFile,
"READ" )
264 testMultiplicity = testFile.Get( anaDirName+
"Multiplicities/summary" )
267 refFile = ROOT.TFile.Open( MyArgs.refFile,
"READ" )
268 refMultiplicity = refFile.Get( anaDirName+
"Multiplicities/summary" )
271 printMultiplicity = refMultiplicity
or testMultiplicity
274 inFileName = MyArgs.testFile,
275 dirName = anaDirName,
276 label = MyArgs.testLabel,
280 printMultiplicity = printMultiplicity
286 inFileName = MyArgs.refFile,
287 dirName = anaDirName,
288 label = MyArgs.refLabel,
292 updateIndex =
not testMultiplicity,
293 printMultiplicity = printMultiplicity
299 ltest = MyArgs.testLabel,
300 lref = MyArgs.refLabel,
303 printMultiplicity = printMultiplicity
307 df = pd.DataFrame( data, index=index )
308 titleStr = f
"Summary for TrackAnalysis = {anaName}:"
309 print( f
"\n\n---------------\n{titleStr}" )
313 with open( anaOutName,
'w' )
as f :
317 os.system( f
"echo \"<br><b>{titleStr}</b><br>\" >> {outFile}" )
318 os.system( f
"cat {anaOutName} >> {outFile}" )
319 os.remove( f
"{anaOutName}" )