7 #include "nug4/G4Base/PrimaryParticleInformation.h" 16 #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 <TGeoManager.h> 29 #include <TGeoMaterial.h> 31 #include <TLorentzVector.h> 56 bool storeTrajectories,
57 bool keepEMShowerDaughters,
102 <<
"parentage for " << trackid
103 <<
" " << (*itr).second;
107 parentid = (*itr).second;
110 MF_LOG_DEBUG(
"ParticleListAction") <<
"final parent ID " << parentid;
120 G4ParticleDefinition* particleDefinition = track->GetDefinition();
121 G4int pdgCode = particleDefinition->GetPDGEncoding();
124 TGeoManager *geomanager = geo->ROOTGeoManager();
130 size_t mcTruthIndex = 0;
139 const G4DynamicParticle* dynamicParticle = track->GetDynamicParticle();
140 const G4PrimaryParticle* primaryParticle = dynamicParticle->GetPrimaryParticle();
141 if ( primaryParticle ){
142 const G4VUserPrimaryParticleInformation* gppi = primaryParticle->GetUserInformation();
143 const g4b::PrimaryParticleInformation* ppi =
dynamic_cast<const g4b::PrimaryParticleInformation*
>(gppi);
148 process_name =
"primary";
154 mcTruthIndex = ppi->MCTruthIndex();
169 process_name = track->GetCreatorProcess()->GetProcessName();
170 bool is_em_shower_daughter = ( 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(
"hIoni") != std::string::npos ||
179 process_name.find(
"eIoni") != std::string::npos ||
180 process_name.find(
"ionIoni") != std::string::npos ||
181 (process_name.find(
"Ion") != std::string::npos &&
182 process_name.find(
"mu") != std::string::npos) ||
183 process_name.find(
"annihil") != std::string::npos );
184 const G4ThreeVector& trackpos = track->GetPosition();
186 auto geonode = geomanager->FindNode(trackpos[0]/
CLHEP::cm,
191 matname = geonode->GetMedium()->GetMaterial()->GetName();
196 if( is_em_shower_daughter &&
198 ! std::regex_match(matname, re_material)))
226 G4double
energy = track->GetKineticEnergy();
258 <<
"can't find parent id: " 260 <<
" in the particle list, or fParentIDMap." 263 <<
" the mother ID for" 266 <<
" in the hope that it will aid debugging.";
282 <<
"Cannot find MCTruth index for track id " 304 const G4ThreeVector& polarization = track->GetPolarization();
315 <<
" particles in the list";
319 <<
"attempting to put " 321 <<
" into fTrackIDToMCTruthIndex map " 339 <<
"dropping particle with track id " 350 if (aTrack->GetStep()->GetPostStepPoint()->GetProcessDefinedStep())
352 G4String
process = aTrack->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
375 const G4StepPoint* preStepPoint = step->GetPreStepPoint();
377 const G4ThreeVector
position = preStepPoint->GetPosition();
378 G4double
time = preStepPoint->GetGlobalTime();
381 TLorentzVector fourPos(position.x() /
CLHEP::cm,
386 const G4ThreeVector
momentum = preStepPoint->GetMomentum();
387 const G4double
energy = preStepPoint->GetTotalEnergy();
398 if (step->GetPostStepPoint()->GetProcessDefinedStep())
400 G4String
process = step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
408 const G4StepPoint* postStepPoint = step->GetPostStepPoint();
410 const G4ThreeVector
position = postStepPoint->GetPosition();
411 G4double
time = postStepPoint->GetGlobalTime();
414 TLorentzVector fourPos(position.x() /
CLHEP::cm,
419 const G4ThreeVector
momentum = postStepPoint->GetMomentum();
420 const G4double
energy = postStepPoint->GetTotalEnergy();
437 :
public std::unary_function<sim::ParticleList::value_type, void>
444 void operator()( sim::ParticleList::value_type& particleListEntry )
447 int particleID = particleListEntry.first;
452 int parentID = particleList->GetMotherOf(particleID);
455 if ( parentID <= 0 )
return;
463 if ( parentEntry == particleList->end() ){
471 if ( !parentEntry->second )
return;
499 updateDaughterInformation);
511 if( (*pn).first > highestID ) highestID = (*pn).first;
527 if( (*pn).first > highestID ) highestID = (*pn).first;
542 TLorentzVector
const& mom,
static constexpr double cm
virtual void EndOfEventAction(const G4Event *)
unsigned int NumberTrajectoryPoints() const
int GetParentage(int trackid) const
void AddDaughter(const int trackID)
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
const simb::MCTrajectory & Trajectory() const
std::map< int, int > fParentIDMap
key is current track ID, value is parent ID
std::unique_ptr< PositionInVolumeFilter > fFilter
filter for particles to be kept
std::map< int, size_t > TrackIDToMCTruthIndexMap() const
static constexpr double MeV
ParticleInfo_t fCurrentParticle
virtual void BeginOfEventAction(const G4Event *)
static const int NoParticleId
sim::ParticleList && YieldList()
std::string fEMShowerDaughterMatRegex
if keeping EM shower daughters, save only in media matching this
G4bool fstoreTrajectories
Whether to store particle trajectories with each particle.
virtual void SteppingAction(const G4Step *)
void SetPolarization(const TVector3 &p)
virtual void PreTrackingAction(const G4Track *)
static constexpr double GeV
std::map< int, size_t > fTrackIDToMCTruthIndex
map track ID to index of MCTruth in input list
virtual ~ParticleListAction()
void clear()
Resets the information (does not release memory it does not own)
Code to link reconstructed objects back to the MC truth information.
void SetWeight(double wt)
void SetEndProcess(std::string s)
static int fTrackIDOffset
void AddPointToCurrentParticle(TLorentzVector const &pos, TLorentzVector const &mom, std::string const &process)
Adds a trajectory point to the current particle, and runs the filter.
virtual void PostTrackingAction(const G4Track *)
General GArSoft Utilities.
sim::ParticleList * fParticleList
#define MF_LOG_VERBATIM(category)
bool keep
if there was decision to keep
sim::ParticleList * GetList() const
bool fKeepEMShowerDaughters
whether to keep EM shower secondaries, tertiaries, etc
simb::MCParticle * particle
simple structure representing particle
ParticleListAction(double energyCut, bool storeTrajectories=false, bool keepEMShowerDaughters=false, std::string EMShowerDaughterMatRegex=".*")
#define MF_LOG_WARNING(category)
def momentum(x1, x2, x3, scale=1.)
static int fCurrentTrackID
LArSoft geometry interface.
art framework interface to geometry description
static bool IsDropped(simb::MCParticle const *p)
returns whether the specified particle has been marked as dropped
def parent(G, child, parent_type)
cet::coded_exception< error, detail::translate > exception
bool hasParticle() const
Returns whether there is a particle.