# Combing 1D histograms from different files into a single 2D histogram using the file ID?

**URL:** <https://root-forum.cern.ch/t/combing-1d-histograms-from-different-files-into-a-single-2d-histogram-using-the-file-id/57839>\
**Category:** Newbie\
**Tags:** root\
**Created:** [January 15, 2024, 7:26am UTC](https://root-forum.cern.ch/t/combing-1d-histograms-from-different-files-into-a-single-2d-histogram-using-the-file-id/57839 "2024-01-15T07:26:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [January 15, 2024, 7:26am UTC](https://root-forum.cern.ch/t/combing-1d-histograms-from-different-files-into-a-single-2d-histogram-using-the-file-id/57839/1 "2024-01-15T07:26:06Z")

</div>

Hi everyone,

I have a set of .root files of the form  
xyz\_1.root  
xyz\_2.root  
…  
xyz\_2362.root (various numbers are missing in between the files)

Each file has a stored 1D histogram containing energy spectra.

I am trying to merge these 1D histograms into a single 2D histogram such that the **X-axis** is the **unique file number** and the Y-axis has the corresponding energies of that file.

Is there any built-in command (n similar lines of `hadd` ) that can help me achieve this? Any suggestions/examples in this regard will be helpful and appreciated.

Thanks a lot !

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [January 15, 2024, 9:56am UTC](https://root-forum.cern.ch/t/combing-1d-histograms-from-different-files-into-a-single-2d-histogram-using-the-file-id/57839/2 "2024-01-15T09:56:20Z")

</div>

Hi,

Thanks for the question.  
I don’t think we have native support for this interesting, but very custom, operation. It should not be a lot of work to combine in a loop all histos as slices of a 2D histo though.

Cheers,  
D
