36 auto particleTable{G4ParticleTable::GetParticleTable()};
38 auto particle{parameters.
getParameter<std::string>(
"particle")};
39 if (
auto particleDef{particleTable->FindParticle(particle)};
42 std::cout <<
"[ ParticleGun ] : Firing particle of type " << particle
45 theGun_.SetParticleDefinition(particleDef);
50 std::cout <<
"[ ParticleGun ] : Setting energy to " << energy * GeV
53 theGun_.SetParticleEnergy(energy * GeV);
55 auto position{parameters.
getParameter<std::vector<double> >(
"position")};
56 if (!position.empty()) {
57 G4ThreeVector pVec(position[0] * mm, position[1] * mm, position[2] * mm);
59 std::cout <<
"[ ParticleGun ] : position " << pVec << std::endl;
61 theGun_.SetParticlePosition(pVec);
65 if (time < 0) time = 0.0;
67 std::cout <<
"[ ParticleGun ] : Setting particle time to " << time
70 theGun_.SetParticleTime(time * ns);
72 auto direction{parameters.
getParameter<std::vector<double> >(
"direction")};
73 if (!direction.empty()) {
74 G4ThreeVector dVec(direction[0], direction[1], direction[2]);
76 std::cout <<
"[ ParticleGun ] : direction " << dVec.unit() << std::endl;
78 theGun_.SetParticleMomentumDirection(dVec);
92 theGun_.GetParticleDefinition()->GetParticleName());
97 theGun_.GetParticleMomentumDirection().x());
99 theGun_.GetParticleMomentumDirection().y());
101 theGun_.GetParticleMomentumDirection().z());
Extension of G4ParticleGun.
Class that extends the functionality of G4ParticleGun.
int verbosity_
LDMX Verbosity for this generator.
ParticleGun(const std::string &name, const framework::config::Parameters ¶meters)
Constructor.
void GeneratePrimaryVertex(G4Event *event) override
Generate the primary vertices in the Geant4 event.
G4ParticleGun theGun_
The actual Geant4 implementation of the ParticleGun.
void RecordConfig(const std::string &id, ldmx::RunHeader &rh) override
Record the configuration of the primary generator into the run header.