219 histoPath, histoLegend, histoColor, histoType, histoName = getHistoInfo(args.objectType, args.runNumber)
220
221
224 b_wholeHisto = False
225 b_ValueNotEntries = False
226
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)
230 else:
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!)")
234
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!")
238 b_wholeHisto = True
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!)")
248 b_wholeHisto = True
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!")
254 b_wholeHisto = True
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!")
260 b_wholeHisto = True
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!")
266 b_wholeHisto = True
267
268
269 if (args.objectType == "NumberTightFwdElectrons" or args.objectType == "NumberTau"):
270 canvasOption = "logy"
271 else:
272 canvasOption = ""
273
274
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)
282 sys.exit()
283
284 f = R.TFile.Open(runFilePath)
285
286 histo = {}
287
288
289 for iHisto in histoPath.keys():
290
291
292 histo[iHisto] = f.Get(histoPath[iHisto])
293 histo[iHisto].SetTitle("%s (%s) - Run %d"%(histo[iHisto].GetTitle(),histoLegend[iHisto],args.runNumber))
294
295
300 regionBins = {}
301 for iHisto in histoPath.keys():
302 if b_wholeHisto:
303 regionBins[iHisto] = []
304 if ("2d" in histoType):
305 maxBin = (histo[iHisto].GetNbinsX()+2)*(histo[iHisto].GetNbinsY()+2)
306 else:
307 maxBin = (histo[iHisto].GetNbinsX()+2)
308 for iBin in range(maxBin):
309 regionBins[iHisto].append(iBin)
310 else:
311 nSteps = 1000
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)
345
346
349
350 c = {}
351 box = {}
352 line = {}
353 line2 = {}
354 arrow = {}
355 for iHisto in histoPath.keys():
356 total_tmp = 0
357 for iBin in regionBins[iHisto]:
358 total_tmp = total_tmp + histo[iHisto].GetBinContent(iBin)
359 if total_tmp == 0:
360 continue
361
362 c[iHisto] = R.TCanvas(histoLegend[iHisto])
363 if "logy" in canvasOption:
364 c[iHisto].SetLogy(1)
365
366 if histoType.startswith("2d"):
367 R.gStyle.SetPalette(1)
368 R.gStyle.SetOptStat("")
369
370 histo[iHisto].Draw("COLZ")
371 if not b_wholeHisto:
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)
379 box[iHisto].Draw()
380
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)
387 histo[iHisto].Draw()
388
389 if not b_wholeHisto:
390 if histoType == "1d_eta_Occupancy" or histoType == "1d_phi_Occupancy":
391 if maxH >0.:
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)
399 box[iHisto].Draw()
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)
404 line[iHisto].Draw()
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)
408 arrow[iHisto].Draw()
409
410
414
415 lbFilePathList = pathExtract.returnEosHistPathLB(args.runNumber,args.lowerLumiBlock,args.upperLumiBlock,args.stream,args.amiTag,args.tag)
416 nbHitInHot = []
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)
420 sys.exit()
421
422 LBs = [int(f.split(
"_lb")[1].
split(
".")[0])
for f
in lbFilePathList]
424 print(
"Max LB is",maxLB)
425
426 nLB=maxLB
427 nbHitInHot = {}
428 for iHisto in histoPath.keys():
429 nbHitInHot[iHisto] = [0.] * (nLB+1)
430 lowerLB = maxLB
431 upperLB = 0
432 lbCanvas = []
433 histoLBNoisy = []
434 fLB = {}
435
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]))
440
441
442
443 for count,lbFile in enumerate(lbFilePathList):
444 lbFilePath = "root://eosatlas.cern.ch/%s"%(lbFile).rstrip()
445
446 ilb = int((lbFile.split(
"_lb")[1]).
split(
"._")[0])
447 if (count%100 == 0):
448 sys.stdout.write("\n I processed %d/%d files \n LBs:"%(count,len(lbFilePathList)))
449 sys.stdout.write("%d "%(ilb))
450 sys.stdout.flush()
451 fLB[lbFile] = R.TFile.Open(lbFilePath)
452 histoLB = {}
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)
458
459 fLB[lbFile].Close()
460
461
465
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
471
472 if (lowerLB == upperLB):
473 lowerLB = lowerLB - 1
474 upperLB = upperLB + 4
475
478
479 maxNbInHot = 0
480 maxNbInHot_histo = ""
481 totalInRegionRecomp = {}
482 totalInRegion = {}
483 suspiciousLBlist = []
484
485
486
487 for iHisto in histoPath.keys():
488 totalInRegionRecomp[iHisto] = 0
489 totalInRegion[iHisto] = 0
490
491
492 sortedLB = {}
493
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)
498
499 sortedLB[iHisto] = [0] * nLB
500 for i in range(nLB):
501 totalInRegionRecomp[iHisto] = totalInRegionRecomp[iHisto] + nbHitInHot[iHisto][i]
502
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
509
510 sortedLB[iHisto].
sort(key=dict(zip(sortedLB[iHisto],nbHitInHot[iHisto])).get,reverse=
True)
511 nLB_aboveThreshold = 0
512 for i in range(nLB):
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]]))
517 else:
518 print(
"%d-LB: %d -> %.2f"%(i,sortedLB[iHisto][i],nbHitInHot[iHisto][sortedLB[iHisto][i]]))
519
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])
529 else:
530 print(
"In the whole run, the value is %.2f"%(totalInRegion[iHisto]))
531
532 affectedLB_forSummaryBinning = []
533 if (maxNbInHot != 0):
534 for i in range(35):
535 if (nbHitInHot[maxNbInHot_histo][sortedLB[maxNbInHot_histo][i]] > 0.05*maxNbInHot):
536 affectedLB_forSummaryBinning.append(sortedLB[maxNbInHot_histo][i])
537
538
541 leg = R.TLegend(0.855, 0.90-0.05*len(histoPath.keys()),
542 0.98, 0.9 )
543 leg.SetBorderSize(0)
544
545 if (upperLB>=lowerLB):
546 c0 = R.TCanvas("c0","Evolution vs LB",1400,550)
547 R.gStyle.SetOptStat("")
548 if histoType != "2d_xy_Occupancy":
549 c0.SetLogy(1)
550 c0.SetLeftMargin(.045)
551 c0.SetRightMargin(.15)
552 h0Evol = {}
553 first = True
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])
562
563 if (h0Evol[iHisto].GetMaximum() >= args.minInLB):
564 leg.AddEntry(h0Evol[iHisto],"#splitline{%s}{(%d entries in the run)}"%(histoLegend[iHisto],totalInRegion[iHisto]))
565
566 if first:
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)
571 first = False
572 else:
573 h0Evol[iHisto].Draw("PSAME HIST")
574 leg.Draw()
575 c0.Update()
576
577
578 leg2 = R.TLegend(0.855, 0.90-0.05*len(histoPath.keys()),
579 0.98, 0.9 )
580 leg2.SetBorderSize(0)
581
582 h_affectedLB = {}
583
584 print(
"Affected luminosity blocks sorted by the noise amplitude",affectedLB_forSummaryBinning)
585
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":
590 c0_2.SetLogy(1)
591 c0_2.SetLeftMargin(.045)
592 c0_2.SetRightMargin(.15)
593
594 onlineLumi = GetOnlineLumiFromCOOL(args.runNumber,0)
595 cumulatedAffectedLumi = 0.
596
597 first = True
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)
600
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)
605
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]])
611
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]))
614
615 if first:
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)
620 first = False
621 else:
622 h_affectedLB[iHisto].Draw("PSAME HIST")
623
624 leg2.Draw()
625
626 c0_2.SetGridx()
627 c0_2.Update()
628
629 print(
"WARNING: only the 35 most affected LB are displayed in the summary plot")
630
631
632 if args.defectQuery:
633 print(
"I am looking for LAr/Tile/Calo defects defined for the suspicious LB")
634 from DQDefects import DefectsDB
635 db = 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)
638 for iDef in defects:
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))
646 else:
647 print(
"%s: %d->%d set by %s - %s"%(iDef.channel,iDef.since.lumi,iDef.until.lumi-1,iDef.user,iDef.comment))
648
649 input("Please press the Enter key to proceed")
650
651 sys.exit()
652
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...
std::vector< std::string > split(const std::string &s, const std::string &t=":")