CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes
PixelMapPlotter.HistogramManager Class Reference

GLOBAL VARS. More...

Public Member Functions

def __init__
 
def drawLine
 
def drawRectangle
 
def fillHistograms
 
def prettifyCanvas
 
def saveHistograms
 

Public Attributes

 barrelHists
 
 forwardHists
 

Detailed Description

GLOBAL VARS.

Definition at line 37 of file PixelMapPlotter.py.

Constructor & Destructor Documentation

def PixelMapPlotter.HistogramManager.__init__ (   self)

Definition at line 38 of file PixelMapPlotter.py.

38 
39  def __init__(self):
40  self.barrelHists = []
41  self.forwardHists = []
42 
43  # barrel histograms
44  i = 1
45  for maxLadder in onlineMaxLadder:
46  nBinsX = (maxOnlineModule * 2 + 1) * rocsInRow
47  nBinsY = (maxLadder * 2 + 1) * rocsInCol
48 
49  name = "PXBarrel_Layer" + str(i);
50  title = "PXBarrel_Layer" + str(i);
51 
52  histObj = ROOT.TH2F(name, title, nBinsX, -(maxOnlineModule + 0.5), maxOnlineModule + 0.5, nBinsY, -(maxLadder + 0.5), maxLadder + 0.5)
53  histObj.GetXaxis().SetTitle("OnlineSignedModule");
54  histObj.GetYaxis().SetTitle("OnlineSignedLadder");
55  histObj.SetOption("COLZ")
56  histObj.SetStats(0)
57  histObj.SetTitle("OnlineSignedModule")
58 
59  self.barrelHists.append(deepcopy(histObj))
60  i = i + 1
61 
62  # forward histograms
63  i = 1
64  for maxBlade in onlineMaxBlade:
65  nBinsX = (maxOnlineDisk * 2 + 1) * rocsInRow
66  nBinsY = (maxBlade * 2 + 1) * 2 * rocsInCol
67 
68  name = "PXForward_Ring" + str(i);
69  title = "PXForward_Ring" + str(i);
70 
71  histObj = ROOT.TH2F(name, title, nBinsX, -(maxOnlineDisk + 0.5), maxOnlineDisk + 0.5, nBinsY, -(maxBlade + 0.5), maxBlade + 0.5)
72  histObj.GetXaxis().SetTitle("OnlineSignedDisk");
73  histObj.GetYaxis().SetTitle("OnlineSignedBladePanel");
74  histObj.SetOption("COLZ")
75  histObj.SetStats(0)
76 
77 
78  self.forwardHists.append(deepcopy(histObj))
79  i = i + 1
#define str(s)

Member Function Documentation

def PixelMapPlotter.HistogramManager.drawLine (   self,
  lineObj,
  x1,
  x2,
  y1,
  y2,
  width = 2,
  style = 1,
  color = 1 
)

Definition at line 110 of file PixelMapPlotter.py.

Referenced by PixelMapPlotter.HistogramManager.drawRectangle(), and PixelMapPlotter.HistogramManager.prettifyCanvas().

111  def drawLine(self, lineObj, x1, x2, y1, y2, width=2, style=1, color=1):
112  lineObj.SetLineWidth(width)
113  lineObj.SetLineStyle(style)
114  lineObj.SetLineColor(color)
115 
116  lineObj.DrawLine(x1, y1, x2, y2)
def PixelMapPlotter.HistogramManager.drawRectangle (   self,
  lineObj,
  x1,
  x2,
  y1,
  y2,
  width = 2,
  style = 1,
  color = 1 
)

Definition at line 117 of file PixelMapPlotter.py.

References PixelMapPlotter.HistogramManager.drawLine().

Referenced by PixelMapPlotter.HistogramManager.prettifyCanvas().

118  def drawRectangle(self, lineObj, x1, x2, y1, y2, width=2, style=1, color=1):
119  self.drawLine(lineObj, x1, x2, y2, y2, width, style, color)
120  self.drawLine(lineObj, x2, x2, y2, y1, width, style, color)
121  self.drawLine(lineObj, x2, x1, y1, y1, width, style, color)
122  self.drawLine(lineObj, x1, x1, y1, y2, width, style, color)
def PixelMapPlotter.HistogramManager.fillHistograms (   self,
  barrelObjs,
  forwardObjs 
)

Definition at line 80 of file PixelMapPlotter.py.

References PixelMapPlotter.HistogramManager.barrelHists, PixelMapPlotter.HistogramManager.forwardHists, PixelMapPlotter.TranslateReasonStringBPix(), and PixelMapPlotter.TranslateReasonStringFPix().

80 
81  def fillHistograms(self, barrelObjs, forwardObjs):
82  for b in barrelObjs:
83  coord = b.GetXYCoords()
84  histRef = self.barrelHists[b.layer - 1]
85 
86  binNum = histRef.FindBin(coord[0], coord[1])
87  if colorCoded:
88  binContent = TranslateReasonStringBPix(b.reason)
89  elif pixelAlive:
90  binContent = float(b.reason)
91  else:
92  binContent = b.roc + 1
93 
94  histRef.SetBinContent(binNum, binContent)
95  # self.barrelHists[b.layer - 1].Fill(coord[0], coord[1], b.roc + 1)
96 
97  for f in forwardObjs:
98  coord = f.GetXYCoords()
99  histRef = self.forwardHists[f.ring - 1]
100 
101  binNum = histRef.FindBin(coord[0], coord[1])
102 
103  if colorCoded:
104  binContent = TranslateReasonStringFPix(f.reason)
105  else:
106  binContent = f.roc + 1
107  histRef.SetBinContent(binNum, binContent)
108 
109  # self.forwardHists[f.ring - 1].Fill(coord[0], coord[1], f.roc + 1)
def PixelMapPlotter.HistogramManager.prettifyCanvas (   self,
  hist 
)

Definition at line 123 of file PixelMapPlotter.py.

References PixelMapPlotter.HistogramManager.drawLine(), PixelMapPlotter.HistogramManager.drawRectangle(), print(), and sistrip::SpyUtilities.range().

Referenced by PixelMapPlotter.HistogramManager.saveHistograms().

124  def prettifyCanvas(self, hist):
125  nBinsX = hist.GetXaxis().GetNbins()
126  xMin = hist.GetXaxis().GetXmin()
127  xMax = hist.GetXaxis().GetXmax()
128  nBinsY = hist.GetYaxis().GetNbins()
129  yMin = hist.GetYaxis().GetXmin()
130  yMax = hist.GetYaxis().GetXmax()
131 
132  xLen = int(xMax)
133  yLen = int(yMax)
134 
135  name = hist.GetName()[0:3]
136  isBarrel = True if name != "PXF" else False
137  print((name, isBarrel))
138 
139  xBaseStep = 1
140  xRange = (nBinsX - 1) // (rocsInRow * 2) + 1
141  yBaseStep = (yMax - yMin) / nBinsY
142  yRange = (nBinsY - 1) // (2) + 1
143  if not isBarrel:
144  yBaseStep = yBaseStep * 2
145  yRange = yRange // 2
146 
147  # horizontal
148  x1 = xMin
149  x2 = xMin + xLen
150  y1 = yMin
151  y2 = yMin
152 
153  lineObj = ROOT.TLine()
154  lineObj.SetBit(ROOT.kCanDelete)
155 
156  for i in range(yRange):
157  w = 1 if i % 2 else 2
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 )
161  self.drawLine(lineObj, -x1, -x2, y1, y2, w)
162 
163  y1 = y1 + yBaseStep
164  y2 = y2 + yBaseStep
165 
166  # vertical
167  x1 = xMin
168  x2 = xMin
169  y1 = yMin
170  y2 = yMin + yLen
171 
172  for i in range(xRange):
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)
176  self.drawLine(lineObj, -x1, -x2, y1, y2, style = 9)
177 
178  x1 = x1 + xBaseStep
179  x2 = x2 + xBaseStep
180 
181  # mark zero ROC
182  zeroModuleHeight = yBaseStep if isBarrel else yBaseStep * 0.5 # because there are two panels height of roc is smaller
183 
184  yRange = int(yMax) if isBarrel else int(yMax) * 2
185 
186  x1_base = 0 + xMin
187  x2_base = xBaseStep / float(rocsInRow) + xMin
188  y1_base = zeroModuleHeight + yMin
189  y2_base = 2 * zeroModuleHeight + yMin
190 
191  for i in range(yRange):
192  y1 = y1_base + i * (zeroModuleHeight * 2) - (zeroModuleHeight if i % 2 else 0)
193  y2 = y2_base + i * (zeroModuleHeight * 2) - (zeroModuleHeight if i % 2 else 0)
194 
195  #negative ladders/blades
196  for j in range(int(xMax)):
197  x1 = x1_base + j * xBaseStep
198  x2 = x2_base + j * xBaseStep
199  if yMax == 6.5 and x1 <0:
200  y1 = y1_base + i * (zeroModuleHeight * 2) + (zeroModuleHeight if i % 2 else 0)
201  y2 = y2_base + i * (zeroModuleHeight * 2) + (zeroModuleHeight if i % 2 else 0)
202  self.drawRectangle(lineObj,(xBaseStep+x1-(x2-x1)),(xBaseStep+x2-(x2-x1)), y1+(y1-y2), y2+(y1-y2), color=8)
203  x1, x2 = -x1, -x2
204  yPosChange = -zeroModuleHeight if i % 2 else zeroModuleHeight
205  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)
206  else:
207  self.drawRectangle(lineObj, x1, x2, y1, y2, color=8)
208 
209  x1, x2 = -x1, -x2
210  yPosChange = -zeroModuleHeight if i % 2 else zeroModuleHeight
211  self.drawRectangle(lineObj, x1, x2, y1 - yPosChange, y2 - yPosChange, color=8)
212 
213 
214  # positive ladders/blades
215  y1 = y1 - yMin + yBaseStep
216  y2 = y2 - yMin + yBaseStep
217 
218  for j in range(int(xMax)):
219  x1 = x1_base + j * xBaseStep
220  x2 = x2_base + j * xBaseStep
221 
222  if yMax== 6.5 and x1 <0:
223  self.drawRectangle(lineObj, xBaseStep+x1-(x2-x1), xBaseStep+x2-(x2-x1), y1+(y1-y2), y2+(y1-y2), color=8)
224  x1, x2 = -x1, -x2
225  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)
226  else:
227  self.drawRectangle(lineObj, x1, x2, y1, y2, color=8)
228  x1, x2 = -x1, -x2
229  self.drawRectangle(lineObj, x1, x2, y1 - yPosChange, y2 - yPosChange, color=8)
230 
231 # hist.GetZaxis().SetRangeUser(-0.5,15.5)
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def PixelMapPlotter.HistogramManager.saveHistograms (   self)

Definition at line 232 of file PixelMapPlotter.py.

References PixelMapPlotter.HistogramManager.barrelHists, PixelMapPlotter.HistogramManager.forwardHists, and PixelMapPlotter.HistogramManager.prettifyCanvas().

233  def saveHistograms(self):
234  for hists in [self.barrelHists, self.forwardHists]:
235  for hist in hists:
236  # if hist.GetEntries():
237  c1 = ROOT.TCanvas(hist.GetName(), hist.GetName(), hRes, vRes)
238  if colorCoded:
239  hist.GetZaxis().SetRangeUser(0,5)
240  ROOT.gStyle.SetPalette(55)
241  elif pixelAlive:
242  hist.GetZaxis().SetRangeUser(0,4160)
243  ROOT.gStyle.SetPalette(70)
244  hist.Draw()
245 
246  txt = TLatex()
247  txt.SetNDC()
248  txt.SetTextFont(1)
249  txt.SetTextColor(1)
250  txt.SetTextAlign(22)
251  txt.SetTextAngle(0)
252  txt.SetTextSize(0.05)
253  txt.DrawLatex(0.5, 0.95, hist.GetName())
254 
255  xMin = hist.GetXaxis().GetXmin()
256 
257  yMin = hist.GetYaxis().GetXmin()
258 
259  box1 = TBox(xMin*1.1,yMin*1.25,xMin*1,yMin*1.15);
260  box1.SetFillColor(kRed+3)
261  box1.Draw()
262  txt.SetTextSize(0.035)
263  txt.DrawLatex(0.25, 0.077, "Dead At Beginning")
264 
265 
266  box2 = TBox(xMin*0.45,yMin*1.25,xMin*0.35,yMin*1.15);
267  box2.SetFillColor(kAzure+2)
268  box2.Draw()
269  txt.SetTextSize(0.035)
270  txt.DrawLatex(0.47, 0.077, "Dead At End")
271 
272 
273  self.prettifyCanvas(hist)
274  colorString = ""
275  if colorCoded:
276  colorString = "_coded"
277  elif pixelAlive:
278  colorString = "_pixelalive"
279  if useFileSuffix:
280  c1.Print(hist.GetName() + colorString + "_" + inputFileName[:-4] + ".png")
281  else:
282  c1.Print(hist.GetName() + colorString + ".png")

Member Data Documentation

PixelMapPlotter.HistogramManager.barrelHists

Definition at line 39 of file PixelMapPlotter.py.

Referenced by PixelMapPlotter.HistogramManager.fillHistograms(), and PixelMapPlotter.HistogramManager.saveHistograms().

PixelMapPlotter.HistogramManager.forwardHists

Definition at line 40 of file PixelMapPlotter.py.

Referenced by PixelMapPlotter.HistogramManager.fillHistograms(), and PixelMapPlotter.HistogramManager.saveHistograms().