# Making a single histogram from 2 files

**URL:** <https://root-forum.cern.ch/t/making-a-single-histogram-from-2-files/48510>\
**Category:** Newbie\
**Tags:** python\
**Created:** [January 23, 2022, 2:40pm UTC](https://root-forum.cern.ch/t/making-a-single-histogram-from-2-files/48510 "2022-01-23T14:40:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@Miguel](https://root-forum.cern.ch/u/Miguel)\
**Post date:** [January 23, 2022, 2:40pm UTC](https://root-forum.cern.ch/t/making-a-single-histogram-from-2-files/48510/1 "2022-01-23T14:40:15Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 24, 2022, 7:10am UTC](https://root-forum.cern.ch/t/making-a-single-histogram-from-2-files/48510/2 "2022-01-24T07:10:12Z")

</div>

> [@Miguel](#):
>
> one single histogram with the two data combined…

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

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [January 24, 2022, 7:22am UTC](https://root-forum.cern.ch/t/making-a-single-histogram-from-2-files/48510/3 "2022-01-24T07:22:09Z")

</div>

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](https://root.cern/doc/master/classTHStack.html) (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.
