actions
Loading...
Searching...
No Matches
gPrimaryGeneratorAction.cc
Go to the documentation of this file.
1
// gemc
2
#include "
gparticle_options.h
"
3
#include "
gPrimaryGeneratorAction.h
"
4
5
6
GPrimaryGeneratorAction::GPrimaryGeneratorAction
(std::shared_ptr<GOptions> gopts) :
7
GBase
(gopts,
GPRIMARYGENERATORACTION_LOGGER
),
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
21
GPrimaryGeneratorAction::~GPrimaryGeneratorAction
() {
22
// Release the internally owned particle gun.
23
delete
gparticleGun;
24
}
25
26
27
void
GPrimaryGeneratorAction::GeneratePrimaries
(G4Event* anEvent) {
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
}
GBase
GBase< GPrimaryGeneratorAction >::log
std::shared_ptr< GLogger > log
GLogger::info
void info(int level, Args &&... args) const
GPrimaryGeneratorAction::GeneratePrimaries
void GeneratePrimaries(G4Event *event) override
Generates the primaries for the given event.
Definition
gPrimaryGeneratorAction.cc:27
GPrimaryGeneratorAction::~GPrimaryGeneratorAction
~GPrimaryGeneratorAction() override
Destructor. Releases the internally owned particle gun.
Definition
gPrimaryGeneratorAction.cc:21
GPrimaryGeneratorAction::GPrimaryGeneratorAction
GPrimaryGeneratorAction(std::shared_ptr< GOptions > gopts)
Constructs the primary generator action.
Definition
gPrimaryGeneratorAction.cc:6
Gparticle::create_default_gparticle
static std::shared_ptr< Gparticle > create_default_gparticle(const std::shared_ptr< GLogger > &log)
gPrimaryGeneratorAction.h
Declares GPrimaryGeneratorAction, the primary particle generation action.
GPRIMARYGENERATORACTION_LOGGER
constexpr const char * GPRIMARYGENERATORACTION_LOGGER
Definition
gPrimaryGeneratorAction.h:19
gparticle_options.h
gparticle::getGParticles
vector< GparticlePtr > getGParticles(const std::shared_ptr< GOptions > &gopts, std::shared_ptr< GLogger > &logger)
gparticle
generator
gPrimaryGeneratorAction.cc
Generated by
1.10.0