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  barrelPath = commonPath + "PXBarrel/";
15  histoname = ["digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_1", "digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_2",
16  "digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_3", "digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_4"]
17  digi2D = fin.Get(barrelPath + histoname[layerNo-1])
18  #return status flag is histogram is empty!
19  if digi2D.GetEntries() == 0 :
20  return 1;
21  Nrocspopulated = 0
22  totalEntries = 0
23  NexpectedROC = [1536, 3584, 5632, 8192]
24  nLadders_bpx = [6, 14, 22, 32]
25  nx = digi2D.GetNbinsX()
26  ny = digi2D.GetNbinsY()
27  for xbin in range(1,nx+1):
28  if xbin >= 33 and xbin <= 40: continue;#region of cross on x-axis
29  for ybin in range(1,ny+1):
30  if (ybin == 2*nLadders_bpx[layerNo-1] + 1) or (ybin == 2*nLadders_bpx[layerNo-1] + 2): continue;#region of cross on y-axis
31  bentries = digi2D.GetBinContent(xbin,ybin)
32  if(bentries > 0):
33  Nrocspopulated+=1
34  totalEntries += bentries
35  meanEntries = float(totalEntries)/Nrocspopulated
36  NineffROC = 0
37  #Loop to chek inefficient ROC per layer
38  for xbin in range(1,nx+1):
39  if xbin >= 33 and xbin <= 40:
40  continue;#region of cross on x-axis
41  for ybin in range(1,ny+1):
42  if (ybin == 2*nLadders_bpx[layerNo-1] + 1) or (ybin == 2*nLadders_bpx[layerNo-1] + 2): continue;#region of cross on y-axis
43  bentries = digi2D.GetBinContent(xbin,ybin);
44  if(bentries > 0 and bentries < meanEntries/4. ):#Assume < 25% of MEAN = inefficient
45  NineffROC+=1;
46  ##Printing Layer no., #dead ROC, #inefficienct ROC, #mean occupancy of Non-zer roc
47  tmpstr = "BPix L" + str(layerNo)
48  print >> os, tmpstr, '{0:4d} {1:4d} {2:4.1f}'.format(NexpectedROC[layerNo-1] - Nrocspopulated, NineffROC, round(meanEntries,1))
49  return 0;
50 #############################################endacp#########################################
51 def countBadROCForward(fin, ringNo, os):
52  forwardPath = commonPath + "PXForward/";
53  histoname = ["digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_1",
54 "digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_2"]
55  digi2D = fin.Get(forwardPath + histoname[ringNo-1])
56  #return status flag is histogram is empty!
57  if digi2D.GetEntries() == 0 :
58  return 1;
59  nblades_perRing_fpx = [22, 34]
60  NexpectedROC_perRing = [704, 1088]
61  Nrocspopulated = [0] * 6
62  totalEntries = [0] * 6
63  dcounter = 0
64  nx = digi2D.GetNbinsX()
65  ny = digi2D.GetNbinsY()
66  for xbin in range(1,nx+1):
67  if xbin >= 25 and xbin <= 32: continue;#region of cross on x-axis
68  if xbin > 1 and (xbin-1)%8 == 0: dcounter += 1;
69  for ybin in range(1,ny+1):
70  if (ybin >= 2*nblades_perRing_fpx[ringNo-1] + 1) and (ybin <= 2*nblades_perRing_fpx[ringNo-1] + 4):
71  continue;#region of cross on y-axis
72  bentries = digi2D.GetBinContent(xbin,ybin)
73  if(bentries > 0):
74  Nrocspopulated[dcounter] += 1
75  totalEntries[dcounter] += bentries
76  #Loop to find inefficient modules
77  meanEntries = [6] * 6
78  for d in range(0,6):
79  meanEntries[d] = float(totalEntries[d])/Nrocspopulated[d]
80  NineffROC = [6] * 6
81  #set disc counter to 0 since it is now 5
82  dcounter = 0;
83  for xbin in range(1,nx+1):
84  if xbin >= 25 and xbin <= 32: continue;#region of cross on x-axis
85  if xbin > 1 and (xbin-1)%8 == 0: dcounter += 1
86  for ybin in range(1,ny+1):
87  if (ybin >= 2*nblades_perRing_fpx[ringNo-1] + 1) and (ybin <= 2*nblades_perRing_fpx[ringNo-1] + 4):
88  continue;#region of cross on y-axis
89  bentries = digi2D.GetBinContent(xbin,ybin)
90  if(bentries > 0):#//Assume < 25% of MEAN = inefficient
91  if bentries > 0 and bentries < meanEntries[dcounter]/4.:
92  NineffROC[dcounter] += 1
93 
94  print >> os, "#Summary for FPix Ring", ringNo
95  for d in range(0,6):
96  disc = 0
97  if d < 3: disc = "M" + str(3 - d)
98  else: disc = "P" + str(d - 2)
99  ##Printing Disc no., #dead ROC, #inefficienct ROC, #mean occupancy of Non-zer roc
100  tmpstr = "FPix R" + str(ringNo) + "D" + str(disc)
101  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))
102  return 0;
103 ################################################main#######################################
104 fname=sys.argv[1]
105 getRunNumber(fname)
106 fin= TFile(fname)
107 outname="PixZeroOccROCs_run" + str(runNumber) + ".txt"
108 global commonPath
109 commonPath = "DQMData/Run " + str(runNumber) + "/PixelPhase1/Run summary/Phase1_MechanicalView/"
110 #histogram of no. of pixel clusters
111 hnpixclus_bpix = fin.Get(commonPath + "charge_PXBarrel")
112 hnpixclus_fpix = fin.Get(commonPath + "charge_PXForward")
113 
114 out_file = open(outname, "w")
115 print >> out_file, "#Layer/Disc KEY NDeadROC NineffROC MeanOccupacy"
116 print >> out_file, "#Pixel Barrel Summary"
117 for l in range(1,5):
118  if countBadROCBarrel(fin, l, out_file) == 1:
119  print >> out_file, "DQM histogram for Layer", str(l), " is empty!"
120 print >> out_file, "#Pixel Forward Summary"
121 for ring in range(1,3):
122  if countBadROCForward(fin, ring, out_file) == 1:
123  print >> out_file, "DQM histogram for Ring", str(ring), " is empty!"
124 
125 print >> out_file, "Number of clusters=", int(hnpixclus_bpix.GetEntries() + hnpixclus_fpix.GetEntries())
126 out_file.close()
def countBadROCForward(fin, ringNo, os)
endacp#########################################
def countBadROCBarrel(fin, layerNo, os)
barrel########################################################
if(dp >Float(M_PI)) dp-