3 from __future__
import print_function
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 = lineSpl[0].
split(
" ")[0]
197 vertices = lineSpl[1]
198 xy = vertices.split(
" ")
202 coordSpl = coord.split(
",")
203 if applyModuleRotation:
204 x.append(-(
float(coordSpl[0]) * sX + tX))
205 y.append((
float(coordSpl[1]) * sY + tY))
207 x.append(
float(coordSpl[0]) * sX + tX)
208 y.append(
float(coordSpl[1]) * sY + tY)
217 if applyModuleRotation:
218 bin = TGraph(verNum, y, x)
220 bin = TGraph(verNum, x, y)
237 for i
in range(maxPxBarrel):
239 currBarrelTranslateX = 0 240 currBarrelTranslateY = barrelLadderShift[i] 242 self.__AddNamedBins(geoFile, currBarrelTranslateX, currBarrelTranslateY, 1, 1, True)
247 for i
in range(-maxPxForward, 0):
248 with open(self.
geometryFilenames[maxPxBarrel + maxPxForward + i],
"r") as geoFile: 249 currForwardTranslateX = forwardDiskXShift[-i - 1] 250 currForwardTranslateY = -forwardDiskYShift 252 self.__AddNamedBins(geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1) 255 for i
in range(maxPxForward):
256 with open(self.
geometryFilenames[maxPxBarrel + maxPxForward + i],
"r") as geoFile: 257 currForwardTranslateX = forwardDiskXShift[i] 258 currForwardTranslateY = forwardDiskYShift 260 self.__AddNamedBins(geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1) 264 print(
"Base Tracker Map: constructed")
267 def __init__(self, inputDQMName, outputDirName, minMaxFileName, limits, modDicName, runNumber, dirs, dirsAliases):
288 for i
in range(maxPxBarrel):
291 for i
in range(-maxPxForward, maxPxForward + 1):
302 for dir
in self.
dirs:
308 with open(self.
detIDsFileName,
"r") as detIDs: # create dictionary online -> rawid 310 items = entry.replace(
"\n",
" ").
split(
" ")
329 lineSpl = y.strip().
split(
" ")
334 currName = lineSpl[0]
335 zMin =
float(lineSpl[1])
336 zMax =
float(lineSpl[2])
337 isLog =
False if lineSpl[3] ==
"0" else True 338 isAbs =
False if lineSpl[4] ==
"0" else True 340 self.
limitsDic.
update({currName : {
"zMin" : zMin,
"zMax" : zMax,
"isLog" : isLog,
"isAbs" : isAbs}})
349 print(group[0].GetName())
350 name =
''.
join(group[0].GetName().
split(
"_per_")[0])
354 nbinsX = obj.GetNbinsX()
355 nbinsY = obj.GetNbinsY()
361 for x
in range(-maxX, maxX + 1):
364 for y
in range(-maxY, maxY + 1, 1):
374 for x
in range(-maxX, maxX + 1):
377 for y
in range(-maxY, maxY + 1):
380 for panel
in range(1, 3):
384 print(
"Unrecognized plot")
386 print(
"Histograms saved to internal data structure")
394 print((d, module[d]))
415 for mv
in monitoredValues:
418 histoTitle =
"Run " + self.
runNumber +
": Tracker Map for " + mv
420 applyLogScale =
False 421 applyAbsValue =
False 425 print(mv +
" found in limits dictionary - applying custom limits...")
427 currentHist.SetMinimum(limitsElem[
"zMin"])
428 currentHist.SetMaximum(limitsElem[
"zMax"])
429 applyLogScale = limitsElem[
"isLog"]
430 applyAbsValue = limitsElem[
"isAbs"]
437 listOfVals.append([val, detId, onlineName])
439 currentHist.Fill(
str(detId),
abs(val))
441 currentHist.Fill(
str(detId), val)
443 listOfVals = sorted(listOfVals, key =
lambda item: item[0])
445 minMaxFile.write(
"\n" + mv +
"\n\n")
447 minMaxFile.write(
"MIN:\n")
448 for i
in range(extremeBinsNum):
449 minMaxFile.write(
"\t" +
str(listOfVals[i][1]) +
" " +
str(listOfVals[i][2]) +
" " +
str(listOfVals[i][0]) +
"\n")
451 minMaxFile.write(
"MAX:\n")
452 for i
in range(extremeBinsNum):
453 minMaxFile.write(
"\t" +
str(listOfVals[-i - 1][1]) +
" " +
str(listOfVals[-i - 1][2]) +
" " +
str(listOfVals[-i - 1][0]) +
"\n")
455 c1 = TCanvas(mv, mv, 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);
481 arrow = TArrow(0.05, 27.0, 0.05, -30.0, 0.02,
"|>")
482 arrow.SetLineWidth(4)
485 phiArrow = TArrow(0.0, 27.0, 30.0, 27.0, 0.02,
"|>")
486 phiArrow.SetLineWidth(4)
489 xArrow = TArrow(25.0, 44.5, 50.0, 44.5, 0.02,
"|>")
490 xArrow.SetLineWidth(4)
493 yArrow = TArrow(25.0, 44.5, 25.0, 69.5, 0.02,
"|>")
494 yArrow.SetLineWidth(4)
508 txt.SetTextSize(0.05)
509 txt.DrawLatex(0.5, 0.95, histoTitle)
511 txt.SetTextSize(0.03)
513 txt.DrawLatex(0.5, 0.125,
"-DISK")
514 txt.DrawLatex(0.5, 0.075,
"NUMBER ->")
515 txt.DrawLatex(0.5, 0.875,
"+DISK")
517 txt.DrawLatex(0.17, 0.35,
"+z")
518 txt.DrawLatexNDC(0.36, 0.685,
"+phi")
519 txt.DrawLatex(0.38, 0.73,
"+x")
520 txt.DrawLatex(0.26, 0.875,
"+y")
523 txt.DrawLatex(0.17, 0.5,
"BARREL")
534 for i
in range(1, len(sys.argv), 1):
536 inputFileName = sys.argv[i]
538 plotWidth =
int(sys.argv[i])
540 plotHeight =
int(sys.argv[i])
545 detIDsFileName = sys.argv[i]
547 deductedRunNumber = inputFileName.split(
"_R000")[1][0:6]
548 print(deductedRunNumber)
550 baseRootDirs = [
"DQMData/Run " + deductedRunNumber +
"/PixelPhase1/Run summary/Phase1_MechanicalView" 551 ,
"DQMData/Run " + deductedRunNumber +
"/PixelPhase1/Run summary/Tracks" 554 baseRootDirsAliases = {baseRootDirs[0]:
"" 555 , baseRootDirs[1]:
"T" 558 readerObj =
TH2PolyOfflineMaps(inputFileName, outputDirectoryName, minMaxFileName, limits, detIDsFileName, deductedRunNumber, baseRootDirs, baseRootDirsAliases)
560 readerObj.ReadHistograms()
562 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)