Home | News | Documentation | Download

Histograms not drawn inside Looper-Class

is there a reason, why I cannot Draw a Histogram from a class?

Usually I’m using looper-classes generated by TTree::MakeClass, in order to do some quick analysis.

void discrete::Loop()

   if (fChain == 0) return;

   Long64_t nentries = fChain->GetEntriesFast();
   TH1D *h= new TH1D("h","h",50,400,900);

   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;
      // if (Cut(ientry) < 0) continue;
			std::cout << "Filling " << VAL<< std::endl;

This produces a canvas but no histogram. TGraphs are working, too.

If I am adding

TFile *f = new TFile("test.root","RECREATE");
TTree *tout = new TTree("tree","tree");

at the beginning of the method it suddenly works!
Bug or feature?


_ROOT Version:6.22.00
Platform: Windows 10
_Compiler: VS2019



Most probably histogram is deleted when TFile is closed.

Before histogram creation, try to add: gROOT->cd();

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