8 from copy
import deepcopy
18 rocXLen = 1.0 / rocsInRow
20 maxRocIdx = rocsInCol * rocsInRow - 1
22 onlineMaxLadder = [6, 14, 22, 32]
23 onlineMaxBlade = [11, 17]
28 useNumberAsPartName =
False 29 inputFileName =
"input.dat" 30 hRes, vRes = 1920, 1080
43 for maxLadder
in onlineMaxLadder:
44 nBinsX = (maxOnlineModule * 2 + 1) * rocsInRow
45 nBinsY = (maxLadder * 2 + 1) * rocsInCol
47 name =
"PXBarrel_Layer" +
str(i);
48 title =
"PXBarrel_Layer" +
str(i);
50 histObj = ROOT.TH2F(name, title, nBinsX, -(maxOnlineModule + 0.5), maxOnlineModule + 0.5, nBinsY, -(maxLadder + 0.5), maxLadder + 0.5)
51 histObj.GetXaxis().SetTitle(
"OnlineSignedModule");
52 histObj.GetYaxis().SetTitle(
"OnlineSignedLadder");
53 histObj.SetOption(
"COLZ")
55 histObj.SetTitle(
"OnlineSignedModule")
57 self.barrelHists.append(deepcopy(histObj))
62 for maxBlade
in onlineMaxBlade:
63 nBinsX = (maxOnlineDisk * 2 + 1) * rocsInRow
64 nBinsY = (maxBlade * 2 + 1) * 2 * rocsInCol
66 name =
"PXForward_Ring" +
str(i);
67 title =
"PXForward_Ring" +
str(i);
69 histObj = ROOT.TH2F(name, title, nBinsX, -(maxOnlineDisk + 0.5), maxOnlineDisk + 0.5, nBinsY, -(maxBlade + 0.5), maxBlade + 0.5)
70 histObj.GetXaxis().SetTitle(
"OnlineSignedDisk");
71 histObj.GetYaxis().SetTitle(
"OnlineSignedBladePanel");
72 histObj.SetOption(
"COLZ")
76 self.forwardHists.append(deepcopy(histObj))
81 coord = b.GetXYCoords()
84 binNum = histRef.FindBin(coord[0], coord[1])
88 binContent =
float(b.reason)
90 binContent = b.roc + 1
92 histRef.SetBinContent(binNum, binContent)
96 coord = f.GetXYCoords()
99 binNum = histRef.FindBin(coord[0], coord[1])
104 binContent = f.roc + 1
105 histRef.SetBinContent(binNum, binContent)
109 def drawLine(self, lineObj, x1, x2, y1, y2, width=2, style=1, color=1):
110 lineObj.SetLineWidth(width)
111 lineObj.SetLineStyle(style)
112 lineObj.SetLineColor(color)
114 lineObj.DrawLine(x1, y1, x2, y2)
116 def drawRectangle(self, lineObj, x1, x2, y1, y2, width=2, style=1, color=1):
117 self.
drawLine(lineObj, x1, x2, y2, y2, width, style, color)
118 self.
drawLine(lineObj, x2, x2, y2, y1, width, style, color)
119 self.
drawLine(lineObj, x2, x1, y1, y1, width, style, color)
120 self.
drawLine(lineObj, x1, x1, y1, y2, width, style, color)
123 nBinsX = hist.GetXaxis().GetNbins()
124 xMin = hist.GetXaxis().GetXmin()
125 xMax = hist.GetXaxis().GetXmax()
126 nBinsY = hist.GetYaxis().GetNbins()
127 yMin = hist.GetYaxis().GetXmin()
128 yMax = hist.GetYaxis().GetXmax()
133 name = hist.GetName()[0:3]
134 isBarrel =
True if name !=
"PXF" else False 135 print(name, isBarrel)
138 xRange = (nBinsX - 1) // (rocsInRow * 2) + 1
139 yBaseStep = (yMax - yMin) / nBinsY
140 yRange = (nBinsY - 1) // (2) + 1
142 yBaseStep = yBaseStep * 2
151 lineObj = ROOT.TLine()
152 lineObj.SetBit(ROOT.kCanDelete)
154 for i
in range(yRange):
155 w = 1
if i % 2
else 2
156 self.
drawLine(lineObj, x1, x2, y1, y2, w)
157 self.
drawLine(lineObj, x1, x2, -y1, -y2, w)
158 self.
drawLine(lineObj, -x1, -x2, -y1, -y2,w )
159 self.
drawLine(lineObj, -x1, -x2, y1, y2, w)
170 for i
in range(xRange):
171 self.
drawLine(lineObj, x1, x2, y1, y2, style = 9)
172 self.
drawLine(lineObj, x1, x2, -y1, -y2, style = 9)
173 self.
drawLine(lineObj, -x1, -x2, -y1, -y2, style = 9)
174 self.
drawLine(lineObj, -x1, -x2, y1, y2, style = 9)
180 zeroModuleHeight = yBaseStep
if isBarrel
else yBaseStep * 0.5
182 yRange =
int(yMax)
if isBarrel
else int(yMax) * 2
185 x2_base = xBaseStep /
float(rocsInRow) + xMin
186 y1_base = zeroModuleHeight + yMin
187 y2_base = 2 * zeroModuleHeight + yMin
189 for i
in range(yRange):
190 y1 = y1_base + i * (zeroModuleHeight * 2) - (zeroModuleHeight
if i % 2
else 0)
191 y2 = y2_base + i * (zeroModuleHeight * 2) - (zeroModuleHeight
if i % 2
else 0)
194 for j
in range(
int(xMax)):
195 x1 = x1_base + j * xBaseStep
196 x2 = x2_base + j * xBaseStep
197 if yMax == 6.5
and x1 <0:
198 y1 = y1_base + i * (zeroModuleHeight * 2) + (zeroModuleHeight
if i % 2
else 0)
199 y2 = y2_base + i * (zeroModuleHeight * 2) + (zeroModuleHeight
if i % 2
else 0)
200 self.
drawRectangle(lineObj,(xBaseStep+x1-(x2-x1)),(xBaseStep+x2-(x2-x1)), y1+(y1-y2), y2+(y1-y2), color=8)
202 yPosChange = -zeroModuleHeight
if i % 2
else zeroModuleHeight
203 self.
drawRectangle(lineObj, x1, x2, y1 - yPosChange-2*(zeroModuleHeight
if i % 2
else 0), y2 - yPosChange-2*(zeroModuleHeight
if i % 2
else 0), color=8)
208 yPosChange = -zeroModuleHeight
if i % 2
else zeroModuleHeight
209 self.
drawRectangle(lineObj, x1, x2, y1 - yPosChange, y2 - yPosChange, color=8)
213 y1 = y1 - yMin + yBaseStep
214 y2 = y2 - yMin + yBaseStep
216 for j
in range(
int(xMax)):
217 x1 = x1_base + j * xBaseStep
218 x2 = x2_base + j * xBaseStep
220 if yMax== 6.5
and x1 <0:
221 self.
drawRectangle(lineObj, xBaseStep+x1-(x2-x1), xBaseStep+x2-(x2-x1), y1+(y1-y2), y2+(y1-y2), color=8)
223 self.
drawRectangle(lineObj, x1, x2, y1 - yPosChange- 2*(zeroModuleHeight
if i % 2
else 0), y2 - yPosChange-2*(zeroModuleHeight
if i % 2
else 0), color=8)
227 self.
drawRectangle(lineObj, x1, x2, y1 - yPosChange, y2 - yPosChange, color=8)
235 c1 = ROOT.TCanvas(hist.GetName(), hist.GetName(), hRes, vRes)
237 hist.GetZaxis().SetRangeUser(0,5)
238 ROOT.gStyle.SetPalette(55)
240 hist.GetZaxis().SetRangeUser(0,4160)
241 ROOT.gStyle.SetPalette(70)
250 txt.SetTextSize(0.05)
251 txt.DrawLatex(0.5, 0.95, hist.GetName())
253 xMin = hist.GetXaxis().GetXmin()
255 yMin = hist.GetYaxis().GetXmin()
257 box1 = TBox(xMin*1.1,yMin*1.25,xMin*1,yMin*1.15);
258 box1.SetFillColor(kRed+3)
260 txt.SetTextSize(0.035)
261 txt.DrawLatex(0.25, 0.077,
"Dead At Beginning")
264 box2 = TBox(xMin*0.45,yMin*1.25,xMin*0.35,yMin*1.15);
265 box2.SetFillColor(kAzure+2)
267 txt.SetTextSize(0.035)
268 txt.DrawLatex(0.47, 0.077,
"Dead At End")
274 colorString =
"_coded" 276 colorString =
"_pixelalive" 278 c1.Print(hist.GetName() + colorString +
"_" + inputFileName[:-4] +
".png")
280 c1.Print(hist.GetName() + colorString +
".png")
285 def __init__ (self, part, sector, layer, ladder, module, roc, reason="unknown"):
303 xBase = -0.625 + ((maxRocIdx - self.
roc if self.
roc >= rocsInRow
else self.
roc) + 1) * rocXLen
321 tmpRoc = maxRocIdx - self.
roc if flipY
else self.
roc;
323 yBase = -0.5 * (tmpRoc // rocsInRow)
325 x = self.
module + (xBase
if self.
module < 0
else -xBase - rocXLen)
333 def __init__ (self, part, disk, blade, panel, ring, roc, reason="unknown"):
351 xBase = -0.625 + ((maxRocIdx - self.
roc if self.
roc >= rocsInRow
else self.
roc) + 1) * rocXLen
353 x = self.
disk + (xBase
if self.
disk < 0
else -xBase - rocXLen)
357 tmpRoc = maxRocIdx - self.
roc if flipY
else self.
roc;
359 yBase = -0.25 - 0.25 * (tmpRoc // rocsInRow) + 0.5 * (self.
panel - 1)
361 y = self.
blade + yBase
367 if thePartStr ==
"mO":
369 elif thePartStr ==
"mI":
371 elif thePartStr ==
"pO":
373 elif thePartStr ==
"pI":
376 print(
"Unrecognized part <%s>, the script is likely to crash..." % (thePartStr))
379 if theReasonStr ==
"unknown":
381 elif theReasonStr ==
"notprogrammable":
383 elif theReasonStr ==
"vcthr":
385 elif theReasonStr ==
"pixelalive":
387 elif theReasonStr ==
"iana":
389 elif theReasonStr ==
"calib":
391 elif theReasonStr==
"fedphases":
393 elif theReasonStr ==
"tbmdelay":
395 elif theReasonStr ==
"power":
399 print(
"Unrecognized part <%s>, the script is likely to crash..." % (theReasonStr))
402 if theReasonStr ==
"flaky":
404 elif theReasonStr ==
"power":
406 elif theReasonStr ==
"tbmdelay":
408 elif theReasonStr ==
"unknown":
412 print(
"Unrecognized part <%s>, the script is likely to crash..." % (theReasonStr))
417 onlineSector =
int(detElements[2][3:])
418 onlineLayer =
int(detElements[3][3:])
420 if detElements[4][-1] ==
"H" or detElements[4][-1] ==
"F":
421 onlineLadder =
int(detElements[4][3:-1])
423 onlineLadder =
int(detElements[4][3:])
425 onlineModule =
int(detElements[5][3:])
427 return Barrel(*[onlinePart, onlineSector, onlineLayer, onlineLadder, onlineModule, roc, reason])
431 onlineDisk =
int(detElements[2][1:])
432 onlineBlade =
int(detElements[3][3:])
433 onlinePanel =
int(detElements[4][3:])
434 onlineRing =
int(detElements[5][3:])
436 return Forward(*[onlinePart, onlineDisk, onlineBlade, onlinePanel, onlineRing, roc, reason])
441 rocString =
str(rocString)
442 iComma=rocString.find(
",")
449 iHyphen=rocString.find(
"-")
451 start=
int(rocString[0:iHyphen])
452 end=
int(rocString[iHyphen+1:len(rocString)])+1
453 listOfRocs.extend(range(start,end))
455 return [
int(rocString)]
467 if len(sys.argv) > 1:
468 inputFileName = sys.argv[1]
471 if len(sys.argv) > 2:
472 opts, args = getopt.getopt(sys.argv[2:],
"bscp", [
"help",
"output="])
475 useNumberAsPartName =
False 484 with open (inputFileName,
"r") as inputFile: 486 for item
in inputFile:
489 inputs = item.split(
" ")
493 detElements = inputs[0].
split(
"_")
494 if detElements[3]==
'LYR1' and (detElements[1]==
'BmI' or detElements[1]==
'BmO'):
498 for roc_rotate
in roc:
499 if int(
str(roc_rotate)) <= 7:
500 rocs.append(
int(
str(roc_rotate))+8)
501 elif int(
str(roc_rotate)) >= 8:
502 rocs.append(
int(
str(roc_rotate)) -8)
508 reason =
str(inputs[2]).lower().
strip()
513 if detElements[0][0] ==
"B":
516 barrelObj.convertParts()
518 barrelObjs.append(barrelObj)
519 elif detElements[0][0] ==
"F":
522 forwardObj.convertParts()
524 forwardObjs.append(forwardObj)
526 print(
"Not recognized part type")
530 histMan.fillHistograms(barrelObjs, forwardObjs)
531 histMan.saveHistograms()
def TranslateReasonStringFPix(theReasonStr)
def GetOnlineForwardCharacteristics(detElements, roc, reason="unknown")
def prettifyCanvas(self, hist)
def GetOnlineBarrelCharacteristics(detElements, roc, reason="unknown")
S & print(S &os, JobReport::InputFile const &f)
def TranslateReasonStringBPix(theReasonStr)
def drawLine(self, lineObj, x1, x2, y1, y2, width=2, style=1, color=1)
def fillHistograms(self, barrelObjs, forwardObjs)
Abs< T >::type abs(const T &t)
def __init__(self, part, disk, blade, panel, ring, roc, reason="unknown")
def GetAffectedRocs(rocString)
def __init__(self, part, sector, layer, ladder, module, roc, reason="unknown")
def drawRectangle(self, lineObj, x1, x2, y1, y2, width=2, style=1, color=1)
def TranslatePartString(thePartStr)