# this script takes an input root file containing TH1F objects and creates a pdf file with these overlapping histograms. Because these histograms are just about the triggers, or the amount of events accepted at some value it is possible to calculate the efficiency of these triggers. import ROOT from ROOT import TFile, TH1F, TEfficiency, TAttMarker, TColor ROOT.gROOT.SetBatch(True) #ROOT.gROOT.SetStyle("ALTAS") #import file f = TFile.Open("output.root") #get h1 h1 = f.Get("mjj_AcceptAll") print(h1.Integral()) # get second histogram h2 = f.Get("mjj_L1_MJJ-500-NFF") print(h2.Integral()) # get third histogram h3 = f.Get("mjj_HLT_j180_2dispjet50_L1J100") print(h3.Integral()) # 4th h4 = f.Get("mjj_HLT_j70_j50a_j0_DJMASS1000j50dphi200x400deta_L1MJJ-500-NFF") print(h4.Integral()) #5th h5 = f.Get("mjj_L1_J100") print(h5.Integral()) h6 = f.Get("mjj_L1OR") print(h6.Integral()) h7 = f.Get("mjj_HLT_2dispjet50_L1MJJ-500-NFF") print(h7.Integral()) h8 = f.Get("mjj_L1_TAU100") print(h8.Integral()) #set h1 preferences h1.SetTitle("# of Events Passed vs MJJ") h1.SetStats(0) h1.SetLineColor(ROOT.kBlack) #set h2 preferences h2.SetTitle("") h2.SetStats(0) h2.SetLineColor(ROOT.kBlue+2) #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) #set h5 pref h5.SetTitle("") h5.SetStats(0) h5.SetLineColor(ROOT.kViolet) #set h6 pref h6.SetTitle("") h6.SetStats(0) h6.SetLineColor(ROOT.kSpring+4) #h7 pref h7.SetTitle("") h7.SetStats(0) h7.SetLineColor(ROOT.kPink-4) #h8 pref h8.SetTitle("") h8.SetStats(0) h8.SetLineColor(ROOT.kMagenta+2) # draw event counts c0 = ROOT.TCanvas("event_counts") c0.cd() h1.Draw() # draw other histogram on same canvas c0.cd() h2.Draw("SAME") c0.cd() h3.Draw("SAME") c0.cd() h4.Draw("SAME") c0.cd() h5.Draw("SAME") c0.cd() h6.Draw("SAME") c0.cd() h7.Draw("SAME") c0.cd() h8.Draw("SAME") #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, "All Accepted Events" + ": "+str(h1.GetEntries()), "l") # "f" shows bin w color "l" shows line leg.AddEntry(h2, "Events passing L1_MJJ-500-NFF" + ": "+str(h2.GetEntries()), "l") leg.AddEntry(h3, "Events passing HLT_j180_2dispjet50_L1J100" + ": "+str(h3.GetEntries()), "l") leg.AddEntry(h4, "Events passing HLT_j70_j50a_j0_DJMASS1000j50dphi200x400deta_L1MJJ-500-NFF" + ": "+str(h4.GetEntries()), "l") leg.AddEntry(h5, "Events passing L1_J100" + ": "+str(h5.GetEntries()), "l") leg.AddEntry(h6, "Events Passing L1OR" + ": "+str(h6.GetEntries()), "l") leg.AddEntry(h7, "Events Passing HLT_2dispjet50_L1MJJ-500-NFF" + ": "+str(h7.GetEntries()), "l") leg.AddEntry(h8, "Events Passing L1_TAU100" + ": "+str(h8.GetEntries()), "l") leg.Draw() #create the overlay file c0.Print("event_overlay_mjj.pdf") # calculate eff eff1 = TEfficiency(h2, h1) #where h1 is the accept_all trigger eff2 = TEfficiency(h3, h1) eff3 = TEfficiency(h4, h1) eff4 = TEfficiency(h5, h1) eff5 = TEfficiency(h6, h1) eff6 = TEfficiency(h7, h1) eff7 = TEfficiency(h8, h1) #set preferences #eff1 eff1.SetTitle("Efficiencies of Various Triggers") eff1.SetMarkerColor(ROOT.kBlue+2) eff1.SetLineColor(ROOT.kBlue+2) eff1.SetMarkerStyle(33) #eff 2 eff2.SetMarkerColor(ROOT.kRed+1) eff2.SetLineColor(ROOT.kRed+1) eff2.SetMarkerStyle(20) #eff 3 eff3.SetMarkerColor(ROOT.kCyan) eff3.SetLineColor(ROOT.kCyan) eff3.SetMarkerStyle(26) #eff 4 eff4.SetMarkerColor(ROOT.kViolet) eff4.SetLineColor(ROOT.kViolet) eff4.SetMarkerStyle(25) #eff 5 eff5.SetMarkerColor(ROOT.kSpring+4) eff5.SetLineColor(ROOT.kSpring+4) eff5.SetMarkerStyle(34) #eff 6 eff6.SetMarkerColor(ROOT.kPink-4) eff6.SetLineColor(ROOT.kPink-4) eff6.SetMarkerStyle(23) #eff 7 eff7.SetMarkerColor(ROOT.kMagenta+2) eff7.SetLineColor(ROOT.kMagenta+2) eff7.SetMarkerStyle(31) #create canvas and draw c1 = ROOT.TCanvas("trigger_efficiency") c1.cd() eff1.Draw() #draw other eff #c1.cd() #eff2.Draw("SAME") c1.cd() eff3.Draw("SAME") #c1.cd() #eff4.Draw("SAME") #c1.cd() #eff5.Draw("SAME") c1.cd() eff6.Draw("SAME") #c1.cd() #eff7.Draw("SAME") #add legend for efficiency histograms leg2 = ROOT.TLegend(.13, .67, .35, .90) #top left leg2.SetBorderSize(0) # no border leg2.SetFillColor(0) # no fill leg2.SetFillStyle(0) # no fill leg2.SetTextFont(42) leg2.SetTextSize(.023) leg2.AddEntry(eff1, "Efficiency of L1_MJJ-500-NFF", "p") #leg2.AddEntry(eff2, "Efficiency of HLT_j180_2dispjet50_L1J100", "p") leg2.AddEntry(eff3, "Efficiency of HLT_j70_j50a_j0_DJMASS1000j50dphi200x400deta_L1MJJ-500-NFF", "p") #leg2.AddEntry(eff4, "Efficiency of L1_J100", "p") #leg2.AddEntry(eff5, "Efficiency of L1OR", "p") leg2.AddEntry(eff6, "Efficiency of HLT_2dispjet50_L1MJJ-500-NFF", "p") #leg2.AddEntry(eff7, "Efficiency of L1_TAU100", "p") leg2.Draw() #create efficiency file c1.Print("TEff_mjj.pdf")