# this program takes a root file that already contains histograms and makes an overlay plot in pdf format of those histograms import ROOT from ROOT import TFile, TH1F, TColor ROOT.gROOT.SetBatch(True) #import file f = TFile.Open("FILE.root") #get h1 h1 = f.Get("histogram_name_1") print(h1.Integral()) # this is to check how many items are in the histogram # get second histogram h2 = f.Get("histogram_2_name") print(h2.Integral()) # get third histogram h3 = f.Get("histogram_3_name") print(h3.Integral()) # 4th h4 = f.Get("histogram_4_name") print(h4.Integral()) # you can add or subtract as many histograms as you need to overlay #set h1 preferences h1.SetTitle("Name of overlay Plot") #define the name of the overlay plot here h1.SetStats(0) h1.SetLineColor(ROOT.kBlack) #choose some line color, options can be found by searching root color wheel #set h2 preferences h2.SetTitle("") # every other histogram title should be blank or else it will get messed up h2.SetStats(0) h2.SetLineColor(ROOT.kBlue+2) #make sure that it is a different color from above #set h3 pref h3.SetTitle("") h3.SetStats(0) h3.SetLineColor(ROOT.kRed+1) #set h4 pref h4.SetTitle("") h4.SetStats(0) h4.SetLineColor(ROOT.kCyan) # draw canvas c0 = ROOT.TCanvas("canvas_name") c0.cd() # go onto the canvas you just created h1.Draw() #draw your first histogram on the canvas # draw other histogram on same canvas c0.cd() h2.Draw("SAME") c0.cd() h3.Draw("SAME") c0.cd() h4.Draw("SAME") c0.cd() #add legend for the overlay histograms leg = ROOT.TLegend(.27, .75, .5, .90) # top right leg.SetBorderSize(0) # no border leg.SetFillColor(0) # no fill leg.SetFillStyle(0) # no fill leg.SetTextFont(42) leg.SetTextSize(.02) leg.AddEntry(h1, "entry_title" + ": "+str(h1.GetEntries()), "l") # "f" shows bin w color "l" shows line leg.AddEntry(h2, "entry_title" + ": "+str(h2.GetEntries()), "l") leg.AddEntry(h3, "entry_title" + ": "+str(h3.GetEntries()), "l") leg.AddEntry(h4, "entry_title" + ": "+str(h4.GetEntries()), "l") leg.Draw() #create the overlay file c0.Print("overlay_file.pdf")