Finding mother particle in root/pythia

Dear Root users,

I am trying to run an adjusted version of the pythia8.C macro (from the root tutorials) in which I want to select all pions of which the mother particle is a lambda c baryon. I have been trying to use the ‘GetFirstMother’ command, but then I realized I don’t know what kind of information this command delivers. In the description of the command it says it returns the ‘mother particle indices’, but I don’t know what that means. Is there anyone out here who can explain to me how I can select particles based on of which particles they are the decay products?

Best regards,

Loek

May be the author of this example, @Andreas_Morsch, can help.

Hi Loek,
GetFirstMother() gives you the index of the mother in the particle stack.
Use
TParticle* part = (TParticle*) particles->At(indexMother);
to retrieve the corresponding TParticle.
Best regards
Andreas

Hello Andreas,

Thank you for your reply! I think I will be able to work it out now.

Best regards,

Loek

Dear Andreas,

I have one more question. The part of the code that concerns the selection of pions with lambda_c as mother particle I have edited is the following:

for (Int_t iev = 0; iev < nev; iev++) {
      pythia8->GenerateEvent();
      if (iev < ndeb) pythia8->EventListing();
      pythia8->ImportParticles(particles,"All");
      Int_t np = particles->GetEntriesFast();
// Particle loop
         for (Int_t ip = 0; ip < np; ip++) {
         TParticle* part = (TParticle*) particles->At(ip);
         Int_t pdg = part->GetPdgCode();
         Float_t pt  = part->Pt();
	 Int_t motherindex = part->GetFirstMother();
	 TParticle* mopart = (TParticle*) particles->At(motherindex);

 if (((pdg == 211) || (pdg == -211) ) && (pt >= 0)) ptPionH->Fill(pt, 1./(2. * pt))
	 if (mopart == 0) continue;
	 Int_t mopdg = mopart->GetPdgCode();
	 if (((pdg == 211) || (pdg == -211) ) && (pt >= 0) && (mopdg == 4122)) ptPionlH->Fill(pt, 1./(2. * pt));

(above, ptPionH and ptPionlH are histograms I have defined in the code)

Now it seems that the code does what I want it to do. It returns the transverse momentum distribution of all pions and it returns the momentum distribution of pions originating from lambda_c baryons. The only problem is that it gives me the following error for a huge amount of particles:

Error in TClonesArray::At: index -1 out of bounds (size: 4000, this: 0x555e943a50c0)

Could you tell me how it is possible that a particle has index -1 and maybe how to prevent this error?

Best regards,

Loek

I assume “-1” means that this is a “primary particle” (so it has no “mother”). Try:

TParticle *part = (TParticle*) particles->At(ip);
if ((!part) || part->IsPrimary()) continue; // skip primary particles

Thanks a lot for helping me out! This was indeed the case.

@LoekMeijers would you mind me moving this thread to the regular ROOT section? I’d like to preserve the content.