# How to merge histograms which are in root files and are provided by pythia8?

**URL:** <https://root-forum.cern.ch/t/how-to-merge-histograms-which-are-in-root-files-and-are-provided-by-pythia8/45317>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [June 9, 2021, 2:25pm UTC](https://root-forum.cern.ch/t/how-to-merge-histograms-which-are-in-root-files-and-are-provided-by-pythia8/45317 "2021-06-09T14:25:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11128](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11128/32/23989_2.png) [@11128](https://root-forum.cern.ch/u/11128)\
**Post date:** [June 9, 2021, 2:25pm UTC](https://root-forum.cern.ch/t/how-to-merge-histograms-which-are-in-root-files-and-are-provided-by-pythia8/45317/1 "2021-06-09T14:25:19Z")

</div>

I have written a code which is written in pythia8 and the export files are root-files that create histograms.how can i merge histograms from different root files?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 9, 2021, 2:38pm UTC](https://root-forum.cern.ch/t/how-to-merge-histograms-which-are-in-root-files-and-are-provided-by-pythia8/45317/2 "2021-06-09T14:38:40Z")

</div>

`hadd`

---

<div class="post-metadata">

**Author:** ![jaofferm](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jaofferm/32/21649_2.png) [@jaofferm](https://root-forum.cern.ch/u/jaofferm)\
**Post date:** [June 9, 2021, 2:42pm UTC](https://root-forum.cern.ch/t/how-to-merge-histograms-which-are-in-root-files-and-are-provided-by-pythia8/45317/3 "2021-06-09T14:42:30Z")

</div>

Looks like Wile E Coyote beat me to the answer!

Just to elaborate a bit, you can run `hadd` like this:  
`hadd result.root file0.root file1.root file2.root ...`

This will work if your histograms (in `file0.root`, `file1.root` etc.) have the same names, binning etc. (Otherwise you can write a macro to combine histograms using [TH1::Add()](https://root.cern.ch/doc/master/classTH1.html#a1913bea50293a57b9ee65bf7f65a26e1)).

This executable should be located at $ROOTSYS/bin/hadd (it should already be set up if you have your $PATH set up for ROOT via $ROOTSYS/bin/thisroot.sh).

---

<div class="post-metadata">

**Author:** ![11128](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11128/32/23989_2.png) [@11128](https://root-forum.cern.ch/u/11128)\
**Post date:** [June 9, 2021, 2:43pm UTC](https://root-forum.cern.ch/t/how-to-merge-histograms-which-are-in-root-files-and-are-provided-by-pythia8/45317/4 "2021-06-09T14:43:51Z")

</div>

Thank you very much .I think i got it
