15 from ROOT
import TFile
16 from ROOT
import TProfile,TH1F
17 from ROOT
import TCanvas
18 from ROOT
import gStyle,gPad,gROOT
19 from ROOT
import kBlack,kOrange,kGreen
22 sys.path.append(
"/afs/cern.ch/user/l/larmon/public/prod/Misc")
24 from DeMoLib
import strLumi,plotStack,initializeMonitoredDefects,retrieveYearTagProperties,MakeTH1,SetXLabel,MakeTProfile
33 nb_letter = tprof_letter.GetNbinsX()
34 nb_subperiod = tprof_subperiod.GetNbinsX()
35 for iBin
in range(1,nb_letter):
36 index_letter[tprof_letter.GetXaxis().GetBinLabel(iBin)] = iBin
38 for iBin
in range(1,nb_subperiod):
39 letter = tprof_subperiod.GetXaxis().GetBinLabel(iBin)[0]
40 if (tprof_letter.IsA().InheritsFrom(
"TProfile")):
41 tprof_letter.Fill(index_letter[letter]-1,tprof_subperiod.GetBinContent(iBin),tprof_subperiod.GetBinEntries(iBin))
42 tprof_letter.Fill(nb_letter-1,tprof_subperiod.GetBinContent(iBin),tprof_subperiod.GetBinEntries(iBin))
43 elif (tprof_letter.IsA().InheritsFrom(
"TH1")):
44 tprof_letter.Fill(index_letter[letter]-1,tprof_subperiod.GetBinContent(iBin))
45 tprof_letter.Fill(nb_letter-1,tprof_subperiod.GetBinContent(iBin))
52 from ROOT
import TLatex
57 l.DrawLatex(x,y,
"ATLAS")
58 delx = 0.115*696*gPad.GetWh()/(472*gPad.GetWw())
63 p.DrawLatex(x+delx,y,text);
71 from argparse
import RawTextHelpFormatter,ArgumentParser
72 from ROOT
import gROOT
74 parser = ArgumentParser(description=
'',formatter_class=RawTextHelpFormatter)
75 parser.add_argument(
'-y',
'--year',dest=
'parser_year',default = [
"2022"],nargs=
'*',help=
'Year [Default: 2022]',action=
'store')
76 parser.add_argument(
'-t',
'--tag',dest=
'parser_tag',default = [
"AtlasReady"],nargs=
'*',help=
'Defect tag [Default: "AtlasReady"]',action=
'store')
77 parser.add_argument(
'-s',
'--system',dest=
'parser_system',default=
"LAr",help=
'System: LAr, CaloCP [Default: "LAr"]',action=
'store')
78 parser.add_argument(
'-d',
'--directory',dest=
'parser_directory',default=
"./",help=
'Directory to display',action=
'store')
79 parser.add_argument(
'-b',
'--batch',dest=
'parser_batchMode',help=
'Batch mode',action=
'store_true')
80 parser.add_argument(
'--yearStats',dest=
'parser_plotYS',help=
'Plot the year stats per period',action=
'store_true')
81 parser.add_argument(
'--yearStatsLarge',dest=
'parser_letterYS',help=
'Plot the year stats as a function of the letter (large) periods',action=
'store_true')
82 parser.add_argument(
'--lumiNotPercent',dest=
'parser_lumiNotPercent',help=
'Display results in term of lumi and not percent',action=
'store_true')
83 parser.add_argument(
'--noRecovPlot',dest=
'parser_noRecovPlot',help=
'Do not plot the recoverable histograms',action=
'store_false')
84 parser.add_argument(
'--savePlots',dest=
'parser_savePlots',help=
'Save yearStats results in ~larmon/public/prod/LADIeS/DeMoPlots',action=
'store_true')
85 parser.add_argument(
'--approvedPlots',dest=
'parser_approvedPlots',help=
'Cosmetics to get the approved plots',action=
'store_true')
86 parser.add_argument(
'--noSingleTagPlot',dest=
'parser_noSingleTagPlot',help=
'When > 1 tag, display only comparison plots',action=
'store_true')
88 args = parser.parse_args()
92 if args.parser_batchMode:
101 initializeMonitoredDefects(args.parser_system,partitions,defects,defectVeto,veto,signOff,args.parser_year[0],args.parser_tag[0])
105 for iYear
in args.parser_year:
106 for iTag
in args.parser_tag:
107 directory =
"%s/YearStats-%s/%s/%s"%(args.parser_directory,args.parser_system,iYear,iTag)
108 if os.path.exists(directory):
110 yearTag =
"%s/%s"%(iYear,ytp[
"Description"])
111 yearTagList.append(yearTag)
112 yearTagDir[yearTag] = directory
116 if len(yearTagList) == 0:
117 print(
"No year / tag matching - Please check YearStats directory")
121 options[
'plotYearStats'] = args.parser_plotYS
122 options[
'plotYearStatsLarge'] = args.parser_letterYS
123 options[
'lumiNotPercent'] = args.parser_lumiNotPercent
124 options[
'recovPlot'] = args.parser_noRecovPlot
125 options[
'savePlots'] = args.parser_savePlots
126 options[
'approvedPlots'] = args.parser_approvedPlots
127 options[
'noSingleTagPlot'] = args.parser_noSingleTagPlot
129 if options[
'savePlots']:
130 options[
'plotYearStats'] =
True
131 options[
'plotYearStatsLarge'] =
False
132 options[
'lumiNotPercent'] =
False
134 if options[
'approvedPlots']:
135 options[
'plotYearStats'] =
False
136 options[
'plotYearStatsLarge'] =
True
137 options[
'lumiNotPercent'] =
False
138 options[
'recovPlot'] =
False
140 if not (options[
'plotYearStats']
or options[
'plotYearStatsLarge']
or options[
'savePlots']):
141 options[
'plotYearStats'] =
True
143 yearTagNb = len(yearTagList)
144 yearTagLabels = yearTagNb*[
""]
145 for iYT
in range(yearTagNb):
146 if options[
'approvedPlots']: yearTagLabels[iYT] = yearTagList[iYT].
split(
"/")[0]
147 else: yearTagLabels[iYT] = yearTagList[iYT]
156 hProfPeriod_IntolDefect = {}
157 hProfPeriod_Veto = {}
158 hProfPeriodLett_IntolDefect = {}
159 hProfPeriodLett_Veto = {}
160 h1Period_IntLuminosity = {}
161 h1PeriodLett_IntLuminosity = {}
165 for iYT
in yearTagList:
166 print((
"I am treating the following year/tag:%s"%iYT))
168 canvasResults[iYT] = {}
169 legendResults[iYT] = {}
170 stackResults[iYT] = {}
172 yearStatsArchiveFilename =
'%s/TProfiles.root'%(yearTagDir[iYT])
173 file[iYT] = TFile(yearStatsArchiveFilename)
174 h1Period_IntLuminosity[iYT] = file[iYT].
Get(
"h1Period_IntLuminosity_archive")
175 subperiodNb[iYT] = h1Period_IntLuminosity[iYT].GetNbinsX()
178 runsCharact[iYT] = {
'Low':1e10,
'High':0,
'Number':0}
180 fTemp =
open(
"%s/runs-ALL.dat"%yearTagDir[iYT])
181 for iline
in fTemp.readlines():
182 runNb =
int(iline.split(
" (")[0])
183 if runNb<runsCharact[iYT][
'Low']:runsCharact[iYT][
'Low']=
int(runNb)
184 if runNb>runsCharact[iYT][
'High']:runsCharact[iYT][
'High']=
int(runNb)
185 runsCharact[iYT][
'Number'] += 1
187 runsCharact[iYT][
'Range']=
"%d->%d"%(runsCharact[iYT][
'Low'],runsCharact[iYT][
'High'])
188 print((
"I found %d runs in this year/tag (%s)"%(runsCharact[iYT][
'Number'],runsCharact[iYT][
'Range'])))
190 if (options[
'plotYearStats']
or options[
'plotYearStatsLarge']):
191 if options[
'approvedPlots']:
192 xAxisTitle =
"Period"
193 legendHead =
"%s - %s"%(args.parser_system,iYT.split(
"/")[0])
195 xAxisTitle =
"Period (%s)"%runsCharact[iYT][
'Range']
196 legendHead =
"%s - %s"%(args.parser_system,iYT)
199 hProfPeriod_IntolDefect[iYT] = {}
200 allIntolDef = [
"allIntol",
"allIntol_recov"]
201 for iDef
in defects[
"intol"]+defects[
"intol_recov"]+allIntolDef:
202 iDefName = iDef.rsplit(
"__",1)[0]
203 hProfPeriod_IntolDefect[iYT][iDef] = file[iYT].
Get(
"hProfPeriod_IntolDefect_%s_archive"%(iDef))
204 hProfPeriod_IntolDefect[iYT][iDef].SetFillColor(defectVeto[
"color"][iDefName])
206 hProfPeriod_Veto[iYT] = {}
207 for iVeto
in veto[
"all"]:
208 hProfPeriod_Veto[iYT][iVeto] = file[iYT].
Get(
"hProfPeriod_Veto_%s_archive"%(iVeto))
209 hProfPeriod_Veto[iYT][iVeto].SetFillColor(defectVeto[
"color"][iVeto])
211 hProfPeriod_Veto[iYT][
"allVeto"] = file[iYT].
Get(
"hProfPeriod_Veto_allVeto_archive")
212 hProfPeriod_Veto[iYT][
"allVeto"].SetFillColor(kBlack)
216 if (options[
'plotYearStats']
and not options[
'noSingleTagPlot']):
217 totalIneffDef =
plotStack(
"defects--%s--%s - %s"%(xAxisTitle,args.parser_system,iYT),hProfPeriod_IntolDefect[iYT],defects[
"intol"],defectVeto[
"description"],h1Period_IntLuminosity[iYT],options[
'lumiNotPercent'],stackResults[iYT],canvasResults[iYT],legendResults[iYT],options[
'recovPlot'],
False,options[
'approvedPlots'])
218 if options[
'approvedPlots']:
222 totalIneffVeto =
plotStack(
"veto--%s--%s"%(xAxisTitle,iYT),hProfPeriod_Veto[iYT],veto[
"all"],defectVeto[
"description"],h1Period_IntLuminosity[iYT],options[
'lumiNotPercent'],stackResults[iYT],canvasResults[iYT],legendResults[iYT],
False,
False,options[
'approvedPlots'])
223 if options[
'approvedPlots']:
228 if (options[
'plotYearStatsLarge']):
231 for iBin
in range(1,subperiodNb[iYT]):
232 subperiod = h1Period_IntLuminosity[iYT].GetXaxis().GetBinLabel(iBin)
233 if (subperiod[0]
not in letperiodList):
234 letperiodList.append(subperiod[0])
235 letperiodNb = len(letperiodList)
238 hProfPeriodLett_IntolDefect[iYT] = {}
239 hProfPeriodLett_Veto[iYT] = {}
240 for iDef
in defects[
"intol"]+defects[
"intol_recov"]+allIntolDef:
241 iDefName = iDef.rsplit(
"__",1)[0]
242 hProfPeriodLett_IntolDefect[iYT][iDef] =
MakeTProfile(
"hProfPeriodLett_IntolDefect_%s_%s"%(iYT,iDef),
"%s"%(defectVeto[
"description"][iDefName]),
"Lost luminosity [%]", -0.5,+0.5+letperiodNb,letperiodNb+1,defectVeto[
"color"][iDefName])
243 SetXLabel(hProfPeriodLett_IntolDefect[iYT][iDef],letperiodList)
244 hProfPeriodLett_IntolDefect[iYT][iDef].GetXaxis().SetBinLabel(letperiodNb+1,
"All")
245 mergeSubPeriod(hProfPeriod_IntolDefect[iYT][iDef],hProfPeriodLett_IntolDefect[iYT][iDef])
247 for iVeto
in veto[
"all"]:
248 hProfPeriodLett_Veto[iYT][iVeto] =
MakeTProfile(
"hProfPeriodLett_Veto_%s_%s"%(iYT,iVeto),
"%s"%(defectVeto[
"description"][iVeto]),
"Lost luminosity [%]", -0.5,+0.5+letperiodNb,letperiodNb+1,defectVeto[
"color"][iVeto])
249 SetXLabel(hProfPeriodLett_Veto[iYT][iVeto],letperiodList)
250 hProfPeriodLett_Veto[iYT][iVeto].GetXaxis().SetBinLabel(letperiodNb+1,
"All")
251 mergeSubPeriod(hProfPeriod_Veto[iYT][iVeto],hProfPeriodLett_Veto[iYT][iVeto])
253 hProfPeriodLett_Veto[iYT][
"allVeto"] =
MakeTProfile(
"hProfPeriodLett_Veto_%s_allVeto"%iYT,
"allVeto",
"Lost luminosity [%]", -0.5,+0.5+letperiodNb,letperiodNb+1,kBlack)
254 SetXLabel(hProfPeriodLett_Veto[iYT][
"allVeto"],letperiodList)
255 hProfPeriodLett_Veto[iYT][
"allVeto"].GetXaxis().SetBinLabel(letperiodNb+1,
"All")
256 mergeSubPeriod(hProfPeriod_Veto[iYT][
"allVeto"],hProfPeriodLett_Veto[iYT][
"allVeto"])
259 h1PeriodLett_IntLuminosity[iYT] =
MakeTH1(
"hProfPeriodLett_IntLuminosity_%s"%(iYT),
"Period",
"Luminosity[pb^{-1}]", -0.5,+0.5+letperiodNb,letperiodNb+1,kBlack)
260 SetXLabel(h1PeriodLett_IntLuminosity[iYT],letperiodList)
261 h1PeriodLett_IntLuminosity[iYT].GetXaxis().SetBinLabel(letperiodNb+1,
"All")
262 h1PeriodLett_IntLuminosity[iYT].SetTitle(
"")
263 mergeSubPeriod(h1Period_IntLuminosity[iYT],h1PeriodLett_IntLuminosity[iYT])
265 if (
not options[
'noSingleTagPlot']):
267 totalIneffDef =
plotStack(
"defects--%s--%s"%(xAxisTitle,legendHead),hProfPeriodLett_IntolDefect[iYT],defects[
"intol"],defectVeto[
"description"],h1PeriodLett_IntLuminosity[iYT],options[
'lumiNotPercent'],stackResults[iYT],canvasResults[iYT],legendResults[iYT],options[
'recovPlot'],
False,options[
'approvedPlots'])
268 if options[
'approvedPlots']:
271 totalIneffVeto =
plotStack(
"veto--%s--%s"%(xAxisTitle,legendHead),hProfPeriodLett_Veto[iYT],veto[
"all"],defectVeto[
"description"],h1PeriodLett_IntLuminosity[iYT],options[
'lumiNotPercent'],stackResults[iYT],canvasResults[iYT],legendResults[iYT],
False,
False,options[
'approvedPlots'])
272 if options[
'approvedPlots']:
276 canvasResults[iYT][
'intLumi']= TCanvas(
"c_intLumi_%s"%(iYT),
"Integrated luminosity per period", 100, 10, 1350, 500)
278 canvasResults[iYT][
'intLumi'].SetLeftMargin(0.08)
279 canvasResults[iYT][
'intLumi'].SetRightMargin(0.35)
281 if (options[
'plotYearStatsLarge']):
282 h1PeriodLett_IntLuminosity[iYT].Draw(
"P HIST")
283 h1PeriodLett_IntLuminosity[iYT].LabelsOption(
"v")
284 h1PeriodLett_IntLuminosity[iYT].GetXaxis().SetTitleOffset(1.45)
285 h1PeriodLett_IntLuminosity[iYT].GetXaxis().SetLabelSize(0.04)
286 for iBin
in range(1,h1PeriodLett_IntLuminosity[iYT].GetNbinsX()+1):
287 print((
"Period %s: %.3f pb-1"%(h1PeriodLett_IntLuminosity[iYT].GetXaxis().GetBinLabel(iBin),h1PeriodLett_IntLuminosity[iYT].GetBinContent(iBin))))
289 h1Period_IntLuminosity[iYT].Draw(
"P HIST")
290 h1Period_IntLuminosity[iYT].LabelsOption(
"v")
291 h1Period_IntLuminosity[iYT].GetXaxis().SetTitleOffset(1.45)
292 h1Period_IntLuminosity[iYT].GetXaxis().SetLabelSize(0.04)
293 for iBin
in range(1,h1Period_IntLuminosity[iYT].GetNbinsX()+1):
294 print((
"Period %s: %.3f pb-1"%(h1Period_IntLuminosity[iYT].GetXaxis().GetBinLabel(iBin),h1Period_IntLuminosity[iYT].GetBinContent(iBin))))
296 canvasResults[iYT][
'intLumi'].SetGridy(1)
299 if options[
"savePlots"]:
300 for iCanvas
in list(canvasResults[iYT].
keys()):
301 canvasResults[iYT][iCanvas].Update()
302 if (
"defects" in iCanvas):
303 canvasResults[iYT][iCanvas].
Print(
"%s/grl-defects.png"%yearTagDir[iYT])
304 if (
"veto" in iCanvas):
305 canvasResults[iYT][iCanvas].
Print(
"%s/grl-veto.png"%yearTagDir[iYT])
306 if (
"intLumi" in iCanvas):
307 canvasResults[iYT][iCanvas].
Print(
"%s/grl-lumi.png"%yearTagDir[iYT])
310 if (yearTagNb >= 2
and (options[
'plotYearStats']
or options[
'plotYearStatsLarge'])):
311 h1YearTag_IntLuminosity =
MakeTH1(
"h1YearTag_IntLuminosity",
"Year/Tag",
"Luminosity[pb^{-1}]", -0.5,-0.5+yearTagNb,yearTagNb,kBlack)
312 SetXLabel(h1YearTag_IntLuminosity,yearTagLabels)
313 for iYT
in range(yearTagNb):
314 h1YearTag_IntLuminosity.Fill(iYT,h1Period_IntLuminosity[yearTagList[iYT]].GetBinContent(subperiodNb[yearTagList[iYT]]))
316 h1YearTag_IntolDefect = {}
317 for iDef
in defects[
"intol"]+defects[
"intol_recov"]+allIntolDef:
318 iDefName = iDef.rsplit(
"__",1)[0]
319 h1YearTag_IntolDefect[iDef] =
MakeTH1(
"h1YearTag_IntolDefect_%s"%(iDef),
"%s"%(defectVeto[
"description"][iDefName]),
"Lost luminosity [%]", -0.5,-0.5+yearTagNb,yearTagNb,defectVeto[
"color"][iDefName])
320 SetXLabel(h1YearTag_IntolDefect[iDef],yearTagLabels)
321 for iYT
in range(yearTagNb):
322 h1YearTag_IntolDefect[iDef].Fill(iYT,hProfPeriod_IntolDefect[yearTagList[iYT]][iDef].GetBinContent(subperiodNb[yearTagList[iYT]]))
325 legendHeader =
"#splitline{ %s "%(yearTagLabels[0].
split(
"/")[0])
326 for iTag
in range(1,yearTagNb):
327 legendHeader +=
" / %s "%(yearTagLabels[iTag].
split(
"/")[0])
328 legendHeader +=
"}{Luminos. : %3.1f fb^{-1} "%(h1Period_IntLuminosity[yearTagList[0]].GetBinContent(subperiodNb[yearTagList[0]])/1000.)
329 for iTag
in range(1,yearTagNb):
330 legendHeader +=
"/ %3.1f fb^{-1}"%(h1Period_IntLuminosity[yearTagList[iTag]].GetBinContent(subperiodNb[yearTagList[iTag]])/1000.)
333 plotStack(
"defects--Year--%s"%legendHeader,h1YearTag_IntolDefect,defects[
"intol"],defectVeto[
"description"],h1YearTag_IntLuminosity,options[
'lumiNotPercent'],stackResults,canvasResults,legendResults,
False,
True,options[
'approvedPlots'])
334 if options[
'approvedPlots']:
336 if options[
"savePlots"]:
337 canvasResults[
"defects--Year--%s"%legendHeader].
Print(
"%s/YearStats-%s/run2-defects-DQPaper_.png"%(args.parser_directory,args.parser_system))
338 canvasResults[
"defects--Year--%s"%legendHeader].
Print(
"%s/YearStats-%s/run2-defects-DQPaper_.pdf"%(args.parser_directory,args.parser_system))
339 canvasResults[
"defects--Year--%s"%legendHeader].
Print(
"%s/YearStats-%s/run2-defects-DQPaper_.eps"%(args.parser_directory,args.parser_system))
342 if (len(veto[
"all"])):
343 for iVeto
in (veto[
"all"]+[
"allVeto"]):
344 h1YearTag_Veto[iVeto] =
MakeTH1(
"h1YearTag_Veto_%s"%(iVeto),
"%s"%(defectVeto[
"description"][iVeto]),
"Lost luminosity [%]", -0.5,-0.5+yearTagNb,yearTagNb,defectVeto[
"color"][iVeto])
345 SetXLabel(h1YearTag_Veto[iVeto],yearTagLabels)
346 for iYT
in range(yearTagNb):
347 h1YearTag_Veto[iVeto].Fill(iYT,hProfPeriod_Veto[yearTagList[iYT]][iVeto].GetBinContent(subperiodNb[yearTagList[iYT]]))
350 plotStack(
"veto--Year--%s"%legendHeader,h1YearTag_Veto,veto[
"all"],defectVeto[
"description"],h1YearTag_IntLuminosity,options[
'lumiNotPercent'],stackResults,canvasResults,legendResults,
False,
True,options[
'approvedPlots'])
351 if options[
'approvedPlots']:
353 if options[
"savePlots"]:
354 canvasResults[
"veto--Year--%s"%legendHeader].
Print(
"%s/YearStats-%s/run2-veto-DQPaper_.png"%(args.parser_directory,args.parser_system))
355 canvasResults[
"veto--Year--%s"%legendHeader].
Print(
"%s/YearStats-%s/run2-veto-DQPaper_.pdf"%(args.parser_directory,args.parser_system))
356 canvasResults[
"veto--Year--%s"%legendHeader].
Print(
"%s/YearStats-%s/run2-veto-DQPaper_.eps"%(args.parser_directory,args.parser_system))
358 if not args.parser_batchMode:
359 input(
"I am done. Type <return> to exit...")