Re: Pythia and generated particles

From: Mario Kadastik <mario.kadastik_at_cern.ch>
Date: Mon, 14 Feb 2005 21:12:13 +0200


Well I managed to get what I wanted. Namely:

TFile f("higgs.root");
TTree *t = (TTree*)f.Get("particles");
TClonesArray *part=0;
TMCParticle *p=0;
Int_t i=0,j=0;
t->SetBranchAddress("particles",&part);
for (i=0; i<t->GetEntries(); i++) {

   t->GetEntry(i);
   for (j=0;j<part->GetEntries();j++) {

       p=(TMCParticle*)part->At(j);
       // here p contains particle nr j from run i.
       printf("Run: %d, Particle nr %d is %s\n",i,j,p->GetName());
    }
}

Maybe a similiar sample should be added to the tutorial/howto part?

Mario

Mario Kadastik wrote:

> Hello,
>
> It seems to me that I'm a bit stuck with Pythia and ROOT trees.
>
> Namely I saved the pythia generated particles as TCloneArrays into a
> root file. If I open it up in TBrowser or scan it, then I can see all
> the relevant data there. Now if I want to loop over the information,
> then I'm stuck.
>
> What I'd like to do is to loop over all events and in every one of
> them loop over all particles and do something. How should that be
> accomplished? At the moment I'm having trouble reading the data out of
> the tree in my code:
>
> TFile f("higgs.root")
> TTree *t = (TTree*)f.Get("particles")
> Float_t *px;
> t->SetBranchAddress("particles.fPx",px)
> t->GetEntry()
> and after that px won't contain anything useful.
>
> If I swap Float_t *px with Float_t px[1000], no change.
> I also tried to t->SetMakeClass(1) and the same with chains, but in
> both cases I get segmentation fault I'm using latest root on Fedora
> Core 3 (downloaded yesterday).
Received on Mon Feb 14 2005 - 20:11:39 MET

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