def plot_corr_root(sumx, sumy, sumz, momentx, momenty, momentz, ecal, energy, hits, ratio, out_file, label, compare=False, gprev=0): c1 = TCanvas("c1", "", 200, 10, 700, 500) #make c1.SetGrid() color = 2 gact, names = get_correlation(sumx, sumy, sumz, momentx, momenty, momentz, ecal, energy, hits, ratio) gact = get_dia(gact) print(gact.shape[0], len(names)) Egraph = ROOT.TGraph2D() fill_graph2D(Egraph, gact) Egraph.Draw('colz') ylen = len(names) c1.Update() Egraph.GetYaxis().SetLabelOffset(1) Egraph.GetYaxis().SetNdivisions(10 * ylen) Egraph.GetXaxis().SetLabelOffset(1) Egraph.GetXaxis().SetNdivisions(10 * ylen) ty = ROOT.TText() ty.SetTextAlign(32) ty.SetTextSize(0.011) ty.SetTextFont(72) tx = ROOT.TText() tx.SetTextAlign(32) tx.SetTextSize(0.011) tx.SetTextFont(72) tx.SetTextAngle(70) y = np.arange(ylen) for i in y: ty.DrawText(-0.42, y[i], names[i]) tx.DrawText(y[i], -0.42, names[ylen - i - 1]) print(len(names)) c1.Update() legend = TLegend(.6, .8, .9, .9) if compare: mse_corr = np.sum(np.square(gprev - gact)) / ylen legend.SetHeader('{} mse_corr/num_features = {:.4f} '.format( label, mse_corr)) else: #legend.AddEntry(Egraph, label, "l") legend.SetHeader(label) legend.Draw() c1.Update() c1.Print(out_file + '_' + label + '.pdf') return gact
def drawAppMVAOutputPlots(region, method, isMC): MCstr = "" if isMC: MCstr = "BsMC12" Region = region[:1].upper() + region[ 1:] #capitalize first letter for retrieving file names HistName = "ApplicationOutput" + MCstr + Region + method CvsName = "canvasMVA_" + MCstr + method + region canvas = TCanvas(CvsName, CvsName) stackBDT = THStack(HistName, HistName) histos = [] appFiles = [] canvas.Draw() # note: TMVApp file name structure: "TMVApp"+Region+method+sample+".root" # "BsMC12TMVApp"+Region+method+sample+".root" appFile = TFile(MCstr + "TMVApp" + Region + method + ".root") histo = appFile.Get("MVA_" + method).Clone(HistName) histo.Scale(1 / histo.GetEntries()) stackBDT.Add(histo) for sample in range(3): appFiles.append( TFile(MCstr + "TMVApp" + Region + method + str(sample) + ".root")) histos.append(appFiles[sample].Get("MVA_" + method).Clone("HistName" + str(sample))) histos[sample].SetLineColor(2 * sample) histos[sample].Scale(1 / histos[sample].GetEntries()) stackBDT.Add(histos[sample]) stackBDT.Draw("nostack") if isMC: applicationBDTLegend = TLegend(0.2, 0.7, 0.5, 0.9, "", "brNDC") #applicationBDTLegend.SetHeader("Bs MC "+region.split("BsMC")[1]) applicationBDTLegend.SetHeader("Bs MC " + Region) else: applicationBDTLegend = TLegend(0.55, 0.7, 0.85, 0.9, "", "brNDC") applicationBDTLegend.SetHeader(Region) applicationBDTLegend.AddEntry(histo, "Full sample", "l") applicationBDTLegend.AddEntry(histos[0], "Trained on 0, tested on 1, applied on 2", "l") applicationBDTLegend.AddEntry(histos[1], "Trained on 1, tested on 2, applied on 0", "l") applicationBDTLegend.AddEntry(histos[2], "Trained on 2, tested on 0, applied on 1", "l") applicationBDTLegend.Draw("same") applicationBDTLegend.SetFillColor(0) applicationBDTLegend.SetLineColor(0) canvas.SaveAs(figuresDir + "Application" + method + "Output_" + MCstr + region + ".pdf")
def make_legend(self): l = TLegend(0.15, 0.85, 0.4, 0.7) if self.country != "wo China": l.SetHeader(self.country, "c") else: l.SetHeader("World (without Mainland China)", "c") for name in self.hists: l.AddEntry(self.hists[name], name) self.legend = l
def EMTFEta(plotter): ## variables for the plot xTitle = "Generated muon |#eta|" title = "%s;%s;%s" % (topTitle, xTitle, yTitle) toPlot = "TMath::Abs(%s)" % (geneta) h_bins = "(20,1.2,2.4)" nBins = int(h_bins[1:-1].split(',')[0]) minBin = float(h_bins[1:-1].split(',')[1]) maxBin = float(h_bins[1:-1].split(',')[2]) c = newCanvas() gPad.SetGridx(xGrid) gPad.SetGridy(yGrid) base = TH1F("base", title, nBins, minBin, maxBin) base.SetMinimum(0) base.SetMaximum(plotter.yMax) base.GetXaxis().SetLabelSize(0.05) base.GetYaxis().SetLabelSize(0.05) base.GetXaxis().SetTitleSize(0.05) base.GetYaxis().SetTitleSize(0.05) base.Draw("") CMS_lumi.CMS_lumi(c, iPeriod, iPos) denom_cut = AND(ok_eta(1.2, 2.4), ok_2_csc_lcts()) h1 = draw_geff(plotter.tree, title, h_bins, toPlot, AND(denom_cut, TCut("genParticle.pt>20")), ok_emtf(20), "same", kBlue) h2 = draw_geff(plotter.tree, title, h_bins, toPlot, AND(denom_cut, TCut("genParticle.pt>15")), ok_emtf(15), "same", kRed) h3 = draw_geff(plotter.tree, title, h_bins, toPlot, AND(denom_cut, TCut("genParticle.pt>10")), ok_emtf(10), "same", kGreen + 2) h4 = draw_geff(plotter.tree, title, h_bins, toPlot, AND(denom_cut, TCut("genParticle.pt>5")), ok_emtf(5), "same", kOrange + 2) h5 = draw_geff(plotter.tree, title, h_bins, toPlot, AND(denom_cut, TCut("genParticle.pt>3")), ok_emtf(0), "same", kBlack) leg = TLegend(0.45, 0.2, .75, 0.5, "", "brNDC") leg.SetBorderSize(0) leg.SetFillStyle(0) leg.SetTextSize(0.05) leg.SetHeader("EMTF") leg.AddEntry(h1, "p_{T} > 20 GeV", "l") leg.AddEntry(h2, "p_{T} > 15 GeV", "l") leg.AddEntry(h3, "p_{T} > 10 GeV", "l") leg.AddEntry(h4, "p_{T} > 5 GeV", "l") leg.AddEntry(h5, "p_{T} > 0 GeV", "l") leg.Draw("same") c.Print("%sEff_EMTF_eta_Pt20_%s" % (plotter.targetDir + subdirectory, plotter.ext)) del c, base, h1, leg, h2, h3, h4, h5
def saveDebugGraph(self, fitList, titleList, name, fitGraph): canvas = TCanvas("Debug_%s" % (name), "y", 1000, 700) # Add a legend legend = TLegend(0.8, 0.9, 1.0, 0.7) legend.SetHeader("Fits:") # Remove Debug.root if it already exists if os.path.exists("Debug.root") and self.GraphNumber == 0: os.remove("Debug.root") self.GraphNumber += 1 # Make sure we did point skimming and created goodPoints and badPoints if not self.goodPoints is None: # goodPoints and badPoints are created together, so we only need to check one self.goodPoints.Draw("AP3") self.badPoints.Draw("P3") legend.AddEntry(self.goodPoints, "Good Points") legend.AddEntry(self.badPoints, "Bad Points") else: fitGraph.SetMarkerColor(4) fitGraph.SetMarkerStyle(7) fitGraph.Draw("AP3") count = 0 # Counting variable for fit in fitList: # Draw fits legend.AddEntry(fit, titleList[count]) fit.SetLineColor(count+6) fit.Draw("same") canvas.Update() count += 1 legend.Draw() canvas.Update() file = TFile("Debug.root", "UPDATE") canvas.Write() file.Close()
def plot_2(var): for s in enumerate(attr): c1 = TCanvas("c1", "Signals", 800, 800) c1.cd() c1.SetGrid() #gStyle.SetTitleFontSize(8.1) if s[1] in ('elf', 'muf', 'chm', 'cm', 'nm'): c1.SetLogx() for cc in channel: hist[cc][s[1]].Draw('colz same') #hist['qcd'][s[1]].Draw() #hist['ctau0'][s[1]].Draw('same') #hist['ttt'][s[1]].Draw('same') legend = TLegend(0.91, 0.91, 0.99, 0.99) legend.SetHeader('samples') for cc in channel: legend.AddEntry(hist[cc][s[1]], cc) #legend.AddEntry(hist['qcd'][s[1]],'qcd') #legend.AddEntry(hist['ctau0'][s[1]],'ctau0') #legend.AddEntry(hist['ttt'][s[1]],'ttt') legend.Draw() c1.Print(path1 + s[1] + var + cutting.replace('(', '_').replace( ')', '_').replace('&&', 'A').replace('>', 'LG').replace( '<', 'LS').replace('=', 'EQ').replace('.', 'P').replace( '-', 'N').replace('Jet', 'J').replace('GenBquark', 'GBQ') + ".pdf") c1.Update()
def makePDFs(root_file, subsystem, x_folder): print "Analyzing %s vs %s" % (subsystem, x_folder) what = "running_wm_rec_selection_vs_rec_tot" cert = root_file.Get("DQM_None_DCS_%s_vs_DQM_%s_DCS_%s/%s/%s" % (subsystem, subsystem, subsystem, x_folder, what)) dcs = root_file.Get("DQM_None_DCS_None_vs_DQM_None_DCS_%s/%s/%s" % (subsystem, x_folder, what)) total = root_file.Get("DQM_None_DCS_None_vs_DQM_%s_DCS_%s/%s/%s" % (subsystem, subsystem, x_folder, what)) d = TCanvas(subsystem, subsystem, 800, 800) cert.SetMinimum(0.95) cert.SetMaximum(1.01) cert.Draw("AP") dcs.SetMarkerColor(kRed) dcs.Draw("P") total.SetMarkerColor(kBlue) total.Draw("P") leg = TLegend(0.6, 0.8, 0.9, 0.9); leg.SetTextFont(102) leg.SetHeader("Info"); leg.AddEntry(cert, "Cert_Eff([DQM+DCS]/[DCS])", "lp"); leg.AddEntry(dcs, "DCS_Eff([DCS]/[ALL])", "lp"); leg.AddEntry(total, "Total_Eff([DQM+DCS]/[ALL])", "lp"); leg.Draw(); d.SaveAs("%s_%s.pdf" % (subsystem, x_folder))
def histo_creation(lumi2017_param, variable_param, binHist_param, minHist_param, maxHist_param, titleX_param, titleY_param): histo = [] legend = TLegend(0.5, 0.5, 0.9, 0.9) canvas = TCanvas() if (lumi2017_param): legend.SetHeader("41.53 fb-1", "C") canvas.SetName(variable_param + "2017") else: legend.SetHeader("35.9 fb-1", "C") canvas.SetName(variable_param + "2016") for i in range(len(MC_sample)): foo = TH1F("essaie{}".format(i), "essaie{}".format(i), binHist_param, minHist_param, maxHist_param) rootfile[i].Get('events').Project("essaie{}".format(i), variable_param, "weight") histo.append(foo) histo[i].SetFillColor(color[i]) histo[i].Scale(luminosity2017 * 1000 * cross_sec[i] / eventsN0[i]) if (not lumi2017_param): histo[i].Scale(lumiRatio) print(histo[i].GetEntries() * lumiRatio * luminosity2017 * 1000 * cross_sec[i] / eventsN0[i]) histo[i].Draw() legend.AddEntry(histo[i], MC_name[i], "f") stack = THStack(variable_param, "") for i in range(len(MC_sample)): stack.Add(histo[len(MC_sample) - (i + 1)]) stack.Draw("HIST") stack.GetXaxis().SetTitle(titleX_param) stack.GetYaxis().SetTitle(titleY_param) legend.Draw() if (lumi2017_param): canvas.SaveAs(localisation + "/results/MC_" + variable_param + "2017.png") else: canvas.SaveAs(localisation + "/results/MC_" + variable_param + "2016.png") canvas.Write()
def createLegends(sample, h1, h2, h3, h4): if sample == "data": leg = TLegend(0.65, 0.75, 0.92, 0.90) if sample == "zjets": leg = TLegend(0.60, 0.75, 0.90, 0.90) leg.SetHeader("Likelihood") if sample == "truth": leg = TLegend(0.60, 0.55, 0.90, 0.72) leg.SetHeader("Truth-matching") leg.SetFillStyle(0) #leg.SetBorderSize(0) leg.SetTextFont(62) leg.SetTextSize(0.03) leg.AddEntry(h1, "p_{T} #in [10, 60] GeV ", "l") leg.AddEntry(h2, "p_{T} #in [60, 90] GeV ", "l") leg.AddEntry(h3, "p_{T} #in [90, 130] GeV ", "l") leg.AddEntry(h4, "p_{T} #in [130, 1000] GeV ", "l") return leg
def draw_subdet(graphs, subdet): l_min = 0 l_max = 0 subdet_str = '' if subdet == 1: l_min = 1 l_max = 4 subdet_str = 'TIB' if subdet == 2: l_min = 5 l_max = 9 subdet_str = 'TOB' if subdet == 3: l_min = 11 l_max = 13 subdet_str = 'TIDm' if subdet == 4: l_min = 14 l_max = 16 subdet_str = 'TIDp' if subdet == 5: l_min = 17 l_max = 24 subdet_str = 'TECm' if subdet == 6: l_min = 26 l_max = 33 subdet_str = 'TECp' leg = TLegend(.92, .3, .99, .7) leg.SetHeader('') leg.SetBorderSize(0) min_y = 1. for layer in range(l_min, l_max + 1): if layer == l_min: graphs[layer - 1].Draw('AP') else: graphs[layer - 1].Draw('P') graphs[layer - 1].SetMarkerColor(1 + layer - l_min) min_y = graphs[layer - 1].GetMinimum( ) if graphs[layer - 1].GetMinimum() < min_y else min_y leg.AddEntry(graphs[layer - 1], ' ' + get_short_layer_name(layer), 'p') graphs[l_min - 1].SetTitle(subdet_str) haxis = graphs[l_min - 1].GetHistogram() haxis.GetYaxis().SetRangeUser(min_y, 1.) leg.Draw() c1.Print('SiStripHitEffTrendPlot_Subdet' + str(subdet) + '.png')
def plotHists(hists,xtitle,plotname,header,ctexts=[ ],otext="",logy=False,y1=0.70): colors = [ kBlue, kRed, kGreen+2, kOrange, kMagenta+1 ] canvas = TCanvas('canvas','canvas',100,100,800,700) canvas.SetMargin(0.12,0.03,0.14,0.06 if otext else 0.03) textsize = 0.040 height = 1.28*(len(hists)+1)*textsize y1 legend = TLegend(0.65,y1,0.88,y1-height) legend.SetTextSize(textsize) legend.SetBorderSize(0) legend.SetFillStyle(0) legend.SetFillColor(0) legend.SetTextFont(62) legend.SetHeader(header) legend.SetTextFont(42) legend.SetMargin(0.2) latex = TLatex() latex.SetTextAlign(13) latex.SetTextFont(42) latex.SetNDC(True) frame = hists[0] frame.GetXaxis().SetTitle(xtitle) frame.GetYaxis().SetTitle("Fraction [%]") frame.GetXaxis().SetLabelSize(0.074) frame.GetYaxis().SetLabelSize(0.046) frame.GetXaxis().SetTitleSize(0.048) frame.GetYaxis().SetTitleSize(0.052) frame.GetXaxis().SetTitleOffset(1.38) frame.GetYaxis().SetTitleOffset(1.12) frame.GetXaxis().SetLabelOffset(0.009) frame.SetMaximum(1.25*max(h.GetMaximum() for h in hists)) if logy: canvas.SetLogy() frame.SetMinimum(1e-3) else: frame.SetMinimum(0) for i, hist in enumerate(hists): hist.Draw('HISTE0E1SAME') hist.SetLineWidth(2) hist.SetLineColor(colors[i%len(colors)]) legend.AddEntry(hist,hist.GetTitle(),'le') legend.Draw() for i, text in enumerate(ctexts): textsize = 0.024 #if i>0 else 0.044 latex.SetTextSize(textsize) latex.DrawLatex(0.14,0.98-canvas.GetTopMargin()-1.7*i*textsize,text) if otext: latex.SetTextSize(0.05) latex.SetTextAlign(31) latex.DrawLatex(1.-canvas.GetRightMargin(),1.-0.84*canvas.GetTopMargin(),otext) canvas.SaveAs(plotname+".png") canvas.SaveAs(plotname+".pdf") canvas.Close() for hist in hists: gDirectory.Delete(hist.GetName())
def limitCompare(method): signal, particle, particleP = "XZH", "Z", "Z'" channels = ["0bonly", "bbonly"] colors = [1, 610 + 4] #, 632, 800+7, 800, 416+1, 860+10, 600, 616, 921, 922] masses, vals, graphs = {}, {}, {} for j, c in enumerate(channels): masses[c], vals[c] = fillValues("./combine/" + method + "/" + signal + c + "_M%d.txt") graphs[c] = TGraph() n = 0 #print vals[c] for i, m in enumerate(masses[c]): #if not signals[i] >= 1000: continue graphs[c].SetPoint(n, m, vals[c][m][3]) n = n + 1 graphs[c].SetLineColor(colors[j]) graphs[c].SetLineWidth(3) graphs[c].Draw("SAME, L") comp = TCanvas("comp", "Exclusion Limits", 800, 600) comp.cd() #c1.SetPad(c1.GetPad(0)) comp.GetPad(0).SetTopMargin(0.06) comp.GetPad(0).SetRightMargin(0.05) comp.GetPad(0).SetTicks(1, 1) comp.GetPad(0).SetLogy() for c in channels: graphs[c].Draw("SAME, L") graphs[channels[0]].GetXaxis().SetRangeUser(800., 5000.) graphs[channels[0]].GetYaxis().SetRangeUser(0.25, 2.5e4) graphs[channels[0]].GetXaxis().SetTitle("m_{" + particleP + "} (GeV)") graphs[channels[0]].GetYaxis().SetTitle("#sigma(" + particleP + ") #bf{#it{#Beta}}(" + particleP + " #rightarrow " + particle + "H) (fb)") drawAnalysis(signal) #drawRegion(signal, True) drawCMS(LUMI, YEAR, "Preliminary") # legend top = 0.9 leg = TLegend(0.4, top - len(channels) * 0.2 / 5., 0.99, top) leg.SetBorderSize(0) leg.SetFillStyle(0) #1001 leg.SetFillColor(0) leg.SetHeader("95% CL expected limits") for c in channels: leg.AddEntry(graphs[c], getChannel(c), "l") leg.Draw() comp.Update() comp.Print("plotsLimit/Multi.png") comp.Print("plotsLimit/Multi.pdf")
def L1TrackMuonPt(plotter): ## variables for the plot topTitle = "" xTitle = "Generated muon p_{T} [GeV]" title = "%s;%s;%s" % (topTitle, xTitle, yTitle) toPlot = genpt h_bins = "(20,0,100)" nBins = int(h_bins[1:-1].split(',')[0]) minBin = float(h_bins[1:-1].split(',')[1]) maxBin = float(h_bins[1:-1].split(',')[2]) c = newCanvas() base = TH1F("base", title, nBins, minBin, maxBin) base.SetMinimum(0) base.SetMaximum(plotter.yMax) base.GetXaxis().SetLabelSize(0.05) base.GetYaxis().SetLabelSize(0.05) base.GetXaxis().SetTitleSize(0.05) base.GetYaxis().SetTitleSize(0.05) base.Draw("") CMS_lumi.CMS_lumi(c, iPeriod, iPos) denom_cut = AND(ok_eta(1.2, 2.4), ok_2_csc_lcts()) h1 = draw_geff(plotter.tree, title, h_bins, toPlot, denom_cut, ok_l1trackmuon(20), "same", kBlue) h2 = draw_geff(plotter.tree, title, h_bins, toPlot, denom_cut, ok_l1trackmuon(15), "same", kRed) h3 = draw_geff(plotter.tree, title, h_bins, toPlot, denom_cut, ok_l1trackmuon(10), "same", kGreen + 2) h4 = draw_geff(plotter.tree, title, h_bins, toPlot, denom_cut, ok_l1trackmuon(5), "same", kOrange + 2) h5 = draw_geff(plotter.tree, title, h_bins, toPlot, denom_cut, ok_l1trackmuon(0), "same", kBlack) leg = TLegend(0.45, 0.2, .75, 0.5, "", "brNDC") leg.SetBorderSize(0) leg.SetFillStyle(0) leg.SetTextSize(0.05) leg.SetHeader("L1TrackMuon") leg.AddEntry(h1, "p_{T} > 20 GeV", "l") leg.AddEntry(h2, "p_{T} > 15 GeV", "l") leg.AddEntry(h3, "p_{T} > 10 GeV", "l") leg.AddEntry(h4, "p_{T} > 5 GeV", "l") leg.AddEntry(h5, "p_{T} > 0 GeV", "l") leg.Draw("same") c.Print("%sEff_L1TrackMuon_pt_Pt20_%s" % (plotter.targetDir + subdirectory, plotter.ext)) del c, base, h1, leg, h2, h3, h4, h5
def plot2Dhist(): observed_sel = ["TT", "TL", "LT", "LL"] charges = ["OS", "SS"] flavours = ["ElEl", "MuMu"] #input_path = "../OutputPlots_MMRates_LHFit_2DPt/" input_path = "../OutputPlots_MMRates_LHFit_25ns_v7_FinalSelection_NominalBinning/" set_fancy_2D_style() for ch in charges: for flav in flavours: for sl in observed_sel: path = input_path + ch + "_" + flav + "_" + sl + "/" + ch + "_" + flav + "_" + sl + "_Lep0Pt_VS_Lep1Pt.root" myfile = TFile(path) myhist = myfile.Get("observed") c = TCanvas("c1", "Temp", 50, 50, 1000, 800) header = None if ch == "OS": header = "2 Lep SS Real CR" elif ch == "SS": header = "2 Lep SS Fake CR" legend = TLegend(0.2, 0.8, 0.4, 0.85) # (x1,y1 (--> bottom left corner), x2, y2 (--> top right corner) ) legend.SetHeader(header) legend.SetBorderSize(0) # no border legend.SetFillStyle(0) # Legend transparent background legend.SetTextSize(0.04) # Increase entry font size! legend.SetTextFont(42) # Helvetica leg_ATLAS = TLatex() leg_lumi = TLatex() leg_ATLAS.SetTextSize(0.03) leg_ATLAS.SetNDC() leg_lumi.SetTextSize(0.03) leg_lumi.SetNDC() myhist.Draw("colz text") legend.Draw() leg_ATLAS.DrawLatex(0.2, 0.75, "#bf{#it{ATLAS}} Work In Progress") leg_lumi.DrawLatex( 0.2, 0.7, "#sqrt{s} = 13 TeV, #int L dt = 3.2 fb^{-1}") canvasname = ch + "_" + flav + "_" + sl + "_observed" c.SaveAs(canvasname + ".png")
def setup_canvas(hist_name): canvas = TCanvas(hist_name, hist_name, 0, 0, 800, 800) canvas.SetMargin(0.13, 0.05, 0.12, 0.05) canvas.SetTicks(1, 1) leg = TLegend(0.3, 0.15, 0.75, 0.4) leg.SetNColumns(3) leg.SetBorderSize(0) leg.SetTextSize(0.03) leg.SetTextFont(42) leg.SetMargin(0.2) leg.SetHeader("Train setup: #it{N}_{ev}^{training}, #it{n}_{#it{#varphi}}" +\ " #times #it{n}_{#it{r}} #times #it{n}_{#it{z}}", "C") return canvas, leg
def compare_variables(sample, var_list, name): cv = TCanvas("cv", "cv", 1000, 800) cv.SetGrid() cv.cd() if "CSV" in name: leg = TLegend(0.12, 0.6, 0.45, 0.88) elif "pT" in name: leg = TLegend(0.62, 0.6, 0.95, 0.88) nomefile[sample] = TFile.Open( NTUPLEDIR + samples[sample]['file'] + ".root", 'read') leg.SetHeader(samples[sample]['leg_name']) massimo = 0 for i, s in enumerate(var_list): histo[s] = nomefile[sample].Get(samples[sample]['type'] + "/" + s) histo[s].SetLineColor(colors[i]) histo[s].SetLineWidth(3) histo[s].SetTitle("") if "CSV" in name: histo[s].GetXaxis().SetTitle("CSV score") elif "pT" in name: histo[s].GetXaxis().SetTitle("p_{T} [GeV]") leg.AddEntry(histo[s], variables[s]['legend_label']) histo[s].GetXaxis().SetRangeUser(variables[s]['xmin'], variables[s]['xmax']) if sample == "ZH_MS-40_ctauS-1": print i, s, massimo massimo = max(massimo, histo[s].GetMaximum()) histo[s].Draw("same") histo[s].SetMaximum(massimo * 1.2) uncert[s] = histo[s].Clone(s + "_err") uncert[s].SetMarkerStyle(0) uncert[s].SetFillColor(colors[i]) uncert[s].SetFillStyle(3001) uncert[s].Draw("SAME,E2") if variables[s]['log']: cv.SetLogy() leg.Draw() latex = TLatex() latex.SetNDC() latex.SetTextAlign(33) latex.SetTextSize(0.04) latex.SetTextFont(62) latex.DrawLatex(0.20, 0.96, "CMS") latex.SetTextFont(52) latex.DrawLatex(0.36, 0.96, "Simulation") cv.Print(PLOTDIR + name + "_" + sample + '.png') cv.Print(PLOTDIR + name + "_" + sample + '.pdf') cv.Close()
def checkForOutliers(hist, qaContainer): """ Checks for outliers in selected histograms. Outliers are calculated by looking at the standard deviation. See: :func:`hasSignalOutlier()`. This function is mainly a proof of concept, but could become more viable with a bit more work. Note: This function will add a large TLegend to the histogram noting the mean and the number of outliers. It will also display the recalculated mean excluding the outlier(s). Args: hist (TH1): The histogram to be processed. qaContainer (:class:`~processRuns.qa.qaFunctionContainer`): Contains information about the QA function and histograms, as well as the run being processed. Returns: None """ # If outlier data point, print warning banner if hist.GetName() == "": tempList = hasSignalOutlier( hist ) # array of info from hasSignalOutlier function, to print on legend numOutliers = tempList[0] mean = tempList[1] stdev = tempList[2] newMean = tempList[3] newStdev = tempList[4] if (numOutliers): # Create TLegend and fill with information if there is an outlier. leg = TLegend(0.15, 0.5, 0.7, 0.8) SetOwnership(leg, False) leg.SetBorderSize(4) leg.SetShadowColor(2) leg.SetHeader("#splitline{OUTLIER SIGNAL DETECTED}{IN %s BINS!}" % numOutliers) leg.AddEntry( None, "Mean: %s, Stdev: %s" % ('%.2f' % mean, '%.2f' % stdev), "") leg.AddEntry( None, "New mean: %s, New Stdev: %s" % ('%.2f' % newMean, '%.2f' % newStdev), "") leg.SetTextSize(0.04) leg.SetTextColor(2) leg.Draw()
def runAllSamples(self): gStyle.SetOptStat(0) gROOT.SetBatch(True) dict_run_hist = dict( (k, self.runSample(k, h)) for k, h in self.dict_path_dir.items()) max_list = [ tuple(h.GetMaximum() for h in hist) for hist in dict_run_hist.values() ] max_h = max(max_list) gROOT.SetBatch(False) legend = TLegend(0.15, 0.7, 0.45, 0.83) legend.SetHeader("Legend", "C") c = TCanvas("C", "C", 2000, 500) c.Divide(3, 1) c.SetLogy() i = 0 for k, (h, h_in, h_out) in dict_run_hist.items(): h.SetLineColor(i + 1) h_in.SetLineColor(i + 1) h_out.SetLineColor(i + 1) legend.AddEntry(h, k, "l") opt = "hist" if i != 0: opt += " same" h.SetTitle("Runs") h.SetMaximum(max_h[0]) h_in.SetMaximum(max_h[1]) h_out.SetMaximum(max_h[2]) c.cd(1) h.Draw(opt) c.cd(2) h_in.Draw(opt) c.cd(3) h_out.Draw(opt) i += 1 legend.Draw() c.Print("test.png")
def setup_canvas(suffix, hist_name, opt_name, x_label, y_label): full_name = "%s_canvas_%s_%s" % (hist_name, suffix, opt_name) canvas = TCanvas(full_name, full_name, 0, 0, 800, 800) canvas.SetMargin(0.12, 0.05, 0.12, 0.05) canvas.SetTicks(1, 1) frame = canvas.DrawFrame(-5, -0.5, +5, +0.5) setup_frame(frame, x_label, y_label) leg = TLegend(0.5, 0.7, 0.9, 0.9) leg.SetBorderSize(0) leg.SetTextFont(42) leg.SetTextSize(0.03) leg.SetHeader("Train setup: #it{N}_{ev}^{training}, #it{n}_{#it{#varphi}}" +\ " #times #it{n}_{#it{r}} #times #it{n}_{#it{z}}", "C") return canvas, frame, leg
def draw_bragg_max(self): #three histograms for bragg maxima self.bragg_maxima_can = TCanvas("max_can_" + self.name, "Bragg maxima") self.bragg_histograms = [TH1D(self.name + "line%i" %i, "Bragg max", 100, 130, 230) for i in range(3)] for i, line in enumerate(self.spectral_lines): self.ntuple.Draw("maxC>>%sline%i" %(self.name, i), line, "goff") for i, hist in enumerate(self.bragg_histograms): hist.SetLineStyle(i + 1) if i: hist.Draw("same") else: hist.Draw() hist.GetYaxis().SetRangeUser(0,75) leg_hist = TLegend(0.75,0.75,0.98,0.98) leg_hist.SetHeader("Bragg maxima") [leg_hist.AddEntry(hist,"alpha energy %i" %(i+1),"l") for i, hist in enumerate(self.bragg_histograms)] leg_hist.Draw();
h_Night = f2.Get(folder + '/' + histo) h_Night.SetMarkerStyle(8) h_Night.SetMarkerSize(0.5) mainPad.cd() h_Base.Draw() h_Night.Draw("same p") c1.Update() var_name = histo.split("_", 1)[1] leg = TLegend(0.330986, 0.884087, 0.879499, 0.97053) leg.SetHeader(folder + '' + var_name, "C") leg.SetNColumns(2) leg.SetFillStyle(0) leg.SetBorderSize(0) leg.AddEntry(h_Base, "Baseline", "l") leg.AddEntry(h_Night, "Nightly", "p") leg.Draw() c1.Update() ratioPad.cd() h1clone = h_Night.Clone() h1clone.Sumw2() h1clone.SetStats(0) h1clone.Divide(h_Base)
def plot1D(histname, histnum2D, histden2D, year, channel, title="", log=False): """Plot efficiency.""" dir = ensureDirectory('plots/%d' % year) name = "%s/%s_%s" % (dir, histname, channel) if log: name += "_log" header = "" xtitle = 'jet p_{T} [GeV]' ytitle = 'b tag efficiencies' if '_b_' in histname else 'b mistag rate' xmin, xmax = 20 if log else 10, histnum2D.GetXaxis().GetXmax() ymin, ymax = 5e-3 if log else 0.0, 2.0 colors = [kBlue, kRed, kOrange] x1, y1 = (0.27, 0.44) if '_b_' in histname else (0.55, 0.80) width, height = 0.3, 0.16 x2, y2 = x1 + width, y1 - height hists = createEff1D(histnum2D, histden2D) canvas = TCanvas('canvas', 'canvas', 100, 100, 800, 700) canvas.SetFillColor(0) canvas.SetBorderMode(0) canvas.SetFrameFillStyle(0) canvas.SetFrameBorderMode(0) canvas.SetTopMargin(0.04) canvas.SetBottomMargin(0.13) canvas.SetLeftMargin(0.12) canvas.SetRightMargin(0.05) canvas.SetTickx(0) canvas.SetTicky(0) canvas.SetGrid() gStyle.SetOptTitle(0) if log: canvas.SetLogx() canvas.SetLogy() canvas.cd() frame = hists[0] for i, hist in enumerate(hists): hist.SetLineColor(colors[i % len(colors)]) hist.SetMarkerColor(colors[i % len(colors)]) hist.SetLineWidth(2) hist.SetMarkerSize(2) hist.SetMarkerStyle(1) hist.Draw('PE0SAME') frame.GetXaxis().SetTitle(xtitle) frame.GetYaxis().SetTitle(ytitle) frame.GetXaxis().SetLabelSize(0.048) frame.GetYaxis().SetLabelSize(0.048) frame.GetXaxis().SetTitleSize(0.058) frame.GetYaxis().SetTitleSize(0.058) frame.GetXaxis().SetTitleOffset(1.03) frame.GetYaxis().SetTitleOffset(1.04) frame.GetXaxis().SetLabelOffset(-0.004 if log else 0.005) frame.GetXaxis().SetRangeUser(xmin, xmax) frame.SetMinimum(ymin) frame.SetMaximum(ymax) if title: latex = TLatex() latex.SetTextSize(0.04) latex.SetTextAlign(13) latex.SetTextFont(62) latex.SetNDC(True) latex.DrawLatex(0.15, 0.94, title) legend = TLegend(x1, y1, x2, y2) legend.SetTextSize(0.04) legend.SetBorderSize(0) legend.SetFillStyle(0) legend.SetFillColor(0) if header: legend.SetTextFont(62) legend.SetHeader(header) legend.SetTextFont(42) for hist in hists: legend.AddEntry(hist, hist.GetTitle(), 'lep') legend.Draw() canvas.SaveAs(name + '.pdf') canvas.SaveAs(name + '.png') canvas.Close()
if out > 0: hist.Scale(1. / hist.Integral()) ###hist.Draw('HISTE') ###canvas.SaveAs(histname+".png") ###canvas.SaveAs(histname+".pdf") ###canvas.Close() hists.append(hist) gStyle.SetOptTitle(False) canvas = TCanvas('canvas', 'canvas', 100, 100, 800, 600) canvas.SetTopMargin(0.03) legend = TLegend(0.7, 0.7, 0.85, 0.5) legend.SetTextSize(0.04) legend.SetBorderSize(0) legend.SetFillStyle(0) legend.SetFillColor(0) legend.SetTextFont(62) legend.SetHeader(trigger) legend.SetTextFont(42) plotname = "%s_nTau_%s_comparison" % (trigger, filter) hists[0].SetMaximum(1.18 * max(h.GetMaximum() for h in hists)) for hist in hists: hist.Draw('HISTSAME') legend.AddEntry(hist, hist.GetTitle(), 'l') legend.Draw() canvas.SaveAs(plotname + ".png") canvas.SaveAs(plotname + ".pdf") canvas.Close() for hist in hists: gDirectory.Delete(hist.GetName()) file.Close()
def DrawOverlap(fileVec, histVec, titleVec, legendtext, pngname, logstatus=[0, 0], xRange=[-99999, 99999, 1], text_="", x_=0.5, y_=0.5, legendloc=[0.53, 0.13, 0.93, 0.39]): gStyle.SetOptTitle(0) gStyle.SetOptStat(0) #gStyle.SetTitleOffset(1.1,"Y"); #gStyle.SetTitleOffset(0.9,"X"); gStyle.SetLineWidth(3) gStyle.SetFrameLineWidth(3) i = 0 histList_ = [] histList = [] histList1 = [] maximum = [] ## Legend legpos = legendloc leg = TLegend(legpos[0], legpos[1], legpos[2], legpos[3]) leg.SetBorderSize(0) leg.SetNColumns(2) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(42) leg.SetTextSize(0.049) from PlotTemplates import myCanvas1D c = myCanvas1D() c.SetLogy(logstatus[1]) c.SetLogx(logstatus[0]) #c.SetBottomMargin(0.15) #c.SetLeftMargin(0.15) #c1_2 = TPad("c1_2","newpad",0.04,0.13,1,0.994) #c1_2.Draw() print("you have provided " + str(len(fileVec)) + " files and " + str(len(histVec)) + " histograms to make a overlapping plot") print "opening rootfiles" c.cd() #c1_2.SetBottomMargin(0.013) #c1_2.SetLogy(logstatus[1]) #c1_2.SetLogx(logstatus[0]) #c1_2.cd() ii = 0 inputfile = {} print str(fileVec[(len(fileVec) - 1)]) for ifile_ in range(len(fileVec)): print("opening file " + fileVec[ifile_]) inputfile[ifile_] = TFile(fileVec[ifile_]) print "fetching histograms" for ihisto_ in range(len(histVec)): print("printing histo " + str(histVec[ihisto_])) histo = inputfile[ifile_].Get(histVec[ihisto_]) #status_ = type(histo) is TGraphAsymmErrors histList.append(histo) # for ratio plot as they should nt be normalize histList1.append(histo) #print histList[ii].Integral() #histList[ii].Rebin(xRange[2]) #histList[ii].Scale(1.0/histList[ii].Integral()) maximum.append(histList[ii].GetMaximum()) maximum.sort() ii = ii + 1 print histList for ih in range(len(histList)): tt = type(histList[ih]) if logstatus[1] is 1: histList[ih].SetMaximum(100) #1.4 for log histList[ih].SetMinimum(0.00001) #1.4 for log if logstatus[1] is 0: histList[ih].SetMaximum(1.4) #1.4 for log histList[ih].SetMinimum(0.001) #1.4 for log # print "graph_status =" ,(tt is TGraphAsymmErrors) # print "hist status =", (tt is TH1D) or (tt is TH1F) if ih == 0: if tt is TGraphAsymmErrors: histList[ih].Draw("APL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("hist") if ih > 0: #histList[ih].SetLineWidth(2) if tt is TGraphAsymmErrors: histList[ih].Draw("PL same") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("hist same") if tt is TGraphAsymmErrors: histList[ih].SetMaximum(10) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetMarkerStyle(markerStyle[ih]) histList[ih].SetMarkerSize(1) leg.AddEntry(histList[ih], legendtext[ih], "PL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(3) leg.AddEntry(histList[ih], legendtext[ih], "L") histList[ih].GetYaxis().SetTitle(titleVec[1]) histList[ih].GetYaxis().SetTitleSize(0.052) histList[ih].GetYaxis().SetTitleOffset(1.08) histList[ih].GetYaxis().SetLabelSize(.052) histList[ih].GetXaxis().SetRangeUser(xRange[0], xRange[1]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitle(titleVec[0]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitleSize(0.052) histList[ih].GetXaxis().SetTitleOffset(1.14) #histList[ih].GetXaxis().SetTickLength(0.07) histList[ih].GetXaxis().SetNdivisions(508) from PlotTemplates import SetCMSAxis histList[ih] = SetCMSAxis(histList[ih], 1.0, 1.15) #histList[ih].GetXaxis().SetMoreLogLabels(); #histList[ih].GetXaxis().SetNoExponent(); #histList[ih].GetTGaxis().SetMaxDigits(3); i = i + 1 ''' pt = TPaveText(0.0877181,0.9,0.9580537,0.96,"brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(22) pt.SetTextSize(0.046) text = pt.AddText(0.2,0.5,"CMS Internal") ''' from PlotTemplates import drawenergy1D pt_ = drawenergy1D(False) for ipt in pt_: ipt.Draw() ''' if len(text_) >0: ltx = TLatex() ltx.SetTextFont(42) ltx.SetTextSize(0.049) #text_f = "#font[42]{Phase Scan}" ltx.DrawTextNDC(x_,y_,text_) ''' from PlotTemplates import ExtraText text_ex = ExtraText(text_, x_, y_) text_ex.Draw() ExtraText("ECAL Endcaps", 0.4, 0.85) ltx_ = TLatex() ltx_.SetTextFont(42) ltx_.SetTextSize(0.049) ltx_.DrawLatexNDC(0.32, 0.81, "L1 e-#gamma object p_{T} > 10 GeV") #text_ex.Draw() #pt = TPaveText(0.0877181,0.9,0.9580537,0.96,"brNDC") #text = pt.AddText(0.65,0.5,"Phase Scan data #sqrt{s} = 13 TeV (2018)") #pt.Draw() # t2a = TPaveText(0.0877181,0.81,0.9580537,0.89,"brNDC") # t2a.SetBorderSize(0) # t2a.SetFillStyle(0) # t2a.SetTextSize(0.040) # t2a.SetTextAlign(12) # t2a.SetTextFont(62) # histolabel1= str(fileVec[(len(fileVec)-1)]) # text1 = t2a.AddText(0.06,0.5,"CMS Internal") # t2a.Draw() leg.SetHeader("Matched TP energy") leg.Draw() # # c.cd() outputdirname = './' histname = outputdirname + pngname c.SaveAs(histname + '.png') c.SaveAs(histname + '.pdf')
#outFile.cd() #mc.Write() #data.Write() #dataUp.Write() #dataDown.Write() #ratio.Write() #ratioUp.Write() #ratioDown.Write() #outFile.Close() #print "Histograms written to ../data/PU.root file" leg = TLegend(0.5, 0.7, 0.98, 0.9) leg.SetBorderSize(0) leg.SetFillStyle(0) #1001 leg.SetFillColor(0) leg.SetHeader("Pile-up reweighting") leg.AddEntry(dataUp, "Up", "pl") leg.AddEntry(data, "Central", "pl") leg.AddEntry(dataDown, "Down", "pl") #leg.AddEntry(mc, "MC 25ns", "pl") leg.AddEntry(mc, scenario, "pl") c1 = TCanvas("c1", "PileUp reweighting", 800, 800) c1.cd() c1.GetPad(0).SetTopMargin(0.06) c1.GetPad(0).SetRightMargin(0.05) c1.GetPad(0).SetTicks(1, 1) dataDown.SetTitle(";number of true interactions") dataDown.GetXaxis().SetRangeUser(0., 100) dataDown.Draw("HIST") dataUp.Draw("SAME, HIST")
if 'y-title' in plots[plot]: p.GetYaxis().SetTitle(plots[plot]['y-title']) if 'y-min' in plots[plot]: p.SetMinimum(plots[plot]['y-min']) if 'y-max' in plots[plot]: p.SetMaximum(plots[plot]['y-max']) if 'x-max' in plots[plot]: p.GetXaxis().SetRangeUser(plots[plot]['x-min'], plots[plot]['x-max']) c2.SetGrid() if plots[plot].get('y-log', False): c2.SetLogy(1) else: c2.SetLogy(0) if irun > 0 or ilumisection > 0 or ibx > 0: drawoptions ='same' legend.SetHeader(layer) p.Draw(drawoptions) legend.AddEntry(p.GetName(), '%i %s ls:%i-%i bx:%s' % (run, runs[run]['comments'], lumisection[0], lumisection[1], bx), 'lp') # legend.AddEntry(p.GetName(), '%i LS %i-%i (%.2f - %.2f e33 cm^{-2}/s)' % (run, lumisection[0], lumisection[1], instLumi[run][lumisection[0]], instLumi[run][lumisection[1]]), 'lp') ROOT.gPad.Modified() ROOT.gPad.Update() # end of loop over histos # end of loop over bx intervals # end of loop of lumisections # end of loop over runs latexLabel = TLatex() latexLabel.SetTextSize(0.75 * c1.GetTopMargin()) latexLabel.SetNDC() latexLabel.SetTextFont(42) # helvetica # latexLabel.DrawLatex(0.27, 0.96, layer) legend.Draw()
W = 800 T = 0.08 * H B = 0.12 * H L = 0.12 * W R = 0.1 * W legendHeightPer = 0.04 legendStart = 0.6 legendEnd = 0.97 - (R / W) # legend = TLegend(0.7,0.7,0.88,0.88) legend = TLegend(legendStart, 1 - T / H - 0.01 - legendHeightPer * (6), legendEnd, 0.99 - (T / H) - 0.01) legend.SetBorderSize(0) legend.SetFillColor(0) legend.SetHeader(myDir[idir], "L") TGaxis.SetMaxDigits(3) c = TCanvas('c', '', W, H) c.SetFillColor(0) c.SetBorderMode(0) c.SetFrameFillStyle(0) c.SetFrameBorderMode(0) c.SetLeftMargin(L / W) c.SetRightMargin(R / W) c.SetTopMargin(T / H) c.SetBottomMargin(B / H) c.SetTickx(0) c.SetTicky(0) c.Draw() c.cd()
legend.SetBorderSize(0) yMin=0 yMax = max(eeHist.GetBinContent(eeHist.GetMaximumBin()),emHist.GetBinContent(mmHist.GetMaximumBin()))*1.5 hCanvas.DrawFrame(0,yMin,5,yMax,"; %s ; %s" %("#Delta R(ll)","N_{events} [a.u.]")) ROOT.gStyle.SetOptStat(0) eeHist.SetLineColor(ROOT.kRed) eeHist.SetLineWidth(2) eeHist.SetLineStyle(2) #~ eeHist.SetLineColor(ROOT.kRed) fakeHist = ROOT.TH1F() fakeHist.SetLineColor(ROOT.kWhite) legend.SetHeader("t#bar{t} Simulation") legend.AddEntry(eeHist,"e^{#pm}e^{#mp}","l") legend.AddEntry(emHist,"#mu^{#pm}#mu^{#mp}","l") eeHist.Draw("samehist") mmHist.Draw("samehist") legend.Draw("same") line1 = ROOT.TLine(0.3,0,0.3,yMax) line2 = ROOT.TLine(1.6,0,1.6,yMax) line1.SetLineColor(ROOT.kBlue+3) line2.SetLineColor(ROOT.kBlue+3) line1.SetLineWidth(2) line2.SetLineWidth(2) line1.SetLineStyle(2)
def efficiencytracking(var): # plots the efficiency vs pT, eta and phi for all the species(it extracts the # Efficiency from qa - tracking - efficiency if you have ran with-- make - eff) hadron_list = [ "pion", "proton", "kaon", "electron", "muon", ] color_list = [1, 2, 4, 6, 8] marker_list = [20, 21, 22, 34, 45] fileo2 = TFile("../codeHF/AnalysisResults_O2.root") c1 = TCanvas("c1", "Efficiency") gStyle.SetOptStat(0) gStyle.SetErrorX(0) gStyle.SetFrameLineWidth(2) gStyle.SetTitleSize(0.045, "x") gStyle.SetTitleSize(0.045, "y") gStyle.SetMarkerSize(1) gStyle.SetLabelOffset(0.015, "x") gStyle.SetLabelOffset(0.02, "y") gStyle.SetTickLength(-0.02, "x") gStyle.SetTickLength(-0.02, "y") gStyle.SetTitleOffset(1.1, "x") gStyle.SetTitleOffset(1.0, "y") c1.SetCanvasSize(800, 600) c1.cd() c1.SetGridy() c1.SetGridx() eff_list = [] if var == "Pt": hempty = TH1F("hempty", ";Transverse Momentum(GeV/c);Efficiency", 100, 0.05, 10) gPad.SetLogx() elif var == "Eta": hempty = TH1F("hempty", ";Pseudorapidity;Efficiency", 100, -4.0, 4.0) elif var == "Phi": hempty = TH1F("hempty", ";Azimuthal angle(rad);Efficiency", 100, 0.0, 6.0) hempty.GetYaxis().CenterTitle() hempty.GetXaxis().CenterTitle() hempty.GetXaxis().SetNoExponent() hempty.GetXaxis().SetMoreLogLabels(1) hempty.Draw() leg = TLegend(0.55, 0.15, 0.89, 0.35, "P") leg.SetNColumns(2) leg.SetHeader("Minimum bias KrKr #sqrt{s} = 6.46TeV", "C") leg.SetFillColor(0) for i, had in enumerate(hadron_list): leff = fileo2.Get("qa-tracking-efficiency-%s/Efficiency" % had) if var == "Pt": eff = leff.At(0) elif var == "Eta": eff = leff.At(1) elif var == "Phi": eff = leff.At(2) gPad.Update() eff.Paint("p") gr = eff.GetPaintedGraph().Clone() for j in range(0, gr.GetN()): gr.GetEXlow()[j] = 0 gr.GetEXhigh()[j] = 0 gr.SetLineColor(color_list[i]) gr.SetMarkerColor(color_list[i]) gr.SetMarkerStyle(marker_list[i]) eff_list.append(gr) gr.Draw(" same p") leg.AddEntry(eff_list[i], had, "p") leg.Draw() saveCanvas(c1, "efficiency_tracking_%s" % var)
gComptonPhotMFP.SetPoint(i, hPrimaryEnergy[i].GetMean(), MFPComptonPhot) gComptonPhotMassicCS.SetPoint(i, hPrimaryEnergy[i].GetMean(), massicCSComptonPhot) # plot histograms idx_1 = 3 idx_2 = 10 idx_3 = 28 leg = TLegend(.63, .62, .97, .93) leg.SetBorderSize(0) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(42) leg.SetTextSize(0.035) leg.SetHeader("prim. photon energy", "C") leg.AddEntry(hLStep[idx_1], "40 keV") leg.AddEntry(hLStep[idx_2], "110 keV") leg.AddEntry(hLStep[idx_3], "290 keV") #step length histo c1 = TCanvas("c1", "c1", 200, 10, 1200, 500) c1.Divide(2) c1.cd(1) c1.cd(1).SetLogy() hLStep[idx_1].Draw("hist") hLStep[idx_2].Draw("hist,same") hLStep[idx_2].SetLineColor(kBlue) hLStep[idx_3].Draw("hist,same") hLStep[idx_3].SetLineColor(kRed) leg.Draw("same")