BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSLinkTrackingAction.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 "BDSAcceleratorModel.hh"
19#include "BDSGlobalConstants.hh"
20#include "BDSLinkEventAction.hh"
21#include "BDSLinkTrackingAction.hh"
22#include "BDSPhysicsUtilities.hh"
23#include "BDSTrajectory.hh"
24#include "BDSTrajectoryOptions.hh"
25#include "BDSTrajectoryPrimary.hh"
26#include "BDSUtilities.hh"
27
28#include "G4TrackingManager.hh"
29#include "G4Track.hh"
30#include "G4Types.hh"
31
32#include <set>
33
34class G4LogicalVolume;
35
37 BDSLinkEventAction* eventActionIn,
38 G4int verboseSteppingEventStartIn,
39 G4int verboseSteppingEventStopIn,
40 G4bool verboseSteppingPrimaryOnlyIn,
41 G4int verboseSteppingLevelIn):
42 interactive(!batchMode),
43 eventAction(eventActionIn),
44 verboseSteppingEventStart(verboseSteppingEventStartIn),
45 verboseSteppingEventStop(verboseSteppingEventStopIn),
46 verboseSteppingPrimaryOnly(verboseSteppingPrimaryOnlyIn),
47 verboseSteppingLevel(verboseSteppingLevelIn)
48{
49 trajectoryStorageOptions = {false, true, true, false, false, false, false, false, false};
50}
51
53{
54 G4int eventIndex = eventAction->CurrentEventIndex();
55 G4bool verboseSteppingThisEvent = BDS::VerboseThisEvent(eventIndex, verboseSteppingEventStart, verboseSteppingEventStop);
56 G4bool primaryParticle = track->GetParentID() == 0;
57
58 if (primaryParticle && verboseSteppingThisEvent)
59 {fpTrackingManager->GetSteppingManager()->SetVerboseLevel(verboseSteppingLevel);}
60 else if (!primaryParticle && verboseSteppingThisEvent && !verboseSteppingPrimaryOnly)
61 {fpTrackingManager->GetSteppingManager()->SetVerboseLevel(verboseSteppingLevel);}
62
63 if (!primaryParticle)
64 {// ie secondary particle
65 // only store if we want to or interactive
66 if (interactive)
67 {
68
69 auto traj = new BDSTrajectory(track,
71 trajectoryStorageOptions);
72 fpTrackingManager->SetStoreTrajectory(1);
73 fpTrackingManager->SetTrajectory(traj);
74 }
75 else // mark as don't store
76 {fpTrackingManager->SetStoreTrajectory(0);}
77 }
78 else
79 {// it's a primary particle
80 // if it's a primary track then we always store something
81 // but only store the actual trajectory points if we explicitly want
82 // trajectory points or we're using the visualiser.
83 auto traj = new BDSTrajectoryPrimary(track,
84 interactive, trajectoryStorageOptions, interactive);
85 fpTrackingManager->SetStoreTrajectory(1);
86 fpTrackingManager->SetTrajectory(traj);
87 }
88}
89
91{
92 // turn off verbosity always as we selectively turn it on in the start tracking option
93 fpTrackingManager->GetSteppingManager()->SetVerboseLevel(0);
94
95 if (track->GetParentID() == 0)
96 {
97 G4LogicalVolume* lv = track->GetVolume()->GetLogicalVolume();
98 std::set<G4LogicalVolume*>* collimators = BDSAcceleratorModel::Instance()->VolumeSet("collimators");
99 if (collimators->find(lv) != collimators->end())
101 }
102}
std::set< G4LogicalVolume * > * VolumeSet(const G4String &name)
Returns pointer to a set of logical volumes. If no set by that name exits, create it.
Process information at the event level for Link to trackers.
void SetPrimaryAbsorbedInCollimator(G4bool stoppedIn)
Flag that the primary was absorbed in a collimator - can be done externally to this class.
BDSLinkEventAction * eventAction
Cache of event action to communicate whether a primary stopped in a collimator or not.
BDSLinkTrackingAction()=delete
No default constructor required.
virtual void PostUserTrackingAction(const G4Track *track)
Detect whether track is a primary and if so whether it ended in a collimator.
virtual void PreUserTrackingAction(const G4Track *track)
Used to decide whether or not to store trajectories.
Trajectory information for only the primary.
Trajectory information from track including last scatter etc.
G4bool VerboseThisEvent(G4int eventIndex, G4int eventStart, G4int eventStop)
Logic of whether this event should be verbose or not. Code here so it's not duplicated.