LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
larg4::ParticleListAction Class Reference

#include "ParticleListAction.h"

Inheritance diagram for larg4::ParticleListAction:
g4b::UserAction

Classes

struct  ParticleInfo_t
 

Public Types

using GeneratedParticleIndex_t = simb::GeneratedParticleIndex_t
 

Public Member Functions

 ParticleListAction (double energyCut, bool storeTrajectories=false, bool keepEMShowerDaughters=false, bool keepMCParticleList=true, bool storeDroppedMCParticles=false)
 
virtual void BeginOfEventAction (const G4Event *)
 G4UserEventAction interfaces. More...
 
virtual void EndOfEventAction (const G4Event *)
 
virtual void PreTrackingAction (const G4Track *)
 G4UserTrackingAction interfaces. More...
 
virtual void PostTrackingAction (const G4Track *)
 
virtual void SteppingAction (const G4Step *)
 G4UserSteppingAction interface. More...
 
void ParticleFilter (std::unique_ptr< util::PositionInVolumeFilter > &&filter)
 Grabs a particle filter. More...
 
void ResetTrackIDOffset ()
 
const sim::ParticleListGetList () const
 
std::map< int, GeneratedParticleIndex_t > const & GetPrimaryTruthMap () const
 
bool hasList () const
 Returns whether a particle list is being kept. More...
 
GeneratedParticleIndex_t GetPrimaryTruthIndex (int trackId) const
 Returns the index of primary truth (sim::NoGeneratorIndex if none). More...
 
sim::ParticleList && YieldList ()
 
sim::ParticleList && YieldDroppedList ()
 Yields the (dropped) ParticleList accumulated during the current event. More...
 
virtual void Config (fhicl::ParameterSet const &)
 Override Config() to extract any necessary parameters. More...
 
virtual void PrintConfig (std::string const &)
 Override PrintConfig() to print out current configuration. More...
 
virtual void BeginOfRunAction (const G4Run *)
 G4UserRunAction interfaces. More...
 
virtual void EndOfRunAction (const G4Run *)
 
virtual bool ProvidesStacking ()
 
virtual G4ClassificationOfNewTrack StackClassifyNewTrack (const G4Track *)
 G4UserStackingAction interfaces. More...
 
virtual void StackNewStage ()
 
virtual void StackPrepareNewEvent ()
 
std::string const & GetName () const
 
void SetName (std::string const &name)
 

Static Public Member Functions

static int GetCurrentTrackID ()
 
static int GetCurrentOrigTrackID ()
 
static int GetCurrentPdgCode ()
 
static bool isDropped (simb::MCParticle const *p)
 returns whether the specified particle has been marked as dropped More...
 

Private Member Functions

int GetParentage (int trackid, bool useOrigTrackIDMap=false) const
 
void AddPointToCurrentParticle (TLorentzVector const &pos, TLorentzVector const &mom, std::string const &process)
 Adds a trajectory point to the current particle, and runs the filter. More...
 

Private Attributes

G4double fenergyCut
 
ParticleInfo_t fCurrentParticle
 
std::unique_ptr< sim::ParticleListfparticleList
 
std::unique_ptr< sim::ParticleListfdroppedParticleList
 
G4bool fstoreTrajectories
 Whether to store particle trajectories with each particle. More...
 
std::map< int, int > fParentIDMap
 key is current track ID, value is parent ID More...
 
std::map< int, int > fParentIDMap_OrigTrackID
 key is current track ID, value is parent ID – for real G4 track ID tracking only More...
 
bool fKeepEMShowerDaughters
 whether to keep EM shower secondaries, tertiaries, etc More...
 
std::unique_ptr< util::PositionInVolumeFilterfFilter
 filter for particles to be kept More...
 
std::map< int, GeneratedParticleIndex_tfPrimaryTruthMap
 Map: particle track ID -> index of primary information in MC truth. More...
 

Static Private Attributes

static int fCurrentTrackID = sim::NoParticleId
 
static int fCurrentOrigTrackID = sim::NoParticleId
 except for EM shower particles where it always shows the original track ID More...
 
static int fCurrentPdgCode = 0
 pdg code of current particle More...
 
static int fTrackIDOffset = 0
 

Detailed Description

Definition at line 45 of file ParticleListAction.h.

Member Typedef Documentation

Constructor & Destructor Documentation

larg4::ParticleListAction::ParticleListAction ( double  energyCut,
bool  storeTrajectories = false,
bool  keepEMShowerDaughters = false,
bool  keepMCParticleList = true,
bool  storeDroppedMCParticles = false 
)

Definition at line 57 of file ParticleListAction.cxx.

62  : fenergyCut(energyCut * CLHEP::GeV)
63  , fparticleList(keepMCParticleList ? std::make_unique<sim::ParticleList>() : nullptr)
64  , fdroppedParticleList(storeDroppedMCParticles ? std::make_unique<sim::ParticleList>() :
65  nullptr)
66  , fstoreTrajectories(storeTrajectories)
67  , fKeepEMShowerDaughters(keepEMShowerDaughters)
68  {}
G4bool fstoreTrajectories
Whether to store particle trajectories with each particle.
std::unique_ptr< sim::ParticleList > fdroppedParticleList
bool fKeepEMShowerDaughters
whether to keep EM shower secondaries, tertiaries, etc
std::unique_ptr< sim::ParticleList > fparticleList

Member Function Documentation

void larg4::ParticleListAction::AddPointToCurrentParticle ( TLorentzVector const &  pos,
TLorentzVector const &  mom,
std::string const &  process 
)
private

Adds a trajectory point to the current particle, and runs the filter.

Definition at line 567 of file ParticleListAction.cxx.

References fCurrentParticle, fFilter, larg4::ParticleListAction::ParticleInfo_t::keep, and larg4::ParticleListAction::ParticleInfo_t::particle.

Referenced by SteppingAction().

570  {
571 
572  // Add the first point in the trajectory.
573  fCurrentParticle.particle->AddTrajectoryPoint(pos, mom, process);
574 
575  // also see if we can decide to keep the particle
576  if (!fCurrentParticle.keep) fCurrentParticle.keep = fFilter->mustKeep(pos);
577 
578  } // ParticleListAction::AddPointToCurrentParticle()
std::unique_ptr< util::PositionInVolumeFilter > fFilter
filter for particles to be kept
cet::exempt_ptr< simb::MCParticle > particle
Object representing particle.
bool keep
if there was decision to keep
void larg4::ParticleListAction::BeginOfEventAction ( const G4Event *  )
virtual

G4UserEventAction interfaces.

Reimplemented from g4b::UserAction.

Definition at line 72 of file ParticleListAction.cxx.

References larg4::ParticleListAction::ParticleInfo_t::clear(), fCurrentOrigTrackID, fCurrentParticle, fCurrentPdgCode, fCurrentTrackID, fdroppedParticleList, fParentIDMap, fParentIDMap_OrigTrackID, fparticleList, and sim::NoParticleId.

73  {
74  // Clear any previous particle information.
76  if (fparticleList) fparticleList->clear();
78  fParentIDMap.clear();
82  fCurrentPdgCode = 0;
83  }
static int fCurrentPdgCode
pdg code of current particle
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 ...
std::map< int, int > fParentIDMap
key is current track ID, value is parent ID
void clear()
Resets the information (does not release memory it does not own)
static const int NoParticleId
Definition: sim.h:21
std::unique_ptr< sim::ParticleList > fparticleList
static int fCurrentOrigTrackID
except for EM shower particles where it always shows the original track ID
virtual void g4b::UserAction::BeginOfRunAction ( const G4Run *  )
inlinevirtualinherited

G4UserRunAction interfaces.

The following a list of methods that correspond to the available user action classes in Geant 4.0.1 and higher.

Reimplemented in larg4::VisualizationAction.

Definition at line 74 of file UserAction.h.

74 {};
virtual void g4b::UserAction::Config ( fhicl::ParameterSet const &  )
inlinevirtualinherited

Override Config() to extract any necessary parameters.

Reimplemented in altns::ExampleAction.

Definition at line 65 of file UserAction.h.

Referenced by g4b::UserAction::UserAction().

65 {};
void larg4::ParticleListAction::EndOfEventAction ( const G4Event *  )
virtual

Reimplemented from g4b::UserAction.

Definition at line 462 of file ParticleListAction.cxx.

References fparticleList, and larg4::UpdateDaughterInformation::SetParticleList().

463  {
464  if (!fparticleList) return;
465 
466  // Set up the utility class for the "for_each" algorithm. (We only
467  // need a separate set-up for the utility class because we need to
468  // give it the pointer to the particle list. We're using the STL
469  // "for_each" instead of the C++ "for loop" because it's supposed
470  // to be faster.
471  UpdateDaughterInformation updateDaughterInformation;
472  updateDaughterInformation.SetParticleList(fparticleList.get());
473 
474  // Update the daughter information for each particle in the list.
475  std::for_each(fparticleList->begin(), fparticleList->end(), updateDaughterInformation);
476  }
std::unique_ptr< sim::ParticleList > fparticleList
virtual void g4b::UserAction::EndOfRunAction ( const G4Run *  )
inlinevirtualinherited

Reimplemented in larg4::VisualizationAction.

Definition at line 75 of file UserAction.h.

75 {};
static int larg4::ParticleListAction::GetCurrentOrigTrackID ( )
inlinestatic

Definition at line 104 of file ParticleListAction.h.

Referenced by larg4::LArVoxelReadout::ProcessHits(), and larg4::OpFastScintillation::ProcessStep().

104 { return fCurrentOrigTrackID; }
static int fCurrentOrigTrackID
except for EM shower particles where it always shows the original track ID
static int larg4::ParticleListAction::GetCurrentPdgCode ( )
inlinestatic

Definition at line 105 of file ParticleListAction.h.

105 { return fCurrentPdgCode; }
static int fCurrentPdgCode
pdg code of current particle
static int larg4::ParticleListAction::GetCurrentTrackID ( )
inlinestatic
const sim::ParticleList * larg4::ParticleListAction::GetList ( ) const

Definition at line 480 of file ParticleListAction.cxx.

References fdroppedParticleList, fparticleList, and fTrackIDOffset.

481  {
482  if (!fparticleList) return nullptr;
483 
484  // check if the ParticleNavigator has entries, and if
485  // so grab the highest track id value from it to
486  // add to the fTrackIDOffset
487  int highestID = 0;
488  for (auto pn = fparticleList->begin(); pn != fparticleList->end(); pn++)
489  if ((*pn).first > highestID) highestID = (*pn).first;
490 
491  // If we have stored dropped particles,
492  // include them in the offset.
493  if (fdroppedParticleList) {
494  for (auto pn = fdroppedParticleList->begin(); pn != fdroppedParticleList->end(); pn++)
495  if ((*pn).first > highestID) highestID = (*pn).first;
496  }
497 
498  //Only change the fTrackIDOffset if there is in fact a particle to add to the event
499  if ((fparticleList->size()) != 0) { fTrackIDOffset = highestID + 1; }
500 
501  return fparticleList.get();
502  }
std::unique_ptr< sim::ParticleList > fdroppedParticleList
std::unique_ptr< sim::ParticleList > fparticleList
std::string const& g4b::UserAction::GetName ( ) const
inlineinherited

Definition at line 98 of file UserAction.h.

References g4b::UserAction::myName.

Referenced by g4b::UserActionManager::PrintActionList().

98 { return myName; }
std::string myName
self-knowledge
Definition: UserAction.h:101
int larg4::ParticleListAction::GetParentage ( int  trackid,
bool  useOrigTrackIDMap = false 
) const
private

Definition at line 90 of file ParticleListAction.cxx.

References fParentIDMap, fParentIDMap_OrigTrackID, MF_LOG_DEBUG, and sim::NoParticleId.

Referenced by PreTrackingAction().

91  {
92  int parentid = sim::NoParticleId;
93  const std::map<int, int>* parentIDMap =
94  useOrigTrackIDMap ? &fParentIDMap_OrigTrackID : &fParentIDMap;
95 
96  // search the fParentIDMap recursively until we have the parent id
97  // of the first EM particle that led to this one
98  std::map<int, int>::const_iterator itr = parentIDMap->find(trackid);
99  while (itr != parentIDMap->end()) {
100  MF_LOG_DEBUG("ParticleListAction") << "parentage for " << trackid << " " << (*itr).second;
101 
102  // set the parentid to the current parent ID, when the loop ends
103  // this id will be the first EM particle
104  parentid = (*itr).second;
105  itr = parentIDMap->find(parentid);
106  }
107  MF_LOG_DEBUG("ParticleListAction") << "final parent ID " << parentid;
108 
109  return parentid;
110  }
std::map< int, int > fParentIDMap_OrigTrackID
key is current track ID, value is parent ID – for real G4 track ID tracking only ...
intermediate_table::const_iterator const_iterator
std::map< int, int > fParentIDMap
key is current track ID, value is parent ID
static const int NoParticleId
Definition: sim.h:21
#define MF_LOG_DEBUG(id)
simb::GeneratedParticleIndex_t larg4::ParticleListAction::GetPrimaryTruthIndex ( int  trackId) const

Returns the index of primary truth (sim::NoGeneratorIndex if none).

Definition at line 505 of file ParticleListAction.cxx.

References util::end(), GetPrimaryTruthMap(), and simb::NoGeneratedParticleIndex.

Referenced by larg4::LArG4::produce().

506  {
507  auto const iInfo = GetPrimaryTruthMap().find(trackId);
508  return (iInfo == GetPrimaryTruthMap().end()) ? simb::NoGeneratedParticleIndex : iInfo->second;
509  } // ParticleListAction::GetPrimaryTruthIndex()
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
constexpr GeneratedParticleIndex_t NoGeneratedParticleIndex
Constant representing the absence of generator truth information.
Definition: simb.h:34
std::map< int, GeneratedParticleIndex_t > const & GetPrimaryTruthMap() const
std::map<int, GeneratedParticleIndex_t> const& larg4::ParticleListAction::GetPrimaryTruthMap ( ) const
inline

Returns a map of truth record information index for each of the primary particles (by track ID).

Definition at line 114 of file ParticleListAction.h.

Referenced by GetPrimaryTruthIndex().

115  {
116  return fPrimaryTruthMap;
117  }
std::map< int, GeneratedParticleIndex_t > fPrimaryTruthMap
Map: particle track ID -> index of primary information in MC truth.
bool larg4::ParticleListAction::hasList ( ) const
inline

Returns whether a particle list is being kept.

Definition at line 120 of file ParticleListAction.h.

120 { return static_cast<bool>(fparticleList); }
std::unique_ptr< sim::ParticleList > fparticleList
bool larg4::ParticleListAction::isDropped ( simb::MCParticle const *  p)
static

returns whether the specified particle has been marked as dropped

Definition at line 50 of file ParticleListAction.cxx.

References simb::MCTrajectory::empty(), and simb::MCParticle::Trajectory().

Referenced by larg4::LArG4::produce().

51  {
52  return !p || p->Trajectory().empty();
53  } // ParticleListAction::isDropped()
void larg4::ParticleListAction::ParticleFilter ( std::unique_ptr< util::PositionInVolumeFilter > &&  filter)
inline

Grabs a particle filter.

Definition at line 97 of file ParticleListAction.h.

Referenced by larg4::LArG4::beginRun().

98  {
99  fFilter = std::move(filter);
100  }
std::unique_ptr< util::PositionInVolumeFilter > fFilter
filter for particles to be kept
void larg4::ParticleListAction::PostTrackingAction ( const G4Track *  aTrack)
virtual

Reimplemented from g4b::UserAction.

Definition at line 276 of file ParticleListAction.cxx.

References larg4::ParticleListAction::ParticleInfo_t::clear(), larg4::ParticleListAction::ParticleInfo_t::drop, fCurrentParticle, fdroppedParticleList, fparticleList, fPrimaryTruthMap, larg4::ParticleListAction::ParticleInfo_t::hasParticle(), larg4::ParticleListAction::ParticleInfo_t::isPrimary(), larg4::ParticleListAction::ParticleInfo_t::keep, larg4::ParticleListAction::ParticleInfo_t::particle, and larg4::ParticleListAction::ParticleInfo_t::truthInfoIndex().

277  {
278  if (!fCurrentParticle.hasParticle()) return;
279  assert(fparticleList);
280 
281  if (aTrack) {
282  fCurrentParticle.particle->SetWeight(aTrack->GetWeight());
283  G4String process =
284  aTrack->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
285  fCurrentParticle.particle->SetEndProcess(process);
286  }
287 
288  // We would keep it if it wasn't for KeepEMShowerDaughters = false
289  // It goes into fDroppedParticleList in case LArG4 is configured
290  // to keep a minimal version of it.
291  if (fCurrentParticle.drop) {
295  return;
296  }
297 
298  // if we have found no reason to keep it, drop it!
299  // (we might still need parentage information though)
300  if (!fCurrentParticle.keep) {
301  fparticleList->Archive(fCurrentParticle.particle.get());
302  // after the particle is archived, it is deleted
304  return;
305  }
306 
307  // store truth record pointer, only if it is available
308  if (fCurrentParticle.isPrimary()) {
310  }
311 
312  return;
313  }
std::map< int, GeneratedParticleIndex_t > fPrimaryTruthMap
Map: particle track ID -> index of primary information in MC truth.
std::unique_ptr< sim::ParticleList > fdroppedParticleList
GeneratedParticleIndex_t truthInfoIndex() const
Returns the index of the particle in the generator truth record.
void clear()
Resets the information (does not release memory it does not own)
std::unique_ptr< sim::ParticleList > fparticleList
bool isPrimary() const
Returns whether there is a particle.
cet::exempt_ptr< simb::MCParticle > particle
Object representing particle.
bool hasParticle() const
Returns whether there is a particle.
bool keep
if there was decision to keep
void larg4::ParticleListAction::PreTrackingAction ( const G4Track *  )
virtual

G4UserTrackingAction interfaces.

Reimplemented from g4b::UserAction.

Definition at line 114 of file ParticleListAction.cxx.

References larg4::ParticleListAction::ParticleInfo_t::clear(), larg4::ParticleListAction::ParticleInfo_t::drop, energy, fCurrentOrigTrackID, fCurrentParticle, fCurrentPdgCode, fCurrentTrackID, fdroppedParticleList, fenergyCut, fFilter, fKeepEMShowerDaughters, fParentIDMap, fParentIDMap_OrigTrackID, fparticleList, fTrackIDOffset, GetParentage(), larg4::ParticleListAction::ParticleInfo_t::keep, g4b::PrimaryParticleInformation::MCParticleIndex(), MF_LOG_WARNING, simb::NoGeneratedParticleIndex, sim::NoParticleId, larg4::ParticleListAction::ParticleInfo_t::particle, and larg4::ParticleListAction::ParticleInfo_t::truthIndex.

115  {
116  // Particle type.
117  G4ParticleDefinition* particleDefinition = track->GetDefinition();
118  G4int pdgCode = particleDefinition->GetPDGEncoding();
119 
120  // Get Geant4's ID number for this track. This will be the same
121  // ID number that we'll use in the ParticleList.
122  // It is offset by the number of tracks accumulated from the previous Geant4
123  // runs (if any)
124  G4int trackID = track->GetTrackID() + fTrackIDOffset;
125  fCurrentTrackID = trackID;
126  fCurrentOrigTrackID = trackID;
127  fCurrentPdgCode = pdgCode;
128 
129  if (!fparticleList) {
130  // the rest is about adding a new particle to the list: skip
131  return; // note that fCurrentParticle is clear()'ed
132  }
133 
134  // And the particle's parent (same offset as above):
135  G4int parentID = track->GetParentID() + fTrackIDOffset;
136 
137  std::string process_name = "unknown";
138  bool drop_shower_daughter = false;
139 
140  // Is there an MCTruth object associated with this G4Track? We
141  // have to go up a "chain" of information to find out:
142  const G4DynamicParticle* dynamicParticle = track->GetDynamicParticle();
143  const G4PrimaryParticle* primaryParticle = dynamicParticle->GetPrimaryParticle();
145  if (primaryParticle != 0) {
146  const G4VUserPrimaryParticleInformation* gppi = primaryParticle->GetUserInformation();
148  dynamic_cast<const g4b::PrimaryParticleInformation*>(gppi);
149  if (ppi != 0) {
150  primaryIndex = ppi->MCParticleIndex();
151 
152  // If we've made it this far, a PrimaryParticleInformation
153  // object exists and we are using a primary particle, set the
154  // process name accordingly
155  process_name = "primary";
156 
157  // primary particles should have parentID = 0, even if there
158  // are multiple MCTruths for this event
159  parentID = 0;
160  } // end else no primary particle information
161  } // Is there a G4PrimaryParticle?
162  // If this is not a primary particle...
163  else {
164  // check if this particle was made in an EM shower, don't put it in the particle
165  // list as we don't care about secondaries, tertiaries, etc for these showers
166  // figure out what process is making this track - skip it if it is
167  // one of pair production, compton scattering, photoelectric effect
168  // bremstrahlung, annihilation, any ionization - who wants to save
169  // a buttload of electrons that arent from a CC interaction?
170  process_name = track->GetCreatorProcess()->GetProcessName();
171  drop_shower_daughter =
172  (!fKeepEMShowerDaughters && (process_name.find("conv") != std::string::npos ||
173  process_name.find("LowEnConversion") != std::string::npos ||
174  process_name.find("Pair") != std::string::npos ||
175  process_name.find("compt") != std::string::npos ||
176  process_name.find("Compt") != std::string::npos ||
177  process_name.find("Brem") != std::string::npos ||
178  process_name.find("phot") != std::string::npos ||
179  process_name.find("Photo") != std::string::npos ||
180  process_name.find("Ion") != std::string::npos ||
181  process_name.find("annihil") != std::string::npos));
182  if (drop_shower_daughter) {
183 
184  // figure out the ultimate parentage of this particle
185  // first add this track id and its parent to the fParentIDMap
186  fParentIDMap[trackID] = parentID;
187 
188  fCurrentTrackID = -1 * this->GetParentage(
189  trackID); // the real trackID remains stored in fCurrentOrigTrackID
190 
191  // check that fCurrentTrackID is in the particle list - it is possible
192  // that this particle's parent is a particle that did not get tracked.
193  // An example is a partent that was made due to muMinusCaptureAtRest
194  // and the daughter was made by the phot process. The parent likely
195  // isn't saved in the particle list because it is below the energy cut
196  // which will put a bogus track id value into the sim::IDE object for
197  // the sim::SimChannel if we don't check it.
199 
200  } // end if keeping EM shower daughters
201 
202  // Check the energy of the particle. If it falls below the energy
203  // cut, don't add it to our list.
204  G4double energy = track->GetKineticEnergy();
205  if (energy < fenergyCut) {
207 
208  // do add the particle to the parent id map though
209  // and set the current track id to be it's ultimate parent
210  fParentIDMap[trackID] = parentID;
211  fParentIDMap_OrigTrackID[trackID] = parentID;
212 
213  fCurrentTrackID = -1 * this->GetParentage(trackID);
214  fCurrentOrigTrackID = -1 * this->GetParentage(trackID, true);
215 
216  return;
217  }
218 
219  // check to see if the parent particle has been stored in the particle navigator
220  // if not, then see if it is possible to walk up the fParentIDMap to find the
221  // ultimate parent of this particle. Use that ID as the parent ID for this
222  // particle
223  if (!fparticleList->KnownParticle(parentID) &&
224  !(fdroppedParticleList && fdroppedParticleList->KnownParticle(parentID))) {
225  // do add the particle to the parent id map
226  // just in case it makes a daughter that we have to track as well
227  fParentIDMap[trackID] = parentID;
228  fParentIDMap_OrigTrackID[trackID] = parentID;
229  int pid = this->GetParentage(parentID);
230 
231  // if we still can't find the parent in the particle navigator,
232  // we have to give up
233  if (!fparticleList->KnownParticle(pid) &&
234  !(fdroppedParticleList && fdroppedParticleList->KnownParticle(parentID))) {
235  MF_LOG_WARNING("ParticleListAction")
236  << "can't find parent id: " << parentID << " in the particle list, or fParentIDMap."
237  << " Make " << parentID << " the mother ID for"
238  << " track ID " << fCurrentTrackID << " in the hope that it will aid debugging.";
239  }
240  else
241  parentID = pid;
242  }
243 
244  } // end if not a primary particle
245 
246  // This is probably the PDG mass, but just in case:
247  double mass = dynamicParticle->GetMass() / CLHEP::GeV;
248 
249  // Create the sim::Particle object.
252  new simb::MCParticle(trackID, pdgCode, process_name, parentID, mass);
253  fCurrentParticle.truthIndex = primaryIndex;
254 
255  // if we are not filtering, we have a decision already
256  if (!fFilter) fCurrentParticle.keep = true;
257 
258  // Polarization.
259  const G4ThreeVector& polarization = track->GetPolarization();
260  fCurrentParticle.particle->SetPolarization(
261  TVector3(polarization.x(), polarization.y(), polarization.z()));
262 
263  // if KeepEMShowerDaughters = False and we decided to drop this particle,
264  // record it before throwing it away.
265  if (drop_shower_daughter) {
266  fCurrentParticle.drop = true;
268  return;
269  }
270 
271  // Save the particle in the ParticleList.
273  }
static int fCurrentPdgCode
pdg code of current particle
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
std::map< int, int > fParentIDMap
key is current track ID, value is parent ID
constexpr GeneratedParticleIndex_t NoGeneratedParticleIndex
Constant representing the absence of generator truth information.
Definition: simb.h:34
void clear()
Resets the information (does not release memory it does not own)
bool fKeepEMShowerDaughters
whether to keep EM shower secondaries, tertiaries, etc
static const int NoParticleId
Definition: sim.h:21
double energy
Definition: plottest35.C:25
std::unique_ptr< util::PositionInVolumeFilter > fFilter
filter for particles to be kept
std::unique_ptr< sim::ParticleList > fparticleList
cet::exempt_ptr< simb::MCParticle > particle
Object representing particle.
static int fCurrentOrigTrackID
except for EM shower particles where it always shows the original track ID
#define MF_LOG_WARNING(category)
Float_t track
Definition: plot.C:35
GeneratedParticleIndex_t MCParticleIndex() const
Returns the index of the corresponding particle in truth record.
std::size_t GeneratedParticleIndex_t
Type of particle index in the generator truth record (simb::MCTruth).
Definition: simb.h:30
bool keep
if there was decision to keep
virtual void g4b::UserAction::PrintConfig ( std::string const &  )
inlinevirtualinherited

Override PrintConfig() to print out current configuration.

Reimplemented in altns::ExampleAction.

Definition at line 68 of file UserAction.h.

Referenced by g4b::UserActionManager::PrintActionList().

68 {};
virtual bool g4b::UserAction::ProvidesStacking ( )
inlinevirtualinherited

Does this UserAction do stacking? Override to return "true" if the following interfaces are implemented

Reimplemented in altns::ExampleAction.

Definition at line 90 of file UserAction.h.

Referenced by g4b::UserActionManager::PrintActionList().

90 { return false; }
void larg4::ParticleListAction::ResetTrackIDOffset ( )
inline

Definition at line 107 of file ParticleListAction.h.

Referenced by larg4::LArG4::produce().

107 { fTrackIDOffset = 0; }
void g4b::UserAction::SetName ( std::string const &  name)
inlineinherited

Definition at line 99 of file UserAction.h.

References g4b::UserAction::myName.

Referenced by g4b::UserActionFactory::GetUserAction().

99 { myName = name; }
std::string myName
self-knowledge
Definition: UserAction.h:101
virtual G4ClassificationOfNewTrack g4b::UserAction::StackClassifyNewTrack ( const G4Track *  )
inlinevirtualinherited

G4UserStackingAction interfaces.

Reimplemented in altns::ExampleAction.

Definition at line 93 of file UserAction.h.

93 { return fUrgent; }
virtual void g4b::UserAction::StackNewStage ( )
inlinevirtualinherited

Reimplemented in altns::ExampleAction.

Definition at line 94 of file UserAction.h.

94 {};
virtual void g4b::UserAction::StackPrepareNewEvent ( )
inlinevirtualinherited

Reimplemented in altns::ExampleAction.

Definition at line 95 of file UserAction.h.

95 {};
void larg4::ParticleListAction::SteppingAction ( const G4Step *  )
virtual

G4UserSteppingAction interface.

Reimplemented from g4b::UserAction.

Definition at line 317 of file ParticleListAction.cxx.

References AddPointToCurrentParticle(), energy, fCurrentParticle, fstoreTrajectories, globalTime, larg4::ParticleListAction::ParticleInfo_t::hasParticle(), MF_LOG_DEBUG, larg4::ParticleListAction::ParticleInfo_t::particle, velocity_G4, and velocity_step.

318  {
319 
320  if (!fCurrentParticle.hasParticle()) { return; }
321 
322  // Temporary fix for problem where DeltaTime on the first step
323  // of optical photon propagation is calculated incorrectly. -wforeman
324  globalTime = step->GetTrack()->GetGlobalTime();
325  velocity_G4 = step->GetTrack()->GetVelocity();
326  velocity_step = step->GetStepLength() / step->GetDeltaTime();
327  if ((step->GetTrack()->GetDefinition()->GetPDGEncoding() == 0) &&
328  fabs(velocity_G4 - velocity_step) > 0.0001) {
329  // Subtract the faulty step time from the global time,
330  // and add the correct step time based on G4 velocity.
331  step->GetPostStepPoint()->SetGlobalTime(globalTime - step->GetDeltaTime() +
332  step->GetStepLength() / velocity_G4);
333  }
334 
335  // For the most part, we just want to add the post-step
336  // information to the particle's trajectory. There's one
337  // exception: In PreTrackingAction, the correct time information
338  // is not available. So add the correct vertex information here.
339 
340  if (fCurrentParticle.particle->NumberTrajectoryPoints() == 0) {
341 
342  // Get the pre/along-step information from the G4Step.
343  const G4StepPoint* preStepPoint = step->GetPreStepPoint();
344 
345  const G4ThreeVector position = preStepPoint->GetPosition();
346  G4double time = preStepPoint->GetGlobalTime();
347 
348  // Remember that LArSoft uses cm, ns, GeV.
349  TLorentzVector fourPos(position.x() / CLHEP::cm,
350  position.y() / CLHEP::cm,
351  position.z() / CLHEP::cm,
352  time / CLHEP::ns);
353 
354  const G4ThreeVector momentum = preStepPoint->GetMomentum();
355  const G4double energy = preStepPoint->GetTotalEnergy();
356  TLorentzVector fourMom(momentum.x() / CLHEP::GeV,
357  momentum.y() / CLHEP::GeV,
358  momentum.z() / CLHEP::GeV,
359  energy / CLHEP::GeV);
360 
361  // Add the first point in the trajectory.
362  AddPointToCurrentParticle(fourPos, fourMom, "Start");
363 
364  } // end if this is the first step
365 
366  // At this point, the particle is being transported through the
367  // simulation. This method is being called for every voxel that
368  // the track passes through, but we don't want to update the
369  // trajectory information if we're just updating voxels. To check
370  // for this, look at the process name for the step, and compare it
371  // against the voxelization process name (set in PhysicsList.cxx).
372  G4String process = step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
373  G4bool ignoreProcess = process.contains("LArVoxel") || process.contains("OpDetReadout");
374 
375  MF_LOG_DEBUG("ParticleListAction::SteppingAction")
376  << ": DEBUG - process='" << process << "'"
377  << " ignoreProcess=" << ignoreProcess << " fstoreTrajectories=" << fstoreTrajectories;
378 
379  // We store the initial creation point of the particle
380  // and its final position (ie where it has no more energy, or at least < 1 eV) no matter
381  // what, but whether we store the rest of the trajectory depends
382  // on the process, and on a user switch
383  if (fstoreTrajectories && !ignoreProcess) {
384  // If the particle was marked to drop (EM shower daughters),
385  // then skip unless this step is last in volume.
386  //if (fCurrentParticle.drop && !step->IsLastStepInVolume()) return;
387 
388  // Get the post-step information from the G4Step.
389  const G4StepPoint* postStepPoint = step->GetPostStepPoint();
390 
391  const G4ThreeVector position = postStepPoint->GetPosition();
392  G4double time = postStepPoint->GetGlobalTime();
393 
394  // Remember that LArSoft uses cm, ns, GeV.
395  TLorentzVector fourPos(position.x() / CLHEP::cm,
396  position.y() / CLHEP::cm,
397  position.z() / CLHEP::cm,
398  time / CLHEP::ns);
399 
400  const G4ThreeVector momentum = postStepPoint->GetMomentum();
401  const G4double energy = postStepPoint->GetTotalEnergy();
402  TLorentzVector fourMom(momentum.x() / CLHEP::GeV,
403  momentum.y() / CLHEP::GeV,
404  momentum.z() / CLHEP::GeV,
405  energy / CLHEP::GeV);
406 
407  // Add another point in the trajectory.
408  AddPointToCurrentParticle(fourPos, fourMom, std::string(process));
409  }
410  }
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.
double velocity_step
double energy
Definition: plottest35.C:25
double velocity_G4
double globalTime
cet::exempt_ptr< simb::MCParticle > particle
Object representing particle.
#define MF_LOG_DEBUG(id)
bool hasParticle() const
Returns whether there is a particle.
sim::ParticleList && larg4::ParticleListAction::YieldDroppedList ( )

Yields the (dropped) ParticleList accumulated during the current event.

Definition at line 542 of file ParticleListAction.cxx.

References fdroppedParticleList, fparticleList, and fTrackIDOffset.

Referenced by larg4::LArG4::produce().

543  {
544  if (!fdroppedParticleList) {
545  throw cet::exception("ParticleListAction")
546  << "ParticleListAction::YieldDroppedList(): dropped particle list not build by user "
547  "request.\n";
548  }
549  // check if the ParticleNavigator has entries, and if
550  // so grab the highest track id value from it to
551  // add to the fTrackIDOffset
552  int highestID = 0;
553  for (auto pn = fparticleList->begin(); pn != fparticleList->end(); pn++)
554  if ((*pn).first > highestID) highestID = (*pn).first;
555 
556  // If we have stored dropped particles,
557  // include them in the offset.
558  for (auto pn = fdroppedParticleList->begin(); pn != fdroppedParticleList->end(); pn++)
559  if ((*pn).first > highestID) highestID = (*pn).first;
560 
561  //Only change the fTrackIDOffset if there is in fact a particle to add to the event
562  if ((fparticleList->size()) != 0) { fTrackIDOffset = highestID + 1; }
563 
564  return std::move(*fdroppedParticleList);
565  } // ParticleList&& ParticleListAction::YieldDroppedList()
std::unique_ptr< sim::ParticleList > fdroppedParticleList
std::unique_ptr< sim::ParticleList > fparticleList
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
sim::ParticleList && larg4::ParticleListAction::YieldList ( )

Definition at line 513 of file ParticleListAction.cxx.

References fdroppedParticleList, fparticleList, and fTrackIDOffset.

Referenced by larg4::LArG4::produce().

514  {
515  if (!fparticleList) {
516  // check with `hasList()` before calling this method
517  throw cet::exception("ParticleListAction")
518  << "ParticleListAction::YieldList(): particle list not build by user request.\n";
519  }
520  // check if the ParticleNavigator has entries, and if
521  // so grab the highest track id value from it to
522  // add to the fTrackIDOffset
523  int highestID = 0;
524  for (auto pn = fparticleList->begin(); pn != fparticleList->end(); pn++)
525  if ((*pn).first > highestID) highestID = (*pn).first;
526 
527  // If we have stored dropped particles,
528  // include them in the offset.
529  if (fdroppedParticleList) {
530  for (auto pn = fdroppedParticleList->begin(); pn != fdroppedParticleList->end(); pn++)
531  if ((*pn).first > highestID) highestID = (*pn).first;
532  }
533 
534  //Only change the fTrackIDOffset if there is in fact a particle to add to the event
535  if ((fparticleList->size()) != 0) { fTrackIDOffset = highestID + 1; }
536 
537  return std::move(*fparticleList);
538  } // ParticleList&& ParticleListAction::YieldList()
std::unique_ptr< sim::ParticleList > fdroppedParticleList
std::unique_ptr< sim::ParticleList > fparticleList
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

int larg4::ParticleListAction::fCurrentOrigTrackID = sim::NoParticleId
staticprivate

except for EM shower particles where it always shows the original track ID

g4 real track ID of the current particle (including for EM shower daughters)

Definition at line 155 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), and PreTrackingAction().

ParticleInfo_t larg4::ParticleListAction::fCurrentParticle
private

information about the particle currently being simulated for a single particle.

Definition at line 141 of file ParticleListAction.h.

Referenced by AddPointToCurrentParticle(), BeginOfEventAction(), PostTrackingAction(), PreTrackingAction(), and SteppingAction().

int larg4::ParticleListAction::fCurrentPdgCode = 0
staticprivate

pdg code of current particle

Definition at line 157 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), and PreTrackingAction().

int larg4::ParticleListAction::fCurrentTrackID = sim::NoParticleId
staticprivate

track ID of the current particle, set to eve ID for EM shower particles

Definition at line 152 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), and PreTrackingAction().

std::unique_ptr<sim::ParticleList> larg4::ParticleListAction::fdroppedParticleList
private

The accumulated particle information for all dropped particles in the event.

Definition at line 146 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), GetList(), PostTrackingAction(), PreTrackingAction(), YieldDroppedList(), and YieldList().

G4double larg4::ParticleListAction::fenergyCut
private

The minimum energy for a particle to be included in the list.

Definition at line 139 of file ParticleListAction.h.

Referenced by PreTrackingAction().

std::unique_ptr<util::PositionInVolumeFilter> larg4::ParticleListAction::fFilter
private

filter for particles to be kept

Definition at line 162 of file ParticleListAction.h.

Referenced by AddPointToCurrentParticle(), and PreTrackingAction().

bool larg4::ParticleListAction::fKeepEMShowerDaughters
private

whether to keep EM shower secondaries, tertiaries, etc

Definition at line 160 of file ParticleListAction.h.

Referenced by PreTrackingAction().

std::map<int, int> larg4::ParticleListAction::fParentIDMap
private

key is current track ID, value is parent ID

Definition at line 149 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), GetParentage(), and PreTrackingAction().

std::map<int, int> larg4::ParticleListAction::fParentIDMap_OrigTrackID
private

key is current track ID, value is parent ID – for real G4 track ID tracking only

Definition at line 151 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), GetParentage(), and PreTrackingAction().

std::unique_ptr<sim::ParticleList> larg4::ParticleListAction::fparticleList
private

The accumulated particle information for all particles in the event.

Definition at line 143 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), EndOfEventAction(), GetList(), PostTrackingAction(), PreTrackingAction(), YieldDroppedList(), and YieldList().

std::map<int, GeneratedParticleIndex_t> larg4::ParticleListAction::fPrimaryTruthMap
private

Map: particle track ID -> index of primary information in MC truth.

Definition at line 165 of file ParticleListAction.h.

Referenced by PostTrackingAction().

G4bool larg4::ParticleListAction::fstoreTrajectories
private

Whether to store particle trajectories with each particle.

Definition at line 148 of file ParticleListAction.h.

Referenced by SteppingAction().

int larg4::ParticleListAction::fTrackIDOffset = 0
staticprivate

offset added to track ids when running over multiple MCTruth objects.

Definition at line 158 of file ParticleListAction.h.

Referenced by GetList(), PreTrackingAction(), YieldDroppedList(), and YieldList().


The documentation for this class was generated from the following files: