LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ParticleList.h File Reference

Particle list in DetSim contains Monte Carlo particle information. More...

#include "nusimdata/SimulationBase/MCParticle.h"
#include <set>
#include <ostream>
#include <map>
#include <cstdlib>

Go to the source code of this file.

Classes

class  sim::ParticleList
 
struct  sim::ParticleList::archived_info_type
 

Namespaces

 sim
 Monte Carlo Simulation.
 

Detailed Description

Particle list in DetSim contains Monte Carlo particle information.

Version
Id
ParticleList.h,v 1.13 2010/05/13 16:12:20 seligman Exp
Author
selig.nosp@m.man@.nosp@m.nevis.nosp@m..col.nosp@m.umbia.nosp@m..edu

A container for particles generated during an event simulation. It acts like a map<int,Particle*> but with additional features:

  • A method Cut(double) that will remove all particles with energy less than the argument.
  • Methods TrackId(int) and Particle(int) for those who are unfamiliar with the concepts associated with STL maps: sim::ParticleList* particleList = // ...; int numberOfParticles = particleList->size(); for (int i=0; i<numberOfParticles; ++i) { int trackID = particleList->TrackId(i); simb::MCParticle* particle = particleList->Particle(i); } The STL equivalent to the above statements (more efficient): sim::ParticleList* particleList = // ...; for ( auto i = particleList->begin(); i != particleList->end(); ++i ) { const simb::MCParticle* particle = (i).second; int trackID = particle->TrackId(); // or... int trackID = (*i).first; } or, more compact: sim::ParticleList particleList = // ...; for ( const auto& i: particleList) { const simb::MCParticle particle = i.second; int trackID = particle->TrackId(); // or... int trackID = i.first; } If looping over all the particles, do prefer the second and third forms, since the first one is unacceptably inefficient for large events.
  • Methods to access the list of primary particles in the event: sim::ParticleList particleList = // ...; int numberOfPrimaries = particleList->NumberOfPrimaries(); for ( int i = 0; i != numberOfPrimaries; ++i ) { simb::MCParticle* particle = particleList->Primary(i); ... } There's also a simple test: int trackID = // ...; if ( particleList->IsPrimary(trackID) ) {...}

    (Aside: note that particleList[i] does NOT give you the "i-th" particle in the list; it gives you the particle whose trackID is "i".) Also this form becomes unacceptably inefficient when looping over all the particles in a crowded event: prefer to do a bit more of typing as: sim::ParticleList* particleList = // ...; for ( const auto& i: particleList) { int trackID = i.first; if (!particleList->IsPrimary(trackID)) continue; const simb::MCParticle primary = i.second; // ... }

Definition in file ParticleList.h.