Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:33:03

0001 #!/usr/bin/env python3
0002 from __future__ import print_function
0003 from ROOT import TFile, gStyle,gPad ,TObject, TCanvas, TH1, TH1F, TH2F, TLegend, TPaletteAxis, TList, TLine, TAttLine, TF1,TAxis
0004 import re
0005 import sys, string
0006 
0007 def getRunNumber(filename):
0008     global runNumber
0009     pos=filename.find("__")
0010     runNumber=int(filename[pos-6:pos])
0011     #print runNumber
0012 
0013 ###########################################barrel########################################################
0014 def countBadROCBarrel(fin, layerNo, os):
0015     global bpix_tot_deadROC
0016     global bpix_tot_ineffROC
0017     global bpix_tot_Nrocspopulated
0018     global bpix_tot_totalentries
0019 
0020     barrelPath  = commonPath + "PXBarrel/";
0021     histoname = ["digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_1", "digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_2",  
0022                  "digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_3", "digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_4"]
0023     digi2D = fin.Get(barrelPath + histoname[layerNo-1])
0024     #return status flag is histogram is empty!
0025     if digi2D.GetEntries() == 0 :  
0026         return 1;
0027     Nrocspopulated = 0
0028     totalEntries = 0
0029     NexpectedROC = [1536, 3584, 5632, 8192]
0030     nLadders_bpx = [6, 14, 22, 32]
0031     nx = digi2D.GetNbinsX()
0032     ny = digi2D.GetNbinsY()
0033     for xbin in range(1,nx+1):
0034         if xbin >= 33 and xbin <= 40:    continue;#region of cross on x-axis
0035         for ybin in range(1,ny+1):
0036             if (ybin == 2*nLadders_bpx[layerNo-1] + 1) or (ybin == 2*nLadders_bpx[layerNo-1] + 2):    continue;#region of cross on y-axis
0037             bentries = digi2D.GetBinContent(xbin,ybin)
0038             if(bentries > 0):
0039                 Nrocspopulated+=1
0040                 totalEntries += bentries
0041     meanEntries = float(totalEntries)/Nrocspopulated
0042     NineffROC = 0
0043     #Loop to chek inefficient ROC per layer
0044     for xbin in range(1,nx+1):
0045         if xbin >= 33 and xbin <= 40:
0046             continue;#region of cross on x-axis
0047         for ybin in range(1,ny+1):
0048             if (ybin == 2*nLadders_bpx[layerNo-1] + 1) or (ybin == 2*nLadders_bpx[layerNo-1] + 2):    continue;#region of cross on y-axis
0049             bentries = digi2D.GetBinContent(xbin,ybin);
0050             if(bentries > 0 and bentries < meanEntries/4. ):#Assume < 25% of MEAN = inefficient
0051                 NineffROC+=1;
0052     ##Printing Layer no., #dead ROC, #inefficienct ROC, #mean occupancy of Non-zer roc
0053     tmpstr = "BPix L" + str(layerNo)
0054     print(tmpstr, '{0:4d} {1:4d} {2:4.1f}'.format(NexpectedROC[layerNo-1] - Nrocspopulated, NineffROC, round(meanEntries,1)), file=os)
0055     bpix_tot_deadROC += NexpectedROC[layerNo-1] - Nrocspopulated
0056     bpix_tot_ineffROC += NineffROC
0057     bpix_tot_Nrocspopulated += Nrocspopulated
0058     bpix_tot_totalentries += float(totalEntries)
0059     return 0;
0060 #############################################endacp#########################################
0061 def countBadROCForward(fin, ringNo, os):
0062     global fpix_tot_deadROC
0063     global fpix_tot_ineffROC
0064     global fpix_tot_Nrocspopulated
0065     global fpix_tot_totalentries
0066 
0067     forwardPath  = commonPath + "PXForward/";
0068     histoname = ["digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_1",
0069 "digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_2"]
0070     digi2D = fin.Get(forwardPath + histoname[ringNo-1])
0071     #return status flag is histogram is empty!
0072     if digi2D.GetEntries() == 0 :  
0073         return 1;
0074     nblades_perRing_fpx = [22, 34]
0075     NexpectedROC_perRing = [704, 1088]
0076     Nrocspopulated = [0] * 6
0077     totalEntries = [0] * 6
0078     dcounter = 0
0079     nx = digi2D.GetNbinsX()
0080     ny = digi2D.GetNbinsY()
0081     for xbin in range(1,nx+1):
0082         if xbin >= 25 and xbin <= 32:    continue;#region of cross on x-axis
0083         if xbin > 1 and  (xbin-1)%8 == 0:    dcounter += 1; 
0084         for ybin in range(1,ny+1):
0085             if (ybin >= 2*nblades_perRing_fpx[ringNo-1] + 1) and (ybin <= 2*nblades_perRing_fpx[ringNo-1] + 4):
0086                 continue;#region of cross on y-axis
0087             bentries = digi2D.GetBinContent(xbin,ybin)
0088             if(bentries > 0):
0089                 Nrocspopulated[dcounter] += 1
0090                 totalEntries[dcounter] += bentries
0091     #Loop to find inefficient modules
0092     meanEntries = [6] * 6
0093     for d in range(0,6):
0094         meanEntries[d] = float(totalEntries[d])/Nrocspopulated[d]
0095         NineffROC = [6] * 6
0096     #set disc counter to 0 since it is now 5
0097     dcounter = 0;
0098     for xbin in range(1,nx+1):
0099         if xbin >= 25 and xbin <= 32:    continue;#region of cross on x-axis
0100         if xbin > 1 and  (xbin-1)%8 == 0:    dcounter += 1 
0101         for ybin in range(1,ny+1):
0102             if (ybin >= 2*nblades_perRing_fpx[ringNo-1] + 1) and (ybin <= 2*nblades_perRing_fpx[ringNo-1] + 4):
0103                 continue;#region of cross on y-axis
0104             bentries = digi2D.GetBinContent(xbin,ybin)
0105             if(bentries > 0):#//Assume < 25% of MEAN = inefficient 
0106                 if bentries > 0 and bentries < meanEntries[dcounter]/4.: 
0107                     NineffROC[dcounter] += 1
0108 
0109     print("#Summary for FPix Ring", ringNo, file=os)
0110     for d in range(0,6):
0111         disc = 0
0112         if d < 3:    disc = "M" + str(3 - d)
0113         else:    disc = "P" + str(d - 2)
0114         ##Printing Disc no., #dead ROC, #inefficienct ROC, #mean occupancy of Non-zer roc
0115         tmpstr = "FPix R" + str(ringNo) + "D" + str(disc)
0116         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)
0117         fpix_tot_deadROC += NexpectedROC_perRing[ringNo-1] - Nrocspopulated[d]
0118         fpix_tot_ineffROC += NineffROC[d]
0119         fpix_tot_Nrocspopulated += Nrocspopulated[d]
0120         fpix_tot_totalentries += float(totalEntries[d])
0121 
0122     return 0;
0123 ################################################main#######################################
0124 fname=sys.argv[1]
0125 getRunNumber(fname)
0126 fin= TFile(fname)
0127 outname="PixZeroOccROCs_run" + str(runNumber) + ".txt"
0128 bpix_tot_deadROC = 0
0129 bpix_tot_ineffROC = 0
0130 bpix_tot_Nrocspopulated = 0
0131 bpix_tot_totalentries = 0
0132 
0133 fpix_tot_deadROC = 0
0134 fpix_tot_ineffROC = 0
0135 fpix_tot_Nrocspopulated = 0
0136 fpix_tot_totalentries = 0
0137 
0138 global commonPath
0139 commonPath  = "DQMData/Run " + str(runNumber) + "/PixelPhase1/Run summary/Phase1_MechanicalView/"
0140 #histogram of no. of pixel clusters
0141 hnpixclus_bpix = fin.Get(commonPath + "charge_PXBarrel")
0142 hnpixclus_fpix = fin.Get(commonPath + "charge_PXForward")
0143 
0144 out_file = open(outname, "w")
0145 print("#Layer/Disc KEY NDeadROC NineffROC MeanOccupacy", file=out_file)
0146 print("#Pixel Barrel Summary", file=out_file)
0147 for l in range(1,5):
0148     if countBadROCBarrel(fin, l, out_file) == 1:
0149         print("DQM histogram for Layer", str(l), " is empty!", file=out_file)
0150 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)
0151 print("#Pixel Forward Summary", file=out_file)
0152 for ring in range(1,3):
0153     if countBadROCForward(fin, ring, out_file) == 1:
0154         print("DQM histogram for Ring", str(ring), " is empty!", file=out_file)
0155 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)
0156 print("Number of clusters=", int(hnpixclus_bpix.GetEntries() + hnpixclus_fpix.GetEntries()), file=out_file)
0157 out_file.close()