3 from __future__
import print_function
6 from ROOT
import gROOT, gStyle, gPad, TCanvas, TClass, TGraph, TFile, TArrow, TLatex, TH2Poly, kBlack
7 from copy
import deepcopy
8 from array
import array
16 for dir
in os.environ[
'CMSSW_SEARCH_PATH'].
split(
":"):
17 if os.path.exists(os.path.join(dir,rfile)):
return os.path.join(dir,rfile)
22 inputFileName =
"DQM_V0013_R000292154__StreamExpressCosmics__Commissioning2017-Express-v1__DQMIO.root" 23 limitsFileName =
"limits.dat" 24 outputDirectoryName =
"OUT/" 25 minMaxFileName =
"minmax.out" 27 detIDsFileName =
getFileInPath(
'DQM/SiStripMonitorClient/data/detids.dat')
29 baseRootDirs = [
"DQMData/Run 292154/PixelPhase1/Run summary/Phase1_MechanicalView" 30 ,
"DQMData/Run 292154/PixelPhase1/Run summary/Tracks" 36 barrelLadderShift = [0, 14, 44, 90]
38 forwardDiskXShift = [25, 75, 125]
39 forwardDiskYShift = 45;
41 plotWidth, plotHeight = 3000, 2000
44 limits = [
"num_digis 0.01 90 1 0",
45 "num_clusters 0.01 25 1 0",
46 "Trechitsize_y 0.01 10 0 0",
47 "Trechitsize_x 0.01 10 0 0",
48 "Tresidual_y 0.0000001 0.004 0 1",
49 "Tresidual_x 0.0000001 0.004 0 1",
50 "Tcharge 2000 80000 0 0",
51 "Thitefficiency 0.95 1 0 0",
53 "Tnum_clusters_ontrack 0.01 15 1 0",
57 "charge 2000 80000 0 0",
71 currPath = (dir.GetPath().
split(
":/"))[1]
73 print(
"Exception raised: Path not found in the input file")
76 for obj
in dir.GetListOfKeys():
77 if not obj.IsFolder():
78 if obj.ReadObjectAny(TClass.GetClass(
"TH2")):
79 th2 = deepcopy(obj.ReadObj())
81 if 6 < th2.GetNbinsX() < 10
and name.find(
"per") != -1
and name.find(
"Lumisection") == -1:
82 print(
''.
join([dir.GetPath(),
'/', name]))
87 if currPath.startswith(i):
91 th2.SetName(prefix + th2.GetName())
97 if isXlowerThanZero
and isYlowerThanZero:
99 if isXlowerThanZero
and isYlowerThanZero ==
False:
101 if isXlowerThanZero ==
False and isYlowerThanZero:
103 if isXlowerThanZero ==
False and isYlowerThanZero ==
False:
107 theLadder =
abs(signedLadder)
108 theModule =
abs(signedModule)
148 shortLadder = theLadder - 5 * i
149 for i
in range(0, shortLadder, 2):
154 for i
in range(2, theLadder, 3):
159 sector = (theLadder + 3) // 4
163 thePart = self.
__GetPartStr(signedModule < 0, signedLadder < 0)
165 return "BPix_B" + thePart +
"_SEC" + theSector +
"_LYR" +
str(layer) +
"_LDR" +
str(
abs(signedLadder)) +
"F_MOD" +
str(
abs(signedModule))
168 thePart = self.
__GetPartStr(signedDisk < 0, signedBlade < 0)
169 return "FPix_B" + thePart +
"_D" +
str(
abs(signedDisk)) +
"_BLD" +
str(
abs(signedBlade)) +
"_PNL" +
str(panel) +
"_RNG" +
str(ring)
172 currentGroupName =
"" 178 objName = obj.GetName()
179 objNameSplit = objName.split(
"_")
180 objNameCollected =
''.
join(objNameSplit[0:-1])
181 if objNameCollected != currentGroupName:
182 if len(groupOfHists):
186 currentGroupName = objNameCollected
187 groupOfHists.append(obj)
193 lineSpl = line.strip().
split(
"\"")
195 detId =
str(lineSpl[0].
split(
" ")[1])+
"_("+
str(lineSpl[0].
split(
" ")[0])+
")" 196 vertices = lineSpl[1]
197 xy = vertices.split(
" ")
201 coordSpl = coord.split(
",")
202 if applyModuleRotation:
203 x.append(-(
float(coordSpl[0]) * sX + tX))
204 y.append((
float(coordSpl[1]) * sY + tY))
206 x.append(
float(coordSpl[0]) * sX + tX)
207 y.append(
float(coordSpl[1]) * sY + tY)
213 if applyModuleRotation:
214 bin = TGraph(verNum, y, x)
216 bin = TGraph(verNum, x, y)
233 for i
in range(maxPxBarrel):
235 currBarrelTranslateX = 0 236 currBarrelTranslateY = barrelLadderShift[i] 238 self.__AddNamedBins(geoFile, currBarrelTranslateX, currBarrelTranslateY, 1, 1, True)
243 for i
in range(-maxPxForward, 0):
244 with open(self.
geometryFilenames[maxPxBarrel + maxPxForward + i],
"r") as geoFile: 245 currForwardTranslateX = forwardDiskXShift[-i - 1] 246 currForwardTranslateY = -forwardDiskYShift 248 self.__AddNamedBins(geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1) 251 for i
in range(maxPxForward):
252 with open(self.
geometryFilenames[maxPxBarrel + maxPxForward + i],
"r") as geoFile: 253 currForwardTranslateX = forwardDiskXShift[i] 254 currForwardTranslateY = forwardDiskYShift 256 self.__AddNamedBins(geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1) 260 print(
"Base Tracker Map: constructed")
263 def __init__(self, inputDQMName, outputDirName, minMaxFileName, limits, modDicName, runNumber, dirs, dirsAliases):
284 for i
in range(maxPxBarrel):
287 for i
in range(-maxPxForward, maxPxForward + 1):
298 for dir
in self.
dirs:
304 with open(self.
detIDsFileName,
"r") as detIDs: # create dictionary online -> rawid 306 items = entry.replace(
"\n",
" ").
split(
" ")
325 lineSpl = y.strip().
split(
" ")
330 currName = lineSpl[0]
331 zMin =
float(lineSpl[1])
332 zMax =
float(lineSpl[2])
333 isLog =
False if lineSpl[3] ==
"0" else True 334 isAbs =
False if lineSpl[4] ==
"0" else True 336 self.
limitsDic.
update({currName : {
"zMin" : zMin,
"zMax" : zMax,
"isLog" : isLog,
"isAbs" : isAbs}})
345 print(group[0].GetName())
346 name =
''.
join(group[0].GetName().
split(
"_per_")[0])
350 nbinsX = obj.GetNbinsX()
351 nbinsY = obj.GetNbinsY()
357 for x
in range(-maxX, maxX + 1):
360 for y
in range(-maxY, maxY + 1, 1):
370 for x
in range(-maxX, maxX + 1):
373 for y
in range(-maxY, maxY + 1):
376 for panel
in range(1, 3):
380 print(
"Unrecognized plot")
382 print(
"Histograms saved to internal data structure")
390 print((d, module[d]))
411 for mv
in monitoredValues:
414 histoTitle =
"Run " + self.
runNumber +
": Tracker Map for " + mv
416 applyLogScale =
False 417 applyAbsValue =
False 421 print(mv +
" found in limits dictionary - applying custom limits...")
423 currentHist.SetMinimum(limitsElem[
"zMin"])
424 currentHist.SetMaximum(limitsElem[
"zMax"])
425 applyLogScale = limitsElem[
"isLog"]
426 applyAbsValue = limitsElem[
"isAbs"]
435 listOfVals.append([val, detId, onlineName])
437 nameId =
str(onlineName)+
"_("+
str(detId)+
")" 440 currentHist.Fill(
str(nameId),
abs(val))
442 currentHist.Fill(
str(nameId), val)
444 listOfVals = sorted(listOfVals, key =
lambda item: item[0])
446 minMaxFile.write(
"\n" + mv +
"\n\n")
448 minMaxFile.write(
"MIN:\n")
449 for i
in range(extremeBinsNum):
450 minMaxFile.write(
"\t" +
str(listOfVals[i][1]) +
" " +
str(listOfVals[i][2]) +
" " +
str(listOfVals[i][0]) +
"\n")
452 minMaxFile.write(
"MAX:\n")
453 for i
in range(extremeBinsNum):
454 minMaxFile.write(
"\t" +
str(listOfVals[-i - 1][1]) +
" " +
str(listOfVals[-i - 1][2]) +
" " +
str(listOfVals[-i - 1][0]) +
"\n")
457 c1 = TCanvas(
"MyT",
"MyT", plotWidth , plotHeight)
462 currentHist.Draw(
"AC COLZ L")
465 palette = currentHist.FindObject(
"palette");
466 palette.SetX1NDC(0.89);
467 palette.SetX2NDC(0.91);
468 palette.SetLabelSize(0.05);
479 arrow = TArrow(0.05, 27.0, 0.05, -30.0, 0.02,
"|>")
480 arrow.SetLineWidth(4)
483 phiArrow = TArrow(0.0, 27.0, 30.0, 27.0, 0.02,
"|>")
484 phiArrow.SetLineWidth(4)
487 xArrow = TArrow(25.0, 44.5, 50.0, 44.5, 0.02,
"|>")
488 xArrow.SetLineWidth(4)
491 yArrow = TArrow(25.0, 44.5, 25.0, 69.5, 0.02,
"|>")
492 yArrow.SetLineWidth(4)
506 txt.SetTextSize(0.05)
507 txt.DrawLatex(0.5, 0.95, histoTitle)
509 txt.SetTextSize(0.03)
511 txt.DrawLatex(0.5, 0.125,
"-DISK")
512 txt.DrawLatex(0.5, 0.075,
"NUMBER ->")
513 txt.DrawLatex(0.5, 0.875,
"+DISK")
515 txt.DrawLatex(0.17, 0.35,
"+z")
516 txt.DrawLatexNDC(0.36, 0.685,
"+phi")
517 txt.DrawLatex(0.38, 0.73,
"+x")
518 txt.DrawLatex(0.26, 0.875,
"+y")
521 txt.DrawLatex(0.17, 0.5,
"BARREL")
529 currentHist.GetZaxis().UnZoom()
530 currentHist.SetLineColor(kBlack)
531 currentHist.Draw(
"AL COLZ")
532 currentHist.GetXaxis().SetRangeUser(-10,155)
534 palette.SetX1NDC(0.92);
535 palette.SetX2NDC(0.94);
536 palette.SetY1NDC(0.02);
537 palette.SetY2NDC(0.91);
538 gPad.SetRightMargin(0.08);
539 gPad.SetLeftMargin(0.01);
540 gPad.SetTopMargin(0.09);
541 gPad.SetBottomMargin(0.02);
544 zarrow = TArrow(0, 27, 0, -30, 0.02,
"|>")
545 zarrow.SetLineWidth(3)
547 phiArrow.SetLineWidth(3)
549 xArrow.SetLineWidth(3)
551 yArrow.SetLineWidth(3)
556 txt.SetTextSize(0.05)
557 PixelTitle =
"Run " + self.
runNumber +
": Pixel " + mv
558 txt.DrawLatex(0.5, 0.95, PixelTitle)
560 txt.SetTextSize(0.04)
562 txt.DrawLatex(75, -65,
"-DISK")
563 txt.DrawLatex(75, 65,
"+DISK")
564 txt.DrawLatex(50, -60,
"NUMBER ->")
566 txt.DrawLatex(-5, -20,
"+z")
567 txt.DrawLatex(35, 30,
"+phi")
568 txt.DrawLatex(55, 45,
"+x")
569 txt.DrawLatex(30, 65,
"+y")
572 txt.DrawLatex(-5, 0,
"BARREL")
583 for i
in range(1, len(sys.argv), 1):
585 inputFileName = sys.argv[i]
587 plotWidth =
int(sys.argv[i])
589 plotHeight =
int(sys.argv[i])
594 detIDsFileName = sys.argv[i]
596 deductedRunNumber = inputFileName.split(
"_R000")[1][0:6]
597 print(deductedRunNumber)
599 baseRootDirs = [
"DQMData/Run " + deductedRunNumber +
"/PixelPhase1/Run summary/Phase1_MechanicalView" 600 ,
"DQMData/Run " + deductedRunNumber +
"/PixelPhase1/Run summary/Tracks" 603 baseRootDirsAliases = {baseRootDirs[0]:
"" 604 , baseRootDirs[1]:
"T" 607 readerObj =
TH2PolyOfflineMaps(inputFileName, outputDirectoryName, minMaxFileName, limits, detIDsFileName, deductedRunNumber, baseRootDirs, baseRootDirsAliases)
609 readerObj.ReadHistograms()
611 readerObj.PrintTrackerMaps()
limitsDic
CREATE LIMITS DICTIONARY.
def __GroupHistograms(self)
def __GetBarrelSector(self, layer, signedLadder, signedModule)
def __TraverseDirTree(self, dir)
def __BuildOnlineDiskName(self, signedDisk, signedBlade, panel, ring)
def __init__(self, inputDQMName, outputDirName, minMaxFileName, limits, modDicName, runNumber, dirs, dirsAliases)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Abs< T >::type abs(const T &t)
def split(sequence, size)
static std::string join(char **cmd)
def __CreateTrackerBaseMap(self)
def PrintTrackerMaps(self)
def __GetPartStr(self, isXlowerThanZero, isYlowerThanZero)
def __BuildOnlineBarrelName(self, signedModule, signedLadder, layer)
def __AddNamedBins(self, geoFile, tX, tY, sX, sY, applyModuleRotation=False)