23 #include <unordered_map>
26 #include <G4ChargedGeantino.hh>
28 #include <G4Geantino.hh>
29 #include <G4ParticleDefinition.hh>
30 #include <G4ParticleTable.hh>
31 #include <G4PrimaryParticle.hh>
32 #include <G4PrimaryVertex.hh>
33 #include <G4UnitsTable.hh>
35 namespace ActsExamples {
41 : G4VUserPrimaryGeneratorAction(),
48 anEvent->SetEventID(m_eventNr++);
49 unsigned int eventID = anEvent->GetEventID();
51 ACTS_DEBUG(
"Primary Generator Action for Event: " << eventID);
53 if (eventStore().
store ==
nullptr) {
54 ACTS_WARNING(
"No WhiteBoard instance could be found for this event!");
65 (*eventStore().inputParticles)(*eventStore().store);
69 m_cfg.reserveHitsPerParticle);
72 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
73 G4PrimaryVertex* pVertex =
nullptr;
76 std::optional<Acts::Vector4> lastVertex;
82 unsigned int pCounter = 0;
83 unsigned int trackId = 1;
86 auto currentVertex = part.fourPosition();
87 if (not lastVertex or not currentVertex.isApprox(*lastVertex)) {
89 if (pVertex !=
nullptr) {
90 anEvent->AddPrimaryVertex(pVertex);
92 <<
" particles associated with vertex "
93 << lastVertex->transpose());
96 lastVertex = currentVertex;
97 pVertex =
new G4PrimaryVertex(
98 currentVertex[0] * convertLength, currentVertex[1] * convertLength,
99 currentVertex[2] * convertLength, currentVertex[3] * convertTime);
107 G4int particlePdgCode =
m_cfg.forcedPdgCode.value_or(part.pdg());
108 G4double particleCharge =
m_cfg.forcedCharge.value_or(part.charge());
109 G4double particleMass =
110 m_cfg.forcedMass.value_or(part.mass() * convertEnergy);
113 G4ParticleDefinition* particleDefinition =
114 particleTable->FindParticle(particlePdgCode);
115 if (particleDefinition ==
nullptr) {
116 if (particlePdgCode == 0 && particleMass == 0 && particleCharge == 0) {
117 particleDefinition = G4Geantino::Definition();
119 if (particlePdgCode == 0 && particleMass == 0 && particleCharge != 0) {
120 if (particleCharge != 1) {
121 ACTS_ERROR(
"invalid charged geantino charge " << particleCharge
124 particleDefinition = G4ChargedGeantino::Definition();
129 if (particleDefinition ==
nullptr) {
131 "Could not translate particle with PDG code : " << particlePdgCode);
136 << particleDefinition->GetParticleName()
137 <<
"' and properties:");
143 G4PrimaryParticle*
particle =
new G4PrimaryParticle(particleDefinition);
145 particle->SetMass(particleMass);
146 particle->SetCharge(particleCharge);
147 particle->Set4Momentum(mom4[0], mom4[1], mom4[2], mom4[3]);
148 particle->SetTrackID(trackId++);
151 pVertex->SetPrimary(particle);
153 eventStore().particlesInitial.insert(part);
154 eventStore().trackIdMapping[particle->GetTrackID()] = part.particleId();
159 if (pVertex !=
nullptr) {
160 anEvent->AddPrimaryVertex(pVertex);
161 ACTS_DEBUG(
"Flushing " << pCounter <<
" particles associated with vertex "
162 << lastVertex->transpose());