10 #include "nug4/G4Base/PrimaryParticleInformation.h" 11 #include "nug4/ParticleNavigation/ParticleList.h" 13 #include "cetlib_except/exception.h" 16 #include "Geant4/G4DynamicParticle.hh" 17 #include "Geant4/G4ParticleDefinition.hh" 18 #include "Geant4/G4PrimaryParticle.hh" 19 #include "Geant4/G4Step.hh" 20 #include "Geant4/G4StepPoint.hh" 21 #include "Geant4/G4String.hh" 22 #include "Geant4/G4ThreeVector.hh" 23 #include "Geant4/G4Track.hh" 24 #include "Geant4/G4VProcess.hh" 25 #include "Geant4/G4VUserPrimaryParticleInformation.hh" 27 #include <TLorentzVector.h> 58 bool storeTrajectories,
59 bool keepEMShowerDaughters,
60 bool keepMCParticleList
95 MF_LOG_DEBUG(
"ParticleListAction") <<
"parentage for " << trackid <<
" " << (*itr).second;
99 parentid = (*itr).second;
102 MF_LOG_DEBUG(
"ParticleListAction") <<
"final parent ID " << parentid;
113 G4ParticleDefinition* particleDefinition = track->GetDefinition();
114 G4int pdgCode = particleDefinition->GetPDGEncoding();
136 const G4DynamicParticle* dynamicParticle = track->GetDynamicParticle();
137 const G4PrimaryParticle* primaryParticle = dynamicParticle->GetPrimaryParticle();
139 if (primaryParticle != 0) {
140 const G4VUserPrimaryParticleInformation* gppi = primaryParticle->GetUserInformation();
141 const g4b::PrimaryParticleInformation* ppi =
142 dynamic_cast<const g4b::PrimaryParticleInformation*
>(gppi);
144 primaryIndex = ppi->MCParticleIndex();
149 process_name =
"primary";
164 process_name = track->GetCreatorProcess()->GetProcessName();
166 process_name.find(
"LowEnConversion") != std::string::npos ||
167 process_name.find(
"Pair") != std::string::npos ||
168 process_name.find(
"compt") != std::string::npos ||
169 process_name.find(
"Compt") != std::string::npos ||
170 process_name.find(
"Brem") != std::string::npos ||
171 process_name.find(
"phot") != std::string::npos ||
172 process_name.find(
"Photo") != std::string::npos ||
173 process_name.find(
"Ion") != std::string::npos ||
174 process_name.find(
"annihil") != std::string::npos)) {
200 G4double
energy = track->GetKineticEnergy();
227 <<
"can't find parent id: " << parentID <<
" in the particle list, or fParentIDMap." 228 <<
" Make " << parentID <<
" the mother ID for" 229 <<
" track ID " <<
fCurrentTrackID <<
" in the hope that it will aid debugging.";
238 double mass = dynamicParticle->GetMass() /
CLHEP::GeV;
250 const G4ThreeVector& polarization = track->GetPolarization();
252 TVector3(polarization.x(), polarization.y(), polarization.z()));
277 aTrack->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
299 globalTime = step->GetTrack()->GetGlobalTime();
301 velocity_step = step->GetStepLength() / step->GetDeltaTime();
302 if ((step->GetTrack()->GetDefinition()->GetPDGEncoding() == 0) &&
306 step->GetPostStepPoint()->SetGlobalTime(
globalTime - step->GetDeltaTime() +
318 const G4StepPoint* preStepPoint = step->GetPreStepPoint();
320 const G4ThreeVector
position = preStepPoint->GetPosition();
321 G4double
time = preStepPoint->GetGlobalTime();
324 TLorentzVector fourPos(position.x() /
CLHEP::cm,
329 const G4ThreeVector
momentum = preStepPoint->GetMomentum();
330 const G4double
energy = preStepPoint->GetTotalEnergy();
331 TLorentzVector fourMom(momentum.x() /
CLHEP::GeV,
347 G4String
process = step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
348 G4bool ignoreProcess = process.contains(
"LArVoxel") || process.contains(
"OpDetReadout");
351 <<
": DEBUG - process='" << process <<
"'" 352 <<
" ignoreProcess=" << ignoreProcess <<
" fstoreTrajectories=" <<
fstoreTrajectories;
358 if (fstoreTrajectories && !ignoreProcess) {
360 const G4StepPoint* postStepPoint = step->GetPostStepPoint();
362 const G4ThreeVector
position = postStepPoint->GetPosition();
363 G4double
time = postStepPoint->GetGlobalTime();
366 TLorentzVector fourPos(position.x() /
CLHEP::cm,
371 const G4ThreeVector
momentum = postStepPoint->GetMomentum();
372 const G4double
energy = postStepPoint->GetTotalEnergy();
373 TLorentzVector fourMom(momentum.x() /
CLHEP::GeV,
387 :
public std::unary_function<sim::ParticleList::value_type, void> {
399 int particleID = particleListEntry.first;
404 int parentID = particleList->GetMotherOf(particleID);
407 if (parentID <= 0)
return;
415 if (parentEntry == particleList->end()) {
423 if (!parentEntry->second)
return;
432 sim::ParticleList* particleList;
458 const sim::ParticleList*
468 if ((*pn).first > highestID) highestID = (*pn).first;
492 <<
"ParticleListAction::YieldList(): particle list not build by user request.\n";
499 if ((*pn).first > highestID) highestID = (*pn).first;
510 TLorentzVector
const& mom,
static constexpr double cm
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
int GetParentage(int trackid) 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.
static int fCurrentPdgCode
pdg code of current particle
virtual void BeginOfEventAction(const G4Event *)
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.
constexpr pointer get() const noexcept
const sim::ParticleList * GetList() const
GeneratedParticleIndex_t truthInfoIndex() const
Returns the index of the particle in the generator truth record.
ParticleInfo_t fCurrentParticle
std::map< int, int > fParentIDMap
key is current track ID, value is parent ID
virtual void PreTrackingAction(const G4Track *)
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()
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
static constexpr double GeV
virtual void PostTrackingAction(const G4Track *)
static const int NoParticleId
ParticleListAction(double energyCut, bool storeTrajectories=false, bool keepEMShowerDaughters=false, bool keepMCParticleList=true)
GeneratedParticleIndex_t GetPrimaryTruthIndex(int trackId) const
Returns the index of primary truth (sim::NoGeneratorIndex if none).
Code to link reconstructed objects back to the MC truth information.
std::unique_ptr< util::PositionInVolumeFilter > fFilter
filter for particles to be kept
std::unique_ptr< sim::ParticleList > fparticleList
bool isPrimary() const
Returns whether there is a particle.
cet::exempt_ptr< simb::MCParticle > particle
Object representing particle.
virtual void EndOfEventAction(const G4Event *)
bool hasParticle() const
Returns whether there is a particle.
Tools and modules for checking out the basics of the Monte Carlo.
#define MF_LOG_WARNING(category)
def momentum(x1, x2, x3, scale=1.)
virtual void SteppingAction(const G4Step *)
def parent(G, child, parent_type)
std::map< int, GeneratedParticleIndex_t > const & GetPrimaryTruthMap() const
cet::coded_exception< error, detail::translate > exception
std::size_t GeneratedParticleIndex_t
Type of particle index in the generator truth record (simb::MCTruth).
static int fCurrentTrackID