Filling a histogram from an NTuple with '>>'

Hi,

I’m having trouble filling a histogram from an NTuple with ‘>>’ The following code illustrates the problem:

void SLtest(void)
{
TH1D * AA = new TH1D("AA","STARlight low mass", 60, 0., 0.075);
AA->Sumw2();

TFile *ba = new TFile("SLptlt50.root","READ");
TNtuple *nt = (TNtuple*)ba->Get("esNT");
cout <<"nt filled with "<<nt->GetEntries()<<" entries"<<endl;

nt->Draw("fspt");
nt->Draw("fspt>>AA");

TCanvas *Ctest = new TCanvas("tests","Tests ",600,600);
AA->Draw();
cout << "Low drawn, with "<<AA->GetEntries()<<" entries"<<endl;
}

nt reports that is has 5,000,000 entries, as expected. The first draw, “nt->Draw(“fspt”);” produces what I expect, while the second, AA->Draw(); produces an empty histogram, with Get.Entries reporting zero entries. This appears very similar to code I’ve used in the past, and in some of the ROOT examples. What am I missing?

Spencer Klein, Berkeley

Add gROOT->cd(); right before nt->Draw("fspt>>AA");.

BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).

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