9#include <simulation/kernel/TrackingAction.h>
10#include <simulation/kernel/UserInfo.h>
11#include <simulation/kernel/SensitiveDetectorBase.h>
12#include <framework/logging/Logger.h>
13#include <framework/gearbox/Unit.h>
15#include <G4TrackingManager.hh>
17#include <G4ParticleDefinition.hh>
18#include <G4ParticleTypes.hh>
19#include <G4EmProcessSubType.hh>
20#include <G4DecayProcessType.hh>
22#include <G4ParticleTable.hh>
25using namespace Belle2::Simulation;
28 G4UserTrackingAction(), m_mcParticleGraph(mcParticleGraph),
29 m_ignoreOpticalPhotons(false),
30 m_ignoreSecondaries(false), m_secondariesEnergyCut(0.0),
31 m_ignoreBremsstrahlungPhotons(false), m_bremsstrahlungPhotonsEnergyCut(0.0),
32 m_ignorePairConversions(false), m_pairConversionsEnergyCut(0.0),
33 m_storeTrajectories(false), m_distanceTolerance(0),
61 if (track->GetCurrentStepNumber() > 0)
return;
63 const G4DynamicParticle* dynamicParticle = track->GetDynamicParticle();
68 const bool isPrimary = dynamicParticle->GetPrimaryParticle() !=
nullptr;
69 bool neutral_llp =
false;
71 const G4PrimaryParticle* primaryParticle = dynamicParticle->GetPrimaryParticle();
72 if (primaryParticle->GetUserInformation() !=
nullptr) {
75 if (primaryParticle->GetParticleDefinition() == G4ParticleTable::GetParticleTable()->FindParticle(
"LongLivedNeutralParticle")) {
79 B2WARNING(track->GetDefinition()->GetPDGEncoding() <<
" has no MCParticle user information !");
86 G4ThreeVector dpMom = dynamicParticle->GetMomentum() / CLHEP::MeV *
Unit::MeV;
93 G4ThreeVector trVtxPos = track->GetVertexPosition() / CLHEP::mm *
Unit::mm;
100 currParticle.
setPDG(dynamicParticle->GetPDGcode());
103 currParticle.
setMomentum(dpMom.x(), dpMom.y(), dpMom.z());
112 }
else if (track->GetCreatorProcess() !=
nullptr) {
114 const int& processSubType = track->GetCreatorProcess()->GetProcessSubType();
118 if (processSubType >=
static_cast<int>(DECAY) && processSubType <=
static_cast<int>(DECAY_External))
131 (
m_storeTrajectories == 2 && track->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition())) {
137 }
catch (CouldNotFindUserInfo& exc) {
145 G4StepPoint* postStep = track->GetStep()->GetPostStepPoint();
152 for (G4Track* daughterTrack : *fpTrackingManager->GimmeSecondaries()) {
156 if (daughterTrack->GetDynamicParticle()->GetPrimaryParticle() == NULL &&
157 daughterTrack->GetUserInformation() == NULL) {
159 const_cast<G4Track*
>(daughterTrack)->SetUserInformation(
new TrackInfo(daughterParticle));
164 if (daughterTrack->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition()) {
169 if (track->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition()) {
171 TrackInfo* daughterInfo =
dynamic_cast<TrackInfo*
>(daughterTrack->GetUserInformation());
176 }
else if (daughterTrack->GetCreatorProcess()->GetProcessSubType() == fBremsstrahlung) {
184 }
else if (daughterTrack->GetCreatorProcess()->GetProcessSubType() == fGammaConversion) {
205 if (track->GetTrackStatus() == fSuspend)
return;
208 if (postStep->GetStepStatus() == fWorldBoundary) {
213 if (track->GetKineticEnergy() <= 0.0) {
218 G4ThreeVector decVtx = postStep->GetPosition() / CLHEP::mm *
Unit::mm;
230 }
catch (CouldNotFindUserInfo& exc) {
Class to represent Particle data in graph.
void decaysInto(GraphParticle &daughter)
Tells the graph that this particle decays into daughter.
void setTrackID(int trackID)
Set the track ID for the particle.
void setIgnore(bool ignore=true)
Set or remove the ignore flag.
Class to build, validate and sort a particle decay chain.
Class to save the full simulated trajectory of a particle.
void simplify(float distanceTolerance)
Simplify the trajectory using the Ramer-Douglas-Peuker algorithm.
A Class to store the Monte Carlo particle information.
@ c_LeftDetector
bit 2: Particle left the detector (the simulation volume).
@ c_StoppedInDetector
bit 3: Particle was stopped in the detector (the simulation volume).
void setDecayTime(float time)
Set decay time.
void setMass(float mass)
Set particle mass.
void setDecayVertex(const ROOT::Math::XYZVector &vertex)
Set decay vertex.
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
void setEnergy(float energy)
Set energy.
void setValidVertex(bool valid)
Set indication wether vertex and time information is valid or just default.
void setProductionVertex(const ROOT::Math::XYZVector &vertex)
Set production vertex position.
void setSecondaryPhysicsProcess(int physicsProcess)
Sets the physics process type of a secondary particle.
void setPDG(int pdg)
Set PDG code of the particle.
float getProductionTime() const
Return production time in ns.
void setMomentum(const ROOT::Math::XYZVector &momentum)
Set particle momentum.
void setProductionTime(float time)
Set production time.
@ c_negativeWeight
Flip the sign of the weight to become negative if the original element got re-attributed.
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
static void registerMCParticleRelation(const std::string &name, RelationArray::EConsolidationAction ignoreAction=RelationArray::c_negativeWeight)
Register an relation involving MCParticles.
virtual ~TrackingAction()
Destructor.
bool m_ignoreSecondaries
do not store secondaries in MCParticles
MCParticleGraph & m_mcParticleGraph
Reference to the MCParticle graph which is updated by the tracking action.
TrackingAction(MCParticleGraph &mcParticleGraph)
Constructor.
double m_pairConversionsEnergyCut
kinetic energy cut for stored e+ or e- from pair conversions [MeV]
void setStoreTrajectories(int store, double distanceTolerance)
Sets the trajectory option to enable storing of the simulated particle trajectories.
RelationArray m_relMCTrajectories
RelationArry for the relation between MCParticles and Trajectories.
StoreArray< MCParticleTrajectory > m_storeMCTrajectories
Store array for the Trajectories.
double m_distanceTolerance
distance tolerance to merge trajectory points
void PreUserTrackingAction(const G4Track *track)
Checks if the particle associated to the track is already in the MCParticle list.
double m_secondariesEnergyCut
kinetic energy cut for stored secondaries [MeV]
void PostUserTrackingAction(const G4Track *track)
Updates the data of the MCParticle associated with the Geant4 track.
bool m_ignorePairConversions
do not store e+ or e- from pair conversions in MCparticles
bool m_ignoreBremsstrahlungPhotons
do not store bremsstrahlung photons in MCParticles
bool m_ignoreOpticalPhotons
do not store optical photons in MCParticles
double m_bremsstrahlungPhotonsEnergyCut
kinetic energy cut for stored bremsstrahlung photons [MeV]
int m_storeTrajectories
Store trajectories for 0=none, 1=primary or 2=all particles.
UserInfo class which is used to attach additional information to Geant4 particles and tracks.
void setFraction(double fraction)
Store optical photon propagation fraction (used for performance speed-ups)
void setStatus(int status)
Set status of optical photon (used for performance speed-ups)
double getFraction()
Get optical photon propagation fraction (used for performance speed-ups) status=0: fraction=1 status=...
static Payload getInfo(Carrier &obj)
Static function to just return UserInformation attached to the obj of type Carrier.
int getStatus()
Get status of optical photon (used for performance speed-ups) 0 initial 1 prescaled in StackingAction...
Accessor to arrays stored in the data store.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
static const double mm
[millimeters]
static const double MeV
[megaelectronvolt]
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.