3 from __future__
import print_function
7 from copy
import deepcopy
8 from array
import array
17 for dir
in os.environ[
'CMSSW_SEARCH_PATH'].
split(
":"):
18 if os.path.exists(os.path.join(dir,rfile)):
return os.path.join(dir,rfile)
23 inputFileName =
"DQM_V0013_R000292154__StreamExpressCosmics__Commissioning2017-Express-v1__DQMIO.root" 24 limitsFileName =
"limits.dat" 25 outputDirectoryName =
"OUT/" 26 minMaxFileName =
"minmax.out" 28 detIDsFileName =
getFileInPath(
'DQM/SiStripMonitorClient/data/detids.dat')
30 baseRootDirs = [
"DQMData/Run 292154/PixelPhase1/Run summary/Phase1_MechanicalView" 31 ,
"DQMData/Run 292154/PixelPhase1/Run summary/Tracks" 37 barrelLadderShift = [0, 14, 44, 90]
39 forwardDiskXShift = [25, 75, 125]
40 forwardDiskYShift = 45;
42 plotWidth, plotHeight = 3000, 2000
45 limits = [
"num_digis 0.01 90 1 0",
46 "num_clusters 0.01 25 1 0",
47 "Trechitsize_y 0.01 10 0 0",
48 "Trechitsize_x 0.01 10 0 0",
49 "Tresidual_y 0.0000001 0.004 0 1",
50 "Tresidual_x 0.0000001 0.004 0 1",
51 "Tcharge 2000 80000 0 0",
52 "Thitefficiency 0.95 1 0 0",
54 "Tnum_clusters_ontrack 0.01 15 1 0",
58 "charge 2000 80000 0 0",
72 currPath = (dir.GetPath().
split(
":/"))[1]
74 print(
"Exception raised: Path not found in the input file")
77 for obj
in dir.GetListOfKeys():
78 if not obj.IsFolder():
79 if obj.ReadObjectAny(TClass.GetClass(
"TH2")):
80 th2 = deepcopy(obj.ReadObj())
82 if 6 < th2.GetNbinsX() < 10
and name.find(
"per") != -1
and name.find(
"Lumisection") == -1:
83 print(
''.
join([dir.GetPath(),
'/', name]))
88 if currPath.startswith(i):
92 th2.SetName(prefix + th2.GetName())
93 self.listOfNumHistograms.append(th2)
98 if isXlowerThanZero
and isYlowerThanZero:
100 if isXlowerThanZero
and isYlowerThanZero ==
False:
102 if isXlowerThanZero ==
False and isYlowerThanZero:
104 if isXlowerThanZero ==
False and isYlowerThanZero ==
False:
108 theLadder =
abs(signedLadder)
109 theModule =
abs(signedModule)
149 shortLadder = theLadder - 5 * i
150 for i
in range(0, shortLadder, 2):
155 for i
in range(2, theLadder, 3):
160 sector = (theLadder + 3) // 4
164 thePart = self.
__GetPartStr(signedModule < 0, signedLadder < 0)
166 return "BPix_B" + thePart +
"_SEC" + theSector +
"_LYR" +
str(layer) +
"_LDR" +
str(
abs(signedLadder)) +
"F_MOD" +
str(
abs(signedModule))
169 thePart = self.
__GetPartStr(signedDisk < 0, signedBlade < 0)
170 return "FPix_B" + thePart +
"_D" +
str(
abs(signedDisk)) +
"_BLD" +
str(
abs(signedBlade)) +
"_PNL" +
str(panel) +
"_RNG" +
str(ring)
173 currentGroupName =
"" 179 objName = obj.GetName()
180 objNameSplit = objName.split(
"_")
181 objNameCollected =
''.
join(objNameSplit[0:-1])
182 if objNameCollected != currentGroupName:
183 if len(groupOfHists):
184 self.groupedHistograms.append(groupOfHists)
187 currentGroupName = objNameCollected
188 groupOfHists.append(obj)
189 self.groupedHistograms.append(groupOfHists)
194 lineSpl = line.strip().
split(
"\"")
196 detId = lineSpl[0].
split(
" ")[0]
198 vertices = lineSpl[1]
199 xy = vertices.split(
" ")
203 coordSpl = coord.split(
",")
204 if applyModuleRotation:
205 x.append(-(
float(coordSpl[0]) * sX + tX))
206 y.append((
float(coordSpl[1]) * sY + tY))
208 x.append(
float(coordSpl[0]) * sX + tX)
209 y.append(
float(coordSpl[1]) * sY + tY)
218 if applyModuleRotation:
219 bin = TGraph(verNum, y, x)
221 bin = TGraph(verNum, x, y)
225 self.__BaseTrackerMap.AddBin(bin)
231 self.__BaseTrackerMap.SetFloat(1)
232 self.__BaseTrackerMap.GetXaxis().SetTitle(
"")
233 self.__BaseTrackerMap.GetYaxis().SetTitle(
"")
234 self.__BaseTrackerMap.SetOption(
"COLZ L")
235 self.__BaseTrackerMap.SetStats(0)
238 for i
in range(maxPxBarrel):
240 currBarrelTranslateX = 0 241 currBarrelTranslateY = barrelLadderShift[i] 243 self.__AddNamedBins(geoFile, currBarrelTranslateX, currBarrelTranslateY, 1, 1, True)
248 for i
in range(-maxPxForward, 0):
249 with open(self.
geometryFilenames[maxPxBarrel + maxPxForward + i],
"r") as geoFile: 250 currForwardTranslateX = forwardDiskXShift[-i - 1] 251 currForwardTranslateY = -forwardDiskYShift 253 self.__AddNamedBins(geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1) 256 for i
in range(maxPxForward):
257 with open(self.
geometryFilenames[maxPxBarrel + maxPxForward + i],
"r") as geoFile: 258 currForwardTranslateX = forwardDiskXShift[i] 259 currForwardTranslateY = forwardDiskYShift 261 self.__AddNamedBins(geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1) 265 print(
"Base Tracker Map: constructed")
268 def __init__(self, inputDQMName, outputDirName, minMaxFileName, limits, modDicName, runNumber, dirs, dirsAliases):
289 for i
in range(maxPxBarrel):
290 self.geometryFilenames.append(
getFileInPath(
"DQM/SiStripMonitorClient/data/Geometry/vertices_barrel_" +
str(i + 1)))
292 for i
in range(-maxPxForward, maxPxForward + 1):
295 self.geometryFilenames.append(
getFileInPath(
"DQM/SiStripMonitorClient/data/Geometry/vertices_forward_" +
str(i)))
300 if self.inputFile.IsOpen():
303 for dir
in self.
dirs:
309 with open(self.
detIDsFileName,
"r") as detIDs: # create dictionary online -> rawid 311 items = entry.replace(
"\n",
" ").
split(
" ")
312 self.detDict.update({items[1] :
int(items[0])})
314 self.internalData.update({
int(items[0]) : {}})
330 lineSpl = y.strip().
split(
" ")
335 currName = lineSpl[0]
336 zMin =
float(lineSpl[1])
337 zMax =
float(lineSpl[2])
338 isLog =
False if lineSpl[3] ==
"0" else True 339 isAbs =
False if lineSpl[4] ==
"0" else True 341 self.limitsDic.update({currName : {
"zMin" : zMin,
"zMax" : zMax,
"isLog" : isLog,
"isAbs" : isAbs}})
345 if self.inputFile.IsOpen():
350 print(group[0].GetName())
351 name =
''.
join(group[0].GetName().
split(
"_per_")[0])
352 self.availableNames.append(name)
355 nbinsX = obj.GetNbinsX()
356 nbinsY = obj.GetNbinsY()
362 for x
in range(-maxX, maxX + 1):
365 for y
in range(-maxY, maxY + 1, 1):
375 for x
in range(-maxX, maxX + 1):
378 for y
in range(-maxY, maxY + 1):
381 for panel
in range(1, 3):
385 print(
"Unrecognized plot")
387 print(
"Histograms saved to internal data structure")
395 print((d, module[d]))
416 for mv
in monitoredValues:
419 histoTitle =
"Run " + self.
runNumber +
": Tracker Map for " + mv
421 applyLogScale =
False 422 applyAbsValue =
False 426 print(mv +
" found in limits dictionary - applying custom limits...")
428 currentHist.SetMinimum(limitsElem[
"zMin"])
429 currentHist.SetMaximum(limitsElem[
"zMax"])
430 applyLogScale = limitsElem[
"isLog"]
431 applyAbsValue = limitsElem[
"isAbs"]
438 listOfVals.append([val, detId, onlineName])
440 currentHist.Fill(
str(detId),
abs(val))
442 currentHist.Fill(
str(detId), 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")
456 c1 = TCanvas(mv, mv, plotWidth , plotHeight)
463 currentHist.Draw(
"AC COLZ L")
466 palette = currentHist.FindObject(
"palette");
467 palette.SetX1NDC(0.89);
468 palette.SetX2NDC(0.91);
469 palette.SetLabelSize(0.05);
482 arrow = TArrow(0.05, 27.0, 0.05, -30.0, 0.02,
"|>")
483 arrow.SetLineWidth(4)
486 phiArrow = TArrow(0.0, 27.0, 30.0, 27.0, 0.02,
"|>")
487 phiArrow.SetLineWidth(4)
490 xArrow = TArrow(25.0, 44.5, 50.0, 44.5, 0.02,
"|>")
491 xArrow.SetLineWidth(4)
494 yArrow = TArrow(25.0, 44.5, 25.0, 69.5, 0.02,
"|>")
495 yArrow.SetLineWidth(4)
509 txt.SetTextSize(0.05)
510 txt.DrawLatex(0.5, 0.95, histoTitle)
512 txt.SetTextSize(0.03)
514 txt.DrawLatex(0.5, 0.125,
"-DISK")
515 txt.DrawLatex(0.5, 0.075,
"NUMBER ->")
516 txt.DrawLatex(0.5, 0.875,
"+DISK")
518 txt.DrawLatex(0.17, 0.35,
"+z")
519 txt.DrawLatexNDC(0.36, 0.685,
"+phi")
520 txt.DrawLatex(0.38, 0.73,
"+x")
521 txt.DrawLatex(0.26, 0.875,
"+y")
524 txt.DrawLatex(0.17, 0.5,
"BARREL")
530 if self.inputFile.IsOpen():
531 self.inputFile.Close()
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)
LOTS OF CODE BORROWED FROM: PYTHONBINREADER, PIXELTRACKERMAP.
S & print(S &os, JobReport::InputFile const &f)
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)