10 #include "nug4/G4Base/PrimaryParticleInformation.h"
11 #include "nug4/ParticleNavigation/ParticleList.h"
13 #include "cetlib_except/exception.h"
14 #include "messagefacility/MessageLogger/MessageLogger.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>
53 return !p || p->Trajectory().empty();
61 bool keepMCParticleList,
62 bool storeDroppedMCParticles
64 : fenergyCut(energyCut * CLHEP::
GeV)
65 , fparticleList(keepMCParticleList ?
std::make_unique<sim::ParticleList>() : nullptr)
66 , fdroppedParticleList(storeDroppedMCParticles ?
std::make_unique<sim::ParticleList>() : nullptr)
67 , fstoreTrajectories(storeTrajectories)
99 std::map<int, int>::const_iterator itr = parentIDMap->find(trackid);
100 while (itr != parentIDMap->end()) {
101 MF_LOG_DEBUG(
"ParticleListAction") <<
"parentage for " << trackid <<
" " << (*itr).second;
105 parentid = (*itr).second;
106 itr = parentIDMap->find(parentid);
108 MF_LOG_DEBUG(
"ParticleListAction") <<
"final parent ID " << parentid;
119 G4ParticleDefinition* particleDefinition = track->GetDefinition();
120 G4int pdgCode = particleDefinition->GetPDGEncoding();
140 bool drop_shower_daughter =
false;
144 const G4DynamicParticle* dynamicParticle = track->GetDynamicParticle();
145 const G4PrimaryParticle* primaryParticle = dynamicParticle->GetPrimaryParticle();
146 simb::GeneratedParticleIndex_t primaryIndex = simb::NoGeneratedParticleIndex;
147 if (primaryParticle != 0) {
148 const G4VUserPrimaryParticleInformation* gppi = primaryParticle->GetUserInformation();
149 const g4b::PrimaryParticleInformation* ppi =
150 dynamic_cast<const g4b::PrimaryParticleInformation*
>(gppi);
152 primaryIndex = ppi->MCParticleIndex();
157 process_name =
"primary";
172 process_name = track->GetCreatorProcess()->GetProcessName();
174 process_name.find(
"LowEnConversion") != std::string::npos ||
175 process_name.find(
"Pair") != std::string::npos ||
176 process_name.find(
"compt") != std::string::npos ||
177 process_name.find(
"Compt") != std::string::npos ||
178 process_name.find(
"Brem") != std::string::npos ||
179 process_name.find(
"phot") != std::string::npos ||
180 process_name.find(
"Photo") != std::string::npos ||
181 process_name.find(
"Ion") != std::string::npos ||
182 process_name.find(
"annihil") != std::string::npos));
183 if (drop_shower_daughter) {
204 G4double energy = track->GetKineticEnergy();
234 <<
"can't find parent id: " << parentID <<
" in the particle list, or fParentIDMap."
235 <<
" Make " << parentID <<
" the mother ID for"
236 <<
" track ID " <<
fCurrentTrackID <<
" in the hope that it will aid debugging.";
250 new simb::MCParticle(trackID, pdgCode, process_name, parentID, mass);
257 const G4ThreeVector& polarization = track->GetPolarization();
259 TVector3(polarization.x(), polarization.y(), polarization.z()));
263 if (drop_shower_daughter) {
283 aTrack->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
323 globalTime = step->GetTrack()->GetGlobalTime();
325 velocity_step = step->GetStepLength() / step->GetDeltaTime();
326 if ((step->GetTrack()->GetDefinition()->GetPDGEncoding() == 0) &&
330 step->GetPostStepPoint()->SetGlobalTime(
globalTime - step->GetDeltaTime() +
342 const G4StepPoint* preStepPoint = step->GetPreStepPoint();
344 const G4ThreeVector position = preStepPoint->GetPosition();
345 G4double time = preStepPoint->GetGlobalTime();
348 TLorentzVector fourPos(position.x() / CLHEP::cm,
349 position.y() / CLHEP::cm,
350 position.z() / CLHEP::cm,
353 const G4ThreeVector momentum = preStepPoint->GetMomentum();
354 const G4double energy = preStepPoint->GetTotalEnergy();
355 TLorentzVector fourMom(momentum.x() /
CLHEP::GeV,
371 G4String process = step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
372 G4bool ignoreProcess = process.contains(
"LArVoxel") || process.contains(
"OpDetReadout");
374 MF_LOG_DEBUG(
"ParticleListAction::SteppingAction")
375 <<
": DEBUG - process='" << process <<
"'"
376 <<
" ignoreProcess=" << ignoreProcess <<
" fstoreTrajectories=" <<
fstoreTrajectories;
382 if (fstoreTrajectories && !ignoreProcess) {
388 const G4StepPoint* postStepPoint = step->GetPostStepPoint();
390 const G4ThreeVector position = postStepPoint->GetPosition();
391 G4double time = postStepPoint->GetGlobalTime();
394 TLorentzVector fourPos(position.x() / CLHEP::cm,
395 position.y() / CLHEP::cm,
396 position.z() / CLHEP::cm,
399 const G4ThreeVector momentum = postStepPoint->GetMomentum();
400 const G4double energy = postStepPoint->GetTotalEnergy();
401 TLorentzVector fourMom(momentum.x() /
CLHEP::GeV,
415 :
public std::unary_function<sim::ParticleList::value_type, void> {
427 int particleID = particleListEntry.first;
435 if (parentID <= 0)
return;
441 sim::ParticleList::iterator parentEntry =
particleList->find(parentID);
451 if (!parentEntry->second)
return;
455 simb::MCParticle* parent = (*parentEntry).second;
456 parent->AddDaughter(particleID);
486 const sim::ParticleList*
496 if ((*pn).first > highestID) highestID = (*pn).first;
502 if ((*pn).first > highestID) highestID = (*pn).first;
512 simb::GeneratedParticleIndex_t
526 throw cet::exception(
"ParticleListAction")
527 <<
"ParticleListAction::YieldList(): particle list not build by user request.\n";
534 if ((*pn).first > highestID) highestID = (*pn).first;
540 if ((*pn).first > highestID) highestID = (*pn).first;
555 throw cet::exception(
"ParticleListAction")
556 <<
"ParticleListAction::YieldDroppedList(): dropped particle list not build by user request.\n";
563 if ((*pn).first > highestID) highestID = (*pn).first;
568 if ((*pn).first > highestID) highestID = (*pn).first;
578 TLorentzVector
const& mom,
579 std::string
const& process)
util::quantities::gigaelectronvolt GeV
ParticleListAction(double energyCut, bool storeTrajectories=false, bool keepEMShowerDaughters=false, bool keepMCParticleList=true, bool storeDroppedMCParticles=false)
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
G4bool fstoreTrajectories
Whether to store particle trajectories with each particle.
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.
std::unique_ptr< sim::ParticleList > fdroppedParticleList
std::map< int, int > fParentIDMap_OrigTrackID
key is current track ID, value is parent ID – for real G4 track ID tracking only
GeneratedParticleIndex_t truthIndex
Index of the particle in the original generator truth record.
int GetParentage(int trackid, bool useOrigTrackIDMap=false) const
const sim::ParticleList * GetList() const
process_name use argoneut_mc_hitfinder track
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 *)
BEGIN_PROLOG note Geant4 assumes this is in MeV keepEMShowerDaughters
void clear()
Resets the information (does not release memory it does not own)
sim::ParticleList && YieldList()
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
A value measured in the specified unit.
MF_LOG_WARNING("SimWire")<< "SimWire is an example module that works for the "<< "MicroBooNE detector. Each experiment should implement "<< "its own version of this module to simulate electronics "<< "response."
auto end(FixedBins< T, C > const &) noexcept
sim::ParticleList && YieldDroppedList()
Yields the (dropped) ParticleList accumulated during the current event.
GeneratedParticleIndex_t GetPrimaryTruthIndex(int trackId) const
Returns the index of primary truth (sim::NoGeneratorIndex if none).
fKeepEMShowerDaughters(p.get< bool >("keepEMShowerDaughters", true))
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.
BEGIN_PROLOG note Geant4 assumes this is in MeV does not store electromagnetic shower daughter storeTrajectories
static int fCurrentOrigTrackID
except for EM shower particles where it always shows the original track ID
virtual void EndOfEventAction(const G4Event *)
bool hasParticle() const
Returns whether there is a particle.
virtual void SteppingAction(const G4Step *)
Tools and modules for checking out the basics of the Monte Carlo.
std::map< int, GeneratedParticleIndex_t > const & GetPrimaryTruthMap() const
bool keep
if there was decision to keep
static int fCurrentTrackID
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG process_name