6 from copy
import deepcopy
7 from scipy
import signal
16 for obj
in dir.GetListOfKeys():
17 if not obj.IsFolder():
18 if obj.ReadObjectAny(TClass.GetClass(
"TH2")):
19 th1 = deepcopy(obj.ReadObj())
29 if newName.startswith(
"B"):
30 layer =
"B" + ((newName.split(
"_LYR"))[1])[0]
32 layer = ((newName.split(
"_D"))[1])[0]
33 if newName.startswith(
"FPix_Bm"):
40 self.dicOfModuleHistograms.update({layer : [th1]})
44 def __init__(self, inputDQMName, outputFileName, noiseOutputFileName, dirs):
74 if self.inputFile.IsOpen():
87 meanOfX = (xMax + xMin) * 0.5
88 meanOfY = sum( [math.log(data[i])
for i
in range(len(data))] ) / len(data)
91 for i
in range(xMin, xMax + 1):
92 D = D + (i - meanOfX)**2
96 for i
in range(len(data)):
97 a = a + math.log(data[i]) * (xMin + i - meanOfX)
100 lnb = meanOfY - a * meanOfX
102 return a, math.exp(lnb)
105 meanOfX = (xMax + xMin) * 0.5
106 meanOfY = sum(data) / len(data)
109 for i
in range(xMin, xMax + 1):
110 D = D + (i - meanOfX)**2
113 for i
in range(len(data)):
114 a = a + data[i] * (xMin + i - meanOfX)
117 b = meanOfY - a * meanOfX
123 filtered = [0
for i
in range(len(array))]
125 for i
in range(len(array)):
127 currArray = array[0 : i + radius + 1]
128 elif i + radius + 1 >= len(array):
129 currArray = array[i - radius : ]
132 filtered[i] = currArray[len(currArray) // 2]
136 def __getROCData(self, hist, startPixel, endPixel, row, repeatFilter = 3, filterKernelSize = 5):
138 columnsWithSuspiciouslyNoisyPixels = []
140 for x
in range(startPixel, endPixel):
142 columnPixels = [hist.GetBinContent(x, y + 1)
for y
in range(row * self.
rocMaxRow, (row + 1) * self.
rocMaxRow)]
143 columnSum = sum(columnPixels)
145 columnMean = columnSum / len(columnPixels)
146 for i
in range(len(columnPixels)):
150 columnsWithSuspiciouslyNoisyPixels.append(x)
155 pixelArr.append(columnSum)
157 if len(pixelArr) == 0:
158 return None,
None,
None 160 medFiltRes, sciPyMedFiltRes = deepcopy(pixelArr), deepcopy(pixelArr)
161 for i
in range(repeatFilter):
162 sciPyMedFiltRes = signal.medfilt(sciPyMedFiltRes, filterKernelSize)
165 return pixelArr, medFiltRes, columnsWithSuspiciouslyNoisyPixels, sciPyMedFiltRes
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))]
171 c_min, c_max =
min(pixelArr),
max(pixelArr)
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))]
178 c_diff_inv = 1.0 / (1.0 - pt)
180 return [ (pixelArr[i] - pt) * c_diff_inv
for i
in range(len(pixelArr))]
182 def __determineBarrelNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, val, pos, rocCol, rocRow):
190 if pos
not in columnsWithSuspiciouslyNoisyPixels:
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))
200 def __determineBarrelNoise2(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, normVal, pos, rocCol, rocRow):
208 if pos
not in columnsWithSuspiciouslyNoisyPixels:
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))
218 def __determineEndcapNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal, val, pos, rocCol, rocRow):
227 if pos
not in columnsWithSuspiciouslyNoisyPixels:
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))
241 tempXCoordInROC = histXpos % self.
rocMaxCol 243 realXROC, realYROC = tempXROC, tempYROC
244 xCoordInROC = tempXCoordInROC
248 if histName.find(
"BPix_Bp") != -1:
249 realYROC = 1 - tempYROC
251 rocNum = 15 - realXROC
252 xCoordInROC = self.
rocMaxCol - 1 - xCoordInROC
256 realXROC = 7 - tempXROC
258 rocNum = 15 - realXROC
261 xCoordInROC = self.
rocMaxCol - 1 - xCoordInROC
263 return rocNum, xCoordInROC
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)
271 normMeanOfPixels = sum(pixelArrWithoutDrops) / len(pixelArrWithoutDrops)
279 for i
in range(1, len(pixelArr) - 2):
281 bin1valDiff = minMed - pixelArr[i + 0]
282 bin2valDiff = minMed - pixelArr[i + 1]
284 bin0valDiff = minMed - pixelArr[i - 1]
285 bin3valDiff = minMed - pixelArr[i + 2]
290 if bin1valDiff > currentDoubleBinThreshold
and bin2valDiff > currentDoubleBinThreshold
and not bin3valDiff > currentDoubleBinThreshold
and not bin0valDiff > currentDoubleBinThreshold:
292 doubleColInRoc = ((i + startPixel) % (self.
rocMaxCol)) // 2 + 1
293 doubleDeadCols = doubleDeadCols + 1
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))
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:
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]
318 return doubleDeadCols, noisyColsNum
327 a, b, D = self.
__lmsLin(medFiltRes, startPixel, len(medFiltRes) + startPixel)
329 meanOfPixels = sum(medFiltRes) / len(medFiltRes)
332 for i
in range(1, len(pixelArr) - 2):
335 linVal1 = a * (i + startPixel + 0) + b
336 linVal2 = a * (i + startPixel + 1) + b
338 linVal0 = a * (i + startPixel - 1) + b
339 linVal3 = a * (i + startPixel + 2) + b
341 linVal1 = b * math.exp(a * (i + startPixel + 0))
342 linVal2 = b * math.exp(a * (i + startPixel + 1))
344 linVal0 = b * math.exp(a * (i + startPixel - 1))
345 linVal3 = b * math.exp(a * (i + startPixel + 2))
347 bin1valDiff = linVal1 - pixelArr[i + 0]
348 bin2valDiff = linVal2 - pixelArr[i + 1]
350 bin0valDiff = linVal0 - pixelArr[i - 1]
351 bin3valDiff = linVal3 - pixelArr[i + 2]
359 if bin1valDiff > currentDoubleBinThreshold
and bin2valDiff > currentDoubleBinThreshold
and not bin3valDiff > currentDoubleBinThreshold
and not bin0valDiff > currentDoubleBinThreshold:
361 doubleColInRoc = ((i + startPixel) % (self.
rocMaxCol)) // 2 + 1
362 doubleDeadCols = doubleDeadCols + 1
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))
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:
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]
379 return doubleDeadCols, noisyColsNum
382 doubleDeadCols, noisyColsNum = 0, 0
388 doubleDeadColsInLayer, noisyColsNumInLayer = 0, 0
390 outputFile.write(
"-> " + layer +
"\n\n")
391 noiseFile.write(
"-> " + layer +
"\n\n")
397 endPixel = (rocNum + 1) * self.
rocMaxCol + 1
401 pixelArr, medFiltRes, columnsWithSuspiciouslyNoisyPixels, sciPyMedFiltRes = self.
__getROCData(hist, startPixel, endPixel, row, 3, 5)
414 pixelArrWithoutDropsNormalized = self.
__normalizeArray(pixelArrWithoutDrops)
419 result = self.
__determineBarrelDColInefficiencyAndNoise(medFiltRes, hist.GetName(), pixelArr, pixelArrWithoutDropsNormalized, startPixel, rocCol, row, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)
423 doubleDeadCols, doubleDeadColsInLayer = doubleDeadCols + result[0], doubleDeadColsInLayer + result[0]
424 noisyColsNum, noisyColsNumInLayer = noisyColsNum + result[1], noisyColsNumInLayer + result[1]
426 outputFile.write(
"\n\tTOTAL IN LAYER/DISK: %d\n\n" % (doubleDeadColsInLayer))
427 noiseFile.write(
"\n\tTOTAL IN LAYER/DISK: %d\n\n" % (noisyColsNumInLayer))
429 print(
"Number of inefficient double columns: %d"%(doubleDeadCols))
430 print(
"Number of noisy cols: %d"%(noisyColsNum))
434 for i
in range(1, len(sys.argv), 1):
436 inputFileName = sys.argv[i]
438 runNum = ((inputFileName.split(
"/")[-1].
split(
"."))[0].
split(
"_R000"))[1]
439 print(
"Run number: %s"%(runNum))
440 baseRootDir = [
"DQMData/Run " + runNum +
"/PixelPhase1/Run summary/Phase1_MechanicalView"]
441 print(baseRootDir[0])
442 outputFileName =
"inefficientDPixelColumns.txt" 443 noiseOutputFileName =
"noisyPixelColumns.txt" 445 readerObj =
InefficientDeadROCs(inputFileName, outputFileName, noiseOutputFileName, baseRootDir)
446 readerObj.ReadHistograms()
def __determineBarrelNoise2(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, normVal, pos, rocCol, rocRow)
def __normalizeArray(self, pixelArr)
def __init__(self, inputDQMName, outputFileName, noiseOutputFileName, dirs)
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
def __TraverseDirTree(self, dir)
def __getPixelArrWithRemovedDrops(self, pixelArr, medFiltRes)
def __lmsExp(self, data, xMin, xMax)
def __convertCoordinatesFromHistToROCSpace(self, histName, histXpos, histRow)
def __determineBarrelNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, val, pos, rocCol, rocRow)
def __determineBarrelDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, pixelArrWithoutDrops, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)
def __lmsLin(self, data, xMin, xMax)
pixelNoisynessTh
THRESHOLDS SECTION.
def __getROCData(self, hist, startPixel, endPixel, row, repeatFilter=3, filterKernelSize=5)
def __customMedianFilter(self, array, radius=2)
def __setNormalizedArrayZeroInThePoint(self, pixelArr, pt)
def __determineEndcapNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal, val, pos, rocCol, rocRow)
def __determineEndcapDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)