Making a single histogram from 2 files

Hello there!

I have two files, nu.root and mu.root. Each one of these files has a tree called tree, with a leaf called energy. I want to make three different histograms: one for the energy distribution of muons (mu.root), one for the energy distribution of neutrinos (nu.root) and one for the energy distribution of both muons and neutrinos.

The plots must have 10 bins and the energies are between 10 and 200 GeV.

I have tried something like this:

NAMES=["(nu.root", "nu.pdf"), ("mu.root", "mu.pdf")]

for tuple in NAMES:
  f=ROOT.TFile(tuple[0])
  tree=f.Get("tree")
  c1=TCanvas("canvas")
  hevts = ROOT.TH1D("hevts", "events", 10, 10, 200)
  tree.Draw("energy >> hevts")
  c1.Draw()
  c1.SaveAs(tuple[1])
  c1.Delete()
  f.Close()

This should make both the muon and the neutrino histograms, but I don’t know how to do one single histogram with the two data combined…

Suggestions are welcome!

It depends what you mean by “combined”. Can you clarify ?

Since one is mouns and one neutrinos, I suppose you want them as separate histos but superposed on the same plot. You can add them to a THStack (but probably don’t use the same “hevts” histo for both in tree.Draw..., use 2 different histos, and add the “goff” option to this line so they are not drawn, if you only want the final ‘combined’ plot), and use the “nostack” draw option.