CMS 3D CMS Logo

PCLOthers.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 from __future__ import print_function
4 import ROOT
5 from ROOT import TBufferFile, TH1F, TProfile, TProfile2D, TH2F, TFile, TH1D, TH2D
6 import re
7 import os
8 
9 
10 def draw_line(lineList,x1,x2,y1,y2,width=1,style=1,color=1):
11  from ROOT import TLine
12  l=TLine(x1,y1,x2,y2)
13  l.SetBit(ROOT.kCanDelete)
14  l.SetLineWidth(width)
15  l.SetLineStyle(style)
16  l.SetLineColor(color)
17  l.Draw()
18  lineList.append(l)
19 
20 def draw_box(boxList,xl,xr,yl,yr,opacity=1,color=1,style=1001,lstyle=1,lw=3):
21  from ROOT import TBox
22  b=TBox(xl,yl,xr,yr)
23  b.SetBit(ROOT.kCanDelete)
24  b.SetFillStyle(style)
25  b.SetFillColorAlpha(color, opacity)
26  b.SetLineColor(color)
27  b.SetLineWidth(lw)
28  b.SetLineStyle(lstyle)
29  b.Draw()
30  boxList.append(b)
31 
32 def renderPluginBPIX(lineList,layer) :
33  from ROOT import TCanvas,TLine
34  nlad=[6,14,22,32]
35  coordSign=[(-1,-1),(-1,1),(1,-1),(1,1)]
36  for xsign,ysign in coordSign:
37  xlow = xsign*0.5
38  xhigh= xsign*(0.5+4)
39  ylow = ysign*0.5
40  yhigh= ysign*(0.5 + nlad[layer-1])
41  # Outside Box
42  draw_line(lineList,xlow, xhigh, ylow, ylow) # bottom
43  draw_line(lineList,xlow, xhigh, yhigh, yhigh) # top
44  draw_line(lineList,xlow, xlow, ylow, yhigh) # left
45  draw_line(lineList,xhigh, xhigh, ylow, yhigh) # right
46  # Inner Horizontal lines
47  for lad in range(nlad[layer-1]):
48  lad+=1
49  if lad != nlad[layer-1]:
50  y = ysign * (lad+0.5)
51  draw_line(lineList,xlow, xhigh, y, y)
52  y = ysign * (lad);
53  draw_line(lineList,xlow, xhigh, y, y, 1, 3);
54  # Inner Vertical lines
55  for mod in range(3) :
56  mod+=1
57  x = xsign * (mod + 0.5);
58  draw_line(lineList,x, x, ylow, yhigh);
59 
60  # Draw ROC0
61  for mod in range(4):
62  mod+=1
63  for lad in range(nlad[layer-1]):
64  lad+=1
65  if ysign==1:
66  flipped = not(lad%2==0)
67  else :
68  flipped = not(lad%2==1)
69  if flipped : roc0_orientation = -1
70  else : roc0_orientation = 1
71  if xsign==-1 : roc0_orientation *= -1
72  if ysign==-1 : roc0_orientation *= -1
73  x1 = xsign * (mod+0.5)
74  x2 = xsign * (mod+0.5 - 1./8);
75  y1 = ysign * (lad)
76  y2 = ysign * (lad + roc0_orientation*1./2)
77  if layer == 1 and xsign == -1 :
78  x1 = xsign * (mod-0.5)
79  x2 = xsign * (mod-0.5 + 1./8)
80  y1 = ysign * (lad)
81  y2 = ysign * (lad - roc0_orientation*1./2)
82 
83  draw_line(lineList,x1, x2, y1, y1, 1)
84  draw_line(lineList,x2, x2, y1, y2, 1)
85 
86  else:
87  draw_line(lineList,x1, x2, y1, y1, 1)
88  draw_line(lineList,x2, x2, y1, y2, 1)
89 
90 def maskBPixROC(boxList,xsign,ysign,layer,lad,mod,roc):
91  if roc<8 :
92  rocShiftX=roc*1./8
93  rocShiftY=0
94  else :
95  rocShiftX=(15-roc)*1./8
96  rocShiftY=1./2
97  if ysign==1:
98  flipped = not(lad%2==0)
99  else :
100  flipped = not(lad%2==1)
101  if flipped : roc0_orientation = -1
102  else : roc0_orientation = 1
103  if xsign==-1 : roc0_orientation *= -1
104  if ysign==-1 : roc0_orientation *= -1
105  x1 = xsign * (mod+0.5-rocShiftX)
106  x2 = xsign * (mod+0.5 - 1./8-rocShiftX);
107  y1 = ysign * (lad-roc0_orientation*rocShiftY)
108  y2 = ysign * (lad + roc0_orientation*1./2-roc0_orientation*rocShiftY)
109  if layer == 1 and xsign == -1 :
110  x1 = xsign * (mod-0.5)-rocShiftX
111  x2 = xsign * (mod-0.5 + 1./8)-rocShiftX
112  y1 = ysign * (lad +rocShiftY)
113  y2 = ysign * (lad - roc0_orientation*1./2+rocShiftY)
114  draw_box(boxList,min(x1,x2),max(x1,x2),min(y1, y2),max(y1,y2),0.75)
115 
116 
117 
118 def renderPluginFPIX(lineList,ring) :
119  from ROOT import TCanvas,TLine
120  coordSign=[(-1,-1),(-1,1),(1,-1),(1,1)]
121  for dsk in range(3) :
122  dsk+=1
123  for xsign,ysign in coordSign:
124  for bld in range(5+ring*6):
125  bld+=1
126  # Panel 2 has dashed mid-plane
127  x1 = xsign * (0.5 + dsk - 1)
128  x2 = xsign * (0.5 + dsk)
129  sign = ysign
130  y1 = ysign * (bld + sign*0.5)
131  y2 = ysign * (bld)
132  yp2_mid = ysign * (bld - sign*0.25)
133  y3 = ysign * (bld - sign*0.5)
134  draw_line(lineList,x1, x2, y1, y1)
135  draw_line(lineList,x1, x2, y2, y2)
136  draw_line(lineList,x1, x2, yp2_mid, yp2_mid,1,2)
137  draw_line(lineList,x1, x2, y3, y3)
138  # Vertical lines
139  x = xsign * (0.5 + dsk - 1)
140  draw_line(lineList,x, x, y1, y2)
141  draw_line(lineList,x, x, y2, y3)
142  if ring==2 :
143  x = xsign * (0.5 + dsk)
144  draw_line(lineList,x, x, y1, y2)
145  draw_line(lineList,x, x, y2, y3)
146  #Make a BOX around ROC 0
147  x1 = xsign * (0.5 + dsk - 1/8.)
148  x2 = xsign * (0.5 + dsk)
149  y1_p1 = ysign * (bld + sign*0.25)
150  y2_p1 = ysign * (bld + sign*0.25 + xsign*ysign*0.25)
151  draw_line(lineList,x1, x2, y1_p1, y1_p1, 1)
152  draw_line(lineList,x1, x1, y1_p1, y2_p1, 1)
153  y1_p2 = ysign * (bld - sign*0.25)
154  y2_p2 = ysign * (bld - sign*0.25 - xsign*ysign*0.25)
155  draw_line(lineList,x1, x2, y1_p2, y1_p2)
156  draw_line(lineList,x1, x1, y1_p2, y2_p2)
157 
158 def maskFPixROC(boxList,xsign,ysign,dsk,bld,pnl,roc) :
159  from ROOT import TCanvas,TLine
160  if roc<8 :
161  rocShiftX=roc*1./8
162  rocShiftY=0
163  else :
164  rocShiftX=(15-roc)*1./8
165  rocShiftY=1./4
166  sign=ysign
167  x1 = xsign * (0.5 + dsk - 1/8.-rocShiftX)
168  x2 = xsign * (0.5 + dsk-rocShiftX)
169  if pnl==1:
170  y1 = ysign * (bld + sign*0.25)-xsign*rocShiftY
171  y2 = ysign * (bld + sign*0.25 + xsign*ysign*0.25)-xsign*rocShiftY
172  else:
173  y1 = ysign * (bld - sign*0.25)+xsign*rocShiftY
174  y2 = ysign * (bld - sign*0.25 - xsign*ysign*0.25)+xsign*rocShiftY
175  draw_box(boxList,min(x1,x2),max(x1,x2),min(y1,y2),max(y1,y2),0.75)
176 
177 
178 def dqm_get_dataset(server, match, run, type="offline_data"):
179  datareq = urllib2.Request(('%s/data/json/samples?match=%s') % (server, match))
180  datareq.add_header('User-agent', ident)
181  # Get data
182  data = eval(re.sub(r"\bnan\b", "0", urllib2.build_opener(X509CertOpen()).open(datareq).read()),
183  { "__builtins__": None }, {})
184  ret = ""
185  for l in data['samples']:
186  if l['type'] == type:
187  for x in l['items']:
188  if int(x['run']) == int(run):
189  ret=x['dataset']
190  break
191  print(ret)
192  return ret
193 
194 
195 
196 
197 def main():
198  import sys
199  import os
200  import ROOT
201 
202  if len(sys.argv) != 3:
203  print("input files needed!")
204  return
205  else:
206  filename=sys.argv[1]
207  pclfile=sys.argv[2]
208  print(filename+" -- "+filename[19:25])
209  print(pclfile+" -- "+pclfile[19:25])
210  runNum=filename[19:25]
211 
212  dir="DQMData/Run " + runNum + "/PixelPhase1/Run summary/Pahse1_MechanicalView/"
213  dirERROR="DQMData/Run " + runNum + "/PixelPhase1/Run summary/SiPixelQualityPCL/BadROC_Other/"
214 
215 
216  dirBPix=dir + "PXBarrel/"
217  dirFPix=dir + "PXForward/"
218 
219  hoccB="digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_"
220  hoccF="digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_"
221  hdeadB="Dead Channels per ROC_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_"
222  hdeadF="Dead Channels per ROC_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_"
223 
224  ROOT.gROOT.SetBatch(1)
225  ROOT.gStyle.SetOptStat(0)
226  ROOT.gStyle.SetPalette(52) #104 kTemperatureMap // 55 kRainBow // 97 kRust // 57 kBird
227  color=[]
228  for i in range(0,255):
229  color.append(ROOT.TColor.GetColorPalette(i))
230  ROOT.gStyle.SetPalette(1) #104 kTemperatureMap // 55 kRainBow
231  ROOT.gStyle.SetNumberContours(128)
232  rootf=ROOT.TFile(filename)
233  rootp=ROOT.TFile(pclfile)
234 
235 
236 
237  c=ROOT.TCanvas("c","c",1250,1000)
238  #BPIX
239  print("----> Build maps for BPix")
240  histOccList=[]
241  histDeadList=[]
242  for lyr in range(1,5):
243  histOccList.append(rootf.FindObjectAny(hoccB+str(lyr)))
244  histDeadList.append(rootp.Get(dirERROR+hdeadB+str(lyr)))
245  for hist1, hist2 in zip(histOccList, histDeadList):
246  if hist1 != None or hist2 !=None:
247  hist1.Draw("colz")
248  match=re.search('(?<=PXLayer_)[0-9]',hist1.GetName())
249  if match != None and "per_SignedModuleCoord_per_SignedLadderCoord" in hist1.GetName():
250  lyr=int(match.group(0))
251  hist1.SetTitle("Digi Occupancy Layer {0}".format(lyr))
252  boxList=[]
253  lineList=[]
254  renderPluginBPIX(lineList,lyr)
255  lineWd=3
256  if lyr==4 :
257  lineWd=2
258  if lyr==1:
259  tbmRoc=4
260  else:
261  tbmRoc=8
262  binTBM=[]
263  singleROC=0
264  maxx=hist2.GetMaximum()
265  for biny in range(1,hist2.GetNbinsY()+1):
266  if len(binTBM)!=0:
267  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
268  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
269  y1=hist2.GetYaxis().GetBinLowEdge(biny-1)
270  y2=hist2.GetYaxis().GetBinUpEdge(biny-1)
271  draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny-1)/maxx))],0,1,lineWd)
272  binTBM=[]
273  singleROC=0
274  for binx in range(1,hist2.GetNbinsX()+1):
275  if len(binTBM)==0:
276  check=True
277  elif hist2.GetBinContent(binx,biny)==hist2.GetBinContent(binTBM[len(binTBM)-1],biny):
278  check=True
279  else:
280  check=False
281  if hist2.GetBinContent(binx,biny)!=0 and check:
282  if len(binTBM)==0:
283  binTBM.append(binx)
284  else:
285  if len(binTBM)==(tbmRoc):
286  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
287  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
288  y1=hist2.GetYaxis().GetBinLowEdge(biny)
289  y2=hist2.GetYaxis().GetBinUpEdge(biny)
290  draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
291  binTBM=[]
292  singleROC=0
293  binTBM.append(binx)
294  else:
295  binTBM.append(binx)
296  else:
297  if len(binTBM)!=0:
298  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
299  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
300  y1=hist2.GetYaxis().GetBinLowEdge(biny)
301  y2=hist2.GetYaxis().GetBinUpEdge(biny)
302  draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
303  binTBM=[]
304  if hist2.GetBinContent(binx,biny)!=0:
305  binTBM.append(binx)
306  c.SaveAs('MergedPCLOther_BPix_Layer{0}_TBM.pdf'.format(lyr))
307  os.system('gs -dBATCH -dNOPAUSE -sDEVICE=png16m -dUseCropBox -sOutputFile=MergedPCLOther_BPix_Layer{0}_TBM.png -r144 -q MergedPCLOther_BPix_Layer{0}_TBM.pdf'.format(lyr))
308  os.system('rm -f MergedPCLOther_BPix_Layer{0}_TBM.pdf'.format(lyr))
309  else :
310  print("Some Error in get the histograms for FPIX")
311  #FPIX
312  print("----> Build maps for FPix")
313  for rng in range(1,3):
314  histOccList.append(rootf.FindObjectAny(hoccF+str(rng)))
315  histDeadList.append(rootp.Get(dirERROR+hdeadF+str(rng)))
316  for hist1, hist2 in zip(histOccList, histDeadList):
317  if hist1 != None or hist2 !=None:
318  hist1.Draw("colz")
319  match=re.search('(?<=PXRing_)[0-9]',hist1.GetName())
320  if match != None and "per_SignedDiskCoord_per_SignedBladePanelCoord" in hist1.GetName():
321  ring=int(match.group(0))
322  hist1.SetTitle("Digi Occupancy Ring {0}".format(ring))
323  boxList=[]
324  lineList=[]
325  renderPluginFPIX(lineList,ring)
326  lineWd=3
327  if ring==2 :
328  lineWd=2
329  tbmRoc=8
330  binTBM=[]
331  maxx=hist2.GetMaximum()
332  for biny in range(1,hist2.GetNbinsY()+1):
333  if len(binTBM)!=0:
334  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
335  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
336  y1=hist2.GetYaxis().GetBinLowEdge(biny-1)
337  y2=hist2.GetYaxis().GetBinUpEdge(biny-1)
338  draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny-1)/maxx))],0,1,lineWd)
339  binTBM=[]
340  for binx in range(1,hist2.GetNbinsX()+1):
341  if len(binTBM)==0:
342  check=True
343  elif hist2.GetBinContent(binx,biny)==hist2.GetBinContent(binTBM[len(binTBM)-1],biny):
344  check=True
345  else:
346  check=False
347  if hist2.GetBinContent(binx,biny)!=0 and check:
348  if len(binTBM)==0:
349  binTBM.append(binx)
350  else:
351  if len(binTBM)==tbmRoc:
352  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
353  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
354  y1=hist2.GetYaxis().GetBinLowEdge(biny)
355  y2=hist2.GetYaxis().GetBinUpEdge(biny)
356  draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
357  binTBM=[]
358  binTBM.append(binx)
359  else:
360  binTBM.append(binx)
361  else:
362  if len(binTBM)!=0:
363  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
364  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
365  y1=hist2.GetYaxis().GetBinLowEdge(biny)
366  y2=hist2.GetYaxis().GetBinUpEdge(biny)
367  draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
368  binTBM=[]
369  if hist2.GetBinContent(binx,biny)!=0:
370  binTBM.append(binx)
371  c.SaveAs('MergedPCLOther_FPix_Ring{0}_TBM.pdf'.format(ring))
372  os.system('gs -dBATCH -dNOPAUSE -sDEVICE=png16m -dUseCropBox -sOutputFile=MergedPCLOther_FPix_Ring{0}_TBM.png -r144 -q MergedPCLOther_FPix_Ring{0}_TBM.pdf'.format(ring))
373  os.system('rm -f MergedPCLOther_FPix_Ring{0}_TBM.pdf'.format(ring))
374 
375  else :
376  print("Some Error in get the histograms for FPIX")
377 
378 
379 
380 
381 if __name__ == '__main__':
382  main()
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
PCLOthers.renderPluginBPIX
def renderPluginBPIX(lineList, layer)
Definition: PCLOthers.py:32
min
T min(T a, T b)
Definition: MathUtil.h:58
PCLOthers.draw_line
def draw_line(lineList, x1, x2, y1, y2, width=1, style=1, color=1)
Definition: PCLOthers.py:10
PCLOthers.main
def main()
Definition: PCLOthers.py:197
str
#define str(s)
Definition: TestProcessor.cc:53
PCLOthers.maskFPixROC
def maskFPixROC(boxList, xsign, ysign, dsk, bld, pnl, roc)
Definition: PCLOthers.py:158
PCLOthers.maskBPixROC
def maskBPixROC(boxList, xsign, ysign, layer, lad, mod, roc)
Definition: PCLOthers.py:90
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
createfilelist.int
int
Definition: createfilelist.py:10
main
Definition: main.py:1
ComparisonHelper::zip
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Definition: L1TStage2CaloLayer1.h:41
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
PCLOthers.draw_box
def draw_box(boxList, xl, xr, yl, yr, opacity=1, color=1, style=1001, lstyle=1, lw=3)
Definition: PCLOthers.py:20
format
PCLOthers.renderPluginFPIX
def renderPluginFPIX(lineList, ring)
Definition: PCLOthers.py:118
PCLOthers.dqm_get_dataset
def dqm_get_dataset(server, match, run, type="offline_data")
Definition: PCLOthers.py:178