LDMX Software
Public Member Functions | Private Attributes | List of all members
simcore::generators::GeneralParticleSource Class Reference

Class that extends the functionality of G4GeneralParticleSource. More...

#include <GeneralParticleSource.h>

Public Member Functions

 GeneralParticleSource (const std::string &name, const framework::config::Parameters &parameters)
 Constructor.
 
virtual ~GeneralParticleSource ()=default
 Destructor.
 
void GeneratePrimaryVertex (G4Event *event) override
 Generate the primary vertices in the Geant4 event.
 
void RecordConfig (const std::string &id, ldmx::RunHeader &rh) override
 Record the configuration of the primary generator into the run header.
 
- Public Member Functions inherited from simcore::PrimaryGenerator
 PrimaryGenerator (const std::string &name, const framework::config::Parameters &parameters)
 Constructor.
 
virtual ~PrimaryGenerator ()=default
 Destructor.
 

Private Attributes

G4GeneralParticleSource theG4Source_
 The underlying Geant4 GPS implementation.
 
std::vector< std::string > init_commands_
 storage of initialization commands (for config recording)
 

Additional Inherited Members

- Public Types inherited from simcore::PrimaryGenerator
using Factory = ::simcore::Factory< PrimaryGenerator, std::shared_ptr< PrimaryGenerator >, const std::string &, const framework::config::Parameters & >
 Factory for primary generators.
 
- Protected Attributes inherited from simcore::PrimaryGenerator
std::string name_ {""}
 Name of the PrimaryGenerator.
 

Detailed Description

Class that extends the functionality of G4GeneralParticleSource.

Definition at line 30 of file GeneralParticleSource.h.

Constructor & Destructor Documentation

◆ GeneralParticleSource()

simcore::generators::GeneralParticleSource::GeneralParticleSource ( const std::string &  name,
const framework::config::Parameters parameters 
)

Constructor.

Parameters
parametersParameters used to configure the particle gun.

Parameters: initCommands : vector of Geant4 strings to initialize the GPS

Definition at line 23 of file GeneralParticleSource.cxx.

25 : PrimaryGenerator(name, parameters) {
27 parameters.getParameter<std::vector<std::string>>("initCommands");
28 for (const auto& cmd : init_commands_) {
29 int g4Ret = G4UImanager::GetUIpointer()->ApplyCommand(cmd);
30 if (g4Ret > 0) {
31 EXCEPTION_RAISE("InitCmd",
32 "Initialization command '" + cmd +
33 "' returned a failue status from Geant4: " +
34 std::to_string(g4Ret));
35 }
36 }
37}
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
PrimaryGenerator(const std::string &name, const framework::config::Parameters &parameters)
Constructor.
std::vector< std::string > init_commands_
storage of initialization commands (for config recording)

References framework::config::Parameters::getParameter(), and init_commands_.

Member Function Documentation

◆ GeneratePrimaryVertex()

void simcore::generators::GeneralParticleSource::GeneratePrimaryVertex ( G4Event *  event)
overridevirtual

Generate the primary vertices in the Geant4 event.

Parameters
eventThe Geant4 event.

Implements simcore::PrimaryGenerator.

Definition at line 39 of file GeneralParticleSource.cxx.

39 {
40 // just pass to the Geant4 implementation
41 theG4Source_.GeneratePrimaryVertex(event);
42 return;
43}
G4GeneralParticleSource theG4Source_
The underlying Geant4 GPS implementation.

References theG4Source_.

◆ RecordConfig()

void simcore::generators::GeneralParticleSource::RecordConfig ( const std::string &  id,
ldmx::RunHeader rh 
)
overridevirtual

Record the configuration of the primary generator into the run header.

Note
you must include the id number in each entry into the run header just in case there are other generators

Implements simcore::PrimaryGenerator.

Definition at line 45 of file GeneralParticleSource.cxx.

46 {
47 rh.setStringParameter(id + " Class",
48 "simcore::generators::GeneralParticleSource");
49 std::string init_prefix{id + " Init Cmd "};
50 for (std::size_t i{0}; i < init_commands_.size(); i++) {
51 rh.setStringParameter(init_prefix + std::to_string(i),
52 init_commands_.at(i));
53 }
54}
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:214

References init_commands_, and ldmx::RunHeader::setStringParameter().

Member Data Documentation

◆ init_commands_

std::vector<std::string> simcore::generators::GeneralParticleSource::init_commands_
private

storage of initialization commands (for config recording)

Definition at line 64 of file GeneralParticleSource.h.

Referenced by GeneralParticleSource(), and RecordConfig().

◆ theG4Source_

G4GeneralParticleSource simcore::generators::GeneralParticleSource::theG4Source_
private

The underlying Geant4 GPS implementation.

The creation of this class creates a new messenger that we can pass commands to.

Definition at line 61 of file GeneralParticleSource.h.

Referenced by GeneratePrimaryVertex().


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