CMS 3D CMS Logo

DeadROC_duringRun.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 from __future__ import print_function
4 import sys
5 import string
6 from ROOT import *
7 from array import array
8 
9 def getFileInPath(rfile):
10  import os
11  for dir in os.environ['CMSSW_SEARCH_PATH'].split(":"):
12  if os.path.exists(os.path.join(dir,rfile)): return os.path.join(dir,rfile)
13  return None
14 
15 
16 detIDsFileName = getFileInPath('DQM/SiStripMonitorClient/data/detids.dat')
17 
18 filename_online=sys.argv[1]
19 filename_offline=sys.argv[2]
20 
21 runNum=filename_offline[19:25]
22 
23 dir="DQMData/Run " + runNum + "/PixelPhase1/Run summary/Pahse1_MechanicalView/"
24 
25 
26 dirBPix=dir + "PXBarrel/"
27 dirFPix=dir + "PXForward/"
28 
29 hnameB="digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_"
30 
31 minlad=[-6,-14,-22,-32]
32 
33 shell=""
34 
35 #Barrel
36 def BPIX_list(inputFile):
37  DQMfile=TFile(inputFile)
38  BPIXCounter = []
39  BPIXCounter_v0 = []
40  for l in range(1,5):
41  hname=hnameB + str(l)
42 
43  RocMap=DQMfile.FindObjectAny(hname)
44 
45  for j in range(1,RocMap.GetNbinsY()+1):
46 
47  lad=minlad[l-1] + int(j-1)/2
48  alad=abs(lad)
49 
50  for i in range(1,RocMap.GetNbinsX()+1):
51 
52  roc=0
53 
54  bin=RocMap.GetBin(i,j)
55  digi=RocMap.GetBinContent(bin)
56 
57  if (digi!=0): continue
58 
59  mod=-4 + int((i-1)/8)
60 
61  if (lad==0 or mod==0): continue
62 
63  if (lad < 0 and mod < 0) :
64 
65  shell="BmO"
66 
67  if (alad%2==1):
68  if (j%2==1): roc=(i-1)%8
69  if (j%2==0): roc= 15-(i-1)%8
70 
71  elif (alad%2==0):
72  if (j%2 ==0): roc=(i-1)%8
73  if (j%2 ==1): roc= 15-(i-1)%8
74 
75  if (lad > 0 and mod < 0):
76 
77  shell= "BmI";
78 
79  if (lad%2==1):
80  if (j%2 ==0): roc=(i-1)%8
81  if (j%2 ==1): roc= 15-(i-1)%8
82 
83  if (lad%2==0):
84  if (j%2 ==1): roc=(i-1)%8
85  if (j%2 ==0): roc= 15-(i-1)%8
86 
87  if (lad > 0 and mod > 0):
88 
89  shell= "BpI"
90 
91  if (lad%2==1):
92  if (j%2 ==1): roc=7-(i-1)%8
93  if (j%2 ==0): roc=8+(i-1)%8
94 
95  if (lad%2==0):
96  if (j%2 ==0): roc=7-(i-1)%8
97  if (j%2 ==1): roc=8+(i-1)%8
98 
99  if (lad < 0 and mod > 0):
100  shell= "BpO"
101 
102  if (alad%2==1):
103  if (j%2 ==0): roc=7-(i-1)%8
104  if (j%2 ==1): roc=8+(i-1)%8
105 
106  if (alad%2==0):
107  if (j%2 ==1): roc=7-(i-1)%8
108  if (j%2 ==0): roc=8+(i-1)%8
109 
110  f1=open(getFileInPath('DQM/SiStripMonitorClient/data/detids.dat'))
111  modwritten=False
112  Mod_check = "LYR"+str(l) + "_LDR" + str(abs(lad)) + "F_MOD" +str(abs(mod))
113  shell_check = "BPix_" + str(shell)
114 
115  for line in f1:
116  refName=line.split(" ")[1]
117  if modwritten: break
118  shell_ref = str(refName[:8]).strip()
119  module_ref = str(refName[14:]).strip()
120 
121  if (Mod_check == module_ref) and (shell_check == shell_ref):
122 
123  ModuleName_BPIX = refName.strip()+"_ROC "
124  BmLYR1_check = ModuleName_BPIX.split('_')
125  if ((BmLYR1_check[1] == "BmI" or BmLYR1_check[1] == "BmO") and (BmLYR1_check[3] == "LYR1")):
126  if int(roc) <= 7:
127  roc = str(int(roc)+8)
128  elif int(roc) >= 8:
129  roc =str(int(roc)-8)
130 
131  BPix_Name = ModuleName_BPIX + str(roc)
132  BPIXCounter_v0.append(BPix_Name)
133  BPIXCounter = list(set(BPIXCounter_v0))
134  modwritten=True
135  return BPIXCounter
136 
137 #End of Barrel
138 
139 #Doing FPix
140 
141 hnameF="digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_"
142 minbld=[-11,-17]
143 
144 def FPIX_list(inputFile):
145  FPIXCounter = []
146  DQMfile=TFile(inputFile)
147  for r in range (1,3):
148 
149  hname=hnameF + str(r)
150  RocMap=DQMfile.FindObjectAny(hname)
151 
152  for j in range(1,RocMap.GetNbinsY()+1):
153 
154  bld=minbld[r-1] + int(j-1)/4
155  abld=abs(bld)
156 
157  for i in range(1,RocMap.GetNbinsX()+1):
158 
159  roc=0
160 
161  bin=RocMap.GetBin(i,j)
162  digi=RocMap.GetBinContent(bin)
163 
164  if (digi!=0): continue
165 
166  disk=-3 + int(i-1)/8
167 
168  if (bld==0 or disk==0): continue
169 
170  pnl=0
171 
172  if ((j-1)%4==0 or (j-1)%4==1): pnl=2
173  if ((j-1)%4==2 or (j-1)%4==3): pnl=1
174 
175  if (disk < 0 and bld <0):
176 
177  shell= "BmO"
178 
179  if ((j-1)%4==0 or (j-1)%4==3): roc= 15-(i-1)%8
180  if ((j-1)%4==1 or (j-1)%4==2): roc= (i-1)%8
181 
182  if (disk < 0 and bld >0):
183 
184  shell= "BmI";
185 
186  if ((j-1)%4==0 or (j-1)%4==3): roc= 15-(i-1)%8
187  if ((j-1)%4==1 or (j-1)%4==2): roc= (i-1)%8
188 
189  if (disk > 0 and bld >0):
190 
191  shell= "BpI"
192 
193  if ((j-1)%4==0 or (j-1)%4==3): roc=7-(i-1)%8
194  if ((j-1)%4==1 or (j-1)%4==2): roc=8+(i-1)%8
195 
196  if (disk > 0 and bld <0):
197 
198  shell= "BpO"
199 
200  if ((j-1)%4==0 or (j-1)%4==3): roc=7-(i-1)%8;
201  if ((j-1)%4==1 or (j-1)%4==2): roc=8+(i-1)%8;
202 
203 
204  FPix_Name = "FPix_" + str(shell) + "_D" + str(abs(disk)) + '_BLD'+ str(abs(bld)) + '_PNL' + str(abs(pnl)) + '_RNG'+ str(abs(r)) + "_ROC " + str(roc) +""
205  FPIXCounter.append(FPix_Name)
206  return FPIXCounter
207 
208 
209 deadROCList_online = list(set(BPIX_list(filename_online))) + list(set(FPIX_list(filename_online)))
210 deadROCList_offline = list(set(BPIX_list(filename_offline))) + list(set(FPIX_list(filename_offline)))
211 
212 MaskedROC_DuringRun = list(set(deadROCList_online) - set(deadROCList_offline))
213 print('Number of New Dead ROC: '+ str(len(MaskedROC_DuringRun)))
214 
215 outFileName = 'DeadROC_Diff.txt'
216 outFileName_online = 'DeadROC_online.txt'
217 outFileName_offline = 'DeadROC_offline.txt'
218 f = open(outFileName,"w")
219 f1 = open(outFileName_online,"w")
220 f2 = open(outFileName_offline,"w")
221 
222 for i in range(len(MaskedROC_DuringRun)):
223 
224  f.write(MaskedROC_DuringRun[i]+"\n")
225 f.close()
226 
227 for i in range(len(deadROCList_online)):
228 
229  f1.write(deadROCList_online[i]+"\n")
230 f1.close()
231 
232 for i in range(len(deadROCList_offline)):
233 
234  f2.write(deadROCList_offline[i]+"\n")
235 f2.close()
236 
237 
def BPIX_list(inputFile)
def FPIX_list(inputFile)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def getFileInPath(rfile)
#define str(s)