ROOT file reading

Hi,

I have a question about ~.root file reading.
I wrote the sample macro such as

{

TFile* fFileA;
TFile* fFileB;

fFileA = new TFile("90A_NewAveSpec_MRS_pions_-0.10_0.10_0_10_3_13.root","READ");
fFileB = new TFile("90B_NewAveSpec_MRS_pions_-0.10_0.10_0_10_3_13.root","READ");

fFileA->ls();
fFileB->ls();

// 90A_NewAveSpec_MRS_pions_-0.10_0.10 is TH1F in 90A_NewAveSpec_MRS_pions_-0.10_0.10_0_10_3_13.root file.
TH1F *h1 = (TH1F *)gROOT->FindObject(“90A_NewAveSpec_MRS_pions_-0.10_0.10”);
h1->Draw();
}

But, it does not run. However, I commet out fFileA (or fFileB) case, it runs.
So, would you tell me open and read both root files, and do h1->Draw(); h2->Draw(); ???
The error message is

“Error: illegal pointer to class object h1 0x0 397 new_macro.C:18:”

Thank you!

Replace

TH1F *h1 = (TH1F *)gROOT->FindObject("90A_NewAveSpec_MRS_pions_-0.10_0.10"); by, eg

TH1F *h1 = (TH1F *)fFileA->Get("90A_NewAveSpec_MRS_pions_-0.10_0.10");
Rene

Hi,
Thank you for the reply, however,

{
TFile* fFileA;
TFile* fFileB;

fFileA = new TFile("90A_NewAveSpec_MRS_pions.root");
fFileB = new TFile("90B_NewAveSpec_MRS_pions.root");

fFileA->ls();
fFileB->ls();

TH1F *hA = (TH1F*)fFileA->FindObject("90A_NewAveSpec_MRS_pions.root");
TH1F *hB = (TH1F*)fFileB->FindObject("90B_NewAveSpec_MRS_pions.root");

hA->Draw();
hB->Draw();

}

this code does not work. It shows same previous pointer error message. How should I fix it for this problem?

Thank you!

Please provide the shortest possible RUNNING script (and data files) showing the problem.

Rene

Hi,

I attached the code and the files.
90B_NewAveSpec_MRS_pions_-0.10_0.10_0_10_3_13.root (4.65 KB)
90A_NewAveSpec_MRS_pions_-0.10_0.10_0_10_3_13.root (4.64 KB)
new_macro.C (497 Bytes)

You did not read my mail carefully. See the difference between the statements where I use Get instead of FindObject.

Rene

Yes, it works. I have to use “Get” instead of “FindObject”. I was confused.
Thank you!