def Run(self, processList): len_histoList = len(self.t_histoList) t_tagList = PythonUtils.makeTupleFromFile(processList, ',') l_files = [] f = open(processList, 'r') for file in f: l_files.append(file.strip()) for i in xrange(len(t_tagList)): pFile, tagText = t_tagList[i] PythonUtils.doesFileExist(pFile) t_processList = PythonUtils.makeTupleFromFile(pFile, ',') for j in xrange(len(self.t_histoList)): t_plot = [] name = self.t_histoList[j][2] for k in xrange(len(t_processList)): histoLocation = t_processList[k][1] + self.t_histoList[j][1] t_plot.append([ ROOTUtils.retrieveHistogram(self.histFile, histoLocation, name) ]) saveString = self.saveDir + self.t_histoList[j][ 0] + '_' + t_processList[k][7] PlottingUtils.stackHistograms( t_plot, t_processList, self.t_histoList[j], self.t_legendList[j], self.t_textList[j], self.t_axisList[j], self.l_saveAs, self.t_ratioList[j], saveString, tagText)
def Run(self, processList): len_histoList = len(self.t_histoList) t_tagList = PythonUtils.makeTupleFromFile(processList, ',') l_files = [] f = open(processList, 'r') for file in f: l_files.append(file.strip()) for i in xrange(len(t_tagList)): pFile, tagText = t_tagList[i] PythonUtils.doesFileExist(pFile) t_processList = PythonUtils.makeTupleFromFile(pFile, ',') for j in xrange(len(self.t_histoList)): t_plot = [] name = self.t_histoList[j][2] for k in xrange(len(t_processList)): histoLocation = t_processList[k][1] + self.t_histoList[j][1] t_plot.append([ROOTUtils.retrieveHistogram(self.histFile, histoLocation, name)]) saveString = self.saveDir + self.t_histoList[j][0] + '_' + t_processList[k][7] PlottingUtils.stackHistograms(t_plot, t_processList, self.t_histoList[j], self.t_legendList[j], self.t_textList[j], self.t_axisList[j], self.l_saveAs, self.t_ratioList[j], saveString, tagText)
def Run(self): # Create lists from config file info l_saveAs = PythonUtils.makeListFromString(self.saveAs, ',') ## Check the .list files exist! l_listFile = [ self.axisList, self.histoList, self.legendList, self.overlayList, self.textList, self.histFile ] for file in l_listFile: PythonUtils.doesFileExist(file) ## Make the tuples from the input files t_axisList = PythonUtils.makeTupleFromFile(self.axisList, ',') t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',') t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',') t_textList = PythonUtils.makeTupleFromFile(self.textList, ',') ## match the first item to make sure they're compatible l_tuples = [t_histoList, t_legendList, t_textList] for item in l_tuples: PythonUtils.firstItemMatching(t_axisList, item) l_files = [] f = open(self.overlayList, 'r') for line in f: if line.startswith('#'): continue else: l_files.append(line.strip()) for i in xrange(len(l_files)): PythonUtils.doesFileExist(l_files[i]) t_overlayList = PythonUtils.makeTupleFromFile(l_files[i], ',') t_plots = [] for j in xrange(len(t_overlayList)): histoLocation = t_overlayList[j][1] + t_histoList[i][1] t_plots.append([ ROOTUtils.retrieveHistogram(self.histFile, histoLocation, t_overlayList[j][2]) ]) saveString = self.saveDir + t_histoList[i][0] PlottingUtils.overlayHistograms(t_plots, t_overlayList, t_histoList[i], t_legendList[i], t_textList[i], t_axisList[i], l_saveAs, saveString)
def Run(self): # Create lists from config file info l_saveAs = PythonUtils.makeListFromString(self.saveAs, ',') ## Check the .list files exist! l_listFile = [self.axisList, self.histoList, self.legendList, self.overlayList, self.textList, self.histFile] for file in l_listFile: PythonUtils.doesFileExist(file) ## Make the tuples from the input files t_axisList = PythonUtils.makeTupleFromFile(self.axisList, ',') t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',') t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',') t_textList = PythonUtils.makeTupleFromFile(self.textList, ',') ## match the first item to make sure they're compatible l_tuples = [t_histoList, t_legendList, t_textList] for item in l_tuples: PythonUtils.firstItemMatching(t_axisList, item) l_files = [] f = open(self.overlayList, 'r') for line in f: if line.startswith('#'): continue else: l_files.append(line.strip()) for i in xrange(len(l_files)): PythonUtils.doesFileExist(l_files[i]) t_overlayList = PythonUtils.makeTupleFromFile(l_files[i], ',') t_plots = [] for j in xrange(len(t_overlayList)): histoLocation = t_overlayList[j][1] + t_histoList[i][1] t_plots.append([ROOTUtils.retrieveHistogram(self.histFile, histoLocation, t_overlayList[j][2])]) saveString = self.saveDir + t_histoList[i][0] PlottingUtils.overlayHistograms(t_plots, t_overlayList, t_histoList[i], t_legendList[i], t_textList[i], t_axisList[i], l_saveAs, saveString)
def Run(self): ## Add the trailing slash to the end of latexDir if not self.latexDir.endswith('/'): latexDir = self.latexDir + '/' PythonUtils.doesDirExist(latexDir) else: latexDir = self.latexDir ## Check the .list files exist l_fList = [ self.processList, self.histoList, self.corrList, self.histFile ] for file in l_fList: PythonUtils.doesFileExist(file) ## Make the lists from the list files t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',') t_corrList = PythonUtils.makeTupleFromFile(self.corrList, ',') t_pList = PythonUtils.makeTupleFromFile(self.processList, ',') ## Create the variable name dictionary compTo = '' d_nameVar = {} for i in xrange(len(t_corrList)): d_nameVar[t_corrList[i][0]] = t_corrList[i][1] if t_corrList[i][2] == '1': compTo = t_corrList[i][0] ## Construct the list of processes for each region l_pFiles = [] f = open(self.processList, 'r') for line in f: if not line.startswith('#'): l_pFiles.append(line.strip()) for i in xrange(len(t_pList)): pFile, tagType = t_pList[i] PythonUtils.doesFileExist(pFile) t_processList = PythonUtils.makeTupleFromFile(pFile, ',') ld_sens = [] l_pTV = [] option = '' for k in xrange(len(t_histoList)): l_pTV.append(t_histoList[k][3]) d_sens = {} l_corrName = [] # option = t_histoList[k][2] for name, title in d_nameVar.iteritems(): t_h = [] l_corrName.append(name) for j in xrange(len(t_processList)): option = t_processList[j][0] hLocation = t_processList[j][1] + t_histoList[k][1] t_h.append([ ROOTUtils.retrieveHistogram( self.histFile, hLocation, title), t_processList[j][0], t_processList[j][2], t_processList[j][3] ]) sens, sensErr = ROOTUtils.calculateSensitivity( t_h, t_histoList[k], name) d_sens[name] = [sens, sensErr] d_sens[name] = ROOTUtils.calculateSensitivity( t_h, t_histoList[k], name) l_sens = [t_histoList[k][0] + ' ' + tagType, d_sens] ld_sens.append(l_sens) t_sens = PythonUtils.rankByValue(ld_sens, compTo, 'SENSITIVITY') if self.doLatex: latex = self.writeLatex( t_sens, l_corrName, l_pTV, 'Sensitivity_' + tagType + '_' + option, latexDir) PythonUtils.runLatex(latex, latexDir)
def Run(self): ## Create lists from config file options l_saveAs = PythonUtils.makeListFromString(self.saveAs, ',') ## Check the .list files exist l_listFile = [self.axisList, self.fitList, self.histoList, self.legendList, self.textList, self.variableList, self.histFile] for file in l_listFile: PythonUtils.doesFileExist(file) ## Create the tuples from the .list files t_axisList = PythonUtils.makeTupleFromFile(self.axisList, ',') t_fitList = PythonUtils.makeTupleFromFile(self.fitList, ',') t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',') t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',') t_textList = PythonUtils.makeTupleFromFile(self.textList, ',') ## Math the first titems l_tuples = [t_fitList, t_histoList, t_legendList, t_textList] for item in l_tuples: PythonUtils.firstItemMatching(t_axisList, item) ## Loop over the variable files to get the relevant info for j in xrange(len(t_axisList)): f_str, vRebin, vdoNorm, vXMin, vXMax, vFit, vXValue, vYValue = t_fitList[j] l_files = [] f = open(self.variableList, 'r') for file in f: l_files.append(file.strip()) l_twoD = [] t_legend = [] PythonUtils.doesFileExist(l_files[j]) g = open(l_files[j], 'r') for vFile in g: PythonUtils.doesFileExist(vFile.strip()) vFileParser = ConfigParser.SafeConfigParser() vFileParser.read(vFile.strip()) ## Options vTitle = vFileParser.get('Options','title') vVariable = vFileParser.get('Options','variable') vColour = vFileParser.getint('Options','colour') vMarker = vFileParser.getint('Options','marker') vMarkerSize = vFileParser.getfloat('Options','markerSize') vFitMin = vFileParser.get('Options','fitMin') vFitMax = vFileParser.get('Options','fitMax') ## Create l_statInfo l_statInfo = [t_histoList[j][1], t_histoList[j][1], float(vRebin), int(vdoNorm), float(vXMin), float(vXMax), vFitMin, vFitMax] getMean = 0 getRMS = 0 getRES = 0 if vXValue == 'MEAN': getMean = 1 elif vXValue == 'RMS': getRMS = 1 elif vXValue == 'RESOLUTION': getRES = 1 else: getMean = getRMS = getRES = 0 l_xOption = [getMean, getRMS, getRES] getMean = 0 getRMS = 0 getRES = 0 if vYValue == 'MEAN': getMean = 1 elif vYValue == 'RMS': getRMS = 1 elif vYValue == 'RESOLUTION': getRES = 1 else: getMean = getRMS = getRES = 0 l_yOption = [getMean, getRMS, getRES] ## Get the list of stats l_plot = [ROOTUtils.retrieveHistogram(self.histFile, t_histoList[j][1], vVariable)] l_xValue, l_xErr = ROOTUtils.getHistoStat(l_plot, l_statInfo, l_xOption, vFit, vVariable) l_yValue, l_yErr = ROOTUtils.getHistoStat(l_plot, l_statInfo, l_yOption, vFit, vVariable) ## Get the value we want from the list so we can plot it! xValue = -1 for stat in l_xValue: if stat != -1: xValue = stat for stat in l_yValue: if stat != -1: yValue = stat ## Create a 2D plot and save to a list so can overlay them twoDPlot = PlottingUtils.createTwoD(t_histoList[j], xValue, yValue, vMarker, vMarkerSize, vColour) l_twoD.append(twoDPlot) if vTitle: l_legend = [twoDPlot, vTitle, 'p'] t_legend.append(l_legend) ## Overlay our 2D plots onto one canvas PlottingUtils.overlayTwoD(l_twoD, t_legend, t_histoList[j], t_legendList[j], t_textList[j], t_axisList[j], self.saveDir, l_saveAs)
def Run(self): ## Add the trailing slash to the end of latexDir if not self.latexDir.endswith('/'): latexDir = self.latexDir + '/' PythonUtils.doesDirExist(latexDir) else: latexDir = self.latexDir ## Check the .list files exist l_fList = [self.processList, self.histoList, self.corrList, self.histFile] for file in l_fList: PythonUtils.doesFileExist(file) ## Make the lists from the list files t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',') t_corrList = PythonUtils.makeTupleFromFile(self.corrList, ',') t_pList = PythonUtils.makeTupleFromFile(self.processList, ',') ## Create the variable name dictionary compTo = '' d_nameVar = {} for i in xrange(len(t_corrList)): d_nameVar[t_corrList[i][0]] = t_corrList[i][1] if t_corrList[i][2] == '1': compTo = t_corrList[i][0] ## Construct the list of processes for each region l_pFiles = [] f = open(self.processList, 'r') for line in f: if not line.startswith('#'): l_pFiles.append(line.strip()) for i in xrange(len(t_pList)): pFile, tagType = t_pList[i] PythonUtils.doesFileExist(pFile) t_processList = PythonUtils.makeTupleFromFile(pFile, ',') ld_sens = [] l_pTV = [] option = '' for k in xrange(len(t_histoList)): l_pTV.append(t_histoList[k][3]) d_sens = {} l_corrName = [] # option = t_histoList[k][2] for name, title in d_nameVar.iteritems(): t_h = [] l_corrName.append(name) for j in xrange(len(t_processList)): option = t_processList[j][0] hLocation = t_processList[j][1] + t_histoList[k][1] t_h.append([ROOTUtils.retrieveHistogram(self.histFile, hLocation, title), t_processList[j][0], t_processList[j][2], t_processList[j][3]]) sens, sensErr = ROOTUtils.calculateSensitivity(t_h, t_histoList[k], name) d_sens[name] = [sens, sensErr] d_sens[name] = ROOTUtils.calculateSensitivity(t_h, t_histoList[k], name) l_sens = [t_histoList[k][0] + ' ' + tagType, d_sens] ld_sens.append(l_sens) t_sens = PythonUtils.rankByValue(ld_sens, compTo, 'SENSITIVITY') if self.doLatex: latex = self.writeLatex(t_sens, l_corrName, l_pTV, 'Sensitivity_' + tagType + '_' + option, latexDir) PythonUtils.runLatex(latex, latexDir)
def Run(self, doProfile, createFile): ## Create the lists from the main configFile t_select = PythonUtils.makeTupleFromString(self.selectBins, ',', '?') t_muon = PythonUtils.makeTupleFromString(self.muBins, ',', '?') if createFile: PythonUtils.Info('Creating Histogram File for Profile Plots') ## Check the list files exist l_fList = [self.variableList, self.treeList] for f in l_fList: PythonUtils.doesFileExist(f) ## Make the lists from the list files t_var = PythonUtils.makeTupleFromFile(self.variableList, ',') t_tree = PythonUtils.makeTupleFromFile(self.treeList, ',') for i in xrange(len(t_tree)): tFile, tName, sDir = t_tree[i] PythonUtils.doesFileExist(tFile) d_histType = self.createHistograms(t_var, sDir, tFile, t_muon, self.selectOn, t_select) d_filledHists = self.fillHistograms(d_histType, t_var, tFile, tName, sDir, t_muon, t_select, self.selectOn, self.nEvents) self.saveHistograms(d_filledHists, t_var, self.outHist, sDir, t_muon, self.selectOn, t_select) if doProfile: PythonUtils.Info("Creating Profile Plots!") ## Create the Lists from profile cfg l_saveAs = PythonUtils.makeListFromString(self.plotType, ',') ## Check the list files exist l_pList = [ self.axisList, self.histoList, self.legendList, self.textList, self.varList, self.inFile ] for f in l_pList: PythonUtils.doesFileExist(f) ## Create the list of lists from each list file t_axisList = PythonUtils.makeTupleFromFile(self.axisList, ',') t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',') t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',') t_textList = PythonUtils.makeTupleFromFile(self.textList, ',') ## Check teh first Item matches: l_tList = [t_histoList, t_legendList, t_textList] for l in l_tList: PythonUtils.firstItemMatching(l, t_axisList) ## Add the var list files to a list l_varList = [] f = open(self.varList, 'r') for line in f: if line.startswith('#'): continue else: l_varList.append(line) for i in xrange(len(l_varList)): PythonUtils.doesFileExist(l_varList[i].strip()) t_varList = PythonUtils.makeTupleFromFile( l_varList[i].strip(), ',') l_prof = [] t_legend = [] for j in xrange(len(t_varList)): d_pTMean = {} l_err = [] for bin in t_select: if bin[0] == 'all' or bin[1] == 'Inf': continue if bin[1]: select = self.selectOn + '-' + bin[0] + '-' + bin[1] else: select = self.selectOn + '-' + bin[0] location = t_varList[j][2] + '/' + t_varList[j][ 6] + '/' + select + '/' + t_varList[j][7] pTbin = float( bin[0]) + (float(bin[1]) - float(bin[0])) / 2 pTMean = ROOTUtils.retrieveHistogram( self.inFile, location, t_varList[j][1]).GetMean() pTMeanErr = ROOTUtils.retrieveHistogram( self.inFile, location, t_varList[j][1]).GetMeanError() l_err.append(pTMeanErr) d_pTMean[pTbin] = pTMean h_prof, l_legend = PlottingUtils.twoDprofile( d_pTMean, t_histoList[i], t_varList[j], l_err) l_prof.append(h_prof) t_legend.append(l_legend) saveString = self.plotDir + t_histoList[i][0] PlottingUtils.overlayProfile(l_prof, t_axisList[i], t_histoList[i], t_legendList[i], t_textList[i], t_legend, l_saveAs, saveString)
def Run(self): ## Make the list from the config file l_range = PythonUtils.makeListFromString(self.plotRange, ',') t_select = PythonUtils.makeTupleFromString(self.selectBins, ',','?') ## Check the input and process files exist l_file = [self.processList, self.inputFile] for file in l_file: PythonUtils.doesFileExist(file) ## Loop over the ProcessList files f = open(self.processList, 'r') for line in f: if line.startswith('#'): continue l_process = PythonUtils.makeListFromString(line.strip(), ',') PythonUtils.doesFileExist(l_process[0]) t_process = PythonUtils.makeTupleFromFile(l_process[0], ',') l_yield = [] ##ll ll_VH = ['VH'] ll_VV = ['VV'] ll_top = ['top'] ll_stop = ['stop'] ll_Wl = ['W+l'] ll_Wcl = ['W+cl'] ll_Whf = ['W+hf'] ll_Zl = ['Z+l'] ll_Zcl = ['Z+cl'] ll_Zhf = ['Z+hf'] ll_MJe = ['MJe'] ll_MJm = ['MJm'] ll_tot = ['Total'] ll_data = ['Data'] for bin in t_select: if bin[0] == 'all': select = self.selectOn + '-' + bin[0] else: select = self.selectOn + '-' + bin[0] + '-' + bin[1] ## nEvents nSignal = 0 nTot = 0 nTop = 0 nStop = 0 nWl = 0 nWh = 0 nWcl = 0 nZl = 0 nZh = 0 nZcl = 0 nVV = 0 nMJe = 0 nMJm = 0 nData = 0 ##nEventsErr eSignal = 0 eTot = 0 eTop = 0 eStop = 0 eWl = 0 eWh = 0 eWcl = 0 eZl = 0 eZh = 0 eZcl = 0 eVV = 0 eMJe = 0 eMJm = 0 eData = 0 for i in xrange(len(t_process)): process, sLocation, pType, selection, SF = t_process[i] location = sLocation + '/all/' + select + '/' + self.histLocation hist = ROOTUtils.retrieveHistogram(self.inputFile, location, self.histogram) yValue, yErr = ROOTUtils.getYield(hist, l_range[0], l_range[1], t_process[i][4]) if pType == "SIGNAL": nTot += yValue nSignal += yValue eSignal += yErr eTot += yErr elif pType == "W+H": nTot += yValue nWh += yValue eWh += yErr eTot += yErr elif pType == "W+CL": nTot += yValue nWcl += yValue eWcl += yErr eTot += yErr elif pType == "W+L": nTot += yValue nWl += yValue eWl += yErr eTot += yErr elif pType == "Z+H": nTot += yValue nZh += yValue eZh += yErr eTot += yErr elif pType == "Z+CL": nTot += yValue nZcl += yValue eZcl += yErr eTot += yErr elif pType == "Z+L": nTot += yValue nZl += yValue eZl += yErr eTot += yErr elif pType == "TOP": nTot += yValue nTop += yValue eTop += yErr eTot += yErr elif pType == "STOP": nTot += yValue nStop += yValue nStop += yErr eTot += yErr elif pType == "VV": nTot += yValue nVV += yValue eVV += yErr eTot += yErr elif pType == "MJe": nTot += yValue nMJe += yValue nMJe += yErr eTot += yErr elif pType == "MJm": nTot += yValue nMJm += yValue eMJm += yErr eTot += yErr elif pType == "DATA": nData += yValue eData += yErr else: PythonUtils.Error('Not a valid selection: ' + t_process[i][2] + '!!!\n') l_VH = [nSignal, eSignal] ll_VH.append(l_VH) l_VV = [nVV, eVV] ll_VV.append(l_VV) l_top = [nTop, eTop] ll_top.append(l_top) l_stop = [nStop, eStop] ll_stop.append(l_stop) l_Wl = [nWl, eWl] ll_Wl.append(l_Wl) l_Wcl = [nWcl, eWcl] ll_Wcl.append(l_Wcl) l_Whf = [nWh, eWh] ll_Whf.append(l_Whf) l_Zl = [nZl, eZl] ll_Zl.append(l_Zl) l_Zcl = [nZcl, eZcl] ll_Zcl.append(l_Zcl) l_Zhf = [nZh, eZh] ll_Zhf.append(l_Zhf) l_MJe = [nMJe, eMJe] ll_MJe.append(l_MJe) l_MJm = [nMJm, eMJm] ll_MJm.append(l_MJm) l_tot = [nTot, eTot] ll_tot.append(l_tot) l_data = [nData, eData] ll_data.append(l_data) l_yield = [ll_VH, ll_VV, ll_top, ll_stop, ll_Wl, ll_Wcl, ll_Whf, ll_Zl, ll_Zcl, ll_Zhf, ll_MJe, ll_MJm, ll_tot, ll_data] self.printToScreen(l_yield, select + ' ' + t_process[i][3]) if self.createTex: texFile = self.saveToTex(l_yield, l_process[1], self.outputFile) self.runLatex(self.outputFile, texFile)
def Run(self, doProfile, createFile): ## Create the lists from the main configFile t_select = PythonUtils.makeTupleFromString(self.selectBins, ',', '?') t_muon = PythonUtils.makeTupleFromString(self.muBins, ',', '?') if createFile: PythonUtils.Info('Creating Histogram File for Profile Plots') ## Check the list files exist l_fList = [self.variableList, self.treeList] for f in l_fList: PythonUtils.doesFileExist(f) ## Make the lists from the list files t_var = PythonUtils.makeTupleFromFile(self.variableList, ',') t_tree = PythonUtils.makeTupleFromFile(self.treeList, ',') for i in xrange(len(t_tree)): tFile, tName, sDir = t_tree[i] PythonUtils.doesFileExist(tFile) d_histType = self.createHistograms(t_var, sDir, tFile, t_muon, self.selectOn, t_select) d_filledHists = self.fillHistograms(d_histType, t_var, tFile, tName, sDir, t_muon, t_select, self.selectOn, self.nEvents) self.saveHistograms(d_filledHists, t_var, self.outHist, sDir, t_muon, self.selectOn, t_select) if doProfile: PythonUtils.Info("Creating Profile Plots!") ## Create the Lists from profile cfg l_saveAs = PythonUtils.makeListFromString(self.plotType, ',') ## Check the list files exist l_pList = [self.axisList, self.histoList, self.legendList, self.textList, self.varList, self.inFile] for f in l_pList: PythonUtils.doesFileExist(f) ## Create the list of lists from each list file t_axisList = PythonUtils.makeTupleFromFile(self.axisList, ',') t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',') t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',') t_textList = PythonUtils.makeTupleFromFile(self.textList, ',') ## Check teh first Item matches: l_tList = [t_histoList, t_legendList, t_textList] for l in l_tList: PythonUtils.firstItemMatching(l, t_axisList) ## Add the var list files to a list l_varList = [] f = open(self.varList, 'r') for line in f: if line.startswith('#'): continue else: l_varList.append(line) for i in xrange(len(l_varList)): PythonUtils.doesFileExist(l_varList[i].strip()) t_varList = PythonUtils.makeTupleFromFile(l_varList[i].strip(), ',') l_prof = [] t_legend = [] for j in xrange(len(t_varList)): d_pTMean = {} l_err = [] for bin in t_select: if bin[0] == 'all' or bin[1] == 'Inf': continue if bin[1]: select = self.selectOn + '-' + bin[0] + '-' + bin[1] else: select = self.selectOn + '-' + bin[0] location = t_varList[j][2] + '/' + t_varList[j][6] + '/' + select + '/' + t_varList[j][7] pTbin = float(bin[0]) + (float(bin[1]) - float(bin[0])) / 2 pTMean = ROOTUtils.retrieveHistogram(self.inFile, location, t_varList[j][1]).GetMean() pTMeanErr = ROOTUtils.retrieveHistogram(self.inFile, location, t_varList[j][1]).GetMeanError() l_err.append(pTMeanErr) d_pTMean[pTbin] = pTMean h_prof, l_legend= PlottingUtils.twoDprofile(d_pTMean, t_histoList[i], t_varList[j], l_err) l_prof.append(h_prof) t_legend.append(l_legend) saveString = self.plotDir + t_histoList[i][0] PlottingUtils.overlayProfile(l_prof, t_axisList[i], t_histoList[i], t_legendList[i], t_textList[i], t_legend, l_saveAs, saveString)
def Run(self): ## Make the list from the config file l_range = PythonUtils.makeListFromString(self.plotRange, ',') t_select = PythonUtils.makeTupleFromString(self.selectBins, ',', '?') ## Check the input and process files exist l_file = [self.processList, self.inputFile] for file in l_file: PythonUtils.doesFileExist(file) ## Loop over the ProcessList files f = open(self.processList, 'r') for line in f: if line.startswith('#'): continue l_process = PythonUtils.makeListFromString(line.strip(), ',') PythonUtils.doesFileExist(l_process[0]) t_process = PythonUtils.makeTupleFromFile(l_process[0], ',') l_yield = [] ##ll ll_VH = ['VH'] ll_VV = ['VV'] ll_top = ['top'] ll_stop = ['stop'] ll_Wl = ['W+l'] ll_Wcl = ['W+cl'] ll_Whf = ['W+hf'] ll_Zl = ['Z+l'] ll_Zcl = ['Z+cl'] ll_Zhf = ['Z+hf'] ll_MJe = ['MJe'] ll_MJm = ['MJm'] ll_tot = ['Total'] ll_data = ['Data'] for bin in t_select: if bin[0] == 'all': select = self.selectOn + '-' + bin[0] else: select = self.selectOn + '-' + bin[0] + '-' + bin[1] ## nEvents nSignal = 0 nTot = 0 nTop = 0 nStop = 0 nWl = 0 nWh = 0 nWcl = 0 nZl = 0 nZh = 0 nZcl = 0 nVV = 0 nMJe = 0 nMJm = 0 nData = 0 ##nEventsErr eSignal = 0 eTot = 0 eTop = 0 eStop = 0 eWl = 0 eWh = 0 eWcl = 0 eZl = 0 eZh = 0 eZcl = 0 eVV = 0 eMJe = 0 eMJm = 0 eData = 0 for i in xrange(len(t_process)): process, sLocation, pType, selection, SF = t_process[i] location = sLocation + '/all/' + select + '/' + self.histLocation hist = ROOTUtils.retrieveHistogram(self.inputFile, location, self.histogram) yValue, yErr = ROOTUtils.getYield(hist, l_range[0], l_range[1], t_process[i][4]) if pType == "SIGNAL": nTot += yValue nSignal += yValue eSignal += yErr eTot += yErr elif pType == "W+H": nTot += yValue nWh += yValue eWh += yErr eTot += yErr elif pType == "W+CL": nTot += yValue nWcl += yValue eWcl += yErr eTot += yErr elif pType == "W+L": nTot += yValue nWl += yValue eWl += yErr eTot += yErr elif pType == "Z+H": nTot += yValue nZh += yValue eZh += yErr eTot += yErr elif pType == "Z+CL": nTot += yValue nZcl += yValue eZcl += yErr eTot += yErr elif pType == "Z+L": nTot += yValue nZl += yValue eZl += yErr eTot += yErr elif pType == "TOP": nTot += yValue nTop += yValue eTop += yErr eTot += yErr elif pType == "STOP": nTot += yValue nStop += yValue nStop += yErr eTot += yErr elif pType == "VV": nTot += yValue nVV += yValue eVV += yErr eTot += yErr elif pType == "MJe": nTot += yValue nMJe += yValue nMJe += yErr eTot += yErr elif pType == "MJm": nTot += yValue nMJm += yValue eMJm += yErr eTot += yErr elif pType == "DATA": nData += yValue eData += yErr else: PythonUtils.Error('Not a valid selection: ' + t_process[i][2] + '!!!\n') l_VH = [nSignal, eSignal] ll_VH.append(l_VH) l_VV = [nVV, eVV] ll_VV.append(l_VV) l_top = [nTop, eTop] ll_top.append(l_top) l_stop = [nStop, eStop] ll_stop.append(l_stop) l_Wl = [nWl, eWl] ll_Wl.append(l_Wl) l_Wcl = [nWcl, eWcl] ll_Wcl.append(l_Wcl) l_Whf = [nWh, eWh] ll_Whf.append(l_Whf) l_Zl = [nZl, eZl] ll_Zl.append(l_Zl) l_Zcl = [nZcl, eZcl] ll_Zcl.append(l_Zcl) l_Zhf = [nZh, eZh] ll_Zhf.append(l_Zhf) l_MJe = [nMJe, eMJe] ll_MJe.append(l_MJe) l_MJm = [nMJm, eMJm] ll_MJm.append(l_MJm) l_tot = [nTot, eTot] ll_tot.append(l_tot) l_data = [nData, eData] ll_data.append(l_data) l_yield = [ ll_VH, ll_VV, ll_top, ll_stop, ll_Wl, ll_Wcl, ll_Whf, ll_Zl, ll_Zcl, ll_Zhf, ll_MJe, ll_MJm, ll_tot, ll_data ] self.printToScreen(l_yield, select + ' ' + t_process[i][3]) if self.createTex: texFile = self.saveToTex(l_yield, l_process[1], self.outputFile) self.runLatex(self.outputFile, texFile)
def Run(self): ## Create lists from config file options l_saveAs = PythonUtils.makeListFromString(self.saveAs, ',') ## Check the .list files exist l_listFile = [ self.axisList, self.fitList, self.histoList, self.legendList, self.textList, self.variableList, self.histFile ] for file in l_listFile: PythonUtils.doesFileExist(file) ## Create the tuples from the .list files t_axisList = PythonUtils.makeTupleFromFile(self.axisList, ',') t_fitList = PythonUtils.makeTupleFromFile(self.fitList, ',') t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',') t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',') t_textList = PythonUtils.makeTupleFromFile(self.textList, ',') ## Math the first titems l_tuples = [t_fitList, t_histoList, t_legendList, t_textList] for item in l_tuples: PythonUtils.firstItemMatching(t_axisList, item) ## Loop over the variable files to get the relevant info for j in xrange(len(t_axisList)): f_str, vRebin, vdoNorm, vXMin, vXMax, vFit, vXValue, vYValue = t_fitList[ j] l_files = [] f = open(self.variableList, 'r') for file in f: l_files.append(file.strip()) l_twoD = [] t_legend = [] PythonUtils.doesFileExist(l_files[j]) g = open(l_files[j], 'r') for vFile in g: PythonUtils.doesFileExist(vFile.strip()) vFileParser = ConfigParser.SafeConfigParser() vFileParser.read(vFile.strip()) ## Options vTitle = vFileParser.get('Options', 'title') vVariable = vFileParser.get('Options', 'variable') vColour = vFileParser.getint('Options', 'colour') vMarker = vFileParser.getint('Options', 'marker') vMarkerSize = vFileParser.getfloat('Options', 'markerSize') vFitMin = vFileParser.get('Options', 'fitMin') vFitMax = vFileParser.get('Options', 'fitMax') ## Create l_statInfo l_statInfo = [ t_histoList[j][1], t_histoList[j][1], float(vRebin), int(vdoNorm), float(vXMin), float(vXMax), vFitMin, vFitMax ] getMean = 0 getRMS = 0 getRES = 0 if vXValue == 'MEAN': getMean = 1 elif vXValue == 'RMS': getRMS = 1 elif vXValue == 'RESOLUTION': getRES = 1 else: getMean = getRMS = getRES = 0 l_xOption = [getMean, getRMS, getRES] getMean = 0 getRMS = 0 getRES = 0 if vYValue == 'MEAN': getMean = 1 elif vYValue == 'RMS': getRMS = 1 elif vYValue == 'RESOLUTION': getRES = 1 else: getMean = getRMS = getRES = 0 l_yOption = [getMean, getRMS, getRES] ## Get the list of stats l_plot = [ ROOTUtils.retrieveHistogram(self.histFile, t_histoList[j][1], vVariable) ] l_xValue, l_xErr = ROOTUtils.getHistoStat( l_plot, l_statInfo, l_xOption, vFit, vVariable) l_yValue, l_yErr = ROOTUtils.getHistoStat( l_plot, l_statInfo, l_yOption, vFit, vVariable) ## Get the value we want from the list so we can plot it! xValue = -1 for stat in l_xValue: if stat != -1: xValue = stat for stat in l_yValue: if stat != -1: yValue = stat ## Create a 2D plot and save to a list so can overlay them twoDPlot = PlottingUtils.createTwoD(t_histoList[j], xValue, yValue, vMarker, vMarkerSize, vColour) l_twoD.append(twoDPlot) if vTitle: l_legend = [twoDPlot, vTitle, 'p'] t_legend.append(l_legend) ## Overlay our 2D plots onto one canvas PlottingUtils.overlayTwoD(l_twoD, t_legend, t_histoList[j], t_legendList[j], t_textList[j], t_axisList[j], self.saveDir, l_saveAs)
def Run(self): ## Check the files in the config file exist l_file = [self.histFile, self.correctionList, self.histoList, self.fittingList] for file in l_file: PythonUtils.doesFileExist(file) ## Add the trailing slash to the end of latexDir if not self.latexDir.endswith('/'): latexDir = self.latexDir + '/' PythonUtils.doesDirExist(latexDir) else: latexDir = self.latexDir ## Make tuples from the list files t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',') t_fittingList = PythonUtils.makeTupleFromFile(self.fittingList, ',') ## Loop over the files in correctionsList each one is a new run l_cFiles = [] f = open(self.correctionList, 'r') for file in f: if file.startswith('#'): continue else: l_cFiles.append(file.strip()) for i in xrange(len(l_cFiles)): ld_mean = [] ld_rms = [] ld_res = [] l_getOption = [int(t_fittingList[i][2]), int(t_fittingList[i][3]), int(t_fittingList[i][4])] ## Check the file in the list exists PythonUtils.doesFileExist(l_cFiles[i]) t_corrList = PythonUtils.makeTupleFromFile(l_cFiles[i], ',') d_meanResRMS = {} tagType = '' for j in xrange(len(t_corrList)): h_location = t_corrList[j][1] + t_histoList[i][1] t_histoList[i].append(t_corrList[j][3]) t_histoList[i].append(t_corrList[j][4]) l_hist = [t_histoList[i][0], t_histoList[i][1], t_histoList[i][2], t_histoList[i][3], t_histoList[i][4], t_histoList[i][5], t_corrList[j][3], t_corrList[j][4]] pTVBin = t_histoList[i][6] tagType = t_histoList[i][7] l_h = [ROOTUtils.retrieveHistogram(self.histFile, h_location, t_corrList[j][2])] d_meanResRMS[t_corrList[j][0]] = ROOTUtils.getHistoStat(l_h, l_hist, l_getOption, t_fittingList[i][5], t_corrList[j][0]) ## We now have all the info to calculate the stats from the plots! d_mean = {} d_RMS = {} d_res = {} getMean, getRMS, getResolution = l_getOption compareTo = t_fittingList[i][1] fit = t_fittingList[i][5] l_corrName = [] for k, v in d_meanResRMS.iteritems(): l_corrName.append(k) if getMean: d_mean[k] = [v[0][0], v[1][0]] if getRMS: d_RMS[k] = [v[0][1], v[1][1]] if getResolution: d_res[k] = [v[0][2], v[1][2]] ld_mean.append([t_histoList[i][0], d_mean]) ld_rms.append([t_histoList[i][0], d_RMS]) ld_res.append([t_histoList[i][0], d_res]) t_mRr = [] if getMean: t_mRr.append(PythonUtils.rankByValue(ld_mean, compareTo, fit + ' Mean')) if getRMS: t_mRr.append(PythonUtils.rankByValue(ld_rms, compareTo, fit + ' RMS')) if getResolution: t_mRr.append(PythonUtils.rankByValue(ld_res, compareTo, fit + ' Resolution')) if self.doLatex: latex = self.writeLatex(t_mRr, l_corrName, pTVBin, t_histoList[i][0], latexDir, getMean, getRMS, getResolution) PythonUtils.runLatex(latex, latexDir)