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) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSGlobalConstants.hh"
20#include "BDSLinkStackingAction.hh"
21#include "BDSPhysicsUtilities.hh"
22#include "BDSRunManager.hh"
23
24#include "G4Event.hh"
25#include "G4Track.hh"
26#include "G4TrackStatus.hh"
27#include "G4Types.hh"
28#include "G4ParticleDefinition.hh"
29
30#include <set>
31
32G4double BDSLinkStackingAction::kineticEnergyKilled = 0;
33
35 const std::set<G4int>& pdgIDsToAllowIn,
36 G4bool protonsAndIonsOnlyIn,
37 G4double minimumEKIn):
38 pdgIDsToAllow(pdgIDsToAllowIn),
39 emptyPDGIDs(pdgIDsToAllow.empty()),
40 protonsAndIonsOnly(protonsAndIonsOnlyIn),
41 minimumEK(minimumEKIn)
42{
43 killNeutrinos = globals->KillNeutrinos();
44 stopSecondaries = globals->StopSecondaries();
45 maxTracksPerEvent = globals->MaximumTracksPerEvent();
46 if (maxTracksPerEvent == 0) // 0 is default -> no action - set maximum possible number
47 {maxTracksPerEvent = LONG_MAX;}
48}
49
50BDSLinkStackingAction::~BDSLinkStackingAction()
51{;}
52
53G4ClassificationOfNewTrack BDSLinkStackingAction::ClassifyNewTrack(const G4Track * aTrack)
54{
55 G4ClassificationOfNewTrack result = fUrgent;
56
57 if (aTrack->GetTrackID() > maxTracksPerEvent)
58 {result = fKill;}
59 else if (aTrack->GetKineticEnergy() <= minimumEK)
60 {result = fKill;}
61 else if (stopSecondaries && (aTrack->GetParentID() > 0))
62 {result = fKill;}
63 else
64 {
65 auto definition = aTrack->GetDefinition();
66 G4int pdgID = definition->GetPDGEncoding();
67
68 if (killNeutrinos)
69 {
70 if (pdgID == 12 || pdgID == 14 || pdgID == 16)
71 {result = fKill;}
72 }
73
74 if (protonsAndIonsOnly)
75 {
76 if (!BDS::IsIon(definition) && pdgID != 2212)
77 {result = fKill;}
78 else if (pdgID == 2212)
79 {result = fUrgent;}
80 }
81 else if (!emptyPDGIDs)
82 {
83 if (pdgIDsToAllow.find(pdgID) != pdgIDsToAllow.end())
84 {result = fKill;}
85 }
86 }
87
88 if (result == fKill)
89 {kineticEnergyKilled += aTrack->GetKineticEnergy() * aTrack->GetWeight();}
90 return result;
91}
92
93
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.