CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
MergePCLDeadROC Namespace Reference

Functions

def dqm_get_dataset
 
def draw_box
 
def draw_line
 
def main
 
def maskBPixROC
 
def maskFPixROC
 
def renderPluginBPIX
 
def renderPluginFPIX
 

Function Documentation

def MergePCLDeadROC.dqm_get_dataset (   server,
  match,
  run,
  type = "offline_data" 
)

Definition at line 178 of file MergePCLDeadROC.py.

References print(), and SiPixelLorentzAngle_cfi.read.

179 def dqm_get_dataset(server, match, run, type="offline_data"):
180  datareq = urllib2.Request(('%s/data/json/samples?match=%s') % (server, match))
181  datareq.add_header('User-agent', ident)
182  # Get data
183  data = eval(re.sub(r"\bnan\b", "0", urllib2.build_opener(X509CertOpen()).open(datareq).read()),
184  { "__builtins__": None }, {})
185  ret = ""
186  for l in data['samples']:
187  if l['type'] == type:
188  for x in l['items']:
189  if int(x['run']) == int(run):
190  ret=x['dataset']
191  break
192  print(ret)
193  return ret
194 
195 
196 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def MergePCLDeadROC.draw_box (   boxList,
  xl,
  xr,
  yl,
  yr,
  opacity = 1,
  color = 1,
  style = 1001,
  lstyle = 1,
  lw = 3 
)

Definition at line 20 of file MergePCLDeadROC.py.

Referenced by main(), maskBPixROC(), and maskFPixROC().

20 
21 def draw_box(boxList,xl,xr,yl,yr,opacity=1,color=1,style=1001,lstyle=1,lw=3):
22  from ROOT import TBox
23  b=TBox(xl,yl,xr,yr)
24  b.SetBit(ROOT.kCanDelete)
25  b.SetFillStyle(style)
26  b.SetFillColorAlpha(color, opacity)
27  b.SetLineColor(color)
28  b.SetLineWidth(lw)
29  b.SetLineStyle(lstyle)
30  b.Draw()
31  boxList.append(b)
def MergePCLDeadROC.draw_line (   lineList,
  x1,
  x2,
  y1,
  y2,
  width = 1,
  style = 1,
  color = 1 
)

Definition at line 10 of file MergePCLDeadROC.py.

Referenced by renderPluginBPIX(), and renderPluginFPIX().

10 
11 def draw_line(lineList,x1,x2,y1,y2,width=1,style=1,color=1):
12  from ROOT import TLine
13  l=TLine(x1,y1,x2,y2)
14  l.SetBit(ROOT.kCanDelete)
15  l.SetLineWidth(width)
16  l.SetLineStyle(style)
17  l.SetLineColor(color)
18  l.Draw()
19  lineList.append(l)
def MergePCLDeadROC.main ( )

Definition at line 197 of file MergePCLDeadROC.py.

References draw_box(), print(), sistrip::SpyUtilities.range(), renderPluginBPIX(), renderPluginFPIX(), str, and ComparisonHelper.zip().

198 def main():
199  import sys
200  import os
201  import ROOT
202 
203  if len(sys.argv) != 3:
204  print("input files needed!")
205  return
206  else:
207  filename=sys.argv[1]
208  pclfile=sys.argv[2]
209  print(filename+" -- "+filename[19:25])
210  print(pclfile+" -- "+pclfile[19:25])
211  runNum=filename[19:25]
212 
213  dir="DQMData/Run " + runNum + "/PixelPhase1/Run summary/Pahse1_MechanicalView/"
214  dirERROR="DQMData/Run " + runNum + "/PixelPhase1/Run summary/SiPixelQualityPCL/BadROC_PCL/"
215 
216 
217  dirBPix=dir + "PXBarrel/"
218  dirFPix=dir + "PXForward/"
219 
220  hoccB="digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_"
221  hoccF="digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_"
222  hdeadB="Dead Channels per ROC_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_"
223  hdeadF="Dead Channels per ROC_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_"
224 
225  ROOT.gROOT.SetBatch(1)
226  ROOT.gStyle.SetOptStat(0)
227  ROOT.gStyle.SetPalette(52) #104 kTemperatureMap // 55 kRainBow // 97 kRust // 57 kBird
228  color=[]
229  for i in range(0,255):
230  color.append(ROOT.TColor.GetColorPalette(i))
231  ROOT.gStyle.SetPalette(1) #104 kTemperatureMap // 55 kRainBow
232  ROOT.gStyle.SetNumberContours(128)
233  rootf=ROOT.TFile(filename)
234  rootp=ROOT.TFile(pclfile)
235 
236 
237 
238  c=ROOT.TCanvas("c","c",1250,1000)
239  #BPIX
240  print("----> Build maps for BPix")
241  histOccList=[]
242  histDeadList=[]
243  for lyr in range(1,5):
244  histOccList.append(rootf.FindObjectAny(hoccB+str(lyr)))
245  histDeadList.append(rootp.Get(dirERROR+hdeadB+str(lyr)))
246  for hist1, hist2 in zip(histOccList, histDeadList):
247  if hist1 != None or hist2 !=None:
248  hist1.Draw("colz")
249  match=re.search('(?<=PXLayer_)[0-9]',hist1.GetName())
250  if match != None and "per_SignedModuleCoord_per_SignedLadderCoord" in hist1.GetName():
251  lyr=int(match.group(0))
252  hist1.SetTitle("Digi Occupancy Layer {0}".format(lyr))
253  boxList=[]
254  lineList=[]
255  renderPluginBPIX(lineList,lyr)
256  lineWd=3
257  if lyr==4 :
258  lineWd=2
259  if lyr==1:
260  tbmRoc=4
261  else:
262  tbmRoc=8
263  binTBM=[]
264  singleROC=0
265  maxx=hist2.GetMaximum()
266  for biny in range(1,hist2.GetNbinsY()+1):
267  if len(binTBM)!=0:
268  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
269  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
270  y1=hist2.GetYaxis().GetBinLowEdge(biny-1)
271  y2=hist2.GetYaxis().GetBinUpEdge(biny-1)
272  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)
273  binTBM=[]
274  singleROC=0
275  for binx in range(1,hist2.GetNbinsX()+1):
276  if len(binTBM)==0:
277  check=True
278  elif hist2.GetBinContent(binx,biny)==hist2.GetBinContent(binTBM[len(binTBM)-1],biny):
279  check=True
280  else:
281  check=False
282  if hist2.GetBinContent(binx,biny)!=0 and check:
283  if len(binTBM)==0:
284  binTBM.append(binx)
285  else:
286  if len(binTBM)==(tbmRoc):
287  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
288  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
289  y1=hist2.GetYaxis().GetBinLowEdge(biny)
290  y2=hist2.GetYaxis().GetBinUpEdge(biny)
291  draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
292  binTBM=[]
293  singleROC=0
294  binTBM.append(binx)
295  else:
296  binTBM.append(binx)
297  else:
298  if len(binTBM)!=0:
299  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
300  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
301  y1=hist2.GetYaxis().GetBinLowEdge(biny)
302  y2=hist2.GetYaxis().GetBinUpEdge(biny)
303  draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
304  binTBM=[]
305  if hist2.GetBinContent(binx,biny)!=0:
306  binTBM.append(binx)
307  c.SaveAs('MergedPCLDeadROC_BPix_Layer{0}_TBM.pdf'.format(lyr))
308  os.system('gs -dBATCH -dNOPAUSE -sDEVICE=png16m -dUseCropBox -sOutputFile=MergedPCLDeadROC_BPix_Layer{0}_TBM.png -r144 -q MergedPCLDeadROC_BPix_Layer{0}_TBM.pdf'.format(lyr))
309  os.system('rm -f MergedPCLDeadROC_BPix_Layer{0}_TBM.pdf'.format(lyr))
310  else :
311  print("Some Error in get the histograms for FPIX")
312  #FPIX
313  print("----> Build maps for FPix")
314  for rng in range(1,3):
315  histOccList.append(rootf.FindObjectAny(hoccF+str(rng)))
316  histDeadList.append(rootp.Get(dirERROR+hdeadF+str(rng)))
317  for hist1, hist2 in zip(histOccList, histDeadList):
318  if hist1 != None or hist2 !=None:
319  hist1.Draw("colz")
320  match=re.search('(?<=PXRing_)[0-9]',hist1.GetName())
321  if match != None and "per_SignedDiskCoord_per_SignedBladePanelCoord" in hist1.GetName():
322  ring=int(match.group(0))
323  hist1.SetTitle("Digi Occupancy Ring {0}".format(ring))
324  boxList=[]
325  lineList=[]
326  renderPluginFPIX(lineList,ring)
327  lineWd=3
328  if ring==2 :
329  lineWd=2
330  tbmRoc=8
331  binTBM=[]
332  maxx=hist2.GetMaximum()
333  for biny in range(1,hist2.GetNbinsY()+1):
334  if len(binTBM)!=0:
335  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
336  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
337  y1=hist2.GetYaxis().GetBinLowEdge(biny-1)
338  y2=hist2.GetYaxis().GetBinUpEdge(biny-1)
339  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)
340  binTBM=[]
341  for binx in range(1,hist2.GetNbinsX()+1):
342  if len(binTBM)==0:
343  check=True
344  elif hist2.GetBinContent(binx,biny)==hist2.GetBinContent(binTBM[len(binTBM)-1],biny):
345  check=True
346  else:
347  check=False
348  if hist2.GetBinContent(binx,biny)!=0 and check:
349  if len(binTBM)==0:
350  binTBM.append(binx)
351  else:
352  if len(binTBM)==tbmRoc:
353  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
354  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
355  y1=hist2.GetYaxis().GetBinLowEdge(biny)
356  y2=hist2.GetYaxis().GetBinUpEdge(biny)
357  draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
358  binTBM=[]
359  binTBM.append(binx)
360  else:
361  binTBM.append(binx)
362  else:
363  if len(binTBM)!=0:
364  x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
365  x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
366  y1=hist2.GetYaxis().GetBinLowEdge(biny)
367  y2=hist2.GetYaxis().GetBinUpEdge(biny)
368  draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
369  binTBM=[]
370  if hist2.GetBinContent(binx,biny)!=0:
371  binTBM.append(binx)
372  c.SaveAs('MergedPCLDeadROC_FPix_Ring{0}_TBM.pdf'.format(ring))
373  os.system('gs -dBATCH -dNOPAUSE -sDEVICE=png16m -dUseCropBox -sOutputFile=MergedPCLDeadROC_FPix_Ring{0}_TBM.png -r144 -q MergedPCLDeadROC_FPix_Ring{0}_TBM.pdf'.format(ring))
374  os.system('rm -f MergedPCLDeadROC_FPix_Ring{0}_TBM.pdf'.format(ring))
375 
376  else :
377  print("Some Error in get the histograms for FPIX")
378 
379 
380 
const uint16_t range(const Frame &aFrame)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)
def MergePCLDeadROC.maskBPixROC (   boxList,
  xsign,
  ysign,
  layer,
  lad,
  mod,
  roc 
)

Definition at line 90 of file MergePCLDeadROC.py.

References draw_box(), SiStripPI.max, and min().

90 
91 def maskBPixROC(boxList,xsign,ysign,layer,lad,mod,roc):
92  if roc<8 :
93  rocShiftX=roc*1./8
94  rocShiftY=0
95  else :
96  rocShiftX=(15-roc)*1./8
97  rocShiftY=1./2
98  if ysign==1:
99  flipped = not(lad%2==0)
100  else :
101  flipped = not(lad%2==1)
102  if flipped : roc0_orientation = -1
103  else : roc0_orientation = 1
104  if xsign==-1 : roc0_orientation *= -1
105  if ysign==-1 : roc0_orientation *= -1
106  x1 = xsign * (mod+0.5-rocShiftX)
107  x2 = xsign * (mod+0.5 - 1./8-rocShiftX);
108  y1 = ysign * (lad-roc0_orientation*rocShiftY)
109  y2 = ysign * (lad + roc0_orientation*1./2-roc0_orientation*rocShiftY)
110  if layer == 1 and xsign == -1 :
111  x1 = xsign * (mod-0.5)-rocShiftX
112  x2 = xsign * (mod-0.5 + 1./8)-rocShiftX
113  y1 = ysign * (lad +rocShiftY)
114  y2 = ysign * (lad - roc0_orientation*1./2+rocShiftY)
115  draw_box(boxList,min(x1,x2),max(x1,x2),min(y1, y2),max(y1,y2),0.75)
116 
117 
T min(T a, T b)
Definition: MathUtil.h:58
def MergePCLDeadROC.maskFPixROC (   boxList,
  xsign,
  ysign,
  dsk,
  bld,
  pnl,
  roc 
)

Definition at line 158 of file MergePCLDeadROC.py.

References draw_box(), SiStripPI.max, and min().

159 def maskFPixROC(boxList,xsign,ysign,dsk,bld,pnl,roc) :
160  from ROOT import TCanvas,TLine
161  if roc<8 :
162  rocShiftX=roc*1./8
163  rocShiftY=0
164  else :
165  rocShiftX=(15-roc)*1./8
166  rocShiftY=1./4
167  sign=ysign
168  x1 = xsign * (0.5 + dsk - 1/8.-rocShiftX)
169  x2 = xsign * (0.5 + dsk-rocShiftX)
170  if pnl==1:
171  y1 = ysign * (bld + sign*0.25)-xsign*rocShiftY
172  y2 = ysign * (bld + sign*0.25 + xsign*ysign*0.25)-xsign*rocShiftY
173  else:
174  y1 = ysign * (bld - sign*0.25)+xsign*rocShiftY
175  y2 = ysign * (bld - sign*0.25 - xsign*ysign*0.25)+xsign*rocShiftY
176  draw_box(boxList,min(x1,x2),max(x1,x2),min(y1,y2),max(y1,y2),0.75)
177 
T min(T a, T b)
Definition: MathUtil.h:58
def MergePCLDeadROC.renderPluginBPIX (   lineList,
  layer 
)

Definition at line 32 of file MergePCLDeadROC.py.

References draw_line(), and sistrip::SpyUtilities.range().

Referenced by main().

32 
33 def renderPluginBPIX(lineList,layer) :
34  from ROOT import TCanvas,TLine
35  nlad=[6,14,22,32]
36  coordSign=[(-1,-1),(-1,1),(1,-1),(1,1)]
37  for xsign,ysign in coordSign:
38  xlow = xsign*0.5
39  xhigh= xsign*(0.5+4)
40  ylow = ysign*0.5
41  yhigh= ysign*(0.5 + nlad[layer-1])
42  # Outside Box
43  draw_line(lineList,xlow, xhigh, ylow, ylow) # bottom
44  draw_line(lineList,xlow, xhigh, yhigh, yhigh) # top
45  draw_line(lineList,xlow, xlow, ylow, yhigh) # left
46  draw_line(lineList,xhigh, xhigh, ylow, yhigh) # right
47  # Inner Horizontal lines
48  for lad in range(nlad[layer-1]):
49  lad+=1
50  if lad != nlad[layer-1]:
51  y = ysign * (lad+0.5)
52  draw_line(lineList,xlow, xhigh, y, y)
53  y = ysign * (lad);
54  draw_line(lineList,xlow, xhigh, y, y, 1, 3);
55  # Inner Vertical lines
56  for mod in range(3) :
57  mod+=1
58  x = xsign * (mod + 0.5);
59  draw_line(lineList,x, x, ylow, yhigh);
60 
61  # Draw ROC0
62  for mod in range(4):
63  mod+=1
64  for lad in range(nlad[layer-1]):
65  lad+=1
66  if ysign==1:
67  flipped = not(lad%2==0)
68  else :
69  flipped = not(lad%2==1)
70  if flipped : roc0_orientation = -1
71  else : roc0_orientation = 1
72  if xsign==-1 : roc0_orientation *= -1
73  if ysign==-1 : roc0_orientation *= -1
74  x1 = xsign * (mod+0.5)
75  x2 = xsign * (mod+0.5 - 1./8);
76  y1 = ysign * (lad)
77  y2 = ysign * (lad + roc0_orientation*1./2)
78  if layer == 1 and xsign == -1 :
79  x1 = xsign * (mod-0.5)
80  x2 = xsign * (mod-0.5 + 1./8)
81  y1 = ysign * (lad)
82  y2 = ysign * (lad - roc0_orientation*1./2)
83 
84  draw_line(lineList,x1, x2, y1, y1, 1)
85  draw_line(lineList,x2, x2, y1, y2, 1)
86 
87  else:
88  draw_line(lineList,x1, x2, y1, y1, 1)
89  draw_line(lineList,x2, x2, y1, y2, 1)
const uint16_t range(const Frame &aFrame)
def MergePCLDeadROC.renderPluginFPIX (   lineList,
  ring 
)

Definition at line 118 of file MergePCLDeadROC.py.

References draw_line(), and sistrip::SpyUtilities.range().

Referenced by main().

119 def renderPluginFPIX(lineList,ring) :
120  from ROOT import TCanvas,TLine
121  coordSign=[(-1,-1),(-1,1),(1,-1),(1,1)]
122  for dsk in range(3) :
123  dsk+=1
124  for xsign,ysign in coordSign:
125  for bld in range(5+ring*6):
126  bld+=1
127  # Panel 2 has dashed mid-plane
128  x1 = xsign * (0.5 + dsk - 1)
129  x2 = xsign * (0.5 + dsk)
130  sign = ysign
131  y1 = ysign * (bld + sign*0.5)
132  y2 = ysign * (bld)
133  yp2_mid = ysign * (bld - sign*0.25)
134  y3 = ysign * (bld - sign*0.5)
135  draw_line(lineList,x1, x2, y1, y1)
136  draw_line(lineList,x1, x2, y2, y2)
137  draw_line(lineList,x1, x2, yp2_mid, yp2_mid,1,2)
138  draw_line(lineList,x1, x2, y3, y3)
139  # Vertical lines
140  x = xsign * (0.5 + dsk - 1)
141  draw_line(lineList,x, x, y1, y2)
142  draw_line(lineList,x, x, y2, y3)
143  if ring==2 :
144  x = xsign * (0.5 + dsk)
145  draw_line(lineList,x, x, y1, y2)
146  draw_line(lineList,x, x, y2, y3)
147  #Make a BOX around ROC 0
148  x1 = xsign * (0.5 + dsk - 1/8.)
149  x2 = xsign * (0.5 + dsk)
150  y1_p1 = ysign * (bld + sign*0.25)
151  y2_p1 = ysign * (bld + sign*0.25 + xsign*ysign*0.25)
152  draw_line(lineList,x1, x2, y1_p1, y1_p1, 1)
153  draw_line(lineList,x1, x1, y1_p1, y2_p1, 1)
154  y1_p2 = ysign * (bld - sign*0.25)
155  y2_p2 = ysign * (bld - sign*0.25 - xsign*ysign*0.25)
156  draw_line(lineList,x1, x2, y1_p2, y1_p2)
157  draw_line(lineList,x1, x1, y1_p2, y2_p2)
const uint16_t range(const Frame &aFrame)