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): ## 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)