Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:10

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