16 auto stlVertex{parameters.
getParameter<std::vector<double> >(
"vertex")};
17 auto stlMomentum{parameters.
getParameter<std::vector<double> >(
"momentum")};
22 if (stlVertex.size() != 3 or stlMomentum.size() != 3 or
mpgNParticles_ <= 0) {
23 EXCEPTION_RAISE(
"InvalideConfig",
24 "Parameters pass to '" +
name_ +
"' are not valid.");
27 mpgVertex_ = G4ThreeVector(stlVertex.at(0) * mm, stlVertex.at(1) * mm,
28 stlVertex.at(2) * mm);
29 mpgMomentum_ = G4ThreeVector(stlMomentum.at(0) * MeV, stlMomentum.at(1) * MeV,
30 stlMomentum.at(2) * MeV);
43 int curNVertices = anEvent->GetNumberOfPrimaryVertex();
46 int nInteractions = nInteractionsInput;
49 while (nInteractions == 0) {
51 nInteractions =
random_->Poisson(nInteractionsInput);
56 for (
int i = 0; i < (nInteractions - curNVertices); ++i) {
57 G4PrimaryVertex* curvertex =
58 new G4PrimaryVertex(cur_mpg_vertex, 0.);
60 curvertex->SetWeight(1.);
62 G4PrimaryParticle* primary =
63 new G4PrimaryParticle(cur_mpg_pdgid, cur_mpg_momentum.x(),
64 cur_mpg_momentum.y(), cur_mpg_momentum.z());
69 primary->SetUserInformation(primaryInfo);
71 curvertex->SetPrimary(primary);
72 anEvent->AddPrimaryVertex(curvertex);
Class for generating an event using multiple particles.
Generates a Geant4 event from particle gun, but can have many particles.
void GeneratePrimaryVertex(G4Event *anEvent) override
Generate vertices in the Geant4 event.
G4ThreeVector mpgVertex_
The vertex position from which to fire the particles.
bool mpgEnablePoisson_
Flag denoting whether the number of incident particles should be Poisson distributed.
void RecordConfig(const std::string &id, ldmx::RunHeader &rh) override
Record the configuration of the primary generator into the run header.
MultiParticleGunPrimaryGenerator(const std::string &name, const framework::config::Parameters ¶meters)
Constructor.
int mpgPdgID_
PDG ID of the particle used by the gun.
G4ThreeVector mpgMomentum_
The initial momentum of the particles.
double mpgNParticles_
Number of particles that will be fired by the gun per event.
virtual ~MultiParticleGunPrimaryGenerator()
Destructor.