RE: TClonesArray

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Mon, 07 Mar 2005 13:00:25 -0600

 

> new ((*fpart)[m]) *prt;

Should be:

     new ((*fpart)[m]) TParticle(*prt);

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of Mario Kadastik
Sent: Monday, March 07, 2005 9:42 AM
To: roottalk_at_pcroot.cern.ch
Subject: [ROOT] TClonesArray

Hello,

I'm trying to filter pythia events before saving them to tree. Currently I get them like this:
TClonesArray* particles = (TClonesArray*)pythia->GetListOfParticles(); which I then save to tree like this:
TTree* part = new TTree("parttree","A tree of particles"); part->Branch("particles", &particles);
for (Int_t i=0; i<nEvents; i++) {

    pythia->GenerateEvent()
    part->Fill();
}

What I'd like to do is to only take some of the particles that mach a specific KF code. What I tried to do:
TClonesArray* particles = (TClonesArray*)pythia->GetListOfParticles(); TClonesArray *fpart = new TClonesArray("TMCParticle"); TClonesArray &fp = *fpart;
TMCParticle *prt = new TMCParticle();
Int_t fKF = 0, m=0;
TFile* f = new TFile(file,"RECREATE"); // open file to write output tree TTree* part = new TTree("parttree","A tree of particles"); part->Branch("particles", &fpart);
for (Int_t i = 0; i < nEvents; i++) {

    fpart->Clear();
    pythia->GenerateEvent();
    m=0;
    for (Int_t j=0; j<particles->GetEntries(); j++) {

      prt=(TMCParticle*)particles->At(j);
      fKF=abs(prt->GetKF());
      if (prt->GetKS() < 20 && (fKF==5 || fKF==6 || fKF==9900041 || 
fKF==9900042 || (fKF>10 && fKF<17))) {
           new ((*fpart)[m]) *prt;
            m++;
      }

    }
    part->Fill();
  }

For some reason this doesn't work. I get segfaults at part->Fill(). If I added a cout << "added particle" << endl; just after new ((*fpart)[m]) *prt; then
it ran through a number of Fill()-s and then crashed.

Mario

PS! I did remove some cout << endl; and similiar lines so if it works now then I'd be surprised :) Received on Mon Mar 07 2005 - 20:08:18 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:05 MET