18#include "BDSAcceleratorModel.hh"
20#include "BDSEventAction.hh"
21#include "BDSGlobalConstants.hh"
22#include "BDSPhysicsUtilities.hh"
23#include "BDSPolarizationState.hh"
24#include "BDSIntegratorMag.hh"
25#include "BDSTrackingAction.hh"
26#include "BDSTrajectory.hh"
27#include "BDSTrajectoryPrimary.hh"
28#include "BDSUserTrackInformation.hh"
29#include "BDSUtilities.hh"
32#include "G4TrackingManager.hh"
34#include "G4VPhysicalVolume.hh"
42 G4bool storeTrajectoryIn,
45 G4int verboseSteppingEventStartIn,
46 G4int verboseSteppingEventStopIn,
47 G4bool verboseSteppingPrimaryOnlyIn,
48 G4int verboseSteppingLevelIn,
50 interactive(!batchMode),
51 storeTrajectory(storeTrajectoryIn),
52 storeTrajectoryOptions(storeTrajectoryOptionsIn),
53 eventAction(eventActionIn),
54 verboseSteppingEventStart(verboseSteppingEventStartIn),
55 verboseSteppingEventStop(verboseSteppingEventStopIn),
56 verboseSteppingPrimaryOnly(verboseSteppingPrimaryOnlyIn),
57 verboseSteppingLevel(verboseSteppingLevelIn),
58 defaultPolarisation(defaultPolarisationIn)
61BDSTrackingAction::~BDSTrackingAction()
63 delete defaultPolarisation;
69 G4int eventIndex =
eventAction->CurrentEventIndex();
70 G4bool verboseSteppingThisEvent =
BDS::VerboseThisEvent(eventIndex, verboseSteppingEventStart, verboseSteppingEventStop);
71 G4bool primaryParticle = track->GetParentID() == 0;
74 if (primaryParticle && verboseSteppingThisEvent)
75 {fpTrackingManager->GetSteppingManager()->SetVerboseLevel(verboseSteppingLevel);}
76 else if (!primaryParticle && verboseSteppingThisEvent && !verboseSteppingPrimaryOnly)
77 {fpTrackingManager->GetSteppingManager()->SetVerboseLevel(verboseSteppingLevel);}
87 fpTrackingManager->SetStoreTrajectory(1);
88 fpTrackingManager->SetTrajectory(traj);
91 {fpTrackingManager->SetStoreTrajectory(0);}
98 G4bool storePoints = storeTrajectory ||
interactive;
104 fpTrackingManager->SetStoreTrajectory(1);
105 fpTrackingManager->SetTrajectory(traj);
108 if (
BDS::IsIon(track->GetParticleDefinition()))
111 track->SetUserInformation(trackInfo);
114 const G4ParticleDefinition *particle = track->GetParticleDefinition();
115 G4ProcessManager* pmanager = particle->GetProcessManager();
116 G4VProcess* process = pmanager->GetProcess(
"laserCumulativeCompton");
121 track->SetUserInformation(trackInfo);
128 fpTrackingManager->GetSteppingManager()->SetVerboseLevel(0);
131 G4int trackID = track->GetTrackID();
134 auto status = track->GetTrackStatus();
138 case G4TrackStatus::fAlive:
139 {name =
"fAlive";
break;}
140 case G4TrackStatus::fStopButAlive:
141 {name =
"fStopButAlive";
break;}
142 case G4TrackStatus::fKillTrackAndSecondaries:
143 {name =
"fKillTrackAndSecondaries";
break;}
144 case G4TrackStatus::fStopAndKill:
145 {name =
"fStopAndKill";
break;}
147 {name =
"other";
break;}
149 G4cout <<
"track ID " << trackID <<
" status " << name << G4endl;
152 if (track->GetParentID() == 0)
154 G4LogicalVolume* lv = track->GetVolume()->GetLogicalVolume();
155 std::set<G4LogicalVolume*>* collimators = BDSAcceleratorModel::Instance()->
VolumeSet(
"collimators");
156 if (collimators->find(lv) != collimators->end())
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.
void IncrementNTracks()
Interface for tracking action to increment the number of tracks in each event.
void SetPrimaryAbsorbedInCollimator(G4bool stoppedIn)
Flag that the primary was absorbed in a collimator - can be done externally to this class.
void RegisterPrimaryTrajectory(const BDSTrajectoryPrimary *trajectoryIn)
Append this trajectory to vector of primaries we keep to avoid sifting at the end of event.
static G4bool currentTrackIsPrimary
Polarization state to pass to processes.
virtual void PreUserTrackingAction(const G4Track *track)
Used to decide whether or not to store trajectories.
virtual void PostUserTrackingAction(const G4Track *track)
Detect whether track is a primary and if so whether it ended in a collimator.
BDSTrackingAction()=delete
No default constructor required.
BDSEventAction * eventAction
Cache of trajectory options.
const BDS::TrajectoryOptions storeTrajectoryOptions
Cache of flag from global constants to control storing all 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.
G4bool IsIon(const G4ParticleDefinition *particle)
Whether a particle is an ion. A proton is counted NOT as an ion.