6 from copy
import deepcopy
7 from array
import array
15 for dir
in os.environ[
'CMSSW_SEARCH_PATH'].
split(
":"):
16 if os.path.exists(os.path.join(dir,rfile)):
return os.path.join(dir,rfile)
21 inputFileName =
"DQM_V0013_R000292154__StreamExpressCosmics__Commissioning2017-Express-v1__DQMIO.root" 22 limitsFileName =
"limits.dat" 23 outputDirectoryName =
"OUT/" 24 minMaxFileName =
"minmax.out" 26 detIDsFileName =
getFileInPath(
'DQM/SiStripMonitorClient/data/detids.dat')
28 baseRootDirs = [
"DQMData/Run 292154/PixelPhase1/Run summary/Phase1_MechanicalView" 29 ,
"DQMData/Run 292154/PixelPhase1/Run summary/Tracks" 35 barrelLadderShift = [0, 14, 44, 90]
37 forwardDiskXShift = [25, 75, 125]
38 forwardDiskYShift = 45;
40 plotWidth, plotHeight = 3000, 2000
43 limits = [
"num_digis 0.01 90 1 0",
44 "num_clusters 0.01 25 1 0",
45 "Trechitsize_y 0.01 10 0 0",
46 "Trechitsize_x 0.01 10 0 0",
47 "Tresidual_y 0.0000001 0.004 0 1",
48 "Tresidual_x 0.0000001 0.004 0 1",
49 "Tcharge 2000 80000 0 0",
50 "Thitefficiency 0.95 1 0 0",
52 "Tnum_clusters_ontrack 0.01 15 1 0",
56 "charge 2000 80000 0 0",
70 currPath = (dir.GetPath().
split(
":/"))[1]
72 print(
"Exception raised: Path not found in the input file")
75 for obj
in dir.GetListOfKeys():
76 if not obj.IsFolder():
77 if obj.ReadObjectAny(TClass.GetClass(
"TH2")):
78 th2 = deepcopy(obj.ReadObj())
80 if 6 < th2.GetNbinsX() < 10
and name.find(
"per") != -1
and name.find(
"Lumisection") == -1:
81 print(
''.
join([dir.GetPath(),
'/', name]))
86 if currPath.startswith(i):
90 th2.SetName(prefix + th2.GetName())
91 self.listOfNumHistograms.append(th2)
96 if isXlowerThanZero
and isYlowerThanZero:
98 if isXlowerThanZero
and isYlowerThanZero ==
False:
100 if isXlowerThanZero ==
False and isYlowerThanZero:
102 if isXlowerThanZero ==
False and isYlowerThanZero ==
False:
106 theLadder =
abs(signedLadder)
107 theModule =
abs(signedModule)
147 shortLadder = theLadder - 5 * i
148 for i
in range(0, shortLadder, 2):
153 for i
in range(2, theLadder, 3):
158 sector = (theLadder + 3) // 4
162 thePart = self.
__GetPartStr(signedModule < 0, signedLadder < 0)
164 return "BPix_B" + thePart +
"_SEC" + theSector +
"_LYR" +
str(layer) +
"_LDR" +
str(
abs(signedLadder)) +
"F_MOD" +
str(
abs(signedModule))
167 thePart = self.
__GetPartStr(signedDisk < 0, signedBlade < 0)
168 return "FPix_B" + thePart +
"_D" +
str(
abs(signedDisk)) +
"_BLD" +
str(
abs(signedBlade)) +
"_PNL" +
str(panel) +
"_RNG" +
str(ring)
171 currentGroupName =
"" 177 objName = obj.GetName()
178 objNameSplit = objName.split(
"_")
179 objNameCollected =
''.
join(objNameSplit[0:-1])
180 if objNameCollected != currentGroupName:
181 if len(groupOfHists):
182 self.groupedHistograms.append(groupOfHists)
185 currentGroupName = objNameCollected
186 groupOfHists.append(obj)
187 self.groupedHistograms.append(groupOfHists)
192 lineSpl = line.strip().
split(
"\"")
194 detId = 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)
216 if applyModuleRotation:
217 bin = TGraph(verNum, y, x)
219 bin = TGraph(verNum, x, y)
223 self.__BaseTrackerMap.AddBin(bin)
229 self.__BaseTrackerMap.SetFloat(1)
230 self.__BaseTrackerMap.GetXaxis().SetTitle(
"")
231 self.__BaseTrackerMap.GetYaxis().SetTitle(
"")
232 self.__BaseTrackerMap.SetOption(
"COLZ L")
233 self.__BaseTrackerMap.SetStats(0)
236 for i
in range(maxPxBarrel):
238 currBarrelTranslateX = 0 239 currBarrelTranslateY = barrelLadderShift[i] 241 self.__AddNamedBins(geoFile, currBarrelTranslateX, currBarrelTranslateY, 1, 1, True)
246 for i
in range(-maxPxForward, 0):
247 with open(self.
geometryFilenames[maxPxBarrel + maxPxForward + i],
"r") as geoFile: 248 currForwardTranslateX = forwardDiskXShift[-i - 1] 249 currForwardTranslateY = -forwardDiskYShift 251 self.__AddNamedBins(geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1) 254 for i
in range(maxPxForward):
255 with open(self.
geometryFilenames[maxPxBarrel + maxPxForward + i],
"r") as geoFile: 256 currForwardTranslateX = forwardDiskXShift[i] 257 currForwardTranslateY = forwardDiskYShift 259 self.__AddNamedBins(geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1) 263 print(
"Base Tracker Map: constructed")
266 def __init__(self, inputDQMName, outputDirName, minMaxFileName, limits, modDicName, runNumber, dirs, dirsAliases):
287 for i
in range(maxPxBarrel):
288 self.geometryFilenames.append(
getFileInPath(
"DQM/SiStripMonitorClient/data/Geometry/vertices_barrel_" +
str(i + 1)))
290 for i
in range(-maxPxForward, maxPxForward + 1):
293 self.geometryFilenames.append(
getFileInPath(
"DQM/SiStripMonitorClient/data/Geometry/vertices_forward_" +
str(i)))
298 if self.inputFile.IsOpen():
301 for dir
in self.
dirs:
307 with open(self.
detIDsFileName,
"r") as detIDs: # create dictionary online -> rawid 309 items = entry.replace(
"\n",
" ").
split(
" ")
310 self.detDict.update({items[1] :
int(items[0])})
312 self.internalData.update({
int(items[0]) : {}})
328 lineSpl = y.strip().
split(
" ")
333 currName = lineSpl[0]
334 zMin =
float(lineSpl[1])
335 zMax =
float(lineSpl[2])
336 isLog =
False if lineSpl[3] ==
"0" else True 337 isAbs =
False if lineSpl[4] ==
"0" else True 339 self.limitsDic.update({currName : {
"zMin" : zMin,
"zMax" : zMax,
"isLog" : isLog,
"isAbs" : isAbs}})
343 if self.inputFile.IsOpen():
348 print(group[0].GetName())
349 name =
''.
join(group[0].GetName().
split(
"_per_")[0])
350 self.availableNames.append(name)
353 nbinsX = obj.GetNbinsX()
354 nbinsY = obj.GetNbinsY()
360 for x
in range(-maxX, maxX + 1):
363 for y
in range(-maxY, maxY + 1, 1):
373 for x
in range(-maxX, maxX + 1):
376 for y
in range(-maxY, maxY + 1):
379 for panel
in range(1, 3):
383 print(
"Unrecognized plot")
385 print(
"Histograms saved to internal data structure")
414 for mv
in monitoredValues:
417 histoTitle =
"Run " + self.
runNumber +
": Tracker Map for " + mv
419 applyLogScale =
False 420 applyAbsValue =
False 424 print(mv +
" found in limits dictionary - applying custom limits...")
426 currentHist.SetMinimum(limitsElem[
"zMin"])
427 currentHist.SetMaximum(limitsElem[
"zMax"])
428 applyLogScale = limitsElem[
"isLog"]
429 applyAbsValue = limitsElem[
"isAbs"]
436 listOfVals.append([val, detId, onlineName])
438 currentHist.Fill(
str(detId),
abs(val))
440 currentHist.Fill(
str(detId), val)
442 listOfVals = sorted(listOfVals, key =
lambda item: item[0])
444 minMaxFile.write(
"\n" + mv +
"\n\n")
446 minMaxFile.write(
"MIN:\n")
447 for i
in range(extremeBinsNum):
448 minMaxFile.write(
"\t" +
str(listOfVals[i][1]) +
" " +
str(listOfVals[i][2]) +
" " +
str(listOfVals[i][0]) +
"\n")
450 minMaxFile.write(
"MAX:\n")
451 for i
in range(extremeBinsNum):
452 minMaxFile.write(
"\t" +
str(listOfVals[-i - 1][1]) +
" " +
str(listOfVals[-i - 1][2]) +
" " +
str(listOfVals[-i - 1][0]) +
"\n")
454 c1 = TCanvas(mv, mv, plotWidth , plotHeight)
461 currentHist.Draw(
"AC COLZ L")
464 palette = currentHist.FindObject(
"palette");
465 palette.SetX1NDC(0.89);
466 palette.SetX2NDC(0.91);
467 palette.SetLabelSize(0.05);
480 arrow = TArrow(0.05, 27.0, 0.05, -30.0, 0.02,
"|>")
481 arrow.SetLineWidth(4)
484 phiArrow = TArrow(0.0, 27.0, 30.0, 27.0, 0.02,
"|>")
485 phiArrow.SetLineWidth(4)
488 xArrow = TArrow(25.0, 44.5, 50.0, 44.5, 0.02,
"|>")
489 xArrow.SetLineWidth(4)
492 yArrow = TArrow(25.0, 44.5, 25.0, 69.5, 0.02,
"|>")
493 yArrow.SetLineWidth(4)
507 txt.SetTextSize(0.05)
508 txt.DrawLatex(0.5, 0.95, histoTitle)
510 txt.SetTextSize(0.03)
512 txt.DrawLatex(0.5, 0.125,
"-DISK")
513 txt.DrawLatex(0.5, 0.075,
"NUMBER ->")
514 txt.DrawLatex(0.5, 0.875,
"+DISK")
516 txt.DrawLatex(0.17, 0.35,
"+z")
517 txt.DrawLatexNDC(0.36, 0.685,
"+phi")
518 txt.DrawLatex(0.38, 0.73,
"+x")
519 txt.DrawLatex(0.26, 0.875,
"+y")
522 txt.DrawLatex(0.17, 0.5,
"BARREL")
528 if self.inputFile.IsOpen():
529 self.inputFile.Close()
532 for i
in range(1, len(sys.argv), 1):
534 inputFileName = sys.argv[i]
536 plotWidth =
int(sys.argv[i])
538 plotHeight =
int(sys.argv[i])
543 detIDsFileName = sys.argv[i]
545 deductedRunNumber = inputFileName.split(
"_R000")[1][0:6]
546 print(deductedRunNumber)
548 baseRootDirs = [
"DQMData/Run " + deductedRunNumber +
"/PixelPhase1/Run summary/Phase1_MechanicalView" 549 ,
"DQMData/Run " + deductedRunNumber +
"/PixelPhase1/Run summary/Tracks" 552 baseRootDirsAliases = {baseRootDirs[0]:
"" 553 , baseRootDirs[1]:
"T" 556 readerObj =
TH2PolyOfflineMaps(inputFileName, outputDirectoryName, minMaxFileName, limits, detIDsFileName, deductedRunNumber, baseRootDirs, baseRootDirsAliases)
558 readerObj.ReadHistograms()
560 readerObj.PrintTrackerMaps()
limitsDic
CREATE LIMITS DICTIONARY.
def __GroupHistograms(self)
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
def __GetBarrelSector(self, layer, signedLadder, signedModule)
def __TraverseDirTree(self, dir)
LOTS OF CODE BORROWED FROM: PYTHONBINREADER, PIXELTRACKERMAP.
def __BuildOnlineDiskName(self, signedDisk, signedBlade, panel, ring)
def __init__(self, inputDQMName, outputDirName, minMaxFileName, limits, modDicName, runNumber, dirs, dirsAliases)
Abs< T >::type abs(const T &t)
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)