Combining root histograms not working

Hello, I am trying to get histograms from three different .root files to be plotted on the same plot. This is the code I had used to try to get them to combine:

void simple()
   TFile *f1 = new TFile("TestCAL_Co60_d5z3.root", "READ");
   TH1D *h1 = f1->Get("Edep");

   TFile f2("TestCAL_C060_d5z6.root");
   TH1D *h2 = f2.Get("Edep");

   TFile f3("TestCAL_C060_d5z9.root");
   TH1D *h3 = f3.Get("Edep");


When I run this code, these are the errors I get:

How do I fix this problem?

Thank you.

ROOT Version: 6.26
Platform: Ubuntu
Compiler: Not Provided


try replacing

   TH1D *h1 = f1->Get("Edep");
   TH1D *h2 = f2.Get("Edep");
   TH1D *h3 = f3.Get("Edep");


   TH1D *h1 = static_cast<TH1D*>(f1->Get("Edep"));
   TH1D *h2 = static_cast<TH1D*>(f2.Get("Edep"));
   TH1D *h3 = static_cast<TH1D*>(f3.Get("Edep"));
1 Like

I made those changes and the root files are being read. Now I get an error about using “same” when trying to plot the graphs on the same plot. Here is the error:

This should not happen. Please upload your .root files and the latest version of your simple.C so that we could reproduce the issue.

Here is the C file:
simple.C (384 Bytes)

I cannot upload the root files since they are each ~50 MB, and github wont let me upload them either.
Is there another way to upload or send you the files?

Thank you for your help!

You can use to share large files without registration.

Here is the link to the other files:

Thank you again!

The problem is that Edep in all these files is not a TH1D, but rather a TTree.

Ah I see. Would TChain work in this case? I have never used it but I have heard it could help with TTrees.

No, you just need to fetch info from your TTree, and TChain has nothing to do with this.

Okay. Sorry to ask this, but how would I do that? I am not familiar enough with TTree yet. Thanks

That depends on what it is you want to do exactly. If it is just plotting the content of fEdep_HPGe from all three files on the same canvas, it is easy enough.

Yes, I just want to plot the contents of each fEdep_HPGe on one plot. Where can I find the documentation on how to do this?

Thank you! I will look into this and get back if I have any more questions or if I figure it out.

I was able to figure it out! Thank you!