Problem with TClonesArray


I have a problem of filling a tree with objects which contain a class member of another object with TClonesArray.

In more detail, my Event object has a class member fLayers:

class Event : public TObject {
Layer *fLayers[2];

This class member, in turn, contains Track objects which are stored in TClonesArray fTracks:

class Layer : public TObject { ... TClonesArray *fTracks; ... };

For each event I am trying to create 2 layers and add 1 track into each layer. The program crushes when I am filling the tree.

A smallest possible working example is in attachment. Type make to compile the library and make event to fill the tree with 2 events.

I have seen an example of Event class in $ROOTSYS/test, but it seems I do not understand it completely since in my case (which is a little bit different from this example) the code does not work.

Can anybody please explain me what I’m doing wrong?

My ROOT version is 5.19/01
event.tar.gz (2.05 KB)

At first sight you need add one line (reset counter) in your function:

void Layer::Clear()
  if (fTracks) {
    fTracks->Clear("C"); // will also call Track::Clear
    fNtrack = 0; // !!! reset counter !!!

I hope this help, Jan

Yes, that helps. Thank you, Jan!