CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Member Functions
InefficientDoubleROC.InefficientDeadROCs Class Reference

Public Member Functions

def __init__ (self, inputDQMName, outputFileName, noiseOutputFileName, dirs)
 
def ReadHistograms (self)
 

Public Attributes

 barrelInefficientDColTh
 
 barrelNoisyColumnTh
 
 barrelNoisyColumnTh2
 
 detDict
 
More...
 
 dicOfModuleHistograms
 
 dirs
 
 endcapInefficientDColTh
 
 endcapNoisyColumnTh
 
 inputFile
 
 inputFileName
 
 lookForStr
 
 noiseOutputFileName
 
 outputFileName
 
 pixelNoisynessTh
 THRESHOLDS SECTION. More...
 
 rocMaxCol
 
 rocMaxRow
 
 rocOccupancyTh
 
 rocsInCol
 
 rocsInRow
 

Private Member Functions

def __convertCoordinatesFromHistToROCSpace (self, histName, histXpos, histRow)
 
def __customMedianFilter (self, array, radius=2)
 
def __determineBarrelDColInefficiencyAndNoise (self, medFiltRes, histName, pixelArr, pixelArrWithoutDrops, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)
 
def __determineBarrelNoise (self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, val, pos, rocCol, rocRow)
 
def __determineBarrelNoise2 (self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, normVal, pos, rocCol, rocRow)
 
def __determineEndcapDColInefficiencyAndNoise (self, medFiltRes, histName, pixelArr, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)
 
def __determineEndcapNoise (self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal, val, pos, rocCol, rocRow)
 
def __getPixelArrWithRemovedDrops (self, pixelArr, medFiltRes)
 
def __getROCData (self, hist, startPixel, endPixel, row, repeatFilter=3, filterKernelSize=5)
 
def __lmsExp (self, data, xMin, xMax)
 
def __lmsLin (self, data, xMin, xMax)
 
def __normalizeArray (self, pixelArr)
 
def __setNormalizedArrayZeroInThePoint (self, pixelArr, pt)
 
def __TraverseDirTree (self, dir)
 

Detailed Description

Definition at line 11 of file InefficientDoubleROC.py.

Constructor & Destructor Documentation

def InefficientDoubleROC.InefficientDeadROCs.__init__ (   self,
  inputDQMName,
  outputFileName,
  noiseOutputFileName,
  dirs 
)

Definition at line 44 of file InefficientDoubleROC.py.

44  def __init__(self, inputDQMName, outputFileName, noiseOutputFileName, dirs):
45 
46  self.inputFileName = inputDQMName
47  self.outputFileName = outputFileName
48  self.noiseOutputFileName = noiseOutputFileName
49  self.dirs = dirs
50 
51  self.lookForStr = "digi_occupancy_per_col_per_row_"
52 
53  self.rocMaxCol = 52
54  self.rocMaxRow = 80
55  self.rocsInRow = 8
56  self.rocsInCol = 2
57 
58  self.inputFile = TFile(self.inputFileName)
60 
61  ### THRESHOLDS SECTION
63  self.rocOccupancyTh = 200
64 
65  self.barrelNoisyColumnTh = 1.35
68 
71 
72  ### ###################
73 
74  if self.inputFile.IsOpen():
75  print("%s opened successfully!" % (self.inputFileName))
76  #Get all neeeded histograms
77  for dir in self.dirs:
78  self.__TraverseDirTree(self.inputFile.Get(dir))
79  print("Histograms to read: %d" % (len(self.dicOfModuleHistograms)))
80 
81  self.detDict = {}
82 
83  else:
84  print("Unable to open file %s" % (self.inputFileName))
85 
def __init__(self, inputDQMName, outputFileName, noiseOutputFileName, dirs)
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:10

Member Function Documentation

def InefficientDoubleROC.InefficientDeadROCs.__convertCoordinatesFromHistToROCSpace (   self,
  histName,
  histXpos,
  histRow 
)
private

Definition at line 237 of file InefficientDoubleROC.py.

References InefficientDoubleROC.InefficientDeadROCs.rocMaxCol.

Referenced by InefficientDoubleROC.InefficientDeadROCs.__determineBarrelDColInefficiencyAndNoise(), InefficientDoubleROC.InefficientDeadROCs.__determineBarrelNoise(), InefficientDoubleROC.InefficientDeadROCs.__determineBarrelNoise2(), InefficientDoubleROC.InefficientDeadROCs.__determineEndcapDColInefficiencyAndNoise(), and InefficientDoubleROC.InefficientDeadROCs.__determineEndcapNoise().

237  def __convertCoordinatesFromHistToROCSpace(self, histName, histXpos, histRow):
238  tempXROC = (histXpos / self.rocMaxCol) # 0,...,7
239  tempYROC = histRow
240 
241  tempXCoordInROC = histXpos % self.rocMaxCol
242 
243  realXROC, realYROC = tempXROC, tempYROC
244  xCoordInROC = tempXCoordInROC
245 
246  rocNum = 0
247 
248  if histName.find("BPix_Bp") != -1: #zero ROC is in top left corner
249  realYROC = 1 - tempYROC
250  if realYROC == 1:
251  rocNum = 15 - realXROC
252  xCoordInROC = self.rocMaxCol - 1 - xCoordInROC
253  else:
254  rocNum = realXROC
255  else: # zero ROC is in bottom right corner
256  realXROC = 7 - tempXROC
257  if realYROC == 1:
258  rocNum = 15 - realXROC
259  else:
260  rocNum = realXROC
261  xCoordInROC = self.rocMaxCol - 1 - xCoordInROC
262 
263  return rocNum, xCoordInROC
264 
265 
def __convertCoordinatesFromHistToROCSpace(self, histName, histXpos, histRow)
def InefficientDoubleROC.InefficientDeadROCs.__customMedianFilter (   self,
  array,
  radius = 2 
)
private

Definition at line 121 of file InefficientDoubleROC.py.

Referenced by InefficientDoubleROC.InefficientDeadROCs.__getROCData().

121  def __customMedianFilter(self, array, radius = 2):
122  # contrary to scipy implementation it provides adaptive kernel size instead of copying data on boundaries
123  filtered = [0 for i in range(len(array))]
124  currArray = []
125  for i in range(len(array)):
126  if i - radius < 0:
127  currArray = array[0 : i + radius + 1]
128  elif i + radius + 1 >= len(array):
129  currArray = array[i - radius : ]
130 
131  currArray.sort()
132  filtered[i] = currArray[len(currArray) // 2]
133 
134  return filtered
135 
def __customMedianFilter(self, array, radius=2)
def InefficientDoubleROC.InefficientDeadROCs.__determineBarrelDColInefficiencyAndNoise (   self,
  medFiltRes,
  histName,
  pixelArr,
  pixelArrWithoutDrops,
  startPixel,
  rocCol,
  rocRow,
  outputFile,
  columnsWithSuspiciouslyNoisyPixels,
  noiseFile 
)
private

Definition at line 266 of file InefficientDoubleROC.py.

References InefficientDoubleROC.InefficientDeadROCs.__convertCoordinatesFromHistToROCSpace(), InefficientDoubleROC.InefficientDeadROCs.__determineBarrelNoise2(), InefficientDoubleROC.InefficientDeadROCs.barrelInefficientDColTh, SiStripPI.max, min(), and InefficientDoubleROC.InefficientDeadROCs.rocMaxCol.

Referenced by InefficientDoubleROC.InefficientDeadROCs.ReadHistograms().

266  def __determineBarrelDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, pixelArrWithoutDrops, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile):
267  meanOfPixels = sum(medFiltRes) / len(medFiltRes)
268  maxMed = max(medFiltRes)
269  minMed = min(medFiltRes)
270 
271  normMeanOfPixels = sum(pixelArrWithoutDrops) / len(pixelArrWithoutDrops)
272  # print( meanOfPixels, maxMed, minMed )
273 
274  doubleDeadCols = 0
275  noisyColsNum = 0
276  noisyROC = 0
277 
278  # for x in range(startPixel, endPixel, 1):
279  for i in range(1, len(pixelArr) - 2):
280  # print(i , i + 1)
281  bin1valDiff = minMed - pixelArr[i + 0]#hist.GetBinContent(x+0)
282  bin2valDiff = minMed - pixelArr[i + 1]
283  # WE ONLY WANT A SET OF TWO COLUMNS SO ADJACENT COLUMNS HAVE TO BE NORMAL
284  bin0valDiff = minMed - pixelArr[i - 1]
285  bin3valDiff = minMed - pixelArr[i + 2]
286 
287  # currentDoubleBinThreshold = minMed / math.sqrt(meanOfPixels) * self.barrelInefficientDColTh # error in bin entry grows as sqrt(N)
288  currentDoubleBinThreshold = math.sqrt(meanOfPixels) * self.barrelInefficientDColTh # error in bin entry grows as sqrt(N)
289 
290  if bin1valDiff > currentDoubleBinThreshold and bin2valDiff > currentDoubleBinThreshold and not bin3valDiff > currentDoubleBinThreshold and not bin0valDiff > currentDoubleBinThreshold:
291 
292  doubleColInRoc = ((i + startPixel) % (self.rocMaxCol)) // 2 + 1
293  doubleDeadCols = doubleDeadCols + 1
294 
295  # outputFile.write("%s,\tX: %d-%d\tROC COLUMN: %d\tROC ROW: %d\tDOUBLE COL IN ROC: %d\tTH: %f\tMIN IN ROC: %f\tBINVAL: %f\n" % (histName, startPixel + (i + 0), startPixel + (i + 1), rocCol, rocRow, doubleColInRoc, currentDoubleBinThreshold, minMed, pixelArr[i]))
296  rocNum, xCoordInROC = self.__convertCoordinatesFromHistToROCSpace(histName, startPixel + i, rocRow)
297  outputFile.write("%s\t(x, row)->[rocNum, doubleXPixelColInROC]\t(%d, %d)->[%d, %d];\t{MIN - VAL, TH}\t{%f, %f}\n" % (histName, startPixel + i, rocRow + 1, rocNum, xCoordInROC / 2, bin1valDiff, currentDoubleBinThreshold))
298 
299  # HANDLE NOISY PIXELS
300  if noisyROC == True: #don't go inside if noisyness was determined already
301  continue
302 
303  # res = self.__determineBarrelNoise(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, pixelArr[i], startPixel + i, rocCol, rocRow)
304  # noisyColsNum, noisyROC = noisyColsNum + res[0], res[1]
305  # if i == len(pixelArr) - 3: # CHECK NOISYNESS IN THE RIGHTMOST INNER COL
306  # res = self.__determineBarrelNoise(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, pixelArr[i + 1], startPixel + i + 1, rocCol, rocRow)
307  # noisyColsNum, noisyROC = noisyColsNum + res[0], res[1]
308 
309  # NORMALIZED MEAN NOISE DETERMINATION METHOD
310  res = self.__determineBarrelNoise2(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, pixelArrWithoutDrops[i], startPixel + i, rocCol, rocRow)
311  noisyColsNum, noisyROC = noisyColsNum + res[0], res[1]
312  if i == len(pixelArr) - 3: # CHECK NOISYNESS IN THE RIGHTMOST INNER COL
313  res = self.__determineBarrelNoise2(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, pixelArrWithoutDrops[i + 1], startPixel + i + 1, rocCol, rocRow)
314  noisyColsNum, noisyROC = noisyColsNum + res[0], res[1]
315 
316 
317 
318  return doubleDeadCols, noisyColsNum
319 
def __determineBarrelNoise2(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, normVal, pos, rocCol, rocRow)
def __convertCoordinatesFromHistToROCSpace(self, histName, histXpos, histRow)
T min(T a, T b)
Definition: MathUtil.h:58
def __determineBarrelDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, pixelArrWithoutDrops, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)
def InefficientDoubleROC.InefficientDeadROCs.__determineBarrelNoise (   self,
  noiseFile,
  columnsWithSuspiciouslyNoisyPixels,
  histName,
  meanOfPixels,
  maxMed,
  val,
  pos,
  rocCol,
  rocRow 
)
private

Definition at line 182 of file InefficientDoubleROC.py.

References InefficientDoubleROC.InefficientDeadROCs.__convertCoordinatesFromHistToROCSpace(), InefficientDoubleROC.InefficientDeadROCs.barrelNoisyColumnTh, and InefficientDoubleROC.InefficientDeadROCs.rocOccupancyTh.

182  def __determineBarrelNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, val, pos, rocCol, rocRow):
183  noisyROC = False;
184  if meanOfPixels < self.rocOccupancyTh:
185  #print("Very low mean occupancy: %f in %s in (col, row) (%d, %d)...\tSkipping noisy ROC calculation" % (meanOfPixels, histName, rocCol, rocRow) )
186  noisyROC = True
187  else:
188  th = self.barrelNoisyColumnTh * maxMed
189  if val > th:
190  if pos not in columnsWithSuspiciouslyNoisyPixels:
191  rocNum, xCoordInROC = self.__convertCoordinatesFromHistToROCSpace(histName, pos, rocRow)
192  noiseFile.write("%s\t(x, row)->[rocNum, xRoc]\t(%d, %d)->[%d, %d];\t{VAL, TH}\t{%f, %f}\n" % (histName, pos, rocRow+1, rocNum, xCoordInROC, val, th))
193 
194  return 1, noisyROC
195  # else:
196  # print("WARNING: rejecting %s (x, row) (%d, %d) as being affected by a few noisy pixel(s)" % (histName, pos, rocRow+1))
197 
198  return 0, noisyROC
199 
def __convertCoordinatesFromHistToROCSpace(self, histName, histXpos, histRow)
def __determineBarrelNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, val, pos, rocCol, rocRow)
def InefficientDoubleROC.InefficientDeadROCs.__determineBarrelNoise2 (   self,
  noiseFile,
  columnsWithSuspiciouslyNoisyPixels,
  histName,
  meanOfPixels,
  normMeanOfPixels,
  normVal,
  pos,
  rocCol,
  rocRow 
)
private

Definition at line 200 of file InefficientDoubleROC.py.

References InefficientDoubleROC.InefficientDeadROCs.__convertCoordinatesFromHistToROCSpace(), InefficientDoubleROC.InefficientDeadROCs.barrelNoisyColumnTh2, and InefficientDoubleROC.InefficientDeadROCs.rocOccupancyTh.

Referenced by InefficientDoubleROC.InefficientDeadROCs.__determineBarrelDColInefficiencyAndNoise().

200  def __determineBarrelNoise2(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, normVal, pos, rocCol, rocRow):
201  noisyROC = False;
202  if meanOfPixels < self.rocOccupancyTh:
203  #print("Very low mean occupancy: %f in %s in (col, row) (%d, %d)...\tSkipping noisy ROC calculation" % (meanOfPixels, histName, rocCol, rocRow) )
204  noisyROC = True
205  else:
206  th = self.barrelNoisyColumnTh2 * normMeanOfPixels
207  if normVal > th:
208  if pos not in columnsWithSuspiciouslyNoisyPixels:
209  rocNum, xCoordInROC = self.__convertCoordinatesFromHistToROCSpace(histName, pos, rocRow)
210  noiseFile.write("%s\t(x, row)->[rocNum, xRoc]\t(%d, %d)->[%d, %d];\t{NORMVAL, TH}\t{%f, %f}\n" % (histName, pos, rocRow+1, rocNum, xCoordInROC, normVal, th))
211 
212  return 1, noisyROC
213  # else:
214  # print("WARNING: rejecting %s (x, row) (%d, %d) as being affected by a few noisy pixel(s)" % (histName, pos, rocRow+1))
215 
216  return 0, noisyROC
217 
def __determineBarrelNoise2(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, normVal, pos, rocCol, rocRow)
def __convertCoordinatesFromHistToROCSpace(self, histName, histXpos, histRow)
def InefficientDoubleROC.InefficientDeadROCs.__determineEndcapDColInefficiencyAndNoise (   self,
  medFiltRes,
  histName,
  pixelArr,
  startPixel,
  rocCol,
  rocRow,
  outputFile,
  columnsWithSuspiciouslyNoisyPixels,
  noiseFile 
)
private

Definition at line 320 of file InefficientDoubleROC.py.

References InefficientDoubleROC.InefficientDeadROCs.__convertCoordinatesFromHistToROCSpace(), InefficientDoubleROC.InefficientDeadROCs.__determineEndcapNoise(), InefficientDoubleROC.InefficientDeadROCs.__lmsLin(), InefficientDoubleROC.InefficientDeadROCs.endcapInefficientDColTh, and InefficientDoubleROC.InefficientDeadROCs.rocMaxCol.

Referenced by InefficientDoubleROC.InefficientDeadROCs.ReadHistograms().

320  def __determineEndcapDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile):
321  doubleDeadCols = 0
322  noisyColsNum = 0
323  noisyROC = 0
324 
325  useLin = True
326  # <D> might be used for high noise ROC recognition
327  a, b, D = self.__lmsLin(medFiltRes, startPixel, len(medFiltRes) + startPixel)
328 
329  meanOfPixels = sum(medFiltRes) / len(medFiltRes)
330 
331  # for x in range(startPixel, endPixel, 1):
332  for i in range(1, len(pixelArr) - 2):
333 
334  if useLin == True:
335  linVal1 = a * (i + startPixel + 0) + b
336  linVal2 = a * (i + startPixel + 1) + b
337 
338  linVal0 = a * (i + startPixel - 1) + b
339  linVal3 = a * (i + startPixel + 2) + b
340  else:
341  linVal1 = b * math.exp(a * (i + startPixel + 0))
342  linVal2 = b * math.exp(a * (i + startPixel + 1))
343 
344  linVal0 = b * math.exp(a * (i + startPixel - 1))
345  linVal3 = b * math.exp(a * (i + startPixel + 2))
346 
347  bin1valDiff = linVal1 - pixelArr[i + 0]
348  bin2valDiff = linVal2 - pixelArr[i + 1]
349  # WE ONLY WANT A SET OF TWO COLUMNS SO ADJACENT COLUMNS HAVE TO BE NORMAL
350  bin0valDiff = linVal0 - pixelArr[i - 1]
351  bin3valDiff = linVal3 - pixelArr[i + 2]
352 
353  try:
354  currentDoubleBinThreshold = math.sqrt((linVal1 + linVal2) * 0.5) * self.endcapInefficientDColTh
355  except:
356  # print(a, b, startPixel, i, linVal1, linVal2)
357  continue
358 
359  if bin1valDiff > currentDoubleBinThreshold and bin2valDiff > currentDoubleBinThreshold and not bin3valDiff > currentDoubleBinThreshold and not bin0valDiff > currentDoubleBinThreshold:
360 
361  doubleColInRoc = ((i + startPixel) % (self.rocMaxCol)) // 2 + 1
362  doubleDeadCols = doubleDeadCols + 1
363 
364  # outputFile.write("%s,\tX: %d-%d\tROC COLUMN: %d\tROC ROW: %d\tDOUBLE COL IN ROC: %d\tTH: %f\tLINVAL: %f\tBINVAL: %f\n" % (histName, startPixel + (i + 0), startPixel + (i + 1), rocCol, rocRow, doubleColInRoc, currentDoubleBinThreshold, linVal1, pixelArr[i]))
365  rocNum, xCoordInROC = self.__convertCoordinatesFromHistToROCSpace(histName, startPixel + i, rocRow)
366  outputFile.write("%s\t(x, row)->[rocNum, doubleXPixelColInROC]\t(%d, %d)->[%d, %d];\t{LIN(x) - VAL, TH}\t{%f, %f}\n" % (histName, startPixel + i, rocRow + 1, rocNum, xCoordInROC / 2, bin1valDiff, currentDoubleBinThreshold))
367 
368 
369  # HANDLE NOISY PIXELS
370  if noisyROC == True: #don't go inside if noisyness was determined already
371  continue
372 
373  res = self.__determineEndcapNoise(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal1, pixelArr[i], i + startPixel, rocCol, rocRow)
374  noisyColsNum, noisyROC = noisyColsNum + res[0], res[1]
375  if i == len(pixelArr) - 3: # CHECK NOISYNESS IN THE RIGHTMOST INNER COL
376  res = self.__determineEndcapNoise(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal2, pixelArr[i + 1], i + 1 + startPixel, rocCol, rocRow)
377  noisyColsNum, noisyROC = noisyColsNum + res[0], res[1]
378 
379  return doubleDeadCols, noisyColsNum
380 
def __convertCoordinatesFromHistToROCSpace(self, histName, histXpos, histRow)
def __determineEndcapNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal, val, pos, rocCol, rocRow)
def __determineEndcapDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)
def InefficientDoubleROC.InefficientDeadROCs.__determineEndcapNoise (   self,
  noiseFile,
  columnsWithSuspiciouslyNoisyPixels,
  histName,
  meanOfPixels,
  linVal,
  val,
  pos,
  rocCol,
  rocRow 
)
private

Definition at line 218 of file InefficientDoubleROC.py.

References InefficientDoubleROC.InefficientDeadROCs.__convertCoordinatesFromHistToROCSpace(), InefficientDoubleROC.InefficientDeadROCs.endcapNoisyColumnTh, and InefficientDoubleROC.InefficientDeadROCs.rocOccupancyTh.

Referenced by InefficientDoubleROC.InefficientDeadROCs.__determineEndcapDColInefficiencyAndNoise().

218  def __determineEndcapNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal, val, pos, rocCol, rocRow):
219  noisyROC = False;
220  if meanOfPixels < self.rocOccupancyTh:
221  # print("Very low mean occupancy: %f in %s in (col, row) (%d, %d)...\tSkipping noisy ROC calculation" % (meanOfPixels, histName, rocCol, rocRow) )
222  noisyROC = True
223 
224  else:
225  th = self.endcapNoisyColumnTh * linVal
226  if val > th:
227  if pos not in columnsWithSuspiciouslyNoisyPixels:
228  rocNum, xCoordInROC = self.__convertCoordinatesFromHistToROCSpace(histName, pos, rocRow)
229  noiseFile.write("%s\t(x, row)->[rocNum, xRoc]\t(%d, %d)->[%d, %d];\t{VAL, TH}\t{%f, %f}\n" % (histName, pos, rocRow+1, rocNum, xCoordInROC, val, th))
230 
231  return 1, noisyROC
232  # else:
233  # print("WARNING: rejecting %s (x, row) (%d, %d) as being affected by a few noisy pixel(s)" % (histName, pos, rocRow+1))
234 
235  return 0, noisyROC
236 
def __convertCoordinatesFromHistToROCSpace(self, histName, histXpos, histRow)
def __determineEndcapNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal, val, pos, rocCol, rocRow)
def InefficientDoubleROC.InefficientDeadROCs.__getPixelArrWithRemovedDrops (   self,
  pixelArr,
  medFiltRes 
)
private

Definition at line 167 of file InefficientDoubleROC.py.

References min().

Referenced by InefficientDoubleROC.InefficientDeadROCs.ReadHistograms().

167  def __getPixelArrWithRemovedDrops(self, pixelArr, medFiltRes):
168  return [ (pixelArr[i] if pixelArr[i] > medFiltRes[i] else medFiltRes[i]) if 0 < i < len(pixelArr) - 1 else min(medFiltRes) for i in range(len(pixelArr))]
169 
def __getPixelArrWithRemovedDrops(self, pixelArr, medFiltRes)
T min(T a, T b)
Definition: MathUtil.h:58
def InefficientDoubleROC.InefficientDeadROCs.__getROCData (   self,
  hist,
  startPixel,
  endPixel,
  row,
  repeatFilter = 3,
  filterKernelSize = 5 
)
private

Definition at line 136 of file InefficientDoubleROC.py.

References InefficientDoubleROC.InefficientDeadROCs.__customMedianFilter(), InefficientDoubleROC.InefficientDeadROCs.pixelNoisynessTh, and InefficientDoubleROC.InefficientDeadROCs.rocMaxRow.

Referenced by InefficientDoubleROC.InefficientDeadROCs.ReadHistograms().

136  def __getROCData(self, hist, startPixel, endPixel, row, repeatFilter = 3, filterKernelSize = 5):
137  pixelArr = []
138  columnsWithSuspiciouslyNoisyPixels = []
139 
140  for x in range(startPixel, endPixel):
141 
142  columnPixels = [hist.GetBinContent(x, y + 1) for y in range(row * self.rocMaxRow, (row + 1) * self.rocMaxRow)]
143  columnSum = sum(columnPixels)
144 
145  columnMean = columnSum / len(columnPixels)
146  for i in range(len(columnPixels)):
147  if columnPixels[i] > self.pixelNoisynessTh * columnMean:
148  # col = (startPixel % self.rocMaxCol) + 1
149 
150  columnsWithSuspiciouslyNoisyPixels.append(x)
151 
152  # print("WARNING:\t %s : %dx%d:%d may contain NOISY PIXELS instead of NOISY COLUMNS" % (hist.GetName(), col, row + 1, startPixel + i))
153  break
154 
155  pixelArr.append(columnSum)
156 
157  if len(pixelArr) == 0:
158  return None, None, None # ROC down
159 
160  medFiltRes, sciPyMedFiltRes = deepcopy(pixelArr), deepcopy(pixelArr)
161  for i in range(repeatFilter):
162  sciPyMedFiltRes = signal.medfilt(sciPyMedFiltRes, filterKernelSize) # 5 is obligatory to filter doublets!!!
163  medFiltRes = self.__customMedianFilter(medFiltRes, filterKernelSize // 2)
164 
165  return pixelArr, medFiltRes, columnsWithSuspiciouslyNoisyPixels, sciPyMedFiltRes
166 
def __getROCData(self, hist, startPixel, endPixel, row, repeatFilter=3, filterKernelSize=5)
def __customMedianFilter(self, array, radius=2)
def InefficientDoubleROC.InefficientDeadROCs.__lmsExp (   self,
  data,
  xMin,
  xMax 
)
private

Definition at line 86 of file InefficientDoubleROC.py.

86  def __lmsExp(self, data, xMin, xMax):
87  meanOfX = (xMax + xMin) * 0.5
88  meanOfY = sum( [math.log(data[i]) for i in range(len(data))] ) / len(data)
89 
90  D = 0
91  for i in range(xMin, xMax + 1):
92  D = D + (i - meanOfX)**2
93  # print(D)
94 
95  a = 0
96  for i in range(len(data)):
97  a = a + math.log(data[i]) * (xMin + i - meanOfX)
98  a = a/D
99 
100  lnb = meanOfY - a * meanOfX
101 
102  return a, math.exp(lnb)
103 
def InefficientDoubleROC.InefficientDeadROCs.__lmsLin (   self,
  data,
  xMin,
  xMax 
)
private

Definition at line 104 of file InefficientDoubleROC.py.

Referenced by InefficientDoubleROC.InefficientDeadROCs.__determineEndcapDColInefficiencyAndNoise().

104  def __lmsLin(self, data, xMin, xMax):
105  meanOfX = (xMax + xMin) * 0.5
106  meanOfY = sum(data) / len(data)
107 
108  D = 0
109  for i in range(xMin, xMax + 1):
110  D = D + (i - meanOfX)**2
111 
112  a = 0
113  for i in range(len(data)):
114  a = a + data[i] * (xMin + i - meanOfX)
115  a = a/D
116 
117  b = meanOfY - a * meanOfX
118 
119  return a, b, D
120 
def InefficientDoubleROC.InefficientDeadROCs.__normalizeArray (   self,
  pixelArr 
)
private

Definition at line 170 of file InefficientDoubleROC.py.

References SiStripPI.max, and min().

Referenced by InefficientDoubleROC.InefficientDeadROCs.ReadHistograms().

170  def __normalizeArray(self, pixelArr):
171  c_min, c_max = min(pixelArr), max(pixelArr)
172  if c_min != c_max:
173  c_diff_inv = 1.0 / (c_max - c_min)
174  return [ (pixelArr[i] - c_min) * c_diff_inv for i in range(len(pixelArr))]
175  return [0 for i in range(len(pixelArr))]
176 
T min(T a, T b)
Definition: MathUtil.h:58
def InefficientDoubleROC.InefficientDeadROCs.__setNormalizedArrayZeroInThePoint (   self,
  pixelArr,
  pt 
)
private

Definition at line 177 of file InefficientDoubleROC.py.

177  def __setNormalizedArrayZeroInThePoint(self, pixelArr, pt):
178  c_diff_inv = 1.0 / (1.0 - pt)
179 
180  return [ (pixelArr[i] - pt) * c_diff_inv for i in range(len(pixelArr))]
181 
def __setNormalizedArrayZeroInThePoint(self, pixelArr, pt)
def InefficientDoubleROC.InefficientDeadROCs.__TraverseDirTree (   self,
  dir 
)
private

Definition at line 14 of file InefficientDoubleROC.py.

References InefficientDoubleROC.InefficientDeadROCs.__TraverseDirTree(), mps_setup.append, InefficientDoubleROC.InefficientDeadROCs.dicOfModuleHistograms, and InefficientDoubleROC.InefficientDeadROCs.lookForStr.

Referenced by InefficientDoubleROC.InefficientDeadROCs.__TraverseDirTree(), PhaseITreeProducer.ModuleLvlValuesReader.__TraverseDirTree(), and TH2PolyOfflineMaps.TH2PolyOfflineMaps.__TraverseDirTree().

14  def __TraverseDirTree(self, dir):
15 
16  for obj in dir.GetListOfKeys():
17  if not obj.IsFolder():
18  if obj.ReadObjectAny(TClass.GetClass("TH2")):
19  th1 = deepcopy(obj.ReadObj())
20  name = th1.GetName()
21  if name.startswith(self.lookForStr): #take only module lvl plots
22  # print(''.join([dir.GetPath(), '/', name]))
23  newName = name.split(self.lookForStr)[1]
24  th1.SetName(newName)
25 
26  # used to sort outputs by disk/layer
27  layer = 0
28  # print(newName)
29  if newName.startswith("B"):
30  layer = "B" + ((newName.split("_LYR"))[1])[0]
31  else:
32  layer = ((newName.split("_D"))[1])[0]
33  if newName.startswith("FPix_Bm"):
34  layer = "-" + layer
35  layer = "F" + layer
36 
37  if layer in self.dicOfModuleHistograms:
38  self.dicOfModuleHistograms[layer].append(th1)
39  else:
40  self.dicOfModuleHistograms.update({layer : [th1]})
41  else:
42  self.__TraverseDirTree(obj.ReadObj())
43 
def InefficientDoubleROC.InefficientDeadROCs.ReadHistograms (   self)

Definition at line 381 of file InefficientDoubleROC.py.

References InefficientDoubleROC.InefficientDeadROCs.__determineBarrelDColInefficiencyAndNoise(), InefficientDoubleROC.InefficientDeadROCs.__determineEndcapDColInefficiencyAndNoise(), InefficientDoubleROC.InefficientDeadROCs.__getPixelArrWithRemovedDrops(), InefficientDoubleROC.InefficientDeadROCs.__getROCData(), InefficientDoubleROC.InefficientDeadROCs.__normalizeArray(), InefficientDoubleROC.InefficientDeadROCs.dicOfModuleHistograms, InefficientDoubleROC.InefficientDeadROCs.noiseOutputFileName, DTSurveyConvert.outputFileName, InefficientDoubleROC.InefficientDeadROCs.outputFileName, SiStripGainCosmicCalculator.outputFileName, CSCSkim.outputFileName, reco.print(), InefficientDoubleROC.InefficientDeadROCs.rocMaxCol, InefficientDoubleROC.InefficientDeadROCs.rocsInRow, and split.

381  def ReadHistograms(self):
382  doubleDeadCols, noisyColsNum = 0, 0
383 
384  with open(self.noiseOutputFileName, "w") as noiseFile:
385  with open(self.outputFileName, "w") as outputFile:
386  for layer in self.dicOfModuleHistograms:
387 
388  doubleDeadColsInLayer, noisyColsNumInLayer = 0, 0
389 
390  outputFile.write("-> " + layer + "\n\n")
391  noiseFile.write("-> " + layer + "\n\n")
392 
393  for hist in self.dicOfModuleHistograms[layer]:
394  for row in range(2):
395  for rocNum in range(self.rocsInRow):
396  startPixel = rocNum * self.rocMaxCol + 1
397  endPixel = (rocNum + 1) * self.rocMaxCol + 1 # - 1 ???
398 
399  rocCol = rocNum + 1
400 
401  pixelArr, medFiltRes, columnsWithSuspiciouslyNoisyPixels, sciPyMedFiltRes = self.__getROCData(hist, startPixel, endPixel, row, 3, 5)
402 
403  if pixelArr == None:
404  continue
405 
406  # meanOfPixels = sum(pixelArr) / len(pixelArr)
407  # pixelArrSorted = deepcopy(pixelArr)
408  # pixelArrSorted.sort()
409  # outputFile.write("%s: <x> <med_min> VS. <med_max> | x_min:\t%f %f %f | %f, %f, %f, %f\n" % (hist.GetName(), meanOfPixels, min(medFiltRes), max(medFiltRes), pixelArrSorted[0], pixelArrSorted[1], pixelArrSorted[2], pixelArrSorted[3]))
410 
411  if "F" not in layer:
412  # pixelArrWithoutDrops = self.__getPixelArrWithRemovedDrops(pixelArr, medFiltRes)
413  pixelArrWithoutDrops = self.__getPixelArrWithRemovedDrops(pixelArr, sciPyMedFiltRes)
414  pixelArrWithoutDropsNormalized = self.__normalizeArray(pixelArrWithoutDrops)
415  # tmp_mean = sum(pixelArrWithoutDropsNormalized) / len(pixelArrWithoutDropsNormalized)
416  # pixelArrWithoutDropsNormalized = self.__setNormalizedArrayZeroInThePoint(pixelArrWithoutDropsNormalized, tmp_mean)
417 
418  # print(min(pixelArrWithoutDropsNormalized), max(pixelArrWithoutDropsNormalized))
419  result = self.__determineBarrelDColInefficiencyAndNoise(medFiltRes, hist.GetName(), pixelArr, pixelArrWithoutDropsNormalized, startPixel, rocCol, row, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)
420  else:
421  result = self.__determineEndcapDColInefficiencyAndNoise(medFiltRes, hist.GetName(), pixelArr, startPixel, rocCol, row, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)
422 
423  doubleDeadCols, doubleDeadColsInLayer = doubleDeadCols + result[0], doubleDeadColsInLayer + result[0]
424  noisyColsNum, noisyColsNumInLayer = noisyColsNum + result[1], noisyColsNumInLayer + result[1]
425 
426  outputFile.write("\n\tTOTAL IN LAYER/DISK: %d\n\n" % (doubleDeadColsInLayer))
427  noiseFile.write("\n\tTOTAL IN LAYER/DISK: %d\n\n" % (noisyColsNumInLayer))
428 
429  print("Number of inefficient double columns: %d"%(doubleDeadCols))
430  print("Number of noisy cols: %d"%(noisyColsNum))
431 
432 
433 #--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:10
def __getPixelArrWithRemovedDrops(self, pixelArr, medFiltRes)
def __determineBarrelDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, pixelArrWithoutDrops, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)
def __getROCData(self, hist, startPixel, endPixel, row, repeatFilter=3, filterKernelSize=5)
def __determineEndcapDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)

Member Data Documentation

InefficientDoubleROC.InefficientDeadROCs.barrelInefficientDColTh
InefficientDoubleROC.InefficientDeadROCs.barrelNoisyColumnTh
InefficientDoubleROC.InefficientDeadROCs.barrelNoisyColumnTh2
InefficientDoubleROC.InefficientDeadROCs.detDict
InefficientDoubleROC.InefficientDeadROCs.dicOfModuleHistograms
InefficientDoubleROC.InefficientDeadROCs.dirs
InefficientDoubleROC.InefficientDeadROCs.endcapInefficientDColTh
InefficientDoubleROC.InefficientDeadROCs.endcapNoisyColumnTh
InefficientDoubleROC.InefficientDeadROCs.inputFile

Definition at line 58 of file InefficientDoubleROC.py.

InefficientDoubleROC.InefficientDeadROCs.inputFileName

Definition at line 46 of file InefficientDoubleROC.py.

InefficientDoubleROC.InefficientDeadROCs.lookForStr
InefficientDoubleROC.InefficientDeadROCs.noiseOutputFileName
InefficientDoubleROC.InefficientDeadROCs.outputFileName
InefficientDoubleROC.InefficientDeadROCs.pixelNoisynessTh

THRESHOLDS SECTION.

Definition at line 62 of file InefficientDoubleROC.py.

Referenced by InefficientDoubleROC.InefficientDeadROCs.__getROCData().

InefficientDoubleROC.InefficientDeadROCs.rocMaxCol
InefficientDoubleROC.InefficientDeadROCs.rocMaxRow
InefficientDoubleROC.InefficientDeadROCs.rocOccupancyTh
InefficientDoubleROC.InefficientDeadROCs.rocsInCol

Definition at line 56 of file InefficientDoubleROC.py.

InefficientDoubleROC.InefficientDeadROCs.rocsInRow