actions
Loading...
Searching...
No Matches
gPrimaryGeneratorAction.cc
Go to the documentation of this file.
1// gemc
2#include "gparticle_options.h"
4
5
6GPrimaryGeneratorAction::GPrimaryGeneratorAction(std::shared_ptr<GOptions> gopts) :
8 gparticleGun(nullptr) {
9 // Allocate the particle gun and load configured particle definitions.
10 gparticleGun = new G4ParticleGun();
11 gparticles = gparticle::getGParticles(gopts, log);
12
13 if (gparticles.empty()) {
14 // Ensure a valid generator configuration by creating a default particle.
15 auto default_particle = Gparticle::create_default_gparticle(log);
16 log->info(1, "No gparticle was defined. Creating default:", *default_particle);
17 gparticles.emplace_back(default_particle);
18 }
19}
20
22 // Release the internally owned particle gun.
23 delete gparticleGun;
24}
25
26
28 // Generate primaries by iterating over all configured particle definitions.
29 for (auto& gparticle : gparticles) {
30 log->info(2, gparticle);
31
32 gparticle->shootParticle(gparticleGun, anEvent);
33 }
34}
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void GeneratePrimaries(G4Event *event) override
Generates the primaries for the given event.
~GPrimaryGeneratorAction() override
Destructor. Releases the internally owned particle gun.
GPrimaryGeneratorAction(std::shared_ptr< GOptions > gopts)
Constructs the primary generator action.
static std::shared_ptr< Gparticle > create_default_gparticle(const std::shared_ptr< GLogger > &log)
Declares GPrimaryGeneratorAction, the primary particle generation action.
constexpr const char * GPRIMARYGENERATORACTION_LOGGER
vector< GparticlePtr > getGParticles(const std::shared_ptr< GOptions > &gopts, std::shared_ptr< GLogger > &logger)