Ian_L
July 24, 2023, 4:08pm
1
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");
h1->Draw();
h2->Draw("same");
h3->Draw("same");
}
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
yus
July 24, 2023, 4:52pm
2
Hi,
try replacing
TH1D *h1 = f1->Get("Edep");
...
TH1D *h2 = f2.Get("Edep");
...
TH1D *h3 = f3.Get("Edep");
with
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
Ian_L
July 24, 2023, 5:22pm
3
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:
yus
July 24, 2023, 6:12pm
4
This should not happen. Please upload your .root
files and the latest version of your simple.C
so that we could reproduce the issue.
Ian_L
July 24, 2023, 6:47pm
5
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!
yus
July 24, 2023, 6:52pm
6
You can use https://www.transfernow.net/en to share large files without registration.
Ian_L
July 24, 2023, 7:01pm
7
Here is the link to the other files:
Thank you again!
yus
July 24, 2023, 7:08pm
8
The problem is that Edep
in all these files is not a TH1D
, but rather a TTree
.
Ian_L
July 24, 2023, 7:12pm
9
Ah I see. Would TChain work in this case? I have never used it but I have heard it could help with TTrees.
yus
July 24, 2023, 7:19pm
10
No, you just need to fetch info from your TTree
, and TChain
has nothing to do with this.
Ian_L
July 24, 2023, 7:25pm
11
Okay. Sorry to ask this, but how would I do that? I am not familiar enough with TTree yet. Thanks
yus
July 24, 2023, 7:29pm
12
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.
Ian_L
July 24, 2023, 7:33pm
13
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?
Ian_L
July 24, 2023, 7:41pm
15
Thank you! I will look into this and get back if I have any more questions or if I figure it out.
Ian_L
July 27, 2023, 5:26pm
16
I was able to figure it out! Thank you!