LDMX Software
BertiniEventTopologyProcess.cxx
1#include "SimCore/PhotoNuclearModels/BertiniEventTopologyProcess.h"
2namespace simcore {
3
4void BertiniEventTopologyProcess::cleanupSecondaries() {
5 int secondaries{theParticleChange.GetNumberOfSecondaries()};
6 // Geant4 won't clean up this memory for us by default
7 for (int i{0}; i < secondaries; ++i) {
8 auto secondary{theParticleChange.GetSecondary(i)->GetParticle()};
9 delete secondary;
10 }
11}
12
13G4HadFinalState* BertiniEventTopologyProcess::ApplyYourself(
14 const G4HadProjectile& projectile, G4Nucleus& targetNucleus) {
15 int attempts{1};
16 if (!acceptProjectile(projectile) || !acceptTarget(targetNucleus)) {
17 // Bertini will handle the particle change on its own here
18 return G4CascadeInterface::ApplyYourself(projectile, targetNucleus);
19 }
20
21 while (true) {
22 theParticleChange.Clear();
23 theParticleChange.SetStatusChange(stopAndKill);
24 G4CascadeInterface::ApplyYourself(projectile, targetNucleus);
25 if (acceptEvent()) {
26 incrementEventWeight(attempts);
27 return &theParticleChange;
28 }
29 attempts++;
30 cleanupSecondaries();
31 }
32}
33
34} // namespace simcore