diff --git a/Calibration/EcalAlCaRecoProducers/test/nPU_mc.py b/Calibration/EcalAlCaRecoProducers/test/nPU_mc.py index baba314833bb8..4314918008f48 100644 --- a/Calibration/EcalAlCaRecoProducers/test/nPU_mc.py +++ b/Calibration/EcalAlCaRecoProducers/test/nPU_mc.py @@ -1,6 +1,6 @@ import math import ROOT -from ROOT import * +from ROOT import gSystem, TH1F from DataFormats.FWLite import Events, Handle from PhysicsTools.PythonAnalysis import * #import print_options diff --git a/Calibration/EcalAlCaRecoProducers/test/reRecoValidation.py b/Calibration/EcalAlCaRecoProducers/test/reRecoValidation.py index a957e2f565417..0a667b58f2f19 100644 --- a/Calibration/EcalAlCaRecoProducers/test/reRecoValidation.py +++ b/Calibration/EcalAlCaRecoProducers/test/reRecoValidation.py @@ -1,6 +1,6 @@ import math import ROOT -from ROOT import * +from ROOT import gSystem, TH2F, gStyle from DataFormats.FWLite import Events, Handle from PhysicsTools.PythonAnalysis import * #import print_options diff --git a/Calibration/EcalAlCaRecoProducers/test/recHitsValidation.py b/Calibration/EcalAlCaRecoProducers/test/recHitsValidation.py index ffeddf2124ebb..28859ff0b3dcc 100644 --- a/Calibration/EcalAlCaRecoProducers/test/recHitsValidation.py +++ b/Calibration/EcalAlCaRecoProducers/test/recHitsValidation.py @@ -1,6 +1,6 @@ import math import ROOT -from ROOT import * +from ROOT import gSystem, TH2F from DataFormats.FWLite import Events, Handle from PhysicsTools.PythonAnalysis import * #import print_options diff --git a/CondCore/PopCon/test/fetchCronLogTail.py b/CondCore/PopCon/test/fetchCronLogTail.py index 768f35b8ea9b0..54e51e6450328 100644 --- a/CondCore/PopCon/test/fetchCronLogTail.py +++ b/CondCore/PopCon/test/fetchCronLogTail.py @@ -4,7 +4,6 @@ import os, sys, re import string import math -from ROOT import * import cx_Oracle import time diff --git a/DQM/SiStripMonitorClient/scripts/DeadROC_duringRun.py b/DQM/SiStripMonitorClient/scripts/DeadROC_duringRun.py index 6c7943310465b..6bda8f2c2a0e0 100755 --- a/DQM/SiStripMonitorClient/scripts/DeadROC_duringRun.py +++ b/DQM/SiStripMonitorClient/scripts/DeadROC_duringRun.py @@ -3,7 +3,7 @@ from __future__ import print_function import sys import string -from ROOT import * +from ROOT import TFile from array import array def getFileInPath(rfile): diff --git a/DQM/SiStripMonitorClient/scripts/InefficientDoubleROC.py b/DQM/SiStripMonitorClient/scripts/InefficientDoubleROC.py index ec3d3a8470a08..22adff7dad1c6 100755 --- a/DQM/SiStripMonitorClient/scripts/InefficientDoubleROC.py +++ b/DQM/SiStripMonitorClient/scripts/InefficientDoubleROC.py @@ -3,7 +3,7 @@ from __future__ import print_function import sys import math -from ROOT import * +from ROOT import gROOT, TClass, TFile from copy import deepcopy from scipy import signal @@ -11,9 +11,9 @@ class InefficientDeadROCs: ############################################################################ - + def __TraverseDirTree(self, dir): - + for obj in dir.GetListOfKeys(): if not obj.IsFolder(): if obj.ReadObjectAny(TClass.GetClass("TH2")): @@ -23,7 +23,7 @@ def __TraverseDirTree(self, dir): # print(''.join([dir.GetPath(), '/', name])) newName = name.split(self.lookForStr)[1] th1.SetName(newName) - + # used to sort outputs by disk/layer layer = 0 # print(newName) @@ -34,60 +34,60 @@ def __TraverseDirTree(self, dir): if newName.startswith("FPix_Bm"): layer = "-" + layer layer = "F" + layer - + if layer in self.dicOfModuleHistograms: self.dicOfModuleHistograms[layer].append(th1) else: - self.dicOfModuleHistograms.update({layer : [th1]}) + self.dicOfModuleHistograms.update({layer : [th1]}) else: self.__TraverseDirTree(obj.ReadObj()) - + def __init__(self, inputDQMName, outputFileName, noiseOutputFileName, dirs): - + self.inputFileName = inputDQMName self.outputFileName = outputFileName self.noiseOutputFileName = noiseOutputFileName self.dirs = dirs - + self.lookForStr = "digi_occupancy_per_col_per_row_" - + self.rocMaxCol = 52 self.rocMaxRow = 80 self.rocsInRow = 8 self.rocsInCol = 2 - + self.inputFile = TFile(self.inputFileName) self.dicOfModuleHistograms = {} - + ### THRESHOLDS SECTION self.pixelNoisynessTh = 6 self.rocOccupancyTh = 200 - + self.barrelNoisyColumnTh = 1.35 self.barrelNoisyColumnTh2 = 4.5 self.endcapNoisyColumnTh = 1.5 - + self.barrelInefficientDColTh = 8#2.5 self.endcapInefficientDColTh = 30#8 - + ### ################### - + if self.inputFile.IsOpen(): print("%s opened successfully!" % (self.inputFileName)) #Get all neeeded histograms for dir in self.dirs: self.__TraverseDirTree(self.inputFile.Get(dir)) print("Histograms to read: %d" % (len(self.dicOfModuleHistograms))) - + self.detDict = {} - + else: print("Unable to open file %s" % (self.inputFileName)) - + def __lmsExp(self, data, xMin, xMax): meanOfX = (xMax + xMin) * 0.5 meanOfY = sum( [math.log(data[i]) for i in range(len(data))] ) / len(data) - + D = 0 for i in range(xMin, xMax + 1): D = D + (i - meanOfX)**2 @@ -97,15 +97,15 @@ def __lmsExp(self, data, xMin, xMax): for i in range(len(data)): a = a + math.log(data[i]) * (xMin + i - meanOfX) a = a/D - + lnb = meanOfY - a * meanOfX - + return a, math.exp(lnb) - + def __lmsLin(self, data, xMin, xMax): meanOfX = (xMax + xMin) * 0.5 meanOfY = sum(data) / len(data) - + D = 0 for i in range(xMin, xMax + 1): D = D + (i - meanOfX)**2 @@ -114,11 +114,11 @@ def __lmsLin(self, data, xMin, xMax): for i in range(len(data)): a = a + data[i] * (xMin + i - meanOfX) a = a/D - + b = meanOfY - a * meanOfX - + return a, b, D - + def __customMedianFilter(self, array, radius = 2): # contrary to scipy implementation it provides adaptive kernel size instead of copying data on boundaries filtered = [0 for i in range(len(array))] @@ -128,58 +128,58 @@ def __customMedianFilter(self, array, radius = 2): currArray = array[0 : i + radius + 1] elif i + radius + 1 >= len(array): currArray = array[i - radius : ] - + currArray.sort() filtered[i] = currArray[len(currArray) // 2] - + return filtered - + def __getROCData(self, hist, startPixel, endPixel, row, repeatFilter = 3, filterKernelSize = 5): pixelArr = [] columnsWithSuspiciouslyNoisyPixels = [] - + for x in range(startPixel, endPixel): - + columnPixels = [hist.GetBinContent(x, y + 1) for y in range(row * self.rocMaxRow, (row + 1) * self.rocMaxRow)] columnSum = sum(columnPixels) - + columnMean = columnSum / len(columnPixels) for i in range(len(columnPixels)): if columnPixels[i] > self.pixelNoisynessTh * columnMean: # col = (startPixel % self.rocMaxCol) + 1 - + columnsWithSuspiciouslyNoisyPixels.append(x) - + # print("WARNING:\t %s : %dx%d:%d may contain NOISY PIXELS instead of NOISY COLUMNS" % (hist.GetName(), col, row + 1, startPixel + i)) break - - pixelArr.append(columnSum) - + + pixelArr.append(columnSum) + if len(pixelArr) == 0: return None, None, None # ROC down - + medFiltRes, sciPyMedFiltRes = deepcopy(pixelArr), deepcopy(pixelArr) for i in range(repeatFilter): sciPyMedFiltRes = signal.medfilt(sciPyMedFiltRes, filterKernelSize) # 5 is obligatory to filter doublets!!! medFiltRes = self.__customMedianFilter(medFiltRes, filterKernelSize // 2) - + return pixelArr, medFiltRes, columnsWithSuspiciouslyNoisyPixels, sciPyMedFiltRes - + def __getPixelArrWithRemovedDrops(self, pixelArr, medFiltRes): 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))] - + def __normalizeArray(self, pixelArr): c_min, c_max = min(pixelArr), max(pixelArr) if c_min != c_max: c_diff_inv = 1.0 / (c_max - c_min) return [ (pixelArr[i] - c_min) * c_diff_inv for i in range(len(pixelArr))] return [0 for i in range(len(pixelArr))] - + def __setNormalizedArrayZeroInThePoint(self, pixelArr, pt): c_diff_inv = 1.0 / (1.0 - pt) - + return [ (pixelArr[i] - pt) * c_diff_inv for i in range(len(pixelArr))] - + def __determineBarrelNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, val, pos, rocCol, rocRow): noisyROC = False; if meanOfPixels < self.rocOccupancyTh: @@ -191,13 +191,13 @@ def __determineBarrelNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, if pos not in columnsWithSuspiciouslyNoisyPixels: rocNum, xCoordInROC = self.__convertCoordinatesFromHistToROCSpace(histName, pos, rocRow) 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)) - + return 1, noisyROC # else: # print("WARNING: rejecting %s (x, row) (%d, %d) as being affected by a few noisy pixel(s)" % (histName, pos, rocRow+1)) - + return 0, noisyROC - + def __determineBarrelNoise2(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, normVal, pos, rocCol, rocRow): noisyROC = False; if meanOfPixels < self.rocOccupancyTh: @@ -209,43 +209,43 @@ def __determineBarrelNoise2(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, if pos not in columnsWithSuspiciouslyNoisyPixels: rocNum, xCoordInROC = self.__convertCoordinatesFromHistToROCSpace(histName, pos, rocRow) 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)) - + return 1, noisyROC # else: # print("WARNING: rejecting %s (x, row) (%d, %d) as being affected by a few noisy pixel(s)" % (histName, pos, rocRow+1)) - + return 0, noisyROC - + def __determineEndcapNoise(self, noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal, val, pos, rocCol, rocRow): noisyROC = False; if meanOfPixels < self.rocOccupancyTh: # print("Very low mean occupancy: %f in %s in (col, row) (%d, %d)...\tSkipping noisy ROC calculation" % (meanOfPixels, histName, rocCol, rocRow) ) noisyROC = True - + else: th = self.endcapNoisyColumnTh * linVal if val > th: if pos not in columnsWithSuspiciouslyNoisyPixels: rocNum, xCoordInROC = self.__convertCoordinatesFromHistToROCSpace(histName, pos, rocRow) 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)) - + return 1, noisyROC # else: # print("WARNING: rejecting %s (x, row) (%d, %d) as being affected by a few noisy pixel(s)" % (histName, pos, rocRow+1)) - + return 0, noisyROC - + def __convertCoordinatesFromHistToROCSpace(self, histName, histXpos, histRow): tempXROC = (histXpos / self.rocMaxCol) # 0,...,7 tempYROC = histRow - + tempXCoordInROC = histXpos % self.rocMaxCol - + realXROC, realYROC = tempXROC, tempYROC xCoordInROC = tempXCoordInROC - + rocNum = 0 - + if histName.find("BPix_Bp") != -1: #zero ROC is in top left corner realYROC = 1 - tempYROC if realYROC == 1: @@ -260,22 +260,22 @@ def __convertCoordinatesFromHistToROCSpace(self, histName, histXpos, histRow): else: rocNum = realXROC xCoordInROC = self.rocMaxCol - 1 - xCoordInROC - + return rocNum, xCoordInROC - - + + def __determineBarrelDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, pixelArrWithoutDrops, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile): meanOfPixels = sum(medFiltRes) / len(medFiltRes) maxMed = max(medFiltRes) - minMed = min(medFiltRes) + minMed = min(medFiltRes) normMeanOfPixels = sum(pixelArrWithoutDrops) / len(pixelArrWithoutDrops) # print( meanOfPixels, maxMed, minMed ) - + doubleDeadCols = 0 noisyColsNum = 0 noisyROC = 0 - + # for x in range(startPixel, endPixel, 1): for i in range(1, len(pixelArr) - 2): # print(i , i + 1) @@ -284,15 +284,15 @@ def __determineBarrelDColInefficiencyAndNoise(self, medFiltRes, histName, pixelA # WE ONLY WANT A SET OF TWO COLUMNS SO ADJACENT COLUMNS HAVE TO BE NORMAL bin0valDiff = minMed - pixelArr[i - 1] bin3valDiff = minMed - pixelArr[i + 2] - + # currentDoubleBinThreshold = minMed / math.sqrt(meanOfPixels) * self.barrelInefficientDColTh # error in bin entry grows as sqrt(N) currentDoubleBinThreshold = math.sqrt(meanOfPixels) * self.barrelInefficientDColTh # error in bin entry grows as sqrt(N) - + if bin1valDiff > currentDoubleBinThreshold and bin2valDiff > currentDoubleBinThreshold and not bin3valDiff > currentDoubleBinThreshold and not bin0valDiff > currentDoubleBinThreshold: doubleColInRoc = ((i + startPixel) % (self.rocMaxCol)) // 2 + 1 doubleDeadCols = doubleDeadCols + 1 - + # 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])) rocNum, xCoordInROC = self.__convertCoordinatesFromHistToROCSpace(histName, startPixel + i, rocRow) 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)) @@ -300,68 +300,68 @@ def __determineBarrelDColInefficiencyAndNoise(self, medFiltRes, histName, pixelA # HANDLE NOISY PIXELS if noisyROC == True: #don't go inside if noisyness was determined already continue - + # res = self.__determineBarrelNoise(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, pixelArr[i], startPixel + i, rocCol, rocRow) # noisyColsNum, noisyROC = noisyColsNum + res[0], res[1] # if i == len(pixelArr) - 3: # CHECK NOISYNESS IN THE RIGHTMOST INNER COL # res = self.__determineBarrelNoise(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, maxMed, pixelArr[i + 1], startPixel + i + 1, rocCol, rocRow) - # noisyColsNum, noisyROC = noisyColsNum + res[0], res[1] - + # noisyColsNum, noisyROC = noisyColsNum + res[0], res[1] + # NORMALIZED MEAN NOISE DETERMINATION METHOD res = self.__determineBarrelNoise2(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, pixelArrWithoutDrops[i], startPixel + i, rocCol, rocRow) noisyColsNum, noisyROC = noisyColsNum + res[0], res[1] if i == len(pixelArr) - 3: # CHECK NOISYNESS IN THE RIGHTMOST INNER COL res = self.__determineBarrelNoise2(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, normMeanOfPixels, pixelArrWithoutDrops[i + 1], startPixel + i + 1, rocCol, rocRow) noisyColsNum, noisyROC = noisyColsNum + res[0], res[1] - - - + + + return doubleDeadCols, noisyColsNum - + def __determineEndcapDColInefficiencyAndNoise(self, medFiltRes, histName, pixelArr, startPixel, rocCol, rocRow, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile): doubleDeadCols = 0 noisyColsNum = 0 noisyROC = 0 - + useLin = True # might be used for high noise ROC recognition a, b, D = self.__lmsLin(medFiltRes, startPixel, len(medFiltRes) + startPixel) - + meanOfPixels = sum(medFiltRes) / len(medFiltRes) - + # for x in range(startPixel, endPixel, 1): for i in range(1, len(pixelArr) - 2): - + if useLin == True: linVal1 = a * (i + startPixel + 0) + b linVal2 = a * (i + startPixel + 1) + b - + linVal0 = a * (i + startPixel - 1) + b linVal3 = a * (i + startPixel + 2) + b else: linVal1 = b * math.exp(a * (i + startPixel + 0)) linVal2 = b * math.exp(a * (i + startPixel + 1)) - + linVal0 = b * math.exp(a * (i + startPixel - 1)) linVal3 = b * math.exp(a * (i + startPixel + 2)) - + bin1valDiff = linVal1 - pixelArr[i + 0] bin2valDiff = linVal2 - pixelArr[i + 1] # WE ONLY WANT A SET OF TWO COLUMNS SO ADJACENT COLUMNS HAVE TO BE NORMAL bin0valDiff = linVal0 - pixelArr[i - 1] - bin3valDiff = linVal3 - pixelArr[i + 2] - + bin3valDiff = linVal3 - pixelArr[i + 2] + try: currentDoubleBinThreshold = math.sqrt((linVal1 + linVal2) * 0.5) * self.endcapInefficientDColTh except: # print(a, b, startPixel, i, linVal1, linVal2) continue - + if bin1valDiff > currentDoubleBinThreshold and bin2valDiff > currentDoubleBinThreshold and not bin3valDiff > currentDoubleBinThreshold and not bin0valDiff > currentDoubleBinThreshold: doubleColInRoc = ((i + startPixel) % (self.rocMaxCol)) // 2 + 1 doubleDeadCols = doubleDeadCols + 1 - + # 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])) rocNum, xCoordInROC = self.__convertCoordinatesFromHistToROCSpace(histName, startPixel + i, rocRow) 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)) @@ -370,67 +370,67 @@ def __determineEndcapDColInefficiencyAndNoise(self, medFiltRes, histName, pixelA # HANDLE NOISY PIXELS if noisyROC == True: #don't go inside if noisyness was determined already continue - + res = self.__determineEndcapNoise(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal1, pixelArr[i], i + startPixel, rocCol, rocRow) noisyColsNum, noisyROC = noisyColsNum + res[0], res[1] if i == len(pixelArr) - 3: # CHECK NOISYNESS IN THE RIGHTMOST INNER COL res = self.__determineEndcapNoise(noiseFile, columnsWithSuspiciouslyNoisyPixels, histName, meanOfPixels, linVal2, pixelArr[i + 1], i + 1 + startPixel, rocCol, rocRow) noisyColsNum, noisyROC = noisyColsNum + res[0], res[1] - + return doubleDeadCols, noisyColsNum - - def ReadHistograms(self): + + def ReadHistograms(self): doubleDeadCols, noisyColsNum = 0, 0 - - with open(self.noiseOutputFileName, "w") as noiseFile: - with open(self.outputFileName, "w") as outputFile: + + with open(self.noiseOutputFileName, "w") as noiseFile: + with open(self.outputFileName, "w") as outputFile: for layer in self.dicOfModuleHistograms: - + doubleDeadColsInLayer, noisyColsNumInLayer = 0, 0 - + outputFile.write("-> " + layer + "\n\n") noiseFile.write("-> " + layer + "\n\n") - - for hist in self.dicOfModuleHistograms[layer]: - for row in range(2): + + for hist in self.dicOfModuleHistograms[layer]: + for row in range(2): for rocNum in range(self.rocsInRow): startPixel = rocNum * self.rocMaxCol + 1 endPixel = (rocNum + 1) * self.rocMaxCol + 1 # - 1 ??? - + rocCol = rocNum + 1 - + pixelArr, medFiltRes, columnsWithSuspiciouslyNoisyPixels, sciPyMedFiltRes = self.__getROCData(hist, startPixel, endPixel, row, 3, 5) - + if pixelArr == None: continue - + # meanOfPixels = sum(pixelArr) / len(pixelArr) # pixelArrSorted = deepcopy(pixelArr) # pixelArrSorted.sort() # outputFile.write("%s: VS. | 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])) - + if "F" not in layer: # pixelArrWithoutDrops = self.__getPixelArrWithRemovedDrops(pixelArr, medFiltRes) pixelArrWithoutDrops = self.__getPixelArrWithRemovedDrops(pixelArr, sciPyMedFiltRes) pixelArrWithoutDropsNormalized = self.__normalizeArray(pixelArrWithoutDrops) # tmp_mean = sum(pixelArrWithoutDropsNormalized) / len(pixelArrWithoutDropsNormalized) # pixelArrWithoutDropsNormalized = self.__setNormalizedArrayZeroInThePoint(pixelArrWithoutDropsNormalized, tmp_mean) - + # print(min(pixelArrWithoutDropsNormalized), max(pixelArrWithoutDropsNormalized)) result = self.__determineBarrelDColInefficiencyAndNoise(medFiltRes, hist.GetName(), pixelArr, pixelArrWithoutDropsNormalized, startPixel, rocCol, row, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile) else: result = self.__determineEndcapDColInefficiencyAndNoise(medFiltRes, hist.GetName(), pixelArr, startPixel, rocCol, row, outputFile, columnsWithSuspiciouslyNoisyPixels, noiseFile) - + doubleDeadCols, doubleDeadColsInLayer = doubleDeadCols + result[0], doubleDeadColsInLayer + result[0] - noisyColsNum, noisyColsNumInLayer = noisyColsNum + result[1], noisyColsNumInLayer + result[1] - - outputFile.write("\n\tTOTAL IN LAYER/DISK: %d\n\n" % (doubleDeadColsInLayer)) + noisyColsNum, noisyColsNumInLayer = noisyColsNum + result[1], noisyColsNumInLayer + result[1] + + outputFile.write("\n\tTOTAL IN LAYER/DISK: %d\n\n" % (doubleDeadColsInLayer)) noiseFile.write("\n\tTOTAL IN LAYER/DISK: %d\n\n" % (noisyColsNumInLayer)) - + print("Number of inefficient double columns: %d"%(doubleDeadCols)) print("Number of noisy cols: %d"%(noisyColsNum)) - - + + #--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-- for i in range(1, len(sys.argv), 1): if i == 1: @@ -443,5 +443,5 @@ def ReadHistograms(self): outputFileName = "inefficientDPixelColumns.txt" noiseOutputFileName = "noisyPixelColumns.txt" -readerObj = InefficientDeadROCs(inputFileName, outputFileName, noiseOutputFileName, baseRootDir) +readerObj = InefficientDeadROCs(inputFileName, outputFileName, noiseOutputFileName, baseRootDir) readerObj.ReadHistograms() diff --git a/DQM/SiStripMonitorClient/scripts/PhaseITreeProducer.py b/DQM/SiStripMonitorClient/scripts/PhaseITreeProducer.py index 192d05b2be5c2..a1ed4718aa5b6 100644 --- a/DQM/SiStripMonitorClient/scripts/PhaseITreeProducer.py +++ b/DQM/SiStripMonitorClient/scripts/PhaseITreeProducer.py @@ -2,7 +2,7 @@ from __future__ import print_function import sys -from ROOT import * +from ROOT import TTree, TFile, gROOT, TClass from array import array from copy import deepcopy diff --git a/DQM/SiStripMonitorClient/scripts/PixelMapPlotter.py b/DQM/SiStripMonitorClient/scripts/PixelMapPlotter.py index 43c9da887c93a..6ffb2ec24d3c6 100755 --- a/DQM/SiStripMonitorClient/scripts/PixelMapPlotter.py +++ b/DQM/SiStripMonitorClient/scripts/PixelMapPlotter.py @@ -1,10 +1,10 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python3 from __future__ import print_function import ROOT import sys import getopt -from ROOT import * +from ROOT import TBox, TLatex, TClass from copy import deepcopy diff --git a/DQM/SiStripMonitorClient/scripts/TH2PolyOfflineMaps.py b/DQM/SiStripMonitorClient/scripts/TH2PolyOfflineMaps.py index 9d01390977c72..770dca30e0bc7 100644 --- a/DQM/SiStripMonitorClient/scripts/TH2PolyOfflineMaps.py +++ b/DQM/SiStripMonitorClient/scripts/TH2PolyOfflineMaps.py @@ -3,7 +3,7 @@ from __future__ import print_function import sys import os -from ROOT import * +from ROOT import gROOT, gStyle, gPad, TCanvas, TClass, TGraph, TFile, TArrow, TLatex, TH2Poly, kBlack from copy import deepcopy from array import array @@ -12,9 +12,9 @@ #Find Data files def getFileInPath(rfile): - import os + import os for dir in os.environ['CMSSW_SEARCH_PATH'].split(":"): - if os.path.exists(os.path.join(dir,rfile)): return os.path.join(dir,rfile) + if os.path.exists(os.path.join(dir,rfile)): return os.path.join(dir,rfile) return None @@ -29,8 +29,8 @@ def getFileInPath(rfile): baseRootDirs = ["DQMData/Run 292154/PixelPhase1/Run summary/Phase1_MechanicalView" ,"DQMData/Run 292154/PixelPhase1/Run summary/Tracks" ] - - + + maxPxBarrel = 4 maxPxForward = 3 barrelLadderShift = [0, 14, 44, 90] @@ -58,21 +58,21 @@ def getFileInPath(rfile): "size 0.01 15 0 0",] class TH2PolyOfflineMaps: - + ### # LOTS OF CODE BORROWED FROM: PYTHONBINREADER, PIXELTRACKERMAP ### - + ############################################################################ - + def __TraverseDirTree(self, dir): - + try: currPath = (dir.GetPath().split(":/"))[1] except: print("Exception raised: Path not found in the input file") return - + for obj in dir.GetListOfKeys(): if not obj.IsFolder(): if obj.ReadObjectAny(TClass.GetClass("TH2")): @@ -80,7 +80,7 @@ def __TraverseDirTree(self, dir): name = th2.GetName() if 6 < th2.GetNbinsX() < 10 and name.find("per") != -1 and name.find("Lumisection") == -1: #take only module lvl plots print(''.join([dir.GetPath(), '/', name])) - + # fix when there are plots starting with the same strings in different directories prefix = "" for i in self.dirs: @@ -91,8 +91,8 @@ def __TraverseDirTree(self, dir): th2.SetName(prefix + th2.GetName()) self.listOfNumHistograms.append(th2) else: - self.__TraverseDirTree(obj.ReadObj()) - + self.__TraverseDirTree(obj.ReadObj()) + def __GetPartStr(self, isXlowerThanZero, isYlowerThanZero): if isXlowerThanZero and isYlowerThanZero: return "mO" @@ -102,15 +102,15 @@ def __GetPartStr(self, isXlowerThanZero, isYlowerThanZero): return "pO" if isXlowerThanZero == False and isYlowerThanZero == False: return "pI" - + def __GetBarrelSector(self, layer, signedLadder, signedModule): #adapted from PixelBarrelName theLadder = abs(signedLadder) theModule = abs(signedModule) - + sector = 0 - + if layer == 1: - + if theLadder == 1: if theModule >= 2: return 1 @@ -158,23 +158,23 @@ def __GetBarrelSector(self, layer, signedLadder, signedModule): #adapted from Pi elif layer == 4: sector = (theLadder + 3) // 4 return sector - + def __BuildOnlineBarrelName(self, signedModule, signedLadder, layer): #in Phase1 it is assumed that there are only full modules thePart = self.__GetPartStr(signedModule < 0, signedLadder < 0) theSector = str(self.__GetBarrelSector(layer, signedLadder, signedModule)) return "BPix_B" + thePart + "_SEC" + theSector + "_LYR" + str(layer) + "_LDR" + str(abs(signedLadder)) + "F_MOD" + str(abs(signedModule)) - + def __BuildOnlineDiskName(self, signedDisk, signedBlade, panel, ring): thePart = self.__GetPartStr(signedDisk < 0, signedBlade < 0) - return "FPix_B" + thePart + "_D" + str(abs(signedDisk)) + "_BLD" + str(abs(signedBlade)) + "_PNL" + str(panel) + "_RNG" + str(ring) - + return "FPix_B" + thePart + "_D" + str(abs(signedDisk)) + "_BLD" + str(abs(signedBlade)) + "_PNL" + str(panel) + "_RNG" + str(ring) + def __GroupHistograms(self): currentGroupName = "" groupOfHists = [] self.groupedHistograms = [] - + ##### GROUP ALL LAYERS/RINGS HAVING SIMILAR INFORMATION - for obj in self.listOfNumHistograms: + for obj in self.listOfNumHistograms: objName = obj.GetName() objNameSplit = objName.split("_") objNameCollected = ''.join(objNameSplit[0:-1]) @@ -182,11 +182,11 @@ def __GroupHistograms(self): if len(groupOfHists): self.groupedHistograms.append(groupOfHists) groupOfHists = [] - + currentGroupName = objNameCollected groupOfHists.append(obj) self.groupedHistograms.append(groupOfHists) #the last group - + def __AddNamedBins(self, geoFile, tX, tY, sX, sY, applyModuleRotation = False): for line in geoFile: @@ -209,18 +209,18 @@ def __AddNamedBins(self, geoFile, tX, tY, sX, sY, applyModuleRotation = False): #close polygon x.append(x[0]) y.append(y[0]) - + if applyModuleRotation: bin = TGraph(verNum, y, x) else: bin = TGraph(verNum, x, y) # bin = TGraph(verNum, y, x) # rotation by 90 deg (so that it had the same layout as for the strips) bin.SetName(detId) - + self.__BaseTrackerMap.AddBin(bin) - + def __CreateTrackerBaseMap(self): - + self.__BaseTrackerMap = TH2Poly("Summary", "", -10, 160, -70, 70) # self.__BaseTrackerMap = TH2Poly("Summary", "Tracker Map", 0, 0, 0, 0) self.__BaseTrackerMap.SetFloat(1) @@ -228,37 +228,37 @@ def __CreateTrackerBaseMap(self): self.__BaseTrackerMap.GetYaxis().SetTitle("") self.__BaseTrackerMap.SetOption("COLZ L") self.__BaseTrackerMap.SetStats(0) - + # BARREL FIRST for i in range(maxPxBarrel): with open(self.geometryFilenames[i], "r") as geoFile: currBarrelTranslateX = 0 currBarrelTranslateY = barrelLadderShift[i] - + self.__AddNamedBins(geoFile, currBarrelTranslateX, currBarrelTranslateY, 1, 1, True) - + # break # debug only 1st layer - + # MINUS FORWARD for i in range(-maxPxForward, 0): with open(self.geometryFilenames[maxPxBarrel + maxPxForward + i], "r") as geoFile: currForwardTranslateX = forwardDiskXShift[-i - 1] currForwardTranslateY = -forwardDiskYShift - + self.__AddNamedBins(geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1) - + # PLUS FORWARD for i in range(maxPxForward): with open(self.geometryFilenames[maxPxBarrel + maxPxForward + i], "r") as geoFile: currForwardTranslateX = forwardDiskXShift[i] currForwardTranslateY = forwardDiskYShift - + self.__AddNamedBins(geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1) - + # self.__BaseTrackerMap.Fill("305139728", 2) - + print("Base Tracker Map: constructed") - + ############################################################################ def __init__(self, inputDQMName, outputDirName, minMaxFileName, limits, modDicName, runNumber, dirs, dirsAliases): # def __init__(self, inputDQMName, outputDirName, minMaxFileName, limitsFileName, modDicName, runNumber, dirs, dirsAliases): @@ -268,57 +268,57 @@ def __init__(self, inputDQMName, outputDirName, minMaxFileName, limits, modDicN # self.limitsFileName = limitsFileName self.detIDsFileName = modDicName self.limits = limits - + self.runNumber = runNumber self.dirs = dirs self.dirsAliases = dirsAliases - + self.inputFile = TFile(self.inputFileName) self.listOfNumHistograms = [] self.availableNames = [] - + self.maxLadderToLayer = {6:1, 14:2, 22:3, 32:4} self.maxBladeToRing = {11:1, 17:2} - + self.geometryFilenames = [] for i in range(maxPxBarrel): - self.geometryFilenames.append(getFileInPath("DQM/SiStripMonitorClient/data/Geometry/vertices_barrel_" + str(i + 1))) + self.geometryFilenames.append(getFileInPath("DQM/SiStripMonitorClient/data/Geometry/vertices_barrel_" + str(i + 1))) # self.geometryFilenames.append("DATA/Geometry/vertices_barrel_" + str(i + 1)) for i in range(-maxPxForward, maxPxForward + 1): if i == 0: continue #there is no 0 disk self.geometryFilenames.append(getFileInPath("DQM/SiStripMonitorClient/data/Geometry/vertices_forward_" + str(i))) # self.geometryFilenames.append("DATA/Geometry/vertices_forward_" + str(i)) - + self.internalData = {} - + if self.inputFile.IsOpen(): print("%s opened successfully!" % (self.inputFileName)) #Get all neeeded histograms for dir in self.dirs: self.__TraverseDirTree(self.inputFile.Get(dir)) # print("Histograms to read %d" % (len(self.listOfNumHistograms))) - + self.detDict = {} - + with open(self.detIDsFileName, "r") as detIDs: # create dictionary online -> rawid for entry in detIDs: items = entry.replace("\n", " ").split(" ") self.detDict.update({items[1] : int(items[0])}) # init internal data structure self.internalData.update({int(items[0]) : {}}) - - self.rawToOnlineDict = dict((v,k) for k,v in self.detDict.items()) - + + self.rawToOnlineDict = dict((v,k) for k,v in self.detDict.items()) + self.__GroupHistograms() - + self.__CreateTrackerBaseMap() - + else: print("Unable to open file %s" % (self.inputFileName)) - + ### CREATE LIMITS DICTIONARY - + self.limitsDic = {} for y in limits: @@ -326,7 +326,7 @@ def __init__(self, inputDQMName, outputDirName, minMaxFileName, limits, modDicN if len(lineSpl) < 5: continue - + currName = lineSpl[0] zMin = float(lineSpl[1]) zMax = float(lineSpl[2]) @@ -349,11 +349,11 @@ def ReadHistograms(self): for obj in group: nbinsX = obj.GetNbinsX() nbinsY = obj.GetNbinsY() - + if nbinsX == 9: # BARREL maxX = nbinsX // 2 maxY = nbinsY // 2 - + for x in range(-maxX, maxX + 1): if x == 0: continue @@ -361,12 +361,12 @@ def ReadHistograms(self): if y == 0: continue onlineName = self.__BuildOnlineBarrelName(x, y, self.maxLadderToLayer[maxY]) - self.internalData[self.detDict[onlineName]].update({name : obj.GetBinContent(x + maxX + 1, y + maxY + 1)}) - + self.internalData[self.detDict[onlineName]].update({name : obj.GetBinContent(x + maxX + 1, y + maxY + 1)}) + elif nbinsX == 7: # FORWARD maxX = nbinsX // 2 maxY = nbinsY // 4 - + for x in range(-maxX, maxX + 1): if x == 0: continue @@ -375,12 +375,12 @@ def ReadHistograms(self): continue for panel in range(1, 3): onlineName = self.__BuildOnlineDiskName(x, y, panel, self.maxBladeToRing[maxY]) - self.internalData[self.detDict[onlineName]].update({name : obj.GetBinContent(x + maxX + 1, (y + maxY) * 2 + (3-panel))}) + self.internalData[self.detDict[onlineName]].update({name : obj.GetBinContent(x + maxX + 1, (y + maxY) * 2 + (3-panel))}) else: print("Unrecognized plot") else: print("Histograms saved to internal data structure") - + def DumpData(self): for key in self.internalData: print("#"*20) @@ -388,13 +388,13 @@ def DumpData(self): module = self.internalData[key] for d in module: print((d, module[d])) - + print(len(self.internalData)) - + for i in self.availableNames: print(i) print(len(self.availableNames)) - + def PrintTrackerMaps(self): monitoredValues = [] gStyle.SetPalette(1) @@ -402,24 +402,24 @@ def PrintTrackerMaps(self): monitoredValues = self.internalData[key].keys() # print(monitoredValues) break - + if os.path.exists(self.outputDirName) == False: # check whether directory exists os.system("mkdir " + self.outputDirName) - + with open(self.outputDirName + self.minMaxFileName, "w") as minMaxFile: - + for mv in monitoredValues: currentHist = deepcopy(self.__BaseTrackerMap) # currentHist.SetTitle("Run " + self.runNumber + ": Tracker Map for " + mv) // to make it compatible between ROOT v. histoTitle = "Run " + self.runNumber + ": Tracker Map for " + mv - + applyLogScale = False applyAbsValue = False if mv in self.limitsDic: limitsElem = self.limitsDic[mv] - + print(mv + " found in limits dictionary - applying custom limits...") - + currentHist.SetMinimum(limitsElem["zMin"]) currentHist.SetMaximum(limitsElem["zMax"]) applyLogScale = limitsElem["isLog"] @@ -440,26 +440,26 @@ def PrintTrackerMaps(self): currentHist.Fill(str(nameId), abs(val)) else: currentHist.Fill(str(nameId), val) - + listOfVals = sorted(listOfVals, key = lambda item: item[0]) - + minMaxFile.write("\n" + mv + "\n\n") - + minMaxFile.write("MIN:\n") for i in range(extremeBinsNum): minMaxFile.write("\t" + str(listOfVals[i][1]) + " " + str(listOfVals[i][2]) + " " + str(listOfVals[i][0]) + "\n") - + minMaxFile.write("MAX:\n") for i in range(extremeBinsNum): minMaxFile.write("\t" + str(listOfVals[-i - 1][1]) + " " + str(listOfVals[-i - 1][2]) + " " + str(listOfVals[-i - 1][0]) + "\n") - + #Canvas name = MyT for both Pixel and Strip Tracker Maps c1 = TCanvas("MyT", "MyT", plotWidth , plotHeight) - + if applyLogScale: c1.SetLogz() - currentHist.Draw("AC COLZ L") + currentHist.Draw("AC COLZ L") gPad.Update() palette = currentHist.FindObject("palette"); @@ -471,10 +471,10 @@ def PrintTrackerMaps(self): ### IMPORTANT - REALTIVE POSITIONING IS MESSY IN CURRENT VERION OF PYROOT ### IT CAN CHANGE FROM VERSION TO VERSION, SO YOU HAVE TO ADJUST IT FOR YOUR NEEDS ### !!!!!!!!!!!!! - + # draw axes (z, phi -> BARREL; x, y -> FORWARD) ################################################### - + ### z arrow arrow = TArrow(0.05, 27.0, 0.05, -30.0, 0.02, "|>") arrow.SetLineWidth(4) @@ -493,33 +493,33 @@ def PrintTrackerMaps(self): yArrow.Draw() ################################################### - - # add some captions + + # add some captions txt = TLatex() txt.SetNDC() txt.SetTextFont(1) txt.SetTextColor(1) txt.SetTextAlign(22) txt.SetTextAngle(0) - + # draw new-style title txt.SetTextSize(0.05) txt.DrawLatex(0.5, 0.95, histoTitle) - + txt.SetTextSize(0.03) - + txt.DrawLatex(0.5, 0.125, "-DISK") txt.DrawLatex(0.5, 0.075, "NUMBER ->") txt.DrawLatex(0.5, 0.875, "+DISK") - + txt.DrawLatex(0.17, 0.35, "+z") txt.DrawLatexNDC(0.36, 0.685, "+phi") # WAY TO FORCE IT TO DRAW LATEX CORRECTLY NOT FOUND ('#' DOESN'T WORK) txt.DrawLatex(0.38, 0.73, "+x") txt.DrawLatex(0.26, 0.875, "+y") - + txt.SetTextAngle(90) txt.DrawLatex(0.17, 0.5, "BARREL") - + #save to the png c1.Print(self.outputDirName + mv + ".png") @@ -578,7 +578,7 @@ def __del__(self): if self.inputFile : if self.inputFile.IsOpen(): self.inputFile.Close() - + #--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-- for i in range(1, len(sys.argv), 1): if i == 1: @@ -599,13 +599,13 @@ def __del__(self): baseRootDirs = ["DQMData/Run " + deductedRunNumber + "/PixelPhase1/Run summary/Phase1_MechanicalView" #maybe read it from the input file??? ,"DQMData/Run " + deductedRunNumber + "/PixelPhase1/Run summary/Tracks" ] - + baseRootDirsAliases = {baseRootDirs[0]:"" , baseRootDirs[1]:"T" } -readerObj = TH2PolyOfflineMaps(inputFileName, outputDirectoryName, minMaxFileName, limits, detIDsFileName, deductedRunNumber, baseRootDirs, baseRootDirsAliases) -#readerObj = TH2PolyOfflineMaps(inputFileName, outputDirectoryName, minMaxFileName, limitsFileName, detIDsFileName, deductedRunNumber, baseRootDirs, baseRootDirsAliases) +readerObj = TH2PolyOfflineMaps(inputFileName, outputDirectoryName, minMaxFileName, limits, detIDsFileName, deductedRunNumber, baseRootDirs, baseRootDirsAliases) +#readerObj = TH2PolyOfflineMaps(inputFileName, outputDirectoryName, minMaxFileName, limitsFileName, detIDsFileName, deductedRunNumber, baseRootDirs, baseRootDirsAliases) readerObj.ReadHistograms() # readerObj.DumpData() readerObj.PrintTrackerMaps() diff --git a/DQM/SiStripMonitorClient/scripts/TkMap_script_phase1.py b/DQM/SiStripMonitorClient/scripts/TkMap_script_phase1.py index bdeeab927d29a..e3b72c956794a 100755 --- a/DQM/SiStripMonitorClient/scripts/TkMap_script_phase1.py +++ b/DQM/SiStripMonitorClient/scripts/TkMap_script_phase1.py @@ -2,7 +2,6 @@ from __future__ import print_function import sys -from ROOT import * import os from subprocess import call import os.path diff --git a/DQM/TrackerRemapper/test/PrintTkMap.py b/DQM/TrackerRemapper/test/PrintTkMap.py index c380ef890f7d7..a504a159786ae 100644 --- a/DQM/TrackerRemapper/test/PrintTkMap.py +++ b/DQM/TrackerRemapper/test/PrintTkMap.py @@ -3,7 +3,7 @@ from __future__ import print_function import sys import os -from ROOT import * +from ROOT import gROOT, TArrow, TCanvas, TGraph, TH2Poly, gPad, TLatex from copy import deepcopy from array import array diff --git a/DQMOffline/CalibCalo/test/compare.py b/DQMOffline/CalibCalo/test/compare.py index 2014672341170..dd434cda205da 100755 --- a/DQMOffline/CalibCalo/test/compare.py +++ b/DQMOffline/CalibCalo/test/compare.py @@ -107,7 +107,7 @@ def srcpath(fldr): #try to use pyROOT directly from here, if environment variables were not set #this will run again the program with environment variables of the highest version of CMSSW specified in -v try: - from ROOT import * + from ROOT import gSystem, TFile, TLegend, TCanvas, gDirectory except ImportError: print "Warning: environment variables not set, proceeding anyway running this script with the environment variables of the higher version of CMSSW specified in -v" #storing cmsenv environment variables diff --git a/DQMServices/Components/python/ROOTData.py b/DQMServices/Components/python/ROOTData.py index 29d8cad30fc55..b857e5bf0e5e6 100644 --- a/DQMServices/Components/python/ROOTData.py +++ b/DQMServices/Components/python/ROOTData.py @@ -1,5 +1,5 @@ from __future__ import print_function -from ROOT import * +from ROOT import gDirectory, TBufferFile, TClass from array import array #------------------------------------------------------------------------------- diff --git a/DataFormats/PatCandidates/test/dump_parameterization.py b/DataFormats/PatCandidates/test/dump_parameterization.py index 763b923439d66..19d3716e904a1 100755 --- a/DataFormats/PatCandidates/test/dump_parameterization.py +++ b/DataFormats/PatCandidates/test/dump_parameterization.py @@ -2,7 +2,7 @@ from __future__ import print_function from builtins import range import ROOT -from ROOT import * +from ROOT import gROOT, TFile, TIter import sys if len(sys.argv) < 2 : print("Usage: dump_parameteriza.py filename") diff --git a/HLTrigger/Tools/scripts/timingPdfMaker.py b/HLTrigger/Tools/scripts/timingPdfMaker.py index 39c4aa9a58187..8bf1c053dd73f 100755 --- a/HLTrigger/Tools/scripts/timingPdfMaker.py +++ b/HLTrigger/Tools/scripts/timingPdfMaker.py @@ -21,11 +21,11 @@ import os, glob import os.path import operator -import subprocess +import subprocess import sys, getopt sys.argv.append('-b') -from ROOT import * -import cStringIO +from ROOT import gROOT, gStyle, TFile, TCanvas +import cStringIO gROOT.SetStyle("Plain") diff --git a/PhysicsTools/PythonAnalysis/examples/MCTruth.py b/PhysicsTools/PythonAnalysis/examples/MCTruth.py index 9c08370d79c4c..af829121c660b 100644 --- a/PhysicsTools/PythonAnalysis/examples/MCTruth.py +++ b/PhysicsTools/PythonAnalysis/examples/MCTruth.py @@ -1,6 +1,7 @@ from __future__ import print_function from PhysicsTools.PythonAnalysis import * -from ROOT import * +import ROOT +from ROOT import gSystem, TFile # prepare the FWLite autoloading mechanism gSystem.Load("libFWCoreFWLite.so") ROOT.FWLiteEnabler.enable() diff --git a/PhysicsTools/PythonAnalysis/examples/MCTruth2.py b/PhysicsTools/PythonAnalysis/examples/MCTruth2.py index 832bc0d00049e..bae9042e8e728 100644 --- a/PhysicsTools/PythonAnalysis/examples/MCTruth2.py +++ b/PhysicsTools/PythonAnalysis/examples/MCTruth2.py @@ -1,6 +1,6 @@ from __future__ import print_function from PhysicsTools.PythonAnalysis import * -from ROOT import * +from ROOT import gSystem # prepare the FWLite autoloading mechanism gSystem.Load("libFWCoreFWLite.so") diff --git a/PhysicsTools/PythonAnalysis/examples/interactiveExample.py b/PhysicsTools/PythonAnalysis/examples/interactiveExample.py index 0c9c79b495d7c..39bcc5bdee722 100644 --- a/PhysicsTools/PythonAnalysis/examples/interactiveExample.py +++ b/PhysicsTools/PythonAnalysis/examples/interactiveExample.py @@ -2,7 +2,7 @@ # has to be called with python -i interactiveExample.py from PhysicsTools.PythonAnalysis import * -from ROOT import * +from ROOT import gSystem, TFile # prepare the FWLite autoloading mechanism gSystem.Load("libFWCoreFWLite.so") @@ -26,19 +26,19 @@ for event in events: photons = event.photons print(" Number of photons in event %i: %i" % (event, len(photons))) - if event > 2: break # workaround will become obsolete + if event > 2: break # workaround will become obsolete ##################################################### # all following commands have been used interactively # -## accessing photons +## accessing photons # print photon[0] # ## looping over the photons. what's there? #for photon in photons: -# print photon.energy() +# print photon.energy() # ## selecting photons #selectedPhotons = [p for p in photons if p.energy()> 3] @@ -52,7 +52,7 @@ # print alias # ## how to learn about an object -#help(photon[0]) +#help(photon[0]) # ## how to leave the session # diff --git a/PhysicsTools/PythonAnalysis/examples/start.py b/PhysicsTools/PythonAnalysis/examples/start.py index 45d2bc4e5ae52..8138fa037636a 100644 --- a/PhysicsTools/PythonAnalysis/examples/start.py +++ b/PhysicsTools/PythonAnalysis/examples/start.py @@ -1,6 +1,7 @@ # startup commands for interactive use -from ROOT import * +import ROOT +from ROOT import gSystem from PhysicsTools.PythonAnalysis import * gSystem.Load("libFWCoreFWLite.so") diff --git a/PhysicsTools/PythonAnalysis/examples/trackerHits.py b/PhysicsTools/PythonAnalysis/examples/trackerHits.py index b090dd257b24d..b2213d559029b 100644 --- a/PhysicsTools/PythonAnalysis/examples/trackerHits.py +++ b/PhysicsTools/PythonAnalysis/examples/trackerHits.py @@ -1,6 +1,7 @@ # first load cmstools and ROOT classes from PhysicsTools.PythonAnalysis import * -from ROOT import * +from ROOT import gSystem, gROOT, TFile, TH1F, TCanvas +import ROOT gSystem.Load("libFWCoreFWLite.so") ROOT.FWLiteEnabler.enable() diff --git a/RecoBTag/PerformanceDB/test/plotPerformanceDB.py b/RecoBTag/PerformanceDB/test/plotPerformanceDB.py index 79be401059317..97644cf79afde 100644 --- a/RecoBTag/PerformanceDB/test/plotPerformanceDB.py +++ b/RecoBTag/PerformanceDB/test/plotPerformanceDB.py @@ -14,7 +14,7 @@ import math import subprocess from array import array -from ROOT import * +from ROOT import TCanvas, TFile, TGraphErrors def main(): diff --git a/RecoVertex/BeamSpotProducer/scripts/ntuplemaker.py b/RecoVertex/BeamSpotProducer/scripts/ntuplemaker.py index fdacc9df79636..fff69dca1b7b4 100755 --- a/RecoVertex/BeamSpotProducer/scripts/ntuplemaker.py +++ b/RecoVertex/BeamSpotProducer/scripts/ntuplemaker.py @@ -26,10 +26,10 @@ -f, --final = FINAL: Last IOV. Options: run number, or run:lumi -o, --output = OUTPUT: filename of ROOT file with plots. -x, --xcrossing = XCROSSING : Bunch crossing number. - + Francisco Yumiceva (yumiceva@fnal.gov) Fermilab 2010 - + """ from __future__ import print_function @@ -52,7 +52,7 @@ print(" setenv PYTHONPATH $ROOTSYS/lib\n") sys.exit() -from ROOT import * +from ROOT import gROOT, TFile, TTree from array import array def getFill( json, run ): @@ -146,7 +146,7 @@ def getFill( json, run ): option,args = parse(__doc__) if not args and not option: exit() - if not option.data: + if not option.data: print(" need to provide beam spot data file") exit() @@ -237,7 +237,7 @@ def getFill( json, run ): passiov = True if iIOV.since >= int(tmprunlast) and iIOV.till >= 4294967295: print(" IOV: " + str(iIOV.since) + " to " + str(iIOV.till)) - passiov = True + passiov = True if passiov: acommand = 'getBeamSpotDB.py -t '+ tag + " -r " + str(iIOV.since) +otherArgs if IOVbase=="lumibase": @@ -290,7 +290,7 @@ def getFill( json, run ): sortAndCleanBeamList(listbeam,IOVbase) - ################################### + ################################### for ii in range(0,len(listbeam)): diff --git a/RecoVertex/BeamSpotProducer/test/scripts/pv.py b/RecoVertex/BeamSpotProducer/test/scripts/pv.py index 116af377af0d2..f0cbda04c182b 100644 --- a/RecoVertex/BeamSpotProducer/test/scripts/pv.py +++ b/RecoVertex/BeamSpotProducer/test/scripts/pv.py @@ -1,9 +1,9 @@ #! /usr/bin/env python -#import ROOT from __future__ import print_function +import ROOT from builtins import range -from ROOT import * +from ROOT import gROOT, gSystem, TFile, TH1I, TCanvas, TFitterMinuit #gROOT, TFile, TCanvas, TH1F, TH1I, TLegend, TH2F, gPad #from ROOT import TCanvas, TH1F, TH1I diff --git a/Validation/MuonGEMHits/test/Compare.py b/Validation/MuonGEMHits/test/Compare.py index 5d05ec1e69a64..a59f76dd06634 100755 --- a/Validation/MuonGEMHits/test/Compare.py +++ b/Validation/MuonGEMHits/test/Compare.py @@ -4,7 +4,7 @@ Copied from GEMCode/GEMValidation """ -from ROOT import * +from ROOT import TFile, gStyle, TCanvas, gPad, TH1F import os import sys diff --git a/Validation/MuonGEMHits/test/MakePlot.py b/Validation/MuonGEMHits/test/MakePlot.py index d4b45741e6f95..21eb2481d7b5f 100755 --- a/Validation/MuonGEMHits/test/MakePlot.py +++ b/Validation/MuonGEMHits/test/MakePlot.py @@ -4,7 +4,7 @@ Copied from GEMCode/GEMValidation """ -from ROOT import * +from ROOT import gStyle, TCanvas, gPad, TF1, TPaveText, TCanvas, TFile import os import sys diff --git a/Validation/MuonGEMHits/test/phiView.py b/Validation/MuonGEMHits/test/phiView.py index cbb8cb4b77628..2a1aa5ba14f6d 100755 --- a/Validation/MuonGEMHits/test/phiView.py +++ b/Validation/MuonGEMHits/test/phiView.py @@ -4,7 +4,7 @@ Copied from GEMCode/GEMValidation """ -from ROOT import * +from ROOT import gStyle, TCanvas, TFile import os import sys diff --git a/Validation/RecoTau/Tools/MultipleCompare.py b/Validation/RecoTau/Tools/MultipleCompare.py index cc5b1ed0124b3..3aa0863d4b90d 100644 --- a/Validation/RecoTau/Tools/MultipleCompare.py +++ b/Validation/RecoTau/Tools/MultipleCompare.py @@ -9,7 +9,7 @@ import re import Validation.RecoTau.RecoTauValidation_cfi as validation from optparse import OptionParser -from ROOT import * +from ROOT import gStyle, TDirectory, TDirectoryFile, TLatex, TH1F, TLegend, TPaveText, TPad __author__ = "Mauro Verzetti (mauro.verzetti@cern.ch) and Lucia Perrini (lucia.perrini@cern.ch)" __doc__ = """Script to plot the content of a Validation .root file and compare it to a different file:\n\n @@ -47,8 +47,8 @@ def LoadCommandlineOptions(argv): parser.add_option('--minYaxis',metavar='number',type=float, dest="minYaxis", default=0, help="Sets the minimum range on Y axis in the main pad") parser.add_option('--rebin', dest="rebin", type=int, default=-1, help="Sets the rebinning scale") parser.add_option('--branding','-b',metavar='branding', type=str,help='Define a branding to label the plots (in the top right corner)',dest='branding',default = None) - #parser.add_option('--search,-s',metavar='searchStrings', type=str,help='Sets the label to put in the plots for ref file',dest='testLabel',default = None) No idea on how to tell python3 to use all the strings before a new option, thus moving this from option to argument (but may be empty) - + #parser.add_option('--search,-s',metavar='searchStrings', type=str,help='Sets the label to put in the plots for ref file',dest='testLabel',default = None) No idea on how to tell python3 to use all the strings before a new option, thus moving this from option to argument (but may be empty) + (options,toPlot) = parser.parse_args() if options.help: parser.print_help() @@ -105,7 +105,7 @@ def DetermineHistType(name): #assuming plots name like: tauType_plotType_xAxis or tauType_plotType_selection matches = re.match(r'.*/(.*)_(.*)_(.*)', name) if matches: - prefix = matches.group(1) + prefix = matches.group(1) label = matches.group(3) knowntypes = (['pTRatio','SumPt','Size']) for knowntype in knowntypes: @@ -242,7 +242,7 @@ def optimizeRangeMainPad(argv, pad, hists, maxLogX_, minX_, maxX_, maxLogY_, min minX, maxX = findRange(hists, -1, maxLogX) else: minX, maxX = findRange(hists, minX_, maxX_) - + if pad.GetLogx(): if minX == 0: minX = 0.001 @@ -282,7 +282,7 @@ def optimizeRangeSubPad(argv, pad, hists, maxLogX_, minX_, maxX_, minYRatio_, ma min, max = findRange(hists, min, max) if max > 2: max = 2 #maximal bound - hists[0].SetAxisRange(min, max, "Y") + hists[0].SetAxisRange(min, max, "Y") def getMaximumIncludingErrors(hist): #find maximum considering also the errors @@ -308,7 +308,7 @@ def getMinimumIncludingErrors(hist): min = hist.GetBinContent(i) pos = i if min < 0: - min = 0 + min = 0 return min - distance*hist.GetBinError(pos) @@ -395,7 +395,7 @@ def main(argv=None): statsBox.SetMargin(0.05) statsBox.SetBorderSize(1) - + canvas = TCanvas('MultiPlot','MultiPlot',validation.standardDrawingStuff.canvasSizeX.value(),832) effPad = TPad('effPad','effPad',0.01,0.35,0.99,0.99)#0,0.25,1.,1.,0,0) effPad.SetBottomMargin(0.0)#0.1) @@ -521,7 +521,7 @@ def main(argv=None): tmpHists.extend(testHs) tmpHists.extend(refHs) optimizeRangeMainPad(argv, effPad, tmpHists, maxlX, options.minXaxis, options.maxXaxis, maxlY, options.minYaxis, options.maxYaxis) - + firstD = True if refFile != None: for histo,color in zip(divHistos,colors): @@ -535,7 +535,7 @@ def main(argv=None): histo.GetXaxis().SetLabelSize(0.08) histo.GetXaxis().SetTitleSize(0.08) #histo.GetYaxis().CenterTitle() - + if firstD: histo.Draw('ex0') @@ -543,7 +543,7 @@ def main(argv=None): else: histo.Draw('same ex0') diffPad.Update() - + if options.maxLogX > 0: maxlX=options.maxLogX optimizeRangeSubPad(argv, diffPad, divHistos, maxlX, options.minXaxis, options.maxXaxis, options.minYR, options.maxYR) @@ -553,7 +553,7 @@ def main(argv=None): if drawStats: statsBox.Draw() - + canvas.Print(options.out) diff --git a/Validation/RecoTau/Tools/SteerMultipleCompare.py b/Validation/RecoTau/Tools/SteerMultipleCompare.py index 1a48a782ad222..1b7891467ea36 100644 --- a/Validation/RecoTau/Tools/SteerMultipleCompare.py +++ b/Validation/RecoTau/Tools/SteerMultipleCompare.py @@ -4,7 +4,7 @@ import sys import os import re -from ROOT import * +from ROOT import gROOT, TFile import MultipleCompare as MultipleCompare diff --git a/Validation/RecoVertex/test/makePlots.py b/Validation/RecoVertex/test/makePlots.py index 61cb960a15e64..85c183285b15d 100644 --- a/Validation/RecoVertex/test/makePlots.py +++ b/Validation/RecoVertex/test/makePlots.py @@ -1,5 +1,5 @@ from __future__ import print_function -from ROOT import * +from ROOT import gPad, gStyle, TCanvas import re files = ['DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root']