16 from six.moves
import xmlrpc_client
as xmlrpclib
18 from DataQualityUtils
import pathExtract
20 sys.path.append(
"/afs/cern.ch/user/l/larmon/public/prod/Misc")
21 from LArMonCoolLib
import GetLBTimeStamps,GetOnlineLumiFromCOOL
28 """Return formatted lumiblock string"""
29 return "_lb"+lb.zfill(5)
32 """Histo path definition base on object type"""
46 runstr =
"run_"+
str(runNumber)
48 if objectType ==
"TopoClusters":
49 histoPath = {
"ECA_thr1":runstr+
"/CaloTopoClusters/CalECA/Thresh1ECAOcc",
50 "ECA_thr2":runstr+
"/CaloTopoClusters/CalECA/Thresh2ECAOcc",
51 "ECA_thr3":runstr+
"/CaloTopoClusters/CalECA/Thresh3ECAOcc",
52 "ECC_thr1":runstr+
"/CaloTopoClusters/CalECC/Thresh1ECCOcc",
53 "ECC_thr2":runstr+
"/CaloTopoClusters/CalECC/Thresh2ECCOcc",
54 "ECC_thr3":runstr+
"/CaloTopoClusters/CalECC/Thresh3ECCOcc",
55 "BAR_thr1":runstr+
"/CaloTopoClusters/CalBAR/Thresh1BAROcc",
56 "BAR_thr2":runstr+
"/CaloTopoClusters/CalBAR/Thresh2BAROcc",
57 "BAR_thr3":runstr+
"/CaloTopoClusters/CalBAR/Thresh3BAROcc"}
58 histoLegend = {
"ECA_thr1":
"ECA - Et > 10 GeV",
59 "ECA_thr2":
"ECA - Et > 15 GeV",
60 "ECA_thr3":
"ECA - Et > 25 GeV",
61 "ECC_thr1":
"ECC - Et > 10 GeV",
62 "ECC_thr2":
"ECC - Et > 15 GeV",
63 "ECC_thr3":
"ECC - Et > 25 GeV",
64 "BAR_thr1":
"BAR - Et > 10 GeV",
65 "BAR_thr2":
"BAR - Et > 15 GeV",
66 "BAR_thr3":
"BAR - Et > 25 GeV"}
67 histoType =
"2d_etaPhi_Occupancy"
68 histoName =
"TopoClusters occupancy"
70 elif objectType ==
"EMTopoClusters":
71 histoPath = {
"Et4GeV":runstr+
"/CaloMonitoring/ClusterMon/LArClusterEMNoTrigSel/2d_Rates/m_clus_etaphi_Et_thresh1",
72 "Et10GeV":runstr+
"/CaloMonitoring/ClusterMon/LArClusterEMNoTrigSel/2d_Rates/m_clus_etaphi_Et_thresh2",
73 "Et25GeV":runstr+
"/CaloMonitoring/ClusterMon/LArClusterEMNoTrigSel/2d_Rates/m_clus_etaphi_Et_thresh3"}
74 histoLegend = {
"Et4GeV":
"Et > 4GeV",
75 "Et10GeV":
"Et > 10GeV",
76 "Et25GeV":
"Et > 25GeV"}
77 histoPath = {
"ECA_thr1":runstr+
"/CaloTopoClusters/CalEMECA/EMThresh1ECAOcc",
78 "ECA_thr2":runstr+
"/CaloTopoClusters/CalEMECA/EMThresh2ECAOcc",
79 "ECA_thr3":runstr+
"/CaloTopoClusters/CalEMECA/EMThresh3ECAOcc",
80 "ECC_thr1":runstr+
"/CaloTopoClusters/CalEMECC/EMThresh1ECCOcc",
81 "ECC_thr2":runstr+
"/CaloTopoClusters/CalEMECC/EMThresh2ECCOcc",
82 "ECC_thr3":runstr+
"/CaloTopoClusters/CalEMECC/EMThresh3ECCOcc",
83 "BAR_thr1":runstr+
"/CaloTopoClusters/CalEMBAR/EMThresh1BAROcc",
84 "BAR_thr2":runstr+
"/CaloTopoClusters/CalEMBAR/EMThresh2BAROcc",
85 "BAR_thr3":runstr+
"/CaloTopoClusters/CalEMBAR/EMThresh3BAROcc"}
86 histoLegend = {
"ECA_thr1":
"ECA - Et > 4 GeV",
87 "ECA_thr2":
"ECA - Et > 10 GeV",
88 "ECA_thr3":
"ECA - Et > 15 GeV",
89 "ECC_thr1":
"ECC - Et > 4 GeV",
90 "ECC_thr2":
"ECC - Et > 10 GeV",
91 "ECC_thr3":
"ECC - Et > 15 GeV",
92 "BAR_thr1":
"BAR - Et > 4 GeV",
93 "BAR_thr2":
"BAR - Et > 10 GeV",
94 "BAR_thr3":
"BAR - Et > 15 GeV"}
95 histoType =
"2d_etaPhi_Occupancy"
96 histoName =
"EMTopoClusters occupancy"
98 elif objectType ==
"EMTopoJet":
99 histoPath = {
"noCut":runstr+
"/Jets/AntiKt4EMTopoJets/OccupancyEtaPhi",
100 "cut1":runstr+
"/Jets/AntiKt4EMTopoJets/OccupancyEtaPhisel_20000_inf_pt_inf_500000",
101 "cut2":runstr+
"/Jets/AntiKt4EMTopoJets/OccupancyEtaPhisel_500000_inf_pt_inf_1000000",
102 "cut3":runstr+
"/Jets/AntiKt4EMTopoJets/OccupancyEtaPhisel_1000000_inf_pt_inf_2000000",
103 "cut4":runstr+
"/Jets/AntiKt4EMTopoJets/OccupancyEtaPhisel_2000000_inf_pt_inf_8000000"}
104 histoLegend = {
"noCut":
"No cut",
105 "cut1":
"20GeV-500GeV",
106 "cut2":
"500GeV-1TeV",
109 histoType =
"2d_etaPhi_Occupancy"
110 histoName =
"EMTopoJets"
112 elif objectType ==
"AntiKt4EMTopoJets":
113 histoPath = {
"noCut":runstr+
"/Jets/AntiKt4EMTopoJets/standardHistos/phi_eta"}
114 histoLegend = {
"noCut":
"No cut"}
115 histoType =
"2d_etaPhi_Occupancy"
116 histoName =
"Occupancy of AntiKt4EMTopoJets"
118 elif objectType ==
"AntiKt4EMTopoJets_pt":
119 histoPath = {
"noCut":runstr+
"/Jets/AntiKt4EMTopoJets/standardHistos/phi_eta_pt"}
120 histoLegend = {
"noCut":
"No cut"}
121 histoType =
"2d_etaPhi_MeanPt"
122 histoName =
"Mean Pt of AntiKt4EMTopoJets"
124 elif objectType ==
"MET_Topo_phi":
125 histoPath = {
"MET":runstr+
"/MissingEt/AllTriggers/MET_Calo/EMTopo/MET_Topo_phi"}
126 histoLegend = {
"MET":
"MET"}
127 histoType =
"1d_phi_Occupancy"
128 histoName =
"MET phi"
130 elif objectType ==
"Tau":
131 histoPath = {
"NoCut":runstr+
"/Tau/tauPhiVsEta",
132 "Et15GeV":runstr+
"/Tau/tauPhiVsEta_et15"}
133 histoLegend = {
"NoCut":
"Et > 0 GeV (tbc)",
134 "Et15GeV":
"Et > 15 GeV"}
135 histoType =
"2d_etaPhi_Occupancy"
136 histoName =
"Tau occupancy"
138 elif objectType ==
"Tau_phi":
139 histoPath = {
"single":runstr+
"/Tau/tauPhi"}
140 histoLegend = {
"single":
"All candidates"}
141 histoType =
"1d_phi_Occupancy"
144 elif objectType ==
"Tau_eta":
145 histoPath = {
"single":runstr+
"/Tau/tauEta"}
146 histoLegend = {
"single":
"All candidates"}
147 histoType =
"1d_eta_Occupancy"
148 histoName =
"Tau phi"
150 elif objectType ==
"NumberTau":
151 histoPath = {
"highPt":runstr+
"/Tau/nHightPtTauCandidates"}
152 histoLegend = {
"highPt":
"High Pt (>100GeV) candidates"}
153 histoType =
"1d_integralAbove_Occupancy"
154 histoName =
"Number of Tau candidates"
156 elif objectType ==
"TightFwdElectrons":
157 histoPath = {
"single":runstr+
"/egamma/forwardElectrons/forwardElectronTightEtaPhi"}
158 histoLegend = {
"single":
"10GeV"}
159 histoType =
"2d_etaPhi_Occupancy"
160 histoName =
"Tight electrons"
162 elif objectType ==
"LoosePhotons":
163 histoPath = {
"single":runstr+
"/egamma/CBLoosePhotons/Eta_Phi_distribution_with_Pt.gt.4GeV"}
164 histoLegend = {
"single":
"4GeV"}
165 histoType =
"2d_etaPhi_Occupancy"
166 histoName =
"Loose photons"
168 elif objectType ==
"NumberTightFwdElectrons":
169 histoPath = {
"single":runstr+
"/egamma/forwardElectrons/forwardElectronTightN"}
170 histoLegend = {
"single":
"All candidates"}
171 histoType =
"1d_integralAbove_Occupancy"
172 histoName =
"Number of tight forward electrons"
174 elif objectType ==
"HLT_TausRoIs":
175 histoPath = {
"single":runstr+
"/HLT/ResultMon/HLT_Taus/HLT_TausRoIs"}
176 histoLegend = {
"single":
""}
177 histoType =
"2d_etaPhi_Occupancy"
178 histoName =
"HLT TausRoIs"
180 elif objectType ==
"NumberHLTJet":
181 histoPath = {
"HLTJet":runstr+
"/HLT/JetMon/HLT/10j40_L14J20/HLTJet_n"}
182 histoLegend = {
"HLTJet":
"All candidates"}
183 histoType =
"1d_integralAbove_Occupancy"
184 histoName =
"Number of HLT jets - 10J40_L14J20 trigger"
186 elif objectType ==
"HLT_ConfigConsistency":
187 histoPath = {
"HLTJet":runstr+
"/HLT/ResultMon/ConfigConsistency_HLT"}
188 histoLegend = {
"HLTJet":
"Configuration consistency"}
189 histoType =
"1d_integralAbove_Occupancy"
190 histoName =
"Number of HLT config inconsistencies"
192 elif objectType ==
"LArDigits":
193 histoPath = {
"Null-EMBA":runstr+
"/LAr/Digits/Barrel/NullDigitChan_BarrelA",
194 "Satu-EMBA":runstr+
"/LAr/Digits/Barrel/SaturationChan_BarrelA",
195 "Null-EMBC":runstr+
"/LAr/Digits/Barrel/NullDigitChan_BarrelC",
196 "Satu-EMBC":runstr+
"/LAr/Digits/Barrel/SaturationChan_BarrelC",
198 histoLegend = {
"Null-EMBA":
"Null digit - EMBA",
199 "Satu-EMBA":
"Saturated digit - EMBA",
200 "Null-EMBC":
"Null digit - EMBC",
201 "Satu-EMBC":
"Saturated digit - EMBC",}
202 histoType =
"2d_xy_Occupancy"
203 histoName =
"LAr saturated/null digits"
206 print(
"Object type:",objectType,
"not recognised!")
209 cols = [R.kBlue+1, R.kGreen+1, R.kOrange+7, R.kMagenta+2, R.kCyan-3,
210 R.kGreen-5, R.kRed, R.kCyan, R.kViolet,
211 R.kAzure-4, R.kMagenta-9, R.kGreen-9, R.kYellow]
212 histoColor = {k:cols[
list(histoPath.keys()).
index(k)]
for k
in histoPath.keys()}
214 return histoPath, histoLegend, histoColor, histoType, histoName
219 histoPath, histoLegend, histoColor, histoType, histoName =
getHistoInfo(args.objectType, args.runNumber)
225 b_ValueNotEntries =
False
227 if histoType ==
"2d_etaPhi_Occupancy" or histoType ==
"2d_etaPhi_MeanPt":
228 if histoType ==
"2d_etaPhi_Occupancy":
229 summaryTitle =
"Nb of hits in a region of %.2f around the position (%.2f,%.2f) - %s"%(args.deltaSpot,args.etaSpot,args.phiSpot,histoName)
231 summaryTitle =
"Mean Pt in a region of %.2f around the position (%.2f,%.2f) - %s"%(args.deltaSpot,args.etaSpot,args.phiSpot,histoName)
232 if (args.deltaSpot != 0):
233 print(
"Warning: you have been summing over several bins a variable that may be not summable (different from summing hits!)")
235 statement =
"I have looked for LBs with at least %.0f entries at position (%.2f,%.2f) in %s histogram"%(args.minInLB,args.etaSpot,args.phiSpot,histoName)
236 if (args.etaSpot==-999.
or args.phiSpot==-999.):
237 print(
"No eta/phi defined -> whole histogram considered!")
239 if histoType ==
"2d_xy_Occupancy":
240 b_ValueNotEntries =
True
241 if (args.deltaSpot != 0):
242 print(
"Warning: you have been summing over several bins a variable that may be not summable (different from summing hits!)")
243 summaryTitle =
"Value in a region of %.2f around the position (%.2f,%.2f) - %s"%(args.deltaSpot,args.xSpot,args.ySpot,histoName)
244 statement =
"I have looked for LBs with at least variable > %.2f at position (%.2f,%.2f) in %s histogram"%(args.minInLB,args.xSpot,args.ySpot,histoName)
245 if (args.xSpot==-999.
or args.ySpot==-999.):
246 print(
"No x/y defined -> whole histogram considered!")
247 print(
"Warning: you have been summing over several bins a variable that may be not summable (different from summing hits!)")
249 elif histoType ==
"1d_eta_Occupancy":
250 summaryTitle =
"Nb of hits in a region of %.2f around the eta position %.2f - %s"%(args.deltaSpot,args.etaSpot,histoName)
251 statement =
"I have looked for LBs with at least %.0f entries at eta position %.2f in %s histogram"%(args.minInLB,args.etaSpot,histoName)
252 if (args.etaSpot==-999.):
253 print(
"No eta/phi -> whole histogram considered!")
255 elif histoType ==
"1d_phi_Occupancy":
256 summaryTitle =
"Nb of hits in a region of %.2f around the phi position %.2f - %s"%(args.deltaSpot,args.phiSpot,histoName)
257 statement =
"I have looked for LBs with at least %.0f entries at phi position %.2f in %s histogram"%(args.minInLB,args.phiSpot,histoName)
258 if (args.phiSpot==-999.):
259 print(
"No eta/phi defined -> whole histogram considered!")
261 elif histoType ==
"1d_integralAbove_Occupancy":
262 summaryTitle =
"Nb of hits in the band above %.2f - %s"%(args.integralAbove,histoName)
263 statement =
"I have looked for LBs with at least %.0f entries in band above %.2f in %s histogram"%(args.minInLB,args.integralAbove,histoName)
264 if (args.integralAbove==-999.):
265 print(
"No lower bound defined -> whole histogram considered!")
269 if (args.objectType ==
"NumberTightFwdElectrons" or args.objectType ==
"NumberTau"):
270 canvasOption =
"logy"
278 runFilePath =
"root://eosatlas.cern.ch/%s"%(pathExtract.returnEosHistPath(args.runNumber,args.stream,args.amiTag,args.tag)).rstrip()
279 if (
"FILE NOT FOUND" in runFilePath):
280 print(
"No merged file found for this run")
281 print(
"HINT: check if there is a folder like",
"/eos/atlas/atlastier0/tzero/prod/"+args.tag+
"/physics_CosmicCalo/00"+
str(args.runNumber)+
"/"+args.tag+
".00"+
str(args.runNumber)+
".physics_CosmicCalo.*."+args.amiTag)
284 f = R.TFile.Open(runFilePath)
289 for iHisto
in histoPath.keys():
292 histo[iHisto] = f.Get(histoPath[iHisto])
293 histo[iHisto].SetTitle(
"%s (%s) - Run %d"%(histo[iHisto].GetTitle(),histoLegend[iHisto],args.runNumber))
301 for iHisto
in histoPath.keys():
303 regionBins[iHisto] = []
304 if (
"2d" in histoType):
305 maxBin = (histo[iHisto].GetNbinsX()+2)*(histo[iHisto].GetNbinsY()+2)
307 maxBin = (histo[iHisto].GetNbinsX()+2)
308 for iBin
in range(maxBin):
309 regionBins[iHisto].
append(iBin)
312 subStep = 2*args.deltaSpot/nSteps
313 regionBins[iHisto] = []
314 if histoType ==
"2d_etaPhi_Occupancy" or histoType ==
"2d_etaPhi_MeanPt":
315 for ix
in range(nSteps):
316 iEta = args.etaSpot - args.deltaSpot + ix * subStep
317 for iy
in range (nSteps):
318 iPhi = args.phiSpot - args.deltaSpot + iy * subStep
319 tmpBin = histo[iHisto].
FindBin(iEta,iPhi)
320 if (tmpBin
not in regionBins[iHisto]):
321 regionBins[iHisto].
append(tmpBin)
322 elif histoType ==
"2d_xy_Occupancy":
323 for ix
in range(nSteps):
324 iX = args.xSpot - args.deltaSpot + ix * subStep
325 for iy
in range (nSteps):
326 iY = args.ySpot - args.deltaSpot + iy * subStep
327 tmpBin = histo[iHisto].
FindBin(iX,iY)
328 if (tmpBin
not in regionBins[iHisto]):
329 regionBins[iHisto].
append(tmpBin)
330 elif histoType ==
"1d_eta_Occupancy":
331 for ix
in range(nSteps):
332 iEta = args.etaSpot - args.deltaSpot + ix * subStep
333 tmpBin = histo[iHisto].
FindBin(iEta)
334 if (tmpBin
not in regionBins[iHisto]):
335 regionBins[iHisto].
append(tmpBin)
336 elif histoType ==
"1d_phi_Occupancy":
337 for ix
in range(nSteps):
338 iPhi = args.phiSpot - args.deltaSpot + ix * subStep
339 tmpBin = histo[iHisto].
FindBin(iPhi)
340 if (tmpBin
not in regionBins[iHisto]):
341 regionBins[iHisto].
append(tmpBin)
342 elif (histoType ==
"1d_integralAbove_Occupancy"):
343 for iBin
in range(histo[iHisto].
FindBin(args.integralAbove),histo[iHisto].GetNbinsX()):
344 regionBins[iHisto].
append(iBin)
355 for iHisto
in histoPath.keys():
357 for iBin
in regionBins[iHisto]:
358 total_tmp = total_tmp + histo[iHisto].GetBinContent(iBin)
362 c[iHisto] = R.TCanvas(histoLegend[iHisto])
363 if "logy" in canvasOption:
366 if histoType.startswith(
"2d"):
367 R.gStyle.SetPalette(1)
368 R.gStyle.SetOptStat(
"")
370 histo[iHisto].Draw(
"COLZ")
372 if histoType ==
"2d_etaPhi_Occupancy" or histoType ==
"2d_etaPhi_MeanPt":
373 box[iHisto] = R.TBox(args.etaSpot-args.deltaSpot,args.phiSpot-args.deltaSpot,args.etaSpot+args.deltaSpot,args.phiSpot+args.deltaSpot)
374 elif (histoType ==
"2d_xy_Occupancy"):
375 box[iHisto] = R.TBox(args.xSpot-args.deltaSpot,args.ySpot-args.deltaSpot,args.xSpot+args.deltaSpot,args.ySpot+args.deltaSpot)
376 box[iHisto].SetLineColor(R.kRed+1)
377 box[iHisto].SetLineWidth(3)
378 box[iHisto].SetFillStyle(0)
381 elif histoType.startswith(
"1d"):
382 maxH = histo[iHisto].GetMaximum()*1.2
383 histo[iHisto].SetMaximum(maxH)
384 if histoType ==
"1d_eta_Occupancy" or histoType ==
"1d_phi_Occupancy":
385 minH = histo[iHisto].GetMinimum()*0.8
386 histo[iHisto].SetMinimum(minH)
390 if histoType ==
"1d_eta_Occupancy" or histoType ==
"1d_phi_Occupancy":
392 if histoType ==
"1d_eta_Occupancy":
393 box[iHisto] = R.TBox(args.etaSpot-args.deltaSpot,minH,args.etaSpot+args.deltaSpot,maxH)
394 if histoType ==
"1d_phi_Occupancy":
395 box[iHisto] = R.TBox(args.phiSpot-args.deltaSpot,minH,args.phiSpot+args.deltaSpot,maxH)
396 box[iHisto].SetLineColor(R.kRed+1)
397 box[iHisto].SetLineWidth(3)
398 box[iHisto].SetFillStyle(0)
400 elif histoType ==
"1d_integralAbove_Occupancy":
401 line[iHisto] = R.TLine(args.integralAbove,0,args.integralAbove,maxH)
402 line[iHisto].SetLineColor(R.kRed+1)
403 line[iHisto].SetLineWidth(3)
405 arrow[iHisto] = R.TArrow(args.integralAbove,0.2*histo[iHisto].GetMaximum(),histo[iHisto].GetBinLowEdge(histo[iHisto].GetNbinsX()),0.2*histo[iHisto].GetMaximum(),0.02,
">")
406 arrow[iHisto].SetLineColor(R.kRed+1)
407 arrow[iHisto].SetLineWidth(3)
415 lbFilePathList = pathExtract.returnEosHistPathLB(args.runNumber,args.lowerLumiBlock,args.upperLumiBlock,args.stream,args.amiTag,args.tag)
417 if isinstance(lbFilePathList,str)
and "NOT FOUND" in lbFilePathList:
418 print(
"Could not find per-LB files for this run")
419 print(
"HINT: check if there is a folder like",
"/eos/atlas/atlastier0/tzero/prod/"+args.tag+
"/physics_CosmicCalo/00"+
str(args.runNumber)+
"/"+args.tag+
".00"+
str(args.runNumber)+
".physics_CosmicCalo.*."+args.amiTag)
422 LBs = [
int(f.split(
"_lb")[1].
split(
".")[0])
for f
in lbFilePathList]
424 print(
"Max LB is",maxLB)
428 for iHisto
in histoPath.keys():
429 nbHitInHot[iHisto] = [0.] * (nLB+1)
436 print(
"I have found the merged HIST file %s"%(runFilePath))
437 print(
"I have found %d unmerged HIST files"%(len(lbFilePathList)))
438 print(
"The first one is root://eosatlas.cern.ch/%s"%(lbFilePathList[0]))
439 print(
"The last one is root://eosatlas.cern.ch/%s"%(lbFilePathList[len(lbFilePathList)-1]))
443 for count,lbFile
in enumerate(lbFilePathList):
444 lbFilePath =
"root://eosatlas.cern.ch/%s"%(lbFile).rstrip()
446 ilb =
int((lbFile.split(
"_lb")[1]).
split(
"._")[0])
448 sys.stdout.write(
"\n I processed %d/%d files \n LBs:"%(count,len(lbFilePathList)))
449 sys.stdout.write(
"%d "%(ilb))
451 fLB[lbFile] = R.TFile.Open(lbFilePath)
453 for iHisto
in histoPath.keys():
454 histoLB[iHisto] = fLB[lbFile].
Get(histoPath[iHisto])
455 if (histoLB[iHisto] !=
None):
456 for iBin
in regionBins[iHisto]:
457 nbHitInHot[iHisto][ilb] = nbHitInHot[iHisto][ilb] + histoLB[iHisto].GetBinContent(iBin)
466 for iHisto
in histoPath.keys():
467 for ilb
in range(len(nbHitInHot[iHisto])):
468 if (nbHitInHot[iHisto][ilb]>=args.minInLB):
469 if ilb<lowerLB : lowerLB = ilb
470 if ilb>upperLB : upperLB = ilb
472 if (lowerLB == upperLB):
473 lowerLB = lowerLB - 1
474 upperLB = upperLB + 4
480 maxNbInHot_histo =
""
481 totalInRegionRecomp = {}
483 suspiciousLBlist = []
487 for iHisto
in histoPath.keys():
488 totalInRegionRecomp[iHisto] = 0
489 totalInRegion[iHisto] = 0
494 for iHisto
in histoPath.keys():
495 print(
"======= ",histoLegend[iHisto])
496 for iBin
in regionBins[iHisto]:
497 totalInRegion[iHisto] = totalInRegion[iHisto] + histo[iHisto].GetBinContent(iBin)
499 sortedLB[iHisto] = [0] * nLB
501 totalInRegionRecomp[iHisto] = totalInRegionRecomp[iHisto] + nbHitInHot[iHisto][i]
503 sortedLB[iHisto][i] = i
504 if (nbHitInHot[iHisto][i]>=args.minInLB):
505 suspiciousLBlist.append(i)
506 if (nbHitInHot[iHisto][i]>maxNbInHot):
507 maxNbInHot = nbHitInHot[iHisto][i]
508 maxNbInHot_histo = iHisto
510 sortedLB[iHisto].sort(key=dict(zip(sortedLB[iHisto],nbHitInHot[iHisto])).get,reverse=
True)
511 nLB_aboveThreshold = 0
513 if nbHitInHot[iHisto][sortedLB[iHisto][i]]>=args.minInLB:
514 nLB_aboveThreshold = nLB_aboveThreshold + 1
515 if not b_ValueNotEntries:
516 print(
"%d-LB: %d -> %d hits"%(i,sortedLB[iHisto][i],nbHitInHot[iHisto][sortedLB[iHisto][i]]))
518 print(
"%d-LB: %d -> %.2f"%(i,sortedLB[iHisto][i],nbHitInHot[iHisto][sortedLB[iHisto][i]]))
520 if not b_ValueNotEntries:
521 print(
"In the whole run, there are %d entries"%(totalInRegion[iHisto]))
522 if (totalInRegionRecomp[iHisto] != totalInRegion[iHisto]):
523 print(
"To be compared with %d entries cumulated from unmerged files"%(totalInRegionRecomp[iHisto]))
524 if (totalInRegionRecomp[iHisto] < totalInRegion[iHisto]):
525 print(
"This is normal only if you restricted the LB range...")
526 if (totalInRegionRecomp[iHisto] > totalInRegion[iHisto]):
527 print(
"This can be also caused by multiple processing, try to filter with -a option")
528 print(
"File path of the first file:",lbFilePathList[0])
530 print(
"In the whole run, the value is %.2f"%(totalInRegion[iHisto]))
532 affectedLB_forSummaryBinning = []
533 if (maxNbInHot != 0):
535 if (nbHitInHot[maxNbInHot_histo][sortedLB[maxNbInHot_histo][i]] > 0.05*maxNbInHot):
536 affectedLB_forSummaryBinning.append(sortedLB[maxNbInHot_histo][i])
541 leg = R.TLegend(0.855, 0.90-0.05*len(histoPath.keys()),
545 if (upperLB>=lowerLB):
546 c0 = R.TCanvas(
"c0",
"Evolution vs LB",1400,550)
547 R.gStyle.SetOptStat(
"")
548 if histoType !=
"2d_xy_Occupancy":
550 c0.SetLeftMargin(.045)
551 c0.SetRightMargin(.15)
554 for iHisto
in histoPath.keys():
555 h0Evol[iHisto] = R.TH1I(
"h0Evol%s"%(iHisto),summaryTitle,upperLB-lowerLB+1,lowerLB-0.5,upperLB+0.5)
556 h0Evol[iHisto].SetXTitle(
"Run %d - LumiBlock (Only LB with >= %.0f entries)"%(args.runNumber,args.minInLB))
557 h0Evol[iHisto].SetLineColor(histoColor[iHisto])
558 h0Evol[iHisto].SetMarkerColor(histoColor[iHisto])
559 h0Evol[iHisto].SetMarkerStyle(20)
560 for i
in range(lowerLB,upperLB+1):
561 h0Evol[iHisto].Fill(i,nbHitInHot[iHisto][i])
563 if (h0Evol[iHisto].GetMaximum() >= args.minInLB):
564 leg.AddEntry(h0Evol[iHisto],
"#splitline{%s}{(%d entries in the run)}"%(histoLegend[iHisto],totalInRegion[iHisto]))
567 h0Evol[iHisto].Draw(
"P HIST")
568 if histoType !=
"2d_xy_Occupancy":
569 h0Evol[iHisto].SetMinimum(args.minInLB-0.8)
570 h0Evol[iHisto].SetMaximum(maxNbInHot*1.5)
573 h0Evol[iHisto].Draw(
"PSAME HIST")
578 leg2 = R.TLegend(0.855, 0.90-0.05*len(histoPath.keys()),
580 leg2.SetBorderSize(0)
584 print(
"Affected luminosity blocks sorted by the noise amplitude",affectedLB_forSummaryBinning)
586 if (len(affectedLB_forSummaryBinning)>0):
587 c0_2 = R.TCanvas(
"c0_2",
"Most affected LB summary", 1400,550)
588 R.gStyle.SetOptStat(
"")
589 if histoType !=
"2d_xy_Occupancy":
591 c0_2.SetLeftMargin(.045)
592 c0_2.SetRightMargin(.15)
594 onlineLumi = GetOnlineLumiFromCOOL(args.runNumber,0)
595 cumulatedAffectedLumi = 0.
598 for iHisto
in histoPath.keys():
599 h_affectedLB[iHisto] = R.TH1F(
"affectedLB%s"%(iHisto),
"%s - Most affected LB"%summaryTitle,len(affectedLB_forSummaryBinning),0.5,len(affectedLB_forSummaryBinning)+0.5)
601 h_affectedLB[iHisto].SetXTitle(
"Run %d - LumiBlock / Cumulated luminosity in pb-1"%(args.runNumber))
602 h_affectedLB[iHisto].SetLineColor(histoColor[iHisto])
603 h_affectedLB[iHisto].SetMarkerColor(histoColor[iHisto])
604 h_affectedLB[iHisto].SetMarkerStyle(20)
606 for i
in range(1,len(affectedLB_forSummaryBinning)+1):
607 cumulatedAffectedLumi = cumulatedAffectedLumi + onlineLumi[affectedLB_forSummaryBinning[i-1]]*60/1e6
608 h_affectedLB[iHisto].GetXaxis().SetBinLabel(i,
"%d / %.1f"%(affectedLB_forSummaryBinning[i-1],cumulatedAffectedLumi))
609 h_affectedLB[iHisto].GetXaxis().SetTitleOffset(1.4)
610 h_affectedLB[iHisto].Fill(i,nbHitInHot[iHisto][affectedLB_forSummaryBinning[i-1]])
612 if (h_affectedLB[iHisto].GetMaximum() >= args.minInLB):
613 leg2.AddEntry(h_affectedLB[iHisto],
"#splitline{%s}{(%d entries in the run)}"%(histoLegend[iHisto],totalInRegion[iHisto]))
616 h_affectedLB[iHisto].Draw(
"P HIST")
617 if histoType !=
"2d_xy_Occupancy":
618 h_affectedLB[iHisto].SetMinimum(args.minInLB-0.8)
619 h_affectedLB[iHisto].SetMaximum(maxNbInHot*1.5)
622 h_affectedLB[iHisto].Draw(
"PSAME HIST")
629 print(
"WARNING: only the 35 most affected LB are displayed in the summary plot")
633 print(
"I am looking for LAr/Tile/Calo defects defined for the suspicious LB")
634 from DQDefects
import DefectsDB
636 defectList = [d
for d
in (db.defect_names | db.virtual_defect_names)
if ((d.startswith(
"LAR")
and "SEV" in d)
or (d.startswith(
"TILE"))
or (d.startswith(
"CALO")))]
637 defects = db.retrieve((args.runNumber, 1), (args.runNumber+1, 0), defectList)
639 associatedSuspicious =
False
640 for iLB
in range(iDef.since.lumi,iDef.until.lumi):
641 if iLB
in suspiciousLBlist:
642 associatedSuspicious =
True
643 if associatedSuspicious:
644 if (iDef.since.lumi == iDef.until.lumi-1):
645 print(
"%s: %d set by %s - %s"%(iDef.channel,iDef.since.lumi,iDef.user,iDef.comment))
647 print(
"%s: %d->%d set by %s - %s"%(iDef.channel,iDef.since.lumi,iDef.until.lumi-1,iDef.user,iDef.comment))
649 input(
"Please press the Enter key to proceed")
655 if __name__ ==
"__main__":
656 R.gStyle.SetPalette(1)
657 R.gStyle.SetOptStat(
"em")
659 parser = argparse.ArgumentParser(description=
'Process some integers.')
660 parser.add_argument(
'-r',
'--run',type=int,dest=
'runNumber',default=
'267599',help=
"Run number",action=
'store')
661 parser.add_argument(
'-ll',
'--lowerlb',type=int,dest=
'lowerLumiBlock',default=
'0',help=
"Lower lb",action=
'store')
662 parser.add_argument(
'-ul',
'--upperlb',type=int,dest=
'upperLumiBlock',default=
'999999',help=
"Upper lb",action=
'store')
663 parser.add_argument(
'-s',
'--stream',dest=
'stream',default=
'Main',help=
"Stream with or without prefix: express/CosmicCalo/Main/ZeroBias/MinBias",action=
'store')
664 parser.add_argument(
'-t',
'--tag',dest=
'tag',default=
'',help=
"DAQ tag: data16_13TeV, data16_cos... By default retrieve it via atlasdqm",action=
'store')
665 parser.add_argument(
'-a',
'--amiTag',dest=
'amiTag',default=
'f',help=
"First letter of AMI tag: x->express / f->bulk",action=
'store')
666 parser.add_argument(
'-e',
'--eta',type=float,dest=
'etaSpot',default=
'-999.',help=
'Eta of hot spot',action=
'store')
667 parser.add_argument(
'-p',
'--phi',type=float,dest=
'phiSpot',default=
'-999.',help=
'Phi of hot spot',action=
'store')
668 parser.add_argument(
'-x',
'--x',type=float,dest=
'xSpot',default=
'-999.',help=
'X of hot spot',action=
'store')
669 parser.add_argument(
'-y',
'--y',type=float,dest=
'ySpot',default=
'-999.',help=
'Y of hot spot',action=
'store')
670 parser.add_argument(
'-ia',
'--integralAbove',type=float,dest=
'integralAbove',default=
'-999.',help=
'Lower bound of integral',action=
'store')
671 parser.add_argument(
'-d',
'--delta',type=float,dest=
'deltaSpot',default=
'0.1',help=
'Distance to look around hot spot',action=
'store')
672 parser.add_argument(
'-o',
'--object',dest=
'objectType',default=
'TopoClusters',help=
'2D OCCUPANCY: TopoClusters,EMTopoClusters,\n EMTopoJets,TightFwdElectrons,Tau \n1D OCCUPANCY: EMTopoJets_eta,Tau_eta,Tau_phi \nINTEGRAL : NumberTau,NumberTightFwdElectrons,NumberHLTJet',action=
'store')
673 parser.add_argument(
'-m',
'--min',type=float,dest=
'minInLB',default=
'5',help=
'Min number of occurences in a LB',action=
'store')
674 parser.add_argument(
'-g',
'--grl',dest=
'defectQuery',help=
'Look for Calo/LAr/Tile defects set in suspicious LBs',action=
'store_true')
676 args = parser.parse_args()
680 if (
not os.path.isfile(
"atlasdqmpass.txt")):
681 print(
"To retrieve the data project tag, you need to generate an atlasdqm key and store it in this directory as atlasdqmpass.txt (yourname:key)")
682 print(
"To generate a key, go here : https://atlasdqm.cern.ch/dqauth/")
683 print(
"You can also define by hand the data project tag wit hthe option -t")
685 passfile =
open(
"atlasdqmpass.txt")
686 passwd = passfile.read().strip(); passfile.close()
687 passurl =
'https://%s@atlasdqm.cern.ch'%passwd
688 s = xmlrpclib.ServerProxy(passurl)
689 run_spec = {
'stream':
'physics_CosmicCalo',
'proc_ver': 1,
'source':
'tier0',
'low_run': args.runNumber,
'high_run':args.runNumber}
690 run_info= s.get_run_information(run_spec)
691 if '%d'%args.runNumber
not in run_info.keys()
or len(run_info[
'%d'%args.runNumber])<2:
692 print(
"Unable to retrieve the data project tag via atlasdqm... Please double check your atlasdqmpass.txt or define it by hand with -t option")
694 args.tag = run_info[
'%d'%args.runNumber][1]