3 from __future__
import print_function
9 from copy
import deepcopy
19 rocXLen = 1.0 / rocsInRow
21 maxRocIdx = rocsInCol * rocsInRow - 1
23 onlineMaxLadder = [6, 14, 22, 32]
24 onlineMaxBlade = [11, 17]
29 useNumberAsPartName =
False 30 inputFileName =
"input.dat" 31 hRes, vRes = 1920, 1080
44 for maxLadder
in onlineMaxLadder:
45 nBinsX = (maxOnlineModule * 2 + 1) * rocsInRow
46 nBinsY = (maxLadder * 2 + 1) * rocsInCol
48 name =
"PXBarrel_Layer" +
str(i);
49 title =
"PXBarrel_Layer" +
str(i);
51 histObj = ROOT.TH2F(name, title, nBinsX, -(maxOnlineModule + 0.5), maxOnlineModule + 0.5, nBinsY, -(maxLadder + 0.5), maxLadder + 0.5)
52 histObj.GetXaxis().SetTitle(
"OnlineSignedModule");
53 histObj.GetYaxis().SetTitle(
"OnlineSignedLadder");
54 histObj.SetOption(
"COLZ")
56 histObj.SetTitle(
"OnlineSignedModule")
58 self.barrelHists.append(deepcopy(histObj))
63 for maxBlade
in onlineMaxBlade:
64 nBinsX = (maxOnlineDisk * 2 + 1) * rocsInRow
65 nBinsY = (maxBlade * 2 + 1) * 2 * rocsInCol
67 name =
"PXForward_Ring" +
str(i);
68 title =
"PXForward_Ring" +
str(i);
70 histObj = ROOT.TH2F(name, title, nBinsX, -(maxOnlineDisk + 0.5), maxOnlineDisk + 0.5, nBinsY, -(maxBlade + 0.5), maxBlade + 0.5)
71 histObj.GetXaxis().SetTitle(
"OnlineSignedDisk");
72 histObj.GetYaxis().SetTitle(
"OnlineSignedBladePanel");
73 histObj.SetOption(
"COLZ")
77 self.forwardHists.append(deepcopy(histObj))
82 coord = b.GetXYCoords()
85 binNum = histRef.FindBin(coord[0], coord[1])
89 binContent =
float(b.reason)
91 binContent = b.roc + 1
93 histRef.SetBinContent(binNum, binContent)
97 coord = f.GetXYCoords()
100 binNum = histRef.FindBin(coord[0], coord[1])
105 binContent = f.roc + 1
106 histRef.SetBinContent(binNum, binContent)
110 def drawLine(self, lineObj, x1, x2, y1, y2, width=2, style=1, color=1):
111 lineObj.SetLineWidth(width)
112 lineObj.SetLineStyle(style)
113 lineObj.SetLineColor(color)
115 lineObj.DrawLine(x1, y1, x2, y2)
117 def drawRectangle(self, lineObj, x1, x2, y1, y2, width=2, style=1, color=1):
118 self.
drawLine(lineObj, x1, x2, y2, y2, width, style, color)
119 self.
drawLine(lineObj, x2, x2, y2, y1, width, style, color)
120 self.
drawLine(lineObj, x2, x1, y1, y1, width, style, color)
121 self.
drawLine(lineObj, x1, x1, y1, y2, width, style, color)
124 nBinsX = hist.GetXaxis().GetNbins()
125 xMin = hist.GetXaxis().GetXmin()
126 xMax = hist.GetXaxis().GetXmax()
127 nBinsY = hist.GetYaxis().GetNbins()
128 yMin = hist.GetYaxis().GetXmin()
129 yMax = hist.GetYaxis().GetXmax()
134 name = hist.GetName()[0:3]
135 isBarrel =
True if name !=
"PXF" else False 136 print((name, isBarrel))
139 xRange = (nBinsX - 1) // (rocsInRow * 2) + 1
140 yBaseStep = (yMax - yMin) / nBinsY
141 yRange = (nBinsY - 1) // (2) + 1
143 yBaseStep = yBaseStep * 2
152 lineObj = ROOT.TLine()
153 lineObj.SetBit(ROOT.kCanDelete)
155 for i
in range(yRange):
156 w = 1
if i % 2
else 2
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 )
160 self.
drawLine(lineObj, -x1, -x2, y1, y2, w)
171 for i
in range(xRange):
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)
175 self.
drawLine(lineObj, -x1, -x2, y1, y2, style = 9)
181 zeroModuleHeight = yBaseStep
if isBarrel
else yBaseStep * 0.5
183 yRange =
int(yMax)
if isBarrel
else int(yMax) * 2
186 x2_base = xBaseStep /
float(rocsInRow) + xMin
187 y1_base = zeroModuleHeight + yMin
188 y2_base = 2 * zeroModuleHeight + yMin
190 for i
in range(yRange):
191 y1 = y1_base + i * (zeroModuleHeight * 2) - (zeroModuleHeight
if i % 2
else 0)
192 y2 = y2_base + i * (zeroModuleHeight * 2) - (zeroModuleHeight
if i % 2
else 0)
195 for j
in range(
int(xMax)):
196 x1 = x1_base + j * xBaseStep
197 x2 = x2_base + j * xBaseStep
198 if yMax == 6.5
and x1 <0:
199 y1 = y1_base + i * (zeroModuleHeight * 2) + (zeroModuleHeight
if i % 2
else 0)
200 y2 = y2_base + i * (zeroModuleHeight * 2) + (zeroModuleHeight
if i % 2
else 0)
201 self.
drawRectangle(lineObj,(xBaseStep+x1-(x2-x1)),(xBaseStep+x2-(x2-x1)), y1+(y1-y2), y2+(y1-y2), color=8)
203 yPosChange = -zeroModuleHeight
if i % 2
else zeroModuleHeight
204 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)
209 yPosChange = -zeroModuleHeight
if i % 2
else zeroModuleHeight
210 self.
drawRectangle(lineObj, x1, x2, y1 - yPosChange, y2 - yPosChange, color=8)
214 y1 = y1 - yMin + yBaseStep
215 y2 = y2 - yMin + yBaseStep
217 for j
in range(
int(xMax)):
218 x1 = x1_base + j * xBaseStep
219 x2 = x2_base + j * xBaseStep
221 if yMax== 6.5
and x1 <0:
222 self.
drawRectangle(lineObj, xBaseStep+x1-(x2-x1), xBaseStep+x2-(x2-x1), y1+(y1-y2), y2+(y1-y2), color=8)
224 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)
228 self.
drawRectangle(lineObj, x1, x2, y1 - yPosChange, y2 - yPosChange, color=8)
236 c1 = ROOT.TCanvas(hist.GetName(), hist.GetName(), hRes, vRes)
238 hist.GetZaxis().SetRangeUser(0,5)
239 ROOT.gStyle.SetPalette(55)
241 hist.GetZaxis().SetRangeUser(0,4160)
242 ROOT.gStyle.SetPalette(70)
251 txt.SetTextSize(0.05)
252 txt.DrawLatex(0.5, 0.95, hist.GetName())
254 xMin = hist.GetXaxis().GetXmin()
256 yMin = hist.GetYaxis().GetXmin()
258 box1 = TBox(xMin*1.1,yMin*1.25,xMin*1,yMin*1.15);
259 box1.SetFillColor(kRed+3)
261 txt.SetTextSize(0.035)
262 txt.DrawLatex(0.25, 0.077,
"Dead At Beginning")
265 box2 = TBox(xMin*0.45,yMin*1.25,xMin*0.35,yMin*1.15);
266 box2.SetFillColor(kAzure+2)
268 txt.SetTextSize(0.035)
269 txt.DrawLatex(0.47, 0.077,
"Dead At End")
275 colorString =
"_coded" 277 colorString =
"_pixelalive" 279 c1.Print(hist.GetName() + colorString +
"_" + inputFileName[:-4] +
".png")
281 c1.Print(hist.GetName() + colorString +
".png")
286 def __init__ (self, part, sector, layer, ladder, module, roc, reason="unknown"):
304 xBase = -0.625 + ((maxRocIdx - self.
roc if self.
roc >= rocsInRow
else self.
roc) + 1) * rocXLen
322 tmpRoc = maxRocIdx - self.
roc if flipY
else self.
roc;
324 yBase = -0.5 * (tmpRoc // rocsInRow)
326 x = self.
module + (xBase
if self.
module < 0
else -xBase - rocXLen)
334 def __init__ (self, part, disk, blade, panel, ring, roc, reason="unknown"):
352 xBase = -0.625 + ((maxRocIdx - self.
roc if self.
roc >= rocsInRow
else self.
roc) + 1) * rocXLen
354 x = self.
disk + (xBase
if self.
disk < 0
else -xBase - rocXLen)
358 tmpRoc = maxRocIdx - self.
roc if flipY
else self.
roc;
360 yBase = -0.25 - 0.25 * (tmpRoc // rocsInRow) + 0.5 * (self.
panel - 1)
362 y = self.
blade + yBase
368 if thePartStr ==
"mO":
370 elif thePartStr ==
"mI":
372 elif thePartStr ==
"pO":
374 elif thePartStr ==
"pI":
377 print(
"Unrecognized part <%s>, the script is likely to crash..." % (thePartStr))
380 if theReasonStr ==
"unknown":
382 elif theReasonStr ==
"notprogrammable":
384 elif theReasonStr ==
"vcthr":
386 elif theReasonStr ==
"pixelalive":
388 elif theReasonStr ==
"iana":
390 elif theReasonStr ==
"calib":
392 elif theReasonStr==
"fedphases":
394 elif theReasonStr ==
"tbmdelay":
396 elif theReasonStr ==
"power":
400 print(
"Unrecognized part <%s>, the script is likely to crash..." % (theReasonStr))
403 if theReasonStr ==
"flaky":
405 elif theReasonStr ==
"power":
407 elif theReasonStr ==
"tbmdelay":
409 elif theReasonStr ==
"unknown":
413 print(
"Unrecognized part <%s>, the script is likely to crash..." % (theReasonStr))
418 onlineSector =
int(detElements[2][3:])
419 onlineLayer =
int(detElements[3][3:])
421 if detElements[4][-1] ==
"H" or detElements[4][-1] ==
"F":
422 onlineLadder =
int(detElements[4][3:-1])
424 onlineLadder =
int(detElements[4][3:])
426 onlineModule =
int(detElements[5][3:])
428 return Barrel(*[onlinePart, onlineSector, onlineLayer, onlineLadder, onlineModule, roc, reason])
432 onlineDisk =
int(detElements[2][1:])
433 onlineBlade =
int(detElements[3][3:])
434 onlinePanel =
int(detElements[4][3:])
435 onlineRing =
int(detElements[5][3:])
437 return Forward(*[onlinePart, onlineDisk, onlineBlade, onlinePanel, onlineRing, roc, reason])
442 rocString =
str(rocString)
443 iComma=rocString.find(
",")
450 iHyphen=rocString.find(
"-")
452 start=
int(rocString[0:iHyphen])
453 end=
int(rocString[iHyphen+1:len(rocString)])+1
454 listOfRocs.extend(range(start,end))
456 return [
int(rocString)]
468 if len(sys.argv) > 1:
469 inputFileName = sys.argv[1]
472 if len(sys.argv) > 2:
473 opts, args = getopt.getopt(sys.argv[2:],
"bscp", [
"help",
"output="])
476 useNumberAsPartName =
False 485 with open (inputFileName,
"r") as inputFile: 487 for item
in inputFile:
490 inputs = item.split(
" ")
494 detElements = inputs[0].
split(
"_")
495 if detElements[3]==
'LYR1' and (detElements[1]==
'BmI' or detElements[1]==
'BmO'):
499 for roc_rotate
in roc:
500 if int(
str(roc_rotate)) <= 7:
501 rocs.append(
int(
str(roc_rotate))+8)
502 elif int(
str(roc_rotate)) >= 8:
503 rocs.append(
int(
str(roc_rotate)) -8)
509 reason =
str(inputs[2]).lower().
strip()
514 if detElements[0][0] ==
"B":
517 barrelObj.convertParts()
519 barrelObjs.append(barrelObj)
520 elif detElements[0][0] ==
"F":
523 forwardObj.convertParts()
525 forwardObjs.append(forwardObj)
527 print(
"Not recognized part type")
531 histMan.fillHistograms(barrelObjs, forwardObjs)
532 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)