CMS 3D CMS Logo

DeadROCCounter_Phase1.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 from ROOT import TFile, gStyle,gPad ,TObject, TCanvas, TH1, TH1F, TH2F, TLegend, TPaletteAxis, TList, TLine, TAttLine, TF1,TAxis
3 import re
4 import sys, string
5 
6 def getRunNumber(filename):
7  global runNumber
8  pos=filename.find("__")
9  runNumber=int(filename[pos-6:pos])
10  #print runNumber
11 
12 ###########################################barrel########################################################
13 def countBadROCBarrel(fin, layerNo, os):
14  global bpix_tot_deadROC
15  global bpix_tot_ineffROC
16  global bpix_tot_Nrocspopulated
17  global bpix_tot_totalentries
18 
19  barrelPath = commonPath + "PXBarrel/";
20  histoname = ["digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_1", "digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_2",
21  "digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_3", "digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_4"]
22  digi2D = fin.Get(barrelPath + histoname[layerNo-1])
23  #return status flag is histogram is empty!
24  if digi2D.GetEntries() == 0 :
25  return 1;
26  Nrocspopulated = 0
27  totalEntries = 0
28  NexpectedROC = [1536, 3584, 5632, 8192]
29  nLadders_bpx = [6, 14, 22, 32]
30  nx = digi2D.GetNbinsX()
31  ny = digi2D.GetNbinsY()
32  for xbin in range(1,nx+1):
33  if xbin >= 33 and xbin <= 40: continue;#region of cross on x-axis
34  for ybin in range(1,ny+1):
35  if (ybin == 2*nLadders_bpx[layerNo-1] + 1) or (ybin == 2*nLadders_bpx[layerNo-1] + 2): continue;#region of cross on y-axis
36  bentries = digi2D.GetBinContent(xbin,ybin)
37  if(bentries > 0):
38  Nrocspopulated+=1
39  totalEntries += bentries
40  meanEntries = float(totalEntries)/Nrocspopulated
41  NineffROC = 0
42  #Loop to chek inefficient ROC per layer
43  for xbin in range(1,nx+1):
44  if xbin >= 33 and xbin <= 40:
45  continue;#region of cross on x-axis
46  for ybin in range(1,ny+1):
47  if (ybin == 2*nLadders_bpx[layerNo-1] + 1) or (ybin == 2*nLadders_bpx[layerNo-1] + 2): continue;#region of cross on y-axis
48  bentries = digi2D.GetBinContent(xbin,ybin);
49  if(bentries > 0 and bentries < meanEntries/4. ):#Assume < 25% of MEAN = inefficient
50  NineffROC+=1;
51  ##Printing Layer no., #dead ROC, #inefficienct ROC, #mean occupancy of Non-zer roc
52  tmpstr = "BPix L" + str(layerNo)
53  print >> os, tmpstr, '{0:4d} {1:4d} {2:4.1f}'.format(NexpectedROC[layerNo-1] - Nrocspopulated, NineffROC, round(meanEntries,1))
54  bpix_tot_deadROC += NexpectedROC[layerNo-1] - Nrocspopulated
55  bpix_tot_ineffROC += NineffROC
56  bpix_tot_Nrocspopulated += Nrocspopulated
57  bpix_tot_totalentries += float(totalEntries)
58  return 0;
59 #############################################endacp#########################################
60 def countBadROCForward(fin, ringNo, os):
61  global fpix_tot_deadROC
62  global fpix_tot_ineffROC
63  global fpix_tot_Nrocspopulated
64  global fpix_tot_totalentries
65 
66  forwardPath = commonPath + "PXForward/";
67  histoname = ["digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_1",
68 "digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_2"]
69  digi2D = fin.Get(forwardPath + histoname[ringNo-1])
70  #return status flag is histogram is empty!
71  if digi2D.GetEntries() == 0 :
72  return 1;
73  nblades_perRing_fpx = [22, 34]
74  NexpectedROC_perRing = [704, 1088]
75  Nrocspopulated = [0] * 6
76  totalEntries = [0] * 6
77  dcounter = 0
78  nx = digi2D.GetNbinsX()
79  ny = digi2D.GetNbinsY()
80  for xbin in range(1,nx+1):
81  if xbin >= 25 and xbin <= 32: continue;#region of cross on x-axis
82  if xbin > 1 and (xbin-1)%8 == 0: dcounter += 1;
83  for ybin in range(1,ny+1):
84  if (ybin >= 2*nblades_perRing_fpx[ringNo-1] + 1) and (ybin <= 2*nblades_perRing_fpx[ringNo-1] + 4):
85  continue;#region of cross on y-axis
86  bentries = digi2D.GetBinContent(xbin,ybin)
87  if(bentries > 0):
88  Nrocspopulated[dcounter] += 1
89  totalEntries[dcounter] += bentries
90  #Loop to find inefficient modules
91  meanEntries = [6] * 6
92  for d in range(0,6):
93  meanEntries[d] = float(totalEntries[d])/Nrocspopulated[d]
94  NineffROC = [6] * 6
95  #set disc counter to 0 since it is now 5
96  dcounter = 0;
97  for xbin in range(1,nx+1):
98  if xbin >= 25 and xbin <= 32: continue;#region of cross on x-axis
99  if xbin > 1 and (xbin-1)%8 == 0: dcounter += 1
100  for ybin in range(1,ny+1):
101  if (ybin >= 2*nblades_perRing_fpx[ringNo-1] + 1) and (ybin <= 2*nblades_perRing_fpx[ringNo-1] + 4):
102  continue;#region of cross on y-axis
103  bentries = digi2D.GetBinContent(xbin,ybin)
104  if(bentries > 0):#//Assume < 25% of MEAN = inefficient
105  if bentries > 0 and bentries < meanEntries[dcounter]/4.:
106  NineffROC[dcounter] += 1
107 
108  print >> os, "#Summary for FPix Ring", ringNo
109  for d in range(0,6):
110  disc = 0
111  if d < 3: disc = "M" + str(3 - d)
112  else: disc = "P" + str(d - 2)
113  ##Printing Disc no., #dead ROC, #inefficienct ROC, #mean occupancy of Non-zer roc
114  tmpstr = "FPix R" + str(ringNo) + "D" + str(disc)
115  print >> os, '{0:10s} {1:4d} {2:4d} {3:4.1f}'.format(tmpstr, NexpectedROC_perRing[ringNo-1] - Nrocspopulated[d], NineffROC[d], round(meanEntries[d],1))
116  fpix_tot_deadROC += NexpectedROC_perRing[ringNo-1] - Nrocspopulated[d]
117  fpix_tot_ineffROC += NineffROC[d]
118  fpix_tot_Nrocspopulated += Nrocspopulated[d]
119  fpix_tot_totalentries += float(totalEntries[d])
120 
121  return 0;
122 ################################################main#######################################
123 fname=sys.argv[1]
124 getRunNumber(fname)
125 fin= TFile(fname)
126 outname="PixZeroOccROCs_run" + str(runNumber) + ".txt"
127 bpix_tot_deadROC = 0
128 bpix_tot_ineffROC = 0
129 bpix_tot_Nrocspopulated = 0
130 bpix_tot_totalentries = 0
131 
132 fpix_tot_deadROC = 0
133 fpix_tot_ineffROC = 0
134 fpix_tot_Nrocspopulated = 0
135 fpix_tot_totalentries = 0
136 
137 global commonPath
138 commonPath = "DQMData/Run " + str(runNumber) + "/PixelPhase1/Run summary/Phase1_MechanicalView/"
139 #histogram of no. of pixel clusters
140 hnpixclus_bpix = fin.Get(commonPath + "charge_PXBarrel")
141 hnpixclus_fpix = fin.Get(commonPath + "charge_PXForward")
142 
143 out_file = open(outname, "w")
144 print >> out_file, "#Layer/Disc KEY NDeadROC NineffROC MeanOccupacy"
145 print >> out_file, "#Pixel Barrel Summary"
146 for l in range(1,5):
147  if countBadROCBarrel(fin, l, out_file) == 1:
148  print >> out_file, "DQM histogram for Layer", str(l), " is empty!"
149 print >> out_file, "BPix tot", '{0:4d} {1:4d} {2:4.1f}'.format(bpix_tot_deadROC, bpix_tot_ineffROC, round(float(bpix_tot_totalentries)/bpix_tot_Nrocspopulated,1))
150 print >> out_file, "#Pixel Forward Summary"
151 for ring in range(1,3):
152  if countBadROCForward(fin, ring, out_file) == 1:
153  print >> out_file, "DQM histogram for Ring", str(ring), " is empty!"
154 print >> out_file, "FPix tot", '{0:4d} {1:4d} {2:4.1f}'.format(fpix_tot_deadROC, fpix_tot_ineffROC, round(float(fpix_tot_totalentries)/fpix_tot_Nrocspopulated,1))
155 print >> out_file, "Number of clusters=", int(hnpixclus_bpix.GetEntries() + hnpixclus_fpix.GetEntries())
156 out_file.close()
def countBadROCForward(fin, ringNo, os)
endacp#########################################
def countBadROCBarrel(fin, layerNo, os)
barrel########################################################
if(dp >Float(M_PI)) dp-