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) 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 "BDSAcceleratorModel.hh"
20#include "BDSGlobalConstants.hh"
21#include "BDSLinkEventAction.hh"
22#include "BDSLinkTrackingAction.hh"
23#include "BDSPhysicsUtilities.hh"
24#include "BDSTrajectory.hh"
25#include "BDSTrajectoryOptions.hh"
26#include "BDSTrajectoryPrimary.hh"
27#include "BDSUtilities.hh"
28
29#include "G4TrackingManager.hh"
30#include "G4Track.hh"
31#include "G4Types.hh"
32
33#include <set>
34
35class G4LogicalVolume;
36
38 BDSLinkEventAction* eventActionIn,
39 G4int verboseSteppingEventStartIn,
40 G4int verboseSteppingEventStopIn,
41 G4bool verboseSteppingPrimaryOnlyIn,
42 G4int verboseSteppingLevelIn):
43 interactive(!batchMode),
44 eventAction(eventActionIn),
45 verboseSteppingEventStart(verboseSteppingEventStartIn),
46 verboseSteppingEventStop(verboseSteppingEventStopIn),
47 verboseSteppingPrimaryOnly(verboseSteppingPrimaryOnlyIn),
48 verboseSteppingLevel(verboseSteppingLevelIn)
49{
50 trajectoryStorageOptions = {false, true, true, false, false, false, false, false, false};
51}
52
54{
55 G4int eventIndex = eventAction->CurrentEventIndex();
56 G4bool verboseSteppingThisEvent = BDS::VerboseThisEvent(eventIndex, verboseSteppingEventStart, verboseSteppingEventStop);
57 G4bool primaryParticle = track->GetParentID() == 0;
58
59 if (primaryParticle && verboseSteppingThisEvent)
60 {fpTrackingManager->GetSteppingManager()->SetVerboseLevel(verboseSteppingLevel);}
61 else if (!primaryParticle && verboseSteppingThisEvent && !verboseSteppingPrimaryOnly)
62 {fpTrackingManager->GetSteppingManager()->SetVerboseLevel(verboseSteppingLevel);}
63
64 if (!primaryParticle)
65 {// ie secondary particle
66 // only store if we want to or interactive
67 if (interactive)
68 {
69
70 auto traj = new BDSTrajectory(track,
72 trajectoryStorageOptions);
73 fpTrackingManager->SetStoreTrajectory(1);
74 fpTrackingManager->SetTrajectory(traj);
75 }
76 else // mark as don't store
77 {fpTrackingManager->SetStoreTrajectory(0);}
78 }
79 else
80 {// it's a primary particle
81 // if it's a primary track then we always store something
82 // but only store the actual trajectory points if we explicitly want
83 // trajectory points or we're using the visualiser.
84 auto traj = new BDSTrajectoryPrimary(track,
85 interactive, trajectoryStorageOptions, interactive);
86 fpTrackingManager->SetStoreTrajectory(1);
87 fpTrackingManager->SetTrajectory(traj);
88 }
89}
90
92{
93 // turn off verbosity always as we selectively turn it on in the start tracking option
94 fpTrackingManager->GetSteppingManager()->SetVerboseLevel(0);
95
96 if (track->GetParentID() == 0)
97 {
98 G4LogicalVolume* lv = track->GetVolume()->GetLogicalVolume();
99 std::set<G4LogicalVolume*>* collimators = BDSAcceleratorModel::Instance()->VolumeSet("collimators");
100 if (collimators->find(lv) != collimators->end())
102 }
103}
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.