def twoDprofile(d_ptMean, l_histo, l_corr, l_err): hString,c_x, c_y, yMin, yMax, hBins, saveFile = l_histo cName, cVar, cDir, cColor, cMarker, cSize, cMu, cDir = l_corr l_bin = [] for bin in hBins.split(';'): l_bin.append(float(bin)) arrBin = numpy.asarray(l_bin) h_prof = TH1D('h_prof', cMu, len(l_bin) - 1, arrBin) gROOT.SetBatch(1) c = TCanvas('c', 'c', int(c_x), int(c_y)) gStyle.SetOptStat(0) for k, v in d_ptMean.iteritems(): h_prof.Fill(float(k), float(v)) for b in xrange(0, len(l_bin)): h_prof.SetBinError(b, l_err[b]) h_prof.SetMarkerColor(int(cColor)) h_prof.SetLineColor(int(cColor)) h_prof.SetMarkerStyle(int(cMarker)) if cSize != int(-1): h_prof.SetMarkerSize(float(cSize)) h_prof.Draw('eps') h_prof.SetDirectory(0) if saveFile != '': ROOTUtils.saveToFile(h_prof, saveFile, '', 'PtCorr_' + cMu) l_legend = [h_prof, cName, 'p'] return h_prof, l_legend
def saveHistograms(self, d_filledHists, t_type, outFile, sample, baseDir, selectOn, t_select): PythonUtils.Info('++++++++++++++++++++++++++++++++++++++++++++++++++') PythonUtils.Info(' SAVING HISTOGRAMS: ' + baseDir + ' ') PythonUtils.Info('++++++++++++++++++++++++++++++++++++++++++++++++++') for bin in t_select: ## Don't have a trainling slash for all - looks messy PythonUtils.Info('Creating Histograms for process: ' + baseDir + ' in bin: ' + bin[0] + '-' + bin[1]) if bin[0] == 'all': select = selectOn + '-' + bin[0] else: select = selectOn + '-' + bin[0] + '-' + bin[1] for i in range(len(t_type)): type, typeFile = t_type[i] t_typeFile = PythonUtils.makeTupleFromFile(typeFile, ',') for j in range(len(t_typeFile)): rBranch, tBranch, sName, sLocation, xMin, xMax, nBuns = t_typeFile[ j] location = baseDir + '/' + sample + '/' + select + '/' + sLocation ROOTUtils.saveToFile( d_filledHists[select][type][location + sName], outFile, location, sName)
def scatterPlot(l_scatter, l_file, l_histo, l_axis, l_text, treeFile, saveDir, l_saveAs): ## De construct the list objects f_str, doSave, outputFile, directory, name = l_file s_str, tree, xBranch, yBranch, option = l_scatter h_str, c_x, c_y, xMin, xMax, yMin, yMax, nBins = l_histo a_str, xLabel, yLabel, xOffset, yOffset, a_labelSize, a_textSize = l_axis t_str, plotText, t_textSize, t_alignment, t_start, t_gap, t_x = l_text ## Read the tree f = TFile(treeFile, 'READ') t = f.Get(tree) v1 = array('d', [0]) v2 = array('d', [0]) t.SetBranchAddress(xBranch, v1) t.SetBranchAddress(yBranch, v2) ## Setup the canvas and fill it! gROOT.SetBatch(1) c = TCanvas('c', 'c', int(c_x), int(c_y)) c.SetTicks(1,1) gStyle.SetOptStat(0) hs = TH2D('hs', '', int(nBins), float(xMin), float(xMax), int(nBins), float(yMin), float(yMax)) for i in range(0, t.GetEntries(), 1): t.GetEntry(i) x = v1[0] y = v2[0] hs.Fill(x,y) if int(doSave): hs.Draw() setupAxes(hs, xLabel, yLabel, xOffset, yOffset, a_textSize, xMin, xMax, 1) ROOTUtils.saveToFile(hs, outputFile, directory, name) hs.Draw(option) setupAxes(hs, xLabel, yLabel, xOffset, yOffset, a_textSize, xMin, xMax, 1) setupTextOnPlot(plotText, t_textSize, t_alignment, t_x, t_start, t_gap) savePlots(c, saveDir + h_str, l_saveAs)
def saveHistograms(self, d_filledHists, t_var, outFile, sDir, t_muon, selectOn, t_select): PythonUtils.Info('Saving Histograms: ' + outFile) for sMu in t_muon: b_mu = 'nMu_' + sMu[0] + sMu[1] for bin in t_select: if bin[1]: select = selectOn + '-' + bin[0] + '-' + bin[1] else: select = selectOn + '-' + bin[0] PythonUtils.Info('Saving Histograms for: ' + selectOn + ' In bin range: ' + bin[0] + ' - ' + bin[1]) for i in xrange(len(t_var)): rBranch, tBranch, sName, sLocation, xMin, xMax, nBins = t_var[i] location = sDir + '/' + b_mu + '/' + select + '/' + sLocation ROOTUtils.saveToFile(d_filledHists[b_mu][select][location + sName], outFile, location, sName)
def saveHistograms(self, d_filledHists, t_type, outFile, sample, baseDir, selectOn, t_select): PythonUtils.Info('++++++++++++++++++++++++++++++++++++++++++++++++++') PythonUtils.Info(' SAVING HISTOGRAMS: ' + baseDir + ' ') PythonUtils.Info('++++++++++++++++++++++++++++++++++++++++++++++++++') for bin in t_select: ## Don't have a trainling slash for all - looks messy PythonUtils.Info('Creating Histograms for process: ' + baseDir + ' in bin: ' + bin[0] + '-' + bin[1]) if bin[0] == 'all': select = selectOn + '-' + bin[0] else: select = selectOn + '-' + bin[0] + '-' + bin[1] for i in range(len(t_type)): type, typeFile = t_type[i] t_typeFile = PythonUtils.makeTupleFromFile(typeFile, ',') for j in range(len(t_typeFile)): rBranch, tBranch, sName, sLocation, xMin, xMax, nBuns = t_typeFile[j] location = baseDir + '/' + sample + '/' + select + '/' + sLocation ROOTUtils.saveToFile(d_filledHists[select][type][location + sName], outFile, location, sName)
def saveHistograms(self, d_filledHists, t_var, outFile, sDir, t_muon, selectOn, t_select): PythonUtils.Info('Saving Histograms: ' + outFile) for sMu in t_muon: b_mu = 'nMu_' + sMu[0] + sMu[1] for bin in t_select: if bin[1]: select = selectOn + '-' + bin[0] + '-' + bin[1] else: select = selectOn + '-' + bin[0] PythonUtils.Info('Saving Histograms for: ' + selectOn + ' In bin range: ' + bin[0] + ' - ' + bin[1]) for i in xrange(len(t_var)): rBranch, tBranch, sName, sLocation, xMin, xMax, nBins = t_var[ i] location = sDir + '/' + b_mu + '/' + select + '/' + sLocation ROOTUtils.saveToFile( d_filledHists[b_mu][select][location + sName], outFile, location, sName)