Last active
August 29, 2015 14:17
-
-
Save wiso/7bb25c30e55625fbeee8 to your computer and use it in GitHub Desktop.
Just plot some histograms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ROOT | |
if __name__ == "__main__": | |
common_path = "/users2/mratti/MonoPhotonSL6/Run/looseSR/data-output/" | |
samples = ({"filenames": common_path + "user.mgenest.slim.mc12_8TeV.126744.Sherpa_CT10_munugammaPt80.vCOMMON1.0.root", | |
"treename": "physics", | |
"color": ROOT.kOrange - 9, | |
"fill": True, | |
"name": "Wmunugamma", | |
"title": "W#rightarrow#mu#nu#gamma"}, | |
{"filenames": common_path + "user.mgenest.slim.mc12_8TeV.126022.Sherpa_CT10_nunugammaPt70.vCOMMON1.0.root", | |
"treename": "physics", | |
"color": ROOT.kYellow - 9, | |
"fill": True, | |
"name": "Znunugamma", | |
"title": "Z#rightarrow#nu#nu#gamma"}, | |
{"filenames": common_path + "user.mgenest.slim.mc12_8TeV.158920.MadgraphPythia8_AU2MSTW2008LO_WimpPair_D5_DM10.vCOMMON1.0.root", | |
"treename": "physics", | |
"fill": False, | |
"color": ROOT.kRed, | |
"name": "signal", | |
"title": "signal"}, | |
) | |
sums_names = [("Znunugamma", "Wmunugamma")] | |
luminosity = 20276.9 | |
region_title = "signal region" | |
region_name = "signal_region" | |
region_cut = "(metMOD > 150E3 && phPT > 125E3 && abs(phETA) < 1.37)" | |
quantity = "metMOD / 1E3" | |
quantity_title = "MET [GeV]" | |
quantity_binning = 5, 150, 500 | |
stack = ROOT.THStack("stack" + region_name, region_title + " cut: " + region_cut.replace("&&", " ")) | |
stack.mem = [] | |
legend = ROOT.TLegend(0.67, 0.5, 0.9, 0.65) | |
legend.SetBorderSize(0) | |
for sample in samples: | |
histo = ROOT.TH1F("histo_{}_{}".format(region_name, sample["name"]), | |
sample["title"], *quantity_binning) | |
chain = ROOT.TChain(sample["treename"]) | |
chain.Add(sample["filenames"]) | |
weights = "(weight_pileup * weight_vertex * weight_mc * Xsection * FilterEff *1000. * %f *kfactor / neventsGenerated_MarieHelene)" % luminosity | |
# chain.Project(histo.GetName(), quantity, weights + " && " + region_cut) | |
selection = weights + "*" + region_cut | |
chain.Project(histo.GetName(), quantity, selection) | |
histo.GetXaxis().SetTitle(quantity_title) | |
stack.Add(histo) | |
if sample["fill"]: | |
histo.SetFillColor(sample["color"]) | |
histo.SetLineColor(ROOT.kBlack) | |
else: | |
histo.SetFillColor(0) | |
histo.SetLineColor(sample["color"]) | |
stack.mem.append(histo) | |
legend.AddEntry(histo, "", "F" if sample["fill"] else "L") | |
sample["histo"] = histo | |
canvas = ROOT.TCanvas("canvas_stack_%s" % region_name, | |
"canvas_stack_%s" % region_name) | |
stack.Draw() | |
stack.GetXaxis().SetTitle(quantity_title) | |
canvas.SetLogy() | |
legend.Draw() | |
atlas_label = ROOT.TLatex(0.6, 0.8, "#bf{#it{ATLAS}} Simulation") | |
atlas_label.SetNDC() | |
atlas_label.Draw() | |
lumi_label = ROOT.TLatex(0.48, 0.73, "#scale[0.6]{#int} Ldt = %.1f fb^{-1}, #sqrt{s}= 8 TeV" % (luminosity / 1000.)) | |
lumi_label.SetNDC() | |
lumi_label.Draw() | |
canvas.Update() | |
canvas.SaveAs(canvas.GetName() + ".png") | |
for sum_names in sums_names: | |
# loop on [("Znunugamma", "Wmunugamma")] | |
histos = [] | |
titles = [] | |
for name in sum_names: | |
# loop on ("Znunugamma", "Wmunugamma") | |
for sample in samples: | |
if sample['name'] == name: | |
histos.append(sample['histo']) | |
titles.append(sample['title']) | |
break | |
histo_sum = histos[0] | |
for histo in histos[1:]: | |
histo_sum.Add(histo) | |
histo_sum.SetName("histo_sum_" + "_".join(sum_names)) | |
histo_sum.SetTitle("sum " + ", ".join(sum_names) + ", " + region_title + " cut: " + region_cut.replace("&&", " ")) | |
legend = ROOT.TLegend(0.67, 0.5, 0.9, 0.65) | |
legend.SetBorderSize(0) | |
legend.AddEntry(histo_sum, " + ".join(titles)) | |
canvas_sum = ROOT.TCanvas("canvas_%s_sum_%s" % (region_name, "_".join(sum_names))) | |
canvas_sum.SetLogy() | |
histo_sum.Draw() | |
legend.Draw() | |
canvas_sum.SaveAs(canvas_sum.GetName() + ".png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment