3 from __future__
import print_function
7 from copy
import deepcopy
8 from scipy
import signal
17 for obj
in dir.GetListOfKeys():
18 if not obj.IsFolder():
19 if obj.ReadObjectAny(TClass.GetClass(
"TH2")):
20 th1 = deepcopy(obj.ReadObj())
30 if newName.startswith(
"B"):
31 layer =
"B" + ((newName.split(
"_LYR"))[1])[0]
33 layer = ((newName.split(
"_D"))[1])[0]
34 if newName.startswith(
"FPix_Bm"):
41 self.dicOfModuleHistograms.update({layer : [th1]})
45 def __init__(self, inputDQMName, outputFileName, noiseOutputFileName, dirs):
75 if self.inputFile.IsOpen():
88 meanOfX = (xMax + xMin) * 0.5
89 meanOfY = sum( [math.log(data[i])
for i
in range(len(data))] ) / len(data)
92 for i
in range(xMin, xMax + 1):
93 D = D + (i - meanOfX)**2
97 for i
in range(len(data)):
98 a = a + math.log(data[i]) * (xMin + i - meanOfX)
101 lnb = meanOfY - a * meanOfX
103 return a, math.exp(lnb)
106 meanOfX = (xMax + xMin) * 0.5
107 meanOfY = sum(data) / len(data)
110 for i
in range(xMin, xMax + 1):
111 D = D + (i - meanOfX)**2
114 for i
in range(len(data)):
115 a = a + data[i] * (xMin + i - meanOfX)
118 b = meanOfY - a * meanOfX
124 filtered = [0
for i
in range(len(array))]
126 for i
in range(len(array)):
128 currArray = array[0 : i + radius + 1]
129 elif i + radius + 1 >= len(array):
130 currArray = array[i - radius : ]
133 filtered[i] = currArray[len(currArray) // 2]
137 def __getROCData(self, hist, startPixel, endPixel, row, repeatFilter = 3, filterKernelSize = 5):
139 columnsWithSuspiciouslyNoisyPixels = []
141 for x
in range(startPixel, endPixel):
143 columnPixels = [hist.GetBinContent(x, y + 1)
for y
in range(row * self.
rocMaxRow, (row + 1) * self.
rocMaxRow)]
144 columnSum = sum(columnPixels)
146 columnMean = columnSum / len(columnPixels)
147 for i
in range(len(columnPixels)):
151 columnsWithSuspiciouslyNoisyPixels.append(x)
156 pixelArr.append(columnSum)
158 if len(pixelArr) == 0:
159 return None,
None,
None 161 medFiltRes, sciPyMedFiltRes = deepcopy(pixelArr), deepcopy(pixelArr)
162 for i
in range(repeatFilter):
163 sciPyMedFiltRes = signal.medfilt(sciPyMedFiltRes, filterKernelSize)
166 return pixelArr, medFiltRes, columnsWithSuspiciouslyNoisyPixels, sciPyMedFiltRes
169 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))]
172 c_min, c_max =
min(pixelArr),
max(pixelArr)
174 c_diff_inv = 1.0 / (c_max - c_min)
175 return [ (pixelArr[i] - c_min) * c_diff_inv
for i
in range(len(pixelArr))]
176 return [0
for i
in range(len(pixelArr))]
179 c_diff_inv = 1.0 / (1.0 - pt)
181 return [ (pixelArr[i] - pt) * c_diff_inv
for i
in range(len(pixelArr))]
183 def __determineBarrelNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, val, pos, rocCol, rocRow):
191 if pos
not in columnsWithSuspiciouslyNoisyPixels:
193 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))
201 def __determineBarrelNoise2(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, normVal, pos, rocCol, rocRow):
209 if pos
not in columnsWithSuspiciouslyNoisyPixels:
211 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))
219 def __determineEndcapNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal, val, pos, rocCol, rocRow):
228 if pos
not in columnsWithSuspiciouslyNoisyPixels:
230 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))
242 tempXCoordInROC = histXpos % self.
rocMaxCol 244 realXROC, realYROC = tempXROC, tempYROC
245 xCoordInROC = tempXCoordInROC
249 if histName.find(
"BPix_Bp") != -1:
250 realYROC = 1 - tempYROC
252 rocNum = 15 - realXROC
253 xCoordInROC = self.
rocMaxCol - 1 - xCoordInROC
257 realXROC = 7 - tempXROC
259 rocNum = 15 - realXROC
262 xCoordInROC = self.
rocMaxCol - 1 - xCoordInROC
264 return rocNum, xCoordInROC
267 def __determineBarrelDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, pixelArrWithoutDrops, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile):
268 meanOfPixels = sum(medFiltRes) / len(medFiltRes)
269 maxMed =
max(medFiltRes)
270 minMed =
min(medFiltRes)
272 normMeanOfPixels = sum(pixelArrWithoutDrops) / len(pixelArrWithoutDrops)
280 for i
in range(1, len(pixelArr) - 2):
282 bin1valDiff = minMed - pixelArr[i + 0]
283 bin2valDiff = minMed - pixelArr[i + 1]
285 bin0valDiff = minMed - pixelArr[i - 1]
286 bin3valDiff = minMed - pixelArr[i + 2]
291 if bin1valDiff > currentDoubleBinThreshold
and bin2valDiff > currentDoubleBinThreshold
and not bin3valDiff > currentDoubleBinThreshold
and not bin0valDiff > currentDoubleBinThreshold:
293 doubleColInRoc = ((i + startPixel) % (self.
rocMaxCol)) // 2 + 1
294 doubleDeadCols = doubleDeadCols + 1
298 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))
311 res = self.
__determineBarrelNoise2(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, pixelArrWithoutDrops[i], startPixel + i, rocCol, rocRow)
312 noisyColsNum, noisyROC = noisyColsNum + res[0], res[1]
313 if i == len(pixelArr) - 3:
314 res = self.
__determineBarrelNoise2(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, pixelArrWithoutDrops[i + 1], startPixel + i + 1, rocCol, rocRow)
315 noisyColsNum, noisyROC = noisyColsNum + res[0], res[1]
319 return doubleDeadCols, noisyColsNum
328 a, b, D = self.
__lmsLin(medFiltRes, startPixel, len(medFiltRes) + startPixel)
330 meanOfPixels = sum(medFiltRes) / len(medFiltRes)
333 for i
in range(1, len(pixelArr) - 2):
336 linVal1 = a * (i + startPixel + 0) + b
337 linVal2 = a * (i + startPixel + 1) + b
339 linVal0 = a * (i + startPixel - 1) + b
340 linVal3 = a * (i + startPixel + 2) + b
342 linVal1 = b * math.exp(a * (i + startPixel + 0))
343 linVal2 = b * math.exp(a * (i + startPixel + 1))
345 linVal0 = b * math.exp(a * (i + startPixel - 1))
346 linVal3 = b * math.exp(a * (i + startPixel + 2))
348 bin1valDiff = linVal1 - pixelArr[i + 0]
349 bin2valDiff = linVal2 - pixelArr[i + 1]
351 bin0valDiff = linVal0 - pixelArr[i - 1]
352 bin3valDiff = linVal3 - pixelArr[i + 2]
360 if bin1valDiff > currentDoubleBinThreshold
and bin2valDiff > currentDoubleBinThreshold
and not bin3valDiff > currentDoubleBinThreshold
and not bin0valDiff > currentDoubleBinThreshold:
362 doubleColInRoc = ((i + startPixel) % (self.
rocMaxCol)) // 2 + 1
363 doubleDeadCols = doubleDeadCols + 1
367 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))
374 res = self.
__determineEndcapNoise(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal1, pixelArr[i], i + startPixel, rocCol, rocRow)
375 noisyColsNum, noisyROC = noisyColsNum + res[0], res[1]
376 if i == len(pixelArr) - 3:
377 res = self.
__determineEndcapNoise(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal2, pixelArr[i + 1], i + 1 + startPixel, rocCol, rocRow)
378 noisyColsNum, noisyROC = noisyColsNum + res[0], res[1]
380 return doubleDeadCols, noisyColsNum
383 doubleDeadCols, noisyColsNum = 0, 0
389 doubleDeadColsInLayer, noisyColsNumInLayer = 0, 0
391 outputFile.write(
"-> " + layer +
"\n\n")
392 noiseFile.write(
"-> " + layer +
"\n\n")
398 endPixel = (rocNum + 1) * self.
rocMaxCol + 1
402 pixelArr, medFiltRes, columnsWithSuspiciouslyNoisyPixels, sciPyMedFiltRes = self.
__getROCData(hist, startPixel, endPixel, row, 3, 5)
415 pixelArrWithoutDropsNormalized = self.
__normalizeArray(pixelArrWithoutDrops)
420 result = self.
__determineBarrelDColInefficiencyAndNoise(medFiltRes, hist.GetName(), pixelArr, pixelArrWithoutDropsNormalized, startPixel, rocCol, row, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile)
424 doubleDeadCols, doubleDeadColsInLayer = doubleDeadCols + result[0], doubleDeadColsInLayer + result[0]
425 noisyColsNum, noisyColsNumInLayer = noisyColsNum + result[1], noisyColsNumInLayer + result[1]
427 outputFile.write(
"\n\tTOTAL IN LAYER/DISK: %d\n\n" % (doubleDeadColsInLayer))
428 noiseFile.write(
"\n\tTOTAL IN LAYER/DISK: %d\n\n" % (noisyColsNumInLayer))
430 print(
"Number of inefficient double columns: %d"%(doubleDeadCols))
431 print(
"Number of noisy cols: %d"%(noisyColsNum))
435 for i
in range(1, len(sys.argv), 1):
437 inputFileName = sys.argv[i]
439 runNum = ((inputFileName.split(
"/")[-1].
split(
"."))[0].
split(
"_R000"))[1]
440 print(
"Run number: %s"%(runNum))
441 baseRootDir = [
"DQMData/Run " + runNum +
"/PixelPhase1/Run summary/Phase1_MechanicalView"]
442 print(baseRootDir[0])
443 outputFileName =
"inefficientDPixelColumns.txt" 444 noiseOutputFileName =
"noisyPixelColumns.txt" 446 readerObj =
InefficientDeadROCs(inputFileName, outputFileName, noiseOutputFileName, baseRootDir)
447 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)
S & print(S &os, JobReport::InputFile const &f)
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)