Named Objects in TClonesArrays

Norbert Danneberg (norbert.danneberg@psi.ch)
Tue, 13 Apr 1999 21:34:26 +0100


Hi Rooters,

when I try to store a named object derived from TNamed in TTree and
write this
Tree to disk, I do not receive the name of the object when I try to read
it back.
All other member variables are read in correctly.

Below is the slightly modified Event sample from the /test directory.

I changed Track so that it is derived from TNamed.

class Track : public TNamed {

private:
Float_t fPx; //X component of the momentum
Float_t fPy; //Y component of the momentum
Float_t fPz; //Z component of the momentum
....
}

During filling a name to each Track is assigned in MainEvent.cxx:

// Create and Fill the Track objects
for (Int_t t = 0; t < ntrack; t++){
event->AddTrack(random);
Track* MyTrack = (Track*)event->GetTracks()->At(t); // Added Code
MyTrack->SetName("N"); //Added Code

}

I check after filling if the Name is set correctly:

if (write) nb += tree->Fill(); //fill the tree

Track* MyTrack = (Track*)event->GetTracks()->At(0);
printf("%s\n",MyTrack->GetName());

this gives the correct Name.

But the following testmacro gives empty names for all Track Objects:

{
gROOT->Reset();
f1 = new TFile("Event.root");
Event* ev=new Event();
T->SetBranchAddress("event",&ev);
T->SetBranchStatus("*",1);

for(Int_t i=0;i<1;i++){
T->GetEvent(i);
TClonesArray* TrackList = ev->GetTracks();
Track* MyTrack = (Track*)TrackList->At(0);
MyTrack->Inspect();

printf("%s\n",MyTrack->GetName());
}
}

I am sorry but I do not have a clue whats wrong ??

Thanks, Norbert

--

Norbert Danneberg

ETH Zurich - Institute for Particle Physics Laboratory for Nuclear Physics Phone.: +41-1-633-2034 Hoenggerberg Fax.: +41-1-633-1067 CH-8093 Zurich

ETH Zurich - Institute for Particle Physics Paul Scherrer Institute Phone.: +41-56-310-3284 CH-5232 Villigen PSI Fax.: +41-56-310-4362

email: Norbert.Danneberg@psi.ch