Writing Histograms to Trees

Hi all,

I have a

stl::vector<TH1D*> h(3);
stl::vector<TH1D*> haux1(100);
stl::vector<TH1D*> haux2(100);
stl::vector<TH1D*> haux3(100);

and create TTree branches from it using

t->Branch("h0", "TH1D", &h[0]);
t->Branch("h1", "TH1D", &h[1]);
t->Branch("h2", "TH1D", &h[2]);

with i going from 0 to 2 inclusive.
Histograms haux1, haux2 and haux3 are all created, filled and fitted first, then I do a cycle with:

h[0] = haux1[j];
h[1] = haux2[j];
h[2] = haux3[j];

with j from 0 to 99.

an error comes out every time I call t->Fill() (twice: one for TBranchElement::Fill, one for TTree::Fill):

… Failed filling branch … nbytes=-1

Further more, I’m writing to a file and ROOT crashed when closing it.
Is there anything obvious I shouldn’t be doing?
While debugging I tried:

TH1D* htry = new TH1D("h1","h1",10,0,10);
t->SetBranchAddress("h0", &htry);
t->SetBranchAddress("h1", &htry);
t->SetBranchAddress("h2", &htry);

and it worked fine, though ROOT still crashes on exit.

I’m really stucked and hope someone can help.

Best regards,



There is nothing obviously wrong in your code snippets and many things could lead to the error you see (double delete, writing in a read-only file, etc.).

The best way to submit your problem is to provide the following:

  • ROOT version number
  • OS and compiler version number
  • complete example reproducing the problem with instruction on how to run it.