15 #include "Geant4/G4Event.hh" 17 #include "Geant4/G4Track.hh" 18 #include "Geant4/G4ThreeVector.hh" 19 #include "Geant4/G4ParticleDefinition.hh" 20 #include "Geant4/G4PrimaryParticle.hh" 21 #include "Geant4/G4DynamicParticle.hh" 22 #include "Geant4/G4VUserPrimaryParticleInformation.hh" 23 #include "Geant4/G4Step.hh" 24 #include "Geant4/G4StepPoint.hh" 25 #include "Geant4/G4VProcess.hh" 26 #include "Geant4/G4String.hh" 28 #include <TLorentzVector.h> 58 bool storeTrajectories,
59 bool keepEMShowerDaughters)
105 <<
"parentage for " << trackid
106 <<
" " << (*itr).second;
110 parentid = (*itr).second;
113 LOG_DEBUG(
"ParticleListAction") <<
"final parent ID " << parentid;
123 G4ParticleDefinition* particleDefinition = track->GetDefinition();
124 G4int pdgCode = particleDefinition->GetPDGEncoding();
137 std::string process_name =
"unknown";
141 const G4DynamicParticle* dynamicParticle = track->GetDynamicParticle();
142 const G4PrimaryParticle* primaryParticle = dynamicParticle->GetPrimaryParticle();
144 if ( primaryParticle != 0 ){
145 const G4VUserPrimaryParticleInformation* gppi = primaryParticle->GetUserInformation();
153 process_name =
"primary";
168 process_name = track->GetCreatorProcess()->GetProcessName();
170 && (process_name.find(
"conv") != std::string::npos
171 || process_name.find(
"LowEnConversion") != std::string::npos
172 || process_name.find(
"Pair") != std::string::npos
173 || process_name.find(
"compt") != std::string::npos
174 || process_name.find(
"Compt") != std::string::npos
175 || process_name.find(
"Brem") != std::string::npos
176 || process_name.find(
"phot") != std::string::npos
177 || process_name.find(
"Photo") != std::string::npos
178 || process_name.find(
"Ion") != std::string::npos
179 || process_name.find(
"annihil") != std::string::npos)
207 G4double
energy = track->GetKineticEnergy();
234 <<
"can't find parent id: " 236 <<
" in the particle list, or fParentIDMap." 237 <<
" Make " << parentID <<
" the mother ID for" 239 <<
" in the hope that it will aid debugging.";
248 double mass = dynamicParticle->GetMass()/CLHEP::GeV;
260 const G4ThreeVector& polarization = track->GetPolarization();
263 polarization.z() ) );
285 G4String process = aTrack->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
312 globalTime = step->GetTrack()->GetGlobalTime();
314 velocity_step = step->GetStepLength() / step->GetDeltaTime();
315 if ( (step->GetTrack()->GetDefinition()->GetPDGEncoding()==0) &&
319 step->GetPostStepPoint()->SetGlobalTime(
globalTime - step->GetDeltaTime() + step->GetStepLength()/
velocity_G4);
331 const G4StepPoint* preStepPoint = step->GetPreStepPoint();
333 const G4ThreeVector position = preStepPoint->GetPosition();
334 G4double time = preStepPoint->GetGlobalTime();
337 TLorentzVector fourPos(position.x() / CLHEP::cm,
338 position.y() / CLHEP::cm,
339 position.z() / CLHEP::cm,
342 const G4ThreeVector momentum = preStepPoint->GetMomentum();
343 const G4double
energy = preStepPoint->GetTotalEnergy();
344 TLorentzVector fourMom(momentum.x() / CLHEP::GeV,
345 momentum.y() / CLHEP::GeV,
346 momentum.z() / CLHEP::GeV,
347 energy / CLHEP::GeV);
360 G4String process = step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
361 G4bool ignoreProcess = process.contains(
"LArVoxel") || process.contains(
"OpDetReadout");
363 LOG_DEBUG(
"ParticleListAction::SteppingAction")
364 <<
": DEBUG - process='" 366 <<
" ignoreProcess=" << ignoreProcess
367 <<
" fstoreTrajectories=" 374 if ( fstoreTrajectories && !ignoreProcess ){
376 const G4StepPoint* postStepPoint = step->GetPostStepPoint();
378 const G4ThreeVector position = postStepPoint->GetPosition();
379 G4double time = postStepPoint->GetGlobalTime();
382 TLorentzVector fourPos( position.x() / CLHEP::cm,
383 position.y() / CLHEP::cm,
384 position.z() / CLHEP::cm,
387 const G4ThreeVector momentum = postStepPoint->GetMomentum();
388 const G4double
energy = postStepPoint->GetTotalEnergy();
389 TLorentzVector fourMom( momentum.x() / CLHEP::GeV,
390 momentum.y() / CLHEP::GeV,
391 momentum.z() / CLHEP::GeV,
392 energy / CLHEP::GeV );
404 :
public std::unary_function<sim::ParticleList::value_type, void>
414 int particleID = particleListEntry.first;
419 int parentID = particleList->GetMotherOf(particleID);
422 if ( parentID <= 0 )
return;
430 if ( parentEntry == particleList->end() ){
438 if ( !parentEntry->second )
return;
466 updateDaughterInformation);
478 if( (*pn).first > highestID ) highestID = (*pn).first;
505 if( (*pn).first > highestID ) highestID = (*pn).first;
516 TLorentzVector
const& mom,
517 std::string
const& process)
int GetParentage(int trackid) const
unsigned int NumberTrajectoryPoints() const
G4bool fstoreTrajectories
Whether to store particle trajectories with each particle.
void AddDaughter(const int trackID)
void AddPointToCurrentParticle(TLorentzVector const &pos, TLorentzVector const &mom, std::string const &process)
Adds a trajectory point to the current particle, and runs the filter.
std::unique_ptr< PositionInVolumeFilter > fFilter
filter for particles to be kept
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
static int fCurrentPdgCode
pdg code of current particle
virtual void BeginOfEventAction(const G4Event *)
G4UserEventAction interfaces.
std::map< int, GeneratedParticleIndex_t > fPrimaryTruthMap
Map: particle track ID -> index of primary information in MC truth.
const simb::MCTrajectory & Trajectory() const
GeneratedParticleIndex_t truthIndex
Index of the particle in the original generator truth record.
list_type::value_type value_type
list_type::iterator iterator
void Add(simb::MCParticle *value)
const sim::ParticleList * GetList() const
GeneratedParticleIndex_t truthInfoIndex() const
Returns the index of the particle in the generator truth record.
sim::ParticleList * fparticleList
ParticleInfo_t fCurrentParticle
ParticleListAction(double energyCut, bool storeTrajectories=false, bool keepEMShowerDaughters=false)
std::map< int, int > fParentIDMap
key is current track ID, value is parent ID
virtual void PreTrackingAction(const G4Track *)
G4UserTrackingAction interfaces.
constexpr GeneratedParticleIndex_t NoGeneratedParticleIndex
Constant representing the absence of generator truth information.
void clear()
Resets the information (does not release memory it does not own)
sim::ParticleList && YieldList()
void SetPolarization(const TVector3 &p)
Use Geant4's user "hooks" to maintain a list of particles generated by Geant4.
static int fTrackIDOffset
static bool isDropped(simb::MCParticle const *p)
returns whether the specified particle has been marked as dropped
bool fKeepEMShowerDaughters
whether to keep EM shower secondaries, tertiaries, etc
virtual void PostTrackingAction(const G4Track *)
static const int NoParticleId
simb::MCParticle * particle
simple structure representing particle
GeneratedParticleIndex_t GetPrimaryTruthIndex(int trackId) const
Returns the index of primary truth (sim::NoGeneratorIndex if none).
void SetWeight(double wt)
#define LOG_WARNING(category)
void SetEndProcess(std::string s)
bool isPrimary() const
Returns whether there is a particle.
virtual ~ParticleListAction()
bool KnownParticle(int trackID) const
Returns whether we have had this particle, archived or live.
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
virtual void EndOfEventAction(const G4Event *)
bool hasParticle() const
Returns whether there is a particle.
Particle list in DetSim contains Monte Carlo particle information.
virtual void SteppingAction(const G4Step *)
G4UserSteppingAction interface.
Tools and modules for checking out the basics of the Monte Carlo.
std::map< int, GeneratedParticleIndex_t > const & GetPrimaryTruthMap() const
GeneratedParticleIndex_t MCParticleIndex() const
Returns the index of the corresponding particle in truth record.
void Archive(const key_type &key)
Removes the particle from the list, keeping minimal info of it.
std::size_t GeneratedParticleIndex_t
Type of particle index in the generator truth record (simb::MCTruth).
static int fCurrentTrackID