File indexing completed on 2024-11-26 02:34:10
0001
0002
0003 import ROOT
0004 from ROOT import TBufferFile, TH1F, TProfile, TProfile2D, TH2F, TFile, TH1D, TH2D
0005 import re
0006 import os
0007
0008
0009 def draw_line(lineList,x1,x2,y1,y2,width=1,style=1,color=1):
0010 from ROOT import TLine
0011 l=TLine(x1,y1,x2,y2)
0012 l.SetBit(ROOT.kCanDelete)
0013 l.SetLineWidth(width)
0014 l.SetLineStyle(style)
0015 l.SetLineColor(color)
0016 l.Draw()
0017 lineList.append(l)
0018
0019 def draw_box(boxList,xl,xr,yl,yr,opacity=1,color=1,style=1001,lstyle=1,lw=3):
0020 from ROOT import TBox
0021 b=TBox(xl,yl,xr,yr)
0022 b.SetBit(ROOT.kCanDelete)
0023 b.SetFillStyle(style)
0024 b.SetFillColorAlpha(color, opacity)
0025 b.SetLineColor(color)
0026 b.SetLineWidth(lw)
0027 b.SetLineStyle(lstyle)
0028 b.Draw()
0029 boxList.append(b)
0030
0031 def renderPluginBPIX(lineList,layer) :
0032 from ROOT import TCanvas,TLine
0033 nlad=[6,14,22,32]
0034 coordSign=[(-1,-1),(-1,1),(1,-1),(1,1)]
0035 for xsign,ysign in coordSign:
0036 xlow = xsign*0.5
0037 xhigh= xsign*(0.5+4)
0038 ylow = ysign*0.5
0039 yhigh= ysign*(0.5 + nlad[layer-1])
0040
0041 draw_line(lineList,xlow, xhigh, ylow, ylow)
0042 draw_line(lineList,xlow, xhigh, yhigh, yhigh)
0043 draw_line(lineList,xlow, xlow, ylow, yhigh)
0044 draw_line(lineList,xhigh, xhigh, ylow, yhigh)
0045
0046 for lad in range(nlad[layer-1]):
0047 lad+=1
0048 if lad != nlad[layer-1]:
0049 y = ysign * (lad+0.5)
0050 draw_line(lineList,xlow, xhigh, y, y)
0051 y = ysign * (lad);
0052 draw_line(lineList,xlow, xhigh, y, y, 1, 3);
0053
0054 for mod in range(3) :
0055 mod+=1
0056 x = xsign * (mod + 0.5);
0057 draw_line(lineList,x, x, ylow, yhigh);
0058
0059
0060 for mod in range(4):
0061 mod+=1
0062 for lad in range(nlad[layer-1]):
0063 lad+=1
0064 if ysign==1:
0065 flipped = not(lad%2==0)
0066 else :
0067 flipped = not(lad%2==1)
0068 if flipped : roc0_orientation = -1
0069 else : roc0_orientation = 1
0070 if xsign==-1 : roc0_orientation *= -1
0071 if ysign==-1 : roc0_orientation *= -1
0072 x1 = xsign * (mod+0.5)
0073 x2 = xsign * (mod+0.5 - 1./8);
0074 y1 = ysign * (lad)
0075 y2 = ysign * (lad + roc0_orientation*1./2)
0076 if layer == 1 and xsign == -1 :
0077 x1 = xsign * (mod-0.5)
0078 x2 = xsign * (mod-0.5 + 1./8)
0079 y1 = ysign * (lad)
0080 y2 = ysign * (lad - roc0_orientation*1./2)
0081
0082 draw_line(lineList,x1, x2, y1, y1, 1)
0083 draw_line(lineList,x2, x2, y1, y2, 1)
0084
0085 else:
0086 draw_line(lineList,x1, x2, y1, y1, 1)
0087 draw_line(lineList,x2, x2, y1, y2, 1)
0088
0089 def maskBPixROC(boxList,xsign,ysign,layer,lad,mod,roc):
0090 if roc<8 :
0091 rocShiftX=roc*1./8
0092 rocShiftY=0
0093 else :
0094 rocShiftX=(15-roc)*1./8
0095 rocShiftY=1./2
0096 if ysign==1:
0097 flipped = not(lad%2==0)
0098 else :
0099 flipped = not(lad%2==1)
0100 if flipped : roc0_orientation = -1
0101 else : roc0_orientation = 1
0102 if xsign==-1 : roc0_orientation *= -1
0103 if ysign==-1 : roc0_orientation *= -1
0104 x1 = xsign * (mod+0.5-rocShiftX)
0105 x2 = xsign * (mod+0.5 - 1./8-rocShiftX);
0106 y1 = ysign * (lad-roc0_orientation*rocShiftY)
0107 y2 = ysign * (lad + roc0_orientation*1./2-roc0_orientation*rocShiftY)
0108 if layer == 1 and xsign == -1 :
0109 x1 = xsign * (mod-0.5)-rocShiftX
0110 x2 = xsign * (mod-0.5 + 1./8)-rocShiftX
0111 y1 = ysign * (lad +rocShiftY)
0112 y2 = ysign * (lad - roc0_orientation*1./2+rocShiftY)
0113 draw_box(boxList,min(x1,x2),max(x1,x2),min(y1, y2),max(y1,y2),0.75)
0114
0115
0116
0117 def renderPluginFPIX(lineList,ring) :
0118 from ROOT import TCanvas,TLine
0119 coordSign=[(-1,-1),(-1,1),(1,-1),(1,1)]
0120 for dsk in range(3) :
0121 dsk+=1
0122 for xsign,ysign in coordSign:
0123 for bld in range(5+ring*6):
0124 bld+=1
0125
0126 x1 = xsign * (0.5 + dsk - 1)
0127 x2 = xsign * (0.5 + dsk)
0128 sign = ysign
0129 y1 = ysign * (bld + sign*0.5)
0130 y2 = ysign * (bld)
0131 yp2_mid = ysign * (bld - sign*0.25)
0132 y3 = ysign * (bld - sign*0.5)
0133 draw_line(lineList,x1, x2, y1, y1)
0134 draw_line(lineList,x1, x2, y2, y2)
0135 draw_line(lineList,x1, x2, yp2_mid, yp2_mid,1,2)
0136 draw_line(lineList,x1, x2, y3, y3)
0137
0138 x = xsign * (0.5 + dsk - 1)
0139 draw_line(lineList,x, x, y1, y2)
0140 draw_line(lineList,x, x, y2, y3)
0141 if ring==2 :
0142 x = xsign * (0.5 + dsk)
0143 draw_line(lineList,x, x, y1, y2)
0144 draw_line(lineList,x, x, y2, y3)
0145
0146 x1 = xsign * (0.5 + dsk - 1/8.)
0147 x2 = xsign * (0.5 + dsk)
0148 y1_p1 = ysign * (bld + sign*0.25)
0149 y2_p1 = ysign * (bld + sign*0.25 + xsign*ysign*0.25)
0150 draw_line(lineList,x1, x2, y1_p1, y1_p1, 1)
0151 draw_line(lineList,x1, x1, y1_p1, y2_p1, 1)
0152 y1_p2 = ysign * (bld - sign*0.25)
0153 y2_p2 = ysign * (bld - sign*0.25 - xsign*ysign*0.25)
0154 draw_line(lineList,x1, x2, y1_p2, y1_p2)
0155 draw_line(lineList,x1, x1, y1_p2, y2_p2)
0156
0157 def maskFPixROC(boxList,xsign,ysign,dsk,bld,pnl,roc) :
0158 from ROOT import TCanvas,TLine
0159 if roc<8 :
0160 rocShiftX=roc*1./8
0161 rocShiftY=0
0162 else :
0163 rocShiftX=(15-roc)*1./8
0164 rocShiftY=1./4
0165 sign=ysign
0166 x1 = xsign * (0.5 + dsk - 1/8.-rocShiftX)
0167 x2 = xsign * (0.5 + dsk-rocShiftX)
0168 if pnl==1:
0169 y1 = ysign * (bld + sign*0.25)-xsign*rocShiftY
0170 y2 = ysign * (bld + sign*0.25 + xsign*ysign*0.25)-xsign*rocShiftY
0171 else:
0172 y1 = ysign * (bld - sign*0.25)+xsign*rocShiftY
0173 y2 = ysign * (bld - sign*0.25 - xsign*ysign*0.25)+xsign*rocShiftY
0174 draw_box(boxList,min(x1,x2),max(x1,x2),min(y1,y2),max(y1,y2),0.75)
0175
0176
0177 def dqm_get_dataset(server, match, run, type="offline_data"):
0178 datareq = urllib2.Request(('%s/data/json/samples?match=%s') % (server, match))
0179 datareq.add_header('User-agent', ident)
0180
0181 data = eval(re.sub(r"\bnan\b", "0", urllib2.build_opener(X509CertOpen()).open(datareq).read()),
0182 { "__builtins__": None }, {})
0183 ret = ""
0184 for l in data['samples']:
0185 if l['type'] == type:
0186 for x in l['items']:
0187 if int(x['run']) == int(run):
0188 ret=x['dataset']
0189 break
0190 print(ret)
0191 return ret
0192
0193
0194
0195
0196 def main():
0197 import sys
0198 import os
0199 import ROOT
0200
0201 if len(sys.argv) != 3:
0202 print("input files needed!")
0203 return
0204 else:
0205 filename=sys.argv[1]
0206 pclfile=sys.argv[2]
0207 print(filename+" -- "+filename[19:25])
0208 print(pclfile+" -- "+pclfile[19:25])
0209 runNum=filename[19:25]
0210
0211 dir="DQMData/Run " + runNum + "/PixelPhase1/Run summary/Pahse1_MechanicalView/"
0212 dirERROR="DQMData/Run " + runNum + "/PixelPhase1/Run summary/SiPixelQualityPCL/BadROC_Other/"
0213
0214
0215 dirBPix=dir + "PXBarrel/"
0216 dirFPix=dir + "PXForward/"
0217
0218 hoccB="digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_"
0219 hoccF="digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_"
0220 hdeadB="Dead Channels per ROC_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_"
0221 hdeadF="Dead Channels per ROC_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_"
0222
0223 ROOT.gROOT.SetBatch(1)
0224 ROOT.gStyle.SetOptStat(0)
0225 ROOT.gStyle.SetPalette(52)
0226 color=[]
0227 for i in range(0,255):
0228 color.append(ROOT.TColor.GetColorPalette(i))
0229 ROOT.gStyle.SetPalette(1)
0230 ROOT.gStyle.SetNumberContours(128)
0231 rootf=ROOT.TFile(filename)
0232 rootp=ROOT.TFile(pclfile)
0233
0234
0235
0236 c=ROOT.TCanvas("c","c",1250,1000)
0237
0238 print("----> Build maps for BPix")
0239 histOccList=[]
0240 histDeadList=[]
0241 for lyr in range(1,5):
0242 histOccList.append(rootf.FindObjectAny(hoccB+str(lyr)))
0243 histDeadList.append(rootp.Get(dirERROR+hdeadB+str(lyr)))
0244 for hist1, hist2 in zip(histOccList, histDeadList):
0245 if hist1 != None or hist2 !=None:
0246 hist1.Draw("colz")
0247 match=re.search('(?<=PXLayer_)[0-9]',hist1.GetName())
0248 if match != None and "per_SignedModuleCoord_per_SignedLadderCoord" in hist1.GetName():
0249 lyr=int(match.group(0))
0250 hist1.SetTitle("Digi Occupancy Layer {0}".format(lyr))
0251 boxList=[]
0252 lineList=[]
0253 renderPluginBPIX(lineList,lyr)
0254 lineWd=3
0255 if lyr==4 :
0256 lineWd=2
0257 if lyr==1:
0258 tbmRoc=4
0259 else:
0260 tbmRoc=8
0261 binTBM=[]
0262 singleROC=0
0263 maxx=hist2.GetMaximum()
0264 for biny in range(1,hist2.GetNbinsY()+1):
0265 if len(binTBM)!=0:
0266 x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
0267 x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
0268 y1=hist2.GetYaxis().GetBinLowEdge(biny-1)
0269 y2=hist2.GetYaxis().GetBinUpEdge(biny-1)
0270 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)
0271 binTBM=[]
0272 singleROC=0
0273 for binx in range(1,hist2.GetNbinsX()+1):
0274 if len(binTBM)==0:
0275 check=True
0276 elif hist2.GetBinContent(binx,biny)==hist2.GetBinContent(binTBM[len(binTBM)-1],biny):
0277 check=True
0278 else:
0279 check=False
0280 if hist2.GetBinContent(binx,biny)!=0 and check:
0281 if len(binTBM)==0:
0282 binTBM.append(binx)
0283 else:
0284 if len(binTBM)==(tbmRoc):
0285 x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
0286 x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
0287 y1=hist2.GetYaxis().GetBinLowEdge(biny)
0288 y2=hist2.GetYaxis().GetBinUpEdge(biny)
0289 draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
0290 binTBM=[]
0291 singleROC=0
0292 binTBM.append(binx)
0293 else:
0294 binTBM.append(binx)
0295 else:
0296 if len(binTBM)!=0:
0297 x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
0298 x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
0299 y1=hist2.GetYaxis().GetBinLowEdge(biny)
0300 y2=hist2.GetYaxis().GetBinUpEdge(biny)
0301 draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
0302 binTBM=[]
0303 if hist2.GetBinContent(binx,biny)!=0:
0304 binTBM.append(binx)
0305 c.SaveAs('MergedPCLOther_BPix_Layer{0}_TBM.pdf'.format(lyr))
0306 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))
0307 os.system('rm -f MergedPCLOther_BPix_Layer{0}_TBM.pdf'.format(lyr))
0308 else :
0309 print("Some Error in get the histograms for FPIX")
0310
0311 print("----> Build maps for FPix")
0312 for rng in range(1,3):
0313 histOccList.append(rootf.FindObjectAny(hoccF+str(rng)))
0314 histDeadList.append(rootp.Get(dirERROR+hdeadF+str(rng)))
0315 for hist1, hist2 in zip(histOccList, histDeadList):
0316 if hist1 != None or hist2 !=None:
0317 hist1.Draw("colz")
0318 match=re.search('(?<=PXRing_)[0-9]',hist1.GetName())
0319 if match != None and "per_SignedDiskCoord_per_SignedBladePanelCoord" in hist1.GetName():
0320 ring=int(match.group(0))
0321 hist1.SetTitle("Digi Occupancy Ring {0}".format(ring))
0322 boxList=[]
0323 lineList=[]
0324 renderPluginFPIX(lineList,ring)
0325 lineWd=3
0326 if ring==2 :
0327 lineWd=2
0328 tbmRoc=8
0329 binTBM=[]
0330 maxx=hist2.GetMaximum()
0331 for biny in range(1,hist2.GetNbinsY()+1):
0332 if len(binTBM)!=0:
0333 x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
0334 x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
0335 y1=hist2.GetYaxis().GetBinLowEdge(biny-1)
0336 y2=hist2.GetYaxis().GetBinUpEdge(biny-1)
0337 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)
0338 binTBM=[]
0339 for binx in range(1,hist2.GetNbinsX()+1):
0340 if len(binTBM)==0:
0341 check=True
0342 elif hist2.GetBinContent(binx,biny)==hist2.GetBinContent(binTBM[len(binTBM)-1],biny):
0343 check=True
0344 else:
0345 check=False
0346 if hist2.GetBinContent(binx,biny)!=0 and check:
0347 if len(binTBM)==0:
0348 binTBM.append(binx)
0349 else:
0350 if len(binTBM)==tbmRoc:
0351 x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
0352 x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
0353 y1=hist2.GetYaxis().GetBinLowEdge(biny)
0354 y2=hist2.GetYaxis().GetBinUpEdge(biny)
0355 draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
0356 binTBM=[]
0357 binTBM.append(binx)
0358 else:
0359 binTBM.append(binx)
0360 else:
0361 if len(binTBM)!=0:
0362 x1=hist2.GetXaxis().GetBinLowEdge(binTBM[0])
0363 x2=hist2.GetXaxis().GetBinUpEdge(binTBM[len(binTBM)-1])
0364 y1=hist2.GetYaxis().GetBinLowEdge(biny)
0365 y2=hist2.GetYaxis().GetBinUpEdge(biny)
0366 draw_box(boxList,x1,x2,y1,y2,0.2,color[100+int((224-100)*(1-hist2.GetBinContent(binTBM[0],biny)/maxx))],0,1,lineWd)
0367 binTBM=[]
0368 if hist2.GetBinContent(binx,biny)!=0:
0369 binTBM.append(binx)
0370 c.SaveAs('MergedPCLOther_FPix_Ring{0}_TBM.pdf'.format(ring))
0371 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))
0372 os.system('rm -f MergedPCLOther_FPix_Ring{0}_TBM.pdf'.format(ring))
0373
0374 else :
0375 print("Some Error in get the histograms for FPIX")
0376
0377
0378
0379
0380 if __name__ == '__main__':
0381 main()