BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSLinkStackingAction.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSGlobalConstants.hh"
19#include "BDSLinkStackingAction.hh"
20#include "BDSPhysicsUtilities.hh"
21#include "BDSRunManager.hh"
22
23#include "G4Event.hh"
24#include "G4Track.hh"
25#include "G4TrackStatus.hh"
26#include "G4Types.hh"
27#include "G4ParticleDefinition.hh"
28
29#include <set>
30
31G4double BDSLinkStackingAction::kineticEnergyKilled = 0;
32
34 const std::set<G4int>& pdgIDsToAllowIn,
35 G4bool protonsAndIonsOnlyIn,
36 G4double minimumEKIn):
37 pdgIDsToAllow(pdgIDsToAllowIn),
38 emptyPDGIDs(pdgIDsToAllow.empty()),
39 protonsAndIonsOnly(protonsAndIonsOnlyIn),
40 minimumEK(minimumEKIn)
41{
42 killNeutrinos = globals->KillNeutrinos();
43 stopSecondaries = globals->StopSecondaries();
44 maxTracksPerEvent = globals->MaximumTracksPerEvent();
45 if (maxTracksPerEvent == 0) // 0 is default -> no action - set maximum possible number
46 {maxTracksPerEvent = LONG_MAX;}
47}
48
49BDSLinkStackingAction::~BDSLinkStackingAction()
50{;}
51
52G4ClassificationOfNewTrack BDSLinkStackingAction::ClassifyNewTrack(const G4Track * aTrack)
53{
54 G4ClassificationOfNewTrack result = fUrgent;
55
56 if (aTrack->GetTrackID() > maxTracksPerEvent)
57 {result = fKill;}
58 else if (aTrack->GetKineticEnergy() <= minimumEK)
59 {result = fKill;}
60 else if (stopSecondaries && (aTrack->GetParentID() > 0))
61 {result = fKill;}
62 else
63 {
64 auto definition = aTrack->GetDefinition();
65 G4int pdgID = definition->GetPDGEncoding();
66
67 if (killNeutrinos)
68 {
69 if (pdgID == 12 || pdgID == 14 || pdgID == 16)
70 {result = fKill;}
71 }
72
73 if (protonsAndIonsOnly)
74 {
75 if (!BDS::IsIon(definition) && pdgID != 2212)
76 {result = fKill;}
77 else if (pdgID == 2212)
78 {result = fUrgent;}
79 }
80 else if (!emptyPDGIDs)
81 {
82 if (pdgIDsToAllow.find(pdgID) != pdgIDsToAllow.end())
83 {result = fKill;}
84 }
85 }
86
87 if (result == fKill)
88 {kineticEnergyKilled += aTrack->GetKineticEnergy() * aTrack->GetWeight();}
89 return result;
90}
91
92
A class that holds global options and constants.
G4bool stopSecondaries
Whether particles with parentID > 0 will be killed.
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack)
G4double minimumEK
Minimum kinetic energy to generate a hit for.
BDSLinkStackingAction()=delete
Force use of supplied constructor.
G4bool killNeutrinos
Local copy of whether to kill neutrinos for tracking efficiency.
G4long maxTracksPerEvent
Maximum number of tracks before start killing.
G4bool IsIon(const G4ParticleDefinition *particle)
Whether a particle is an ion. A proton is counted NOT as an ion.