CMS 3D CMS Logo

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