# Multiple root files addition in a single root file

**URL:** <https://root-forum.cern.ch/t/multiple-root-files-addition-in-a-single-root-file/53083>\
**Category:** ROOT\
**Created:** [January 13, 2023, 7:20am UTC](https://root-forum.cern.ch/t/multiple-root-files-addition-in-a-single-root-file/53083 "2023-01-13T07:20:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamaanand](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/9d8465/32.png) [@iamaanand](https://root-forum.cern.ch/u/iamaanand)\
**Post date:** [January 13, 2023, 7:20am UTC](https://root-forum.cern.ch/t/multiple-root-files-addition-in-a-single-root-file/53083/1 "2023-01-13T07:20:34Z")

</div>

How to add same histogram of multiple root files (let’s say 20 or more) in a single root file? Of course I have to use for loop but I am unable to proceed .

This is how I am able to read branches (here ‘Edep’ ) of my root file ‘test.root’ .

```auto
 char const* InputFileName = "test.root"; 

    TFile* Input_file = new TFile(InputFileName);

    TTree* Scoring_tree = (TTree*)Input_file->Get("Scoring");

    cout<<"No. of Entries: "<<Scoring_tree->GetEntries()<<endl;

    Double_t Edep_info;

    TBranch* Edep_Branch = Scoring_tree->GetBranch("Edep");

    Edep_Branch->SetAddress(&Edep_info);

```

---

<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:** [January 13, 2023, 7:52am UTC](https://root-forum.cern.ch/t/multiple-root-files-addition-in-a-single-root-file/53083/2 "2023-01-13T07:52:13Z")

</div>

> [@Analysis skeleton for a TChain](https://root-forum.cern.ch/t/analysis-skeleton-for-a-tchain/52777):
>
> Hi again guys, sorry for my naive questions. I’m still trying to understand the logic of ROOT. Following my previous topic [How to read array variable in a Tree](https://root-forum.cern.ch/t/how-to-read-array-variable-in-a-tree/52673) , I create the .h and .C (and modify it) files but I cannot understand how to generalize this to more root file. I followed the indication provided me by one answer of @Wile_E_Coyote and I understood that I need to use TChain and I read on the Manual on how to use it. I understood it how to use but not the connection with the previous…

> [@Header files for Trees](https://root-forum.cern.ch/t/header-files-for-trees/16308/2):
>
> “Most recent” documentation about how to generate and use an “analysis skeleton”: [TTree::MakeClass](http://root.cern.ch/root/html534/TTree.html#TTree:MakeClass) (see also [“ROOT User’s Guide” → “Trees” → “Using TTree::MakeClass”](http://root.cern.ch/root/html534/guides/users-guide/Trees.html#using-ttreemakeclass)) [TTree::MakeSelector](http://root.cern.ch/root/html534/TTree.html#TTree:MakeSelector) (see also [“ROOT Primer” → “File I/O and Parallel Analysis” → “N-tuples in ROOT” → “For the advanced user: Processing trees with a selector script”](http://root.cern.ch/root/htmldoc/guides/primer/ROOTPrimer.html#for-the-advanced-user-processing-trees-with-a-selector-script) and [“ROOT User’s Guide” → “Trees” → “Using TTree::MakeSelector”](http://root.cern.ch/root/html534/guides/users-guide/Trees.html#using-ttreemakeselector) and [“ROOT User’s Guide” → “Example Analysis”](http://root.cern.ch/root/html534/guides/users-guide/ExampleAnalysis.html)) [TTree::MakeProxy](http://root.cern.ch/root/html534/TTree.html#TTree:MakeProxy)[ROOT::RDataFrame](https://root.cern.ch/doc/master/classROOT_1_1RDataFrame.html) (uses the [T…](https://root.cern.ch/doc/master/classTTreeReader.html)

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [January 27, 2023, 7:52am UTC](https://root-forum.cern.ch/t/multiple-root-files-addition-in-a-single-root-file/53083/3 "2023-01-27T07:52:36Z")

</div>

Closed on January 27, 2023, 7:52am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
