# Using histograms from different macros

**URL:** <https://root-forum.cern.ch/t/using-histograms-from-different-macros/41603>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [September 26, 2020, 9:07am UTC](https://root-forum.cern.ch/t/using-histograms-from-different-macros/41603 "2020-09-26T09:07:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![peanuts](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/a3d4f5/32.png) [@peanuts](https://root-forum.cern.ch/u/peanuts)\
**Post date:** [September 26, 2020, 9:07am UTC](https://root-forum.cern.ch/t/using-histograms-from-different-macros/41603/1 "2020-09-26T09:07:50Z")

</div>

Hello,  
I’m new to Root and C++ programming.  
I have some histograms (h1, h2, h3) in a macro, say macro.C, and I would like to create a new different macro, say newmacro.C, in which I want to use the macro.C’s histograms to make another histogram for different scope. Can I do this in root? What are the commands?

Thank you.

---

<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:** [September 27, 2020, 7:21am UTC](https://root-forum.cern.ch/t/using-histograms-from-different-macros/41603/2 "2020-09-27T07:21:11Z")

</div>

Sure it can be done. One way could be to save the histograms in the first macro to a ROOT file, then on the second macro you open the file and read the histograms from there. There’s some sample code in the “File I/O and Parallel Analysis” section of the ROOT Primer (Primer and more tutorials [here](https://root.cern/get_started/)), or search this forum for many more examples.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [October 6, 2020, 9:39am UTC](https://root-forum.cern.ch/t/using-histograms-from-different-macros/41603/3 "2020-10-06T09:39:55Z")

</div>

…and a belated welcome to the ROOT forum @peanuts 😃 let us know if you need further help/pointers to documentation (in a new topic, marking this as solved).

Cheers,  
Enrico
