gparticle
Loading...
Searching...
No Matches
Gparticle Class Reference

Lightweight particle specification and primary vertex shooter. More...

#include <gparticle.h>

Public Member Functions

 Gparticle (const std::string &name, int multiplicity, double p, double delta_p, const std::string &punit, const std::string &randomMomentumModel, double theta, double delta_theta, const std::string &thetaModel, double phi, double delta_phi, const std::string &aunit, double avx, double avy, double avz, double adelta_vx, double adelta_vy, double adelta_vz, const std::string &vunit, const std::string &randomVertexModel, const std::shared_ptr< GLogger > &logger, int generator_type=1)
 Constructs a particle configuration from user-facing parameters.
 
 Gparticle (const Gparticle &)=delete
 Copying is disabled.
 
Gparticleoperator= (const Gparticle &)=delete
 Copy assignment is disabled.
 
 ~Gparticle ()
 Destructor emits a debug-level lifecycle message.
 
void shootParticle (G4ParticleGun *particleGun, G4Event *anEvent)
 Shoots this particle configuration into a Geant4 event.
 
const std::string & getName () const
 Returns the particle name stored in this generator definition.
 
int getPid () const
 Returns the resolved PDG particle id.
 
int getMultiplicity () const
 Returns how many copies are generated per event.
 
double getMomentum () const
 Returns the nominal momentum magnitude.
 
double getTheta () const
 Returns the nominal polar angle.
 
double getPhi () const
 Returns the nominal azimuthal angle.
 
const G4ThreeVector & getVertex () const
 Returns the nominal vertex position.
 
int getGeneratorType () const
 Returns the generator source type.
 
const std::vector< GparticleRuntimeRecord > & getRuntimeRecords () const
 Returns the runtime records from the most recent shoot.
 

Static Public Member Functions

static std::shared_ptr< Gparticlecreate_default_gparticle (const std::shared_ptr< GLogger > &log)
 Creates a minimal default particle configuration.
 

Friends

std::ostream & operator<< (std::ostream &os, const Gparticle &gp)
 Stream insertion operator used for pretty-printing configuration summaries.
 
std::ostream & operator<< (std::ostream &os, const std::shared_ptr< Gparticle > &ptr)
 Stream insertion operator overload for shared pointers.
 

Detailed Description

A Gparticle instance represents a generator-level particle configuration that can be used to produce primary vertices in a G4Event through a G4ParticleGun.

The class stores:

  • Identity: particle name and resolved PDG id
  • Multiplicity: number of copies shot per event
  • Kinematics: momentum magnitude and angular parameters
  • Vertex: position and optional spread/randomization
  • Randomization models: selection of uniform/gaussian/cosine (angles) and sphere (vertex)

Configuration is typically created by option parsing utilities and then used during event generation by calling shootParticle().

Logging:

  • A logger is provided at construction and retained for diagnostics.
  • Verbosity 2 typically prints a full configuration summary via the stream operator.

Definition at line 88 of file gparticle.h.

Constructor & Destructor Documentation

◆ Gparticle() [1/2]

Gparticle::Gparticle ( const std::string & name,
int multiplicity,
double p,
double delta_p,
const std::string & punit,
const std::string & randomMomentumModel,
double theta,
double delta_theta,
const std::string & thetaModel,
double phi,
double delta_phi,
const std::string & aunit,
double avx,
double avy,
double avz,
double adelta_vx,
double adelta_vy,
double adelta_vz,
const std::string & vunit,
const std::string & randomVertexModel,
const std::shared_ptr< GLogger > & logger,
int generator_type = 1 )

This constructor converts user-facing numeric values paired with unit strings into internal numeric values (in the unit system returned by gutilities helpers), and converts randomization model strings into gutilities::randomModel values.

The particle PDG id is resolved at construction time by consulting the G4ParticleTable using the provided particle name.

Parameters
nameParticle name as understood by G4ParticleTable (e.g. "e-").
multiplicityNumber of particles to shoot per event.
pNominal momentum magnitude (interpreted together with punit).
delta_pSpread parameter for momentum randomization (interpreted with punit).
punitUnit string used to interpret p and delta_p (e.g. "MeV", "GeV").
randomMomentumModelRandom model name for momentum (e.g. "uniform", "gaussian").
thetaNominal polar angle (interpreted together with aunit).
delta_thetaSpread parameter for theta (interpreted with aunit).
thetaModelRandom model name for theta (e.g. "uniform", "cosine", "gaussian").
phiNominal azimuthal angle (interpreted together with aunit).
delta_phiSpread parameter for phi (interpreted with aunit).
aunitUnit string used to interpret angles (typically "deg" or "rad").
avxNominal vertex x component (interpreted together with vunit).
avyNominal vertex y component (interpreted together with vunit).
avzNominal vertex z component (interpreted together with vunit).
adelta_vxSpread parameter for vertex x (interpreted with vunit).
adelta_vySpread parameter for vertex y (interpreted with vunit).
adelta_vzSpread parameter for vertex z (interpreted with vunit).
vunitUnit string used to interpret vertex components (e.g. "cm", "mm").
randomVertexModelRandom model name for vertex (e.g. "uniform", "gaussian", "sphere").
loggerLogger used for diagnostics and error reporting.
generator_typeGenerator source type associated with this particle. Inline -gparticle definitions use the default value 1. File-backed particles preserve the source-file type field when the format provides one, such as the Lund type column.

Definition at line 22 of file gparticle.cc.

◆ Gparticle() [2/2]

Gparticle::Gparticle ( const Gparticle & )
delete

The class is intended to be managed through std::shared_ptr and not copied.

◆ ~Gparticle()

Gparticle::~Gparticle ( )
inline

Definition at line 165 of file gparticle.h.

Member Function Documentation

◆ create_default_gparticle()

static std::shared_ptr< Gparticle > Gparticle::create_default_gparticle ( const std::shared_ptr< GLogger > & log)
inlinestatic

This helper returns an electron with:

  • momentum 1 GeV, no spread
  • angles 0 deg, no spread
  • vertex at (0,0,0) cm, no spread
  • uniform random models where relevant
Parameters
logLogger to associate with the constructed particle.
Returns
A shared pointer to the default Gparticle configuration.

Definition at line 199 of file gparticle.h.

◆ getGeneratorType()

int Gparticle::getGeneratorType ( ) const
inline

For inline -gparticle entries this is normally 1. For file-backed entries this preserves the source format's type field; in Lund files, type 1 is the subset propagated to Geant4 and included in the generated_tracked output bank.

Returns
Generator source type.

Definition at line 284 of file gparticle.h.

◆ getMomentum()

double Gparticle::getMomentum ( ) const
inline
Returns
Momentum after unit conversion to GEMC internal units.

Definition at line 251 of file gparticle.h.

◆ getMultiplicity()

int Gparticle::getMultiplicity ( ) const
inline
Returns
Configured particle multiplicity.

Definition at line 244 of file gparticle.h.

◆ getName()

const std::string & Gparticle::getName ( ) const
inline
Returns
Particle name used for Geant4 lookup and generated-particle output.

Definition at line 230 of file gparticle.h.

◆ getPhi()

double Gparticle::getPhi ( ) const
inline
Returns
Phi after unit conversion to GEMC internal angular units.

Definition at line 265 of file gparticle.h.

◆ getPid()

int Gparticle::getPid ( ) const
inline
Returns
PDG id resolved from G4ParticleTable during construction.

Definition at line 237 of file gparticle.h.

◆ getRuntimeRecords()

const std::vector< GparticleRuntimeRecord > & Gparticle::getRuntimeRecords ( ) const
inline

One record is stored for each generated primary, so a particle with multiplicity N contributes N runtime records.

Definition at line 292 of file gparticle.h.

◆ getTheta()

double Gparticle::getTheta ( ) const
inline
Returns
Theta after unit conversion to GEMC internal angular units.

Definition at line 258 of file gparticle.h.

◆ getVertex()

const G4ThreeVector & Gparticle::getVertex ( ) const
inline
Returns
Vertex after unit conversion to GEMC internal length units.

Definition at line 272 of file gparticle.h.

◆ operator=()

Gparticle & Gparticle::operator= ( const Gparticle & )
delete

◆ shootParticle()

void Gparticle::shootParticle ( G4ParticleGun * particleGun,
G4Event * anEvent )

The method resolves the particle definition from the G4ParticleTable (using the stored particle name) and then, for each copy defined by the configured multiplicity:

  • sets the particle kinetic energy based on randomized momentum and mass
  • sets the momentum direction based on randomized theta/phi
  • sets the vertex position based on the configured vertex model
  • calls GeneratePrimaryVertex on the provided G4ParticleGun

Error handling:

  • If the G4ParticleTable is unavailable, an error is logged.
  • If the particle is not found, an error is logged.
Parameters
particleGunThe G4ParticleGun used to generate the primary vertices.
anEventThe G4Event that receives the generated primary vertices.

Definition at line 77 of file gparticle.cc.

Friends And Related Symbol Documentation

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & os,
const Gparticle & gp )
friend

Definition at line 247 of file gparticle.cc.

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream & os,
const std::shared_ptr< Gparticle > & ptr )
friend
Parameters
osOutput stream.
ptrPointer to a Gparticle; prints "<null Gparticle>" if null.
Returns
Output stream.

Definition at line 361 of file gparticle.h.


The documentation for this class was generated from the following files: