I am using this macro to combine histograms from different folders:
TH1 *h = 0
TH1 *hadd = 0
When I enter the “h->Add(hadd)” I get this error
Error: illegal pointer to class object h 0x0 996 (tmpfile):1:
*** Interpreter error recovered ***
I’m not sure what I’m doing wrong. Thanks for your help.
gROOT->GetObject will not open any ROOT file nor navigate through them. You should try
TFile *myfile = TFile::Open("his00052.root");
TH1 *h = 0;
TFile *myfile = TFile::Open("his00053.root");
TH1 *hadd = 0;
It still showed the same error message when I did the “h.Add(hadd)” command. Thanks.
Then either h or hadd is null because histos/h1 does not exist in your ROOT file and/or is of the wrong type.
The histograms are of TH2F type.
Can you do the “Add” command with TH2F type histograms? Thanks.
[quote]Can you do the “Add” command with TH2F type histograms?[/quote]Yes and you should have been able to retrieve them via the command you gave. Can you post your root file so that I can check.
My apologies, I see that you really meant to mean TFolder when you said ‘folders’ and not (as I unfortunately thought ) directory/TDirectory.
TDirectory::GetObject can not drill trough a TFolder (it can only drill through TDirectories) so you will need to retrieve the TFolder first and then retrieve the histogram from the TFolder.
Thanks, I got it to work using this macro:
TFile *f1 = TFile::Open("his_____.root")
TFolder *folder1 = (TFolder*) f1->Get("histos")
TH2F *h1 = (TH2F*) folder1->FindObjectAny("histo_name")