ATLAS Offline Software
pix_defect.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2 from __future__ import print_function
3 
4 from ROOT import gROOT, TFile
5 import collections
6 defect_val = collections.namedtuple('defect_val',
7  'defect, comment, recoverable')
8 defect_iov = collections.namedtuple('defect_iov',
9  'defect, comment, recoverable, since, until')
10 
11 
12 
13 def find_standby(nlayer, hhits, lb_max, standby_lb):
14  threshold_hit = 10
15  for i in range(0, nlayer):
16  start = 0
17  start_lb = 0
18  end_lb = 0
19 
20  nbin = hhits[i].GetNbinsX()
21 
22  start_lb = 0
23  for j in range(1, nbin-1):
24  val = hhits[i].GetBinContent(j+1)
25  if val >= threshold_hit:
26  end_lb = j
27  if start_lb == 0:
28  start_lb = j
29 
30  for j in range(1, nbin-1):
31  #val_global = hglobal.GetBinContent(j+1)
32  val = hhits[i].GetBinContent(j+1)
33  if val < threshold_hit:
34  if start == 0:
35  start = 1
36  start_lb = j
37  elif start == 1:
38  if j > start_lb and j < end_lb:
39  standby_lb.append([i, start_lb, j-1])
40  start = 0
41  start_lb = 0
42  if start == 1:
43  if lb_max > start_lb:
44  standby_lb.append([i, start_lb, lb_max])
45 
46 
47 def find_notready(nlayer, hist, pct_low, pct_high, notready_lb, lb_max=2000):
48 
49  for i in range(0, nlayer):
50  start = 0
51  start_lb = 0
52 
53  nbin = hist[i].GetNbinsX()
54  if i == 2:
55  for j in range(1, nbin-1):
56  val = hist[2].GetBinContent(
57  j+1)*38/90 + hist[3].GetBinContent(j+1)*52/90
58  if val >= pct_low and val < pct_high:
59  if start == 0:
60  start = 1
61  start_lb = j
62  elif start == 1:
63  notready_lb.append([i, start_lb, j-1])
64  start = 0
65  start_lb = 0
66  if start == 1:
67  notready_lb.append([i, start_lb, lb_max])
68  elif i == 3:
69  # nothing to do
70  pass
71  else:
72  for j in range(1, nbin-1):
73  val = hist[i].GetBinContent(j+1)
74  if val >= pct_low and val < pct_high:
75  if start == 0:
76  start = 1
77  start_lb = j
78  elif start == 1:
79  notready_lb.append([i, start_lb, j-1])
80  start = 0
81  start_lb = 0
82  if start == 1:
83  notready_lb.append([i, start_lb, lb_max])
84 
85 
86 def find_btagdeg(hist, pct_low, pct_high, btagdeg_lb, lb_max):
87  start = 0
88  start_lb = 0
89 
90  nbin = hist.GetNbinsX()
91  for i in range(1, nbin-1):
92  val = hist.GetBinContent(i+1)
93  if val >= pct_low and val < pct_high:
94  if start == 0:
95  start = 1
96  start_lb = i
97  elif start == 1:
98  btagdeg_lb.append([start_lb, i-1])
99  start = 0
100  start_lb = 0
101  if start == 1:
102  btagdeg_lb.append([start_lb, lb_max])
103 
104 
105 def print_def(defect_name, defect_lb):
106  for i in range(0, len(defect_lb)):
107  print(defect_name, "[", defect_lb[i][0], "]:", defect_lb[i][1], "-", defect_lb[i][2])
108 
109 def print_btagdegdef(defect_name, defect_lb):
110  for i in range(0, len(defect_lb)):
111  print(defect_name, ": ", defect_lb[i][0], "-", defect_lb[i][1])
112 
113 
114 def assign_defect(db, defect_name, run, defect_lb):
115  for i in range(0, len(defect_lb)):
116  layer = defect_lb[i][0]
117  if layer == 0:
118  slayer = "IBL"
119  elif layer == 1:
120  slayer = "LAYER0"
121  elif layer == 2:
122  slayer = "BARREL"
123  elif layer == 3:
124  slayer = "BARREL"
125  elif layer == 4:
126  slayer = "ENDCAPA"
127  elif layer == 5:
128  slayer = "ENDCAPC"
129 
130  sdefect = "PIXEL_" + slayer + "_" + defect_name
131 
132  lbstart = defect_lb[i][1]
133  lbend = defect_lb[i][2]
134 
135  start = (run << 32) + lbstart
136  until = (run << 32) + lbend + 1
137 
138  #print(sdefect, ": LB = ", lbstart,"-",lbend,")")
139  comment = "assign " + sdefect
140  db.append(defect_iov(sdefect, comment, False, start, until))
141 
142 
143 
144 def assign_lowstat(db, run, comment):
145  sdefect = "PIXEL_LOWSTAT"
146  lbstart = 1
147  lbend = 2000
148  start = (run << 32) + lbstart
149  until = (run << 32) + lbend + 1
150  #print(sdefect, ": LB = ", lbstart,"-",lbend,")")
151  db.append(defect_iov(sdefect, comment, False, start, until))
152 
153 
154 def assign_btagdegdef(db, defect_name, run, defect_lb):
155  for i in range(0, len(defect_lb)):
156  sdefect = "PIXEL_" + defect_name
157  lbstart = defect_lb[i][0]
158  lbend = defect_lb[i][1]
159 
160  start = (run << 32) + lbstart
161  until = (run << 32) + lbend + 1
162 
163  comment = "assign " + sdefect
164  db.append(defect_iov(sdefect, comment, False, start, until))
165 
166 
167 
168 def execute(run, sfile, lb_max):
169  db = []
170  gROOT.Reset()
171  file = TFile(sfile)
172 
173  shits = []
174  shits.append("InnerDetector/Pixel/IBL/Hits/AvgOccActivePerLumi_IBL2D")
175  shits.append("InnerDetector/Pixel/BLayer/Hits/AvgOccActivePerLumi_BLayer")
176  shits.append("InnerDetector/Pixel/Layer1/Hits/AvgOccActivePerLumi_Layer1")
177  shits.append("InnerDetector/Pixel/Layer2/Hits/AvgOccActivePerLumi_Layer2")
178  shits.append("InnerDetector/Pixel/ECA/Hits/AvgOccActivePerLumi_ECA")
179  shits.append("InnerDetector/Pixel/ECC/Hits/AvgOccActivePerLumi_ECC")
180 
181  sbtagdeg = "InnerDetector/Pixel/PixelExpert/BTagDegEstimation/TotalDegradationPerLumi"
182 
183  sclus = "Global/Luminosity/AnyTrigger/nClustersAll_vs_LB"
184 
185  nlayer = 6
186  hhits = []
187  fexist_hhits = True
188  for i in range(0, nlayer):
189  if not file.Get(shits[i]):
190  fexist_hhits = False
191  continue
192 
193  hhits.append(file.Get(shits[i]))
194 
195  standby_lb = []
196  if fexist_hhits is True:
197  find_standby(nlayer, hhits, lb_max, standby_lb)
198 
199  #print_def("standby", standby_lb)
200  #user = "atlpixdq"
201  #assign_defect(db, "STANDBY", run, standby_lb)
202 
203  fexist_hbtagdeg = True
204  hbtagdeg = file.Get(sbtagdeg)
205  if not hbtagdeg:
206  fexist_hbtagdeg = False
207  btagdegestim_tolerable_lb = []
208  btagdegestim_intolerable_lb = []
209 
210  if fexist_hhits is True and fexist_hbtagdeg is True:
211  find_btagdeg(hbtagdeg, 0.05, 0.25, btagdegestim_tolerable_lb, lb_max)
212  find_btagdeg(hbtagdeg, 0.25, 1., btagdegestim_intolerable_lb, lb_max)
213 
214  if 0:
215  print_btagdegdef("tolerable", btagdegestim_tolerable_lb)
216  print_btagdegdef("intolerable", btagdegestim_intolerable_lb)
217 
218  if 1:
219  assign_btagdegdef(db, "PERFORMANCE_TOLERABLE", run, btagdegestim_tolerable_lb)
220  assign_btagdegdef(db, "PERFORMANCE_INTOLERABLE", run, btagdegestim_intolerable_lb)
221 
222  fexist_hclus = True
223  hclus = file.Get(sclus)
224  if not hclus:
225  fexist_hclus = False
226  if fexist_hclus is True:
227  nevent = hclus.GetEntries()
228  if nevent < 100000:
229  assign_lowstat(db, run, "assign PIXEL_LOWSTAT")
230 
231  return db
python.pix_defect.assign_lowstat
def assign_lowstat(db, run, comment)
Definition: pix_defect.py:144
python.pix_defect.assign_btagdegdef
def assign_btagdegdef(db, defect_name, run, defect_lb)
Definition: pix_defect.py:154
python.pix_defect.execute
def execute(run, sfile, lb_max)
Definition: pix_defect.py:168
python.pix_defect.find_standby
def find_standby(nlayer, hhits, lb_max, standby_lb)
Definition: pix_defect.py:13
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.pix_defect.print_def
def print_def(defect_name, defect_lb)
Definition: pix_defect.py:105
python.pix_defect.defect_iov
defect_iov
Definition: pix_defect.py:8
python.pix_defect.assign_defect
def assign_defect(db, defect_name, run, defect_lb)
Definition: pix_defect.py:114
python.pix_defect.find_btagdeg
def find_btagdeg(hist, pct_low, pct_high, btagdeg_lb, lb_max)
Definition: pix_defect.py:86
python.pix_defect.find_notready
def find_notready(nlayer, hist, pct_low, pct_high, notready_lb, lb_max=2000)
Definition: pix_defect.py:47
python.pix_defect.print_btagdegdef
def print_btagdegdef(defect_name, defect_lb)
Definition: pix_defect.py:109