Retrieving histogrrams from files and plotting them

hi,

i am sure this is trivial but i am trying to retrieve a histogram from a file and plot it. the problem is that is disappears after the macro ends - probably because it goes out of scope. could you explain to me what i am doing wrong?

void combo()
{
TCanvas *c1 = new TCanvas(“c1”,“hists with different scales”,600,400);
TFile sig(“cuts_sig.root”);
TH1F diff_sig = (TH1F)sig.Get(“massd”);
c1->cd();
diff_sig->Draw();
c1->Update();
}

thanks
heather

Hi Heather,

Read the chapter “Object Ownership” page 97 of the Users Guide.

Two solutions
-replace TFile f…
by
TFile *f = new TFile(…

-or activate the option
TH1::AddDirectory(kFALSE);
before opening/reading your file

Rene Brun