TTree with events containing TClonesArray of hits

Dear all.
Basically, I have a hit class with some data members and an event class with the TClonesArray of hits. I would like to have my event in the tree.
I have followed the example in section 12.17 of the ROOT documentation but I still get segfault during the tree.Fill(). In the attachment there is the full code which shows the problem.

Also I have realized that in the documentation it is done this way:

// create a pointer to an Event object
Event *event = new Event();
// create two branches, split one
t4.Branch("event_branch", "Event", &event,16000,2);

And I would expect that the ‘Branch’ method takes the pointer (i.e. event, but not &event).
Am I wrong?

Regards, Egor.
eventsInRootTree.tar.gz (1.38 KB)

Well, we’ve found the mistake. I did not reset the fNumHits, used by the operator new.
The working example is available here. … t/original


Apologies you didn’t get a reply. Sometimes it might help to ping us, to push your post back onto the table.

Cheers, Axel.