Access a histogram

Hallo,

I am facing the following problem when trying to draw a histogram. What I am doing wrong?

TH1F* H_InvMass_dEdXCut[5];
TFile* f0= new TFile(“file0.root”, “READ”);
H_InvMass_dEdXCut[0]= (TH1F*) f0->Get(“InvMass_dEdXCut”);
//H_InvMass_dEdXCut[0]->SetDirectory(0);
//f0->Close(“R”);
H_InvMass_dEdXCut[0]->Draw();

I get the following error message:
Error: illegal pointer to class object H_InvMass_dEdXCut[0] 0x0 351 Macro.C:13:

sorry folks. I got it. very stupid mistake! --> read the right file!! However I would expect that I get an error message telling me that the the hist was not found in file0.root

The right way to do it would be to test if H_InvMass_dEdXCut[0] is null or not.
That will tell you if the histogram was found or not.

1 Like

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