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")