LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ParticleListAction.h
Go to the documentation of this file.
1 
10 //
15 
16 #ifndef LArG4_ParticleListAction_h
17 #define LArG4_ParticleListAction_h
18 
19 #include "Geant4/G4Types.hh"
20 #include "TLorentzVector.h"
21 
22 #include "cetlib/exempt_ptr.h"
23 #include "larcorealg/CoreUtils/ParticleFilters.h" // util::PositionInVolumeFilter
24 #include "nug4/G4Base/UserAction.h"
25 #include "nusimdata/SimulationBase/simb.h" // simb::GeneratedParticleIndex_t
26 
27 #include <map>
28 #include <memory>
29 
30 // Forward declarations.
31 class G4Event;
32 class G4Track;
33 class G4Step;
34 
35 namespace sim {
36  class ParticleList;
37 }
38 
39 namespace simb {
40  class MCParticle;
41 }
42 
43 namespace larg4 {
44 
46  public:
48 
49  struct ParticleInfo_t {
50 
51  cet::exempt_ptr<simb::MCParticle> particle;
52  bool keep = false;
53  bool drop =
54  false;
57 
59  void clear()
60  {
61  particle = nullptr;
62  keep = false;
63  drop = false;
64  truthIndex = simb::NoGeneratedParticleIndex;
65  }
66 
68  bool hasParticle() const { return !particle.empty(); }
69 
71  bool isPrimary() const { return simb::isGeneratedParticleIndex(truthIndex); }
72 
74  bool keepParticle() const { return hasParticle() && keep; }
75 
77  GeneratedParticleIndex_t truthInfoIndex() const { return truthIndex; }
78 
79  }; // ParticleInfo_t
80 
81  // Standard constructors and destructors;
82  ParticleListAction(double energyCut,
83  bool storeTrajectories = false,
84  bool keepEMShowerDaughters = false,
85  bool keepMCParticleList = true,
86  bool storeDroppedMCParticles = false);
87 
88  // UserActions method that we'll override, to obtain access to
89  // Geant4's particle tracks and trajectories.
90  virtual void BeginOfEventAction(const G4Event*);
91  virtual void EndOfEventAction(const G4Event*);
92  virtual void PreTrackingAction(const G4Track*);
93  virtual void PostTrackingAction(const G4Track*);
94  virtual void SteppingAction(const G4Step*);
95 
97  void ParticleFilter(std::unique_ptr<util::PositionInVolumeFilter>&& filter)
98  {
99  fFilter = std::move(filter);
100  }
101 
102  // TrackID of the current particle, EveID if the particle is from an EM shower
103  static int GetCurrentTrackID() { return fCurrentTrackID; }
104  static int GetCurrentOrigTrackID() { return fCurrentOrigTrackID; }
105  static int GetCurrentPdgCode() { return fCurrentPdgCode; }
106 
107  void ResetTrackIDOffset() { fTrackIDOffset = 0; }
108 
109  // Returns the ParticleList accumulated during the current event.
110  const sim::ParticleList* GetList() const;
111 
114  std::map<int, GeneratedParticleIndex_t> const& GetPrimaryTruthMap() const
115  {
116  return fPrimaryTruthMap;
117  }
118 
120  bool hasList() const { return static_cast<bool>(fparticleList); }
121 
123  GeneratedParticleIndex_t GetPrimaryTruthIndex(int trackId) const;
124 
125  // Yields the ParticleList accumulated during the current event.
126  sim::ParticleList&& YieldList();
127 
129  sim::ParticleList&& YieldDroppedList();
130 
132  static bool isDropped(simb::MCParticle const* p);
133 
134  private:
135  // this method will loop over the fParentIDMap to get the
136  // parentage of the provided trackid
137  int GetParentage(int trackid, bool useOrigTrackIDMap = false) const;
138 
139  G4double fenergyCut;
140  ParticleInfo_t fCurrentParticle;
142  std::unique_ptr<sim::ParticleList> fparticleList;
144  std::unique_ptr<sim::ParticleList>
147  G4bool fstoreTrajectories;
149  std::map<int, int> fParentIDMap;
150  std::map<int, int>
152  static int fCurrentTrackID;
153  static int
156  static int fCurrentPdgCode;
158  static int fTrackIDOffset;
159  bool fKeepEMShowerDaughters;
161 
162  std::unique_ptr<util::PositionInVolumeFilter> fFilter;
163 
165  std::map<int, GeneratedParticleIndex_t> fPrimaryTruthMap;
166 
168  void AddPointToCurrentParticle(TLorentzVector const& pos,
169  TLorentzVector const& mom,
170  std::string const& process);
171  };
172 
173 } // namespace LArG4
174 
175 #endif // LArG4_ParticleListAction_h
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 ...
bool keepParticle() const
Returns whether there is a particle known to be kept.
Geant4 interface.
GeneratedParticleIndex_t truthInfoIndex() const
Returns the index of the particle in the generator truth record.
std::map< int, int > fParentIDMap
key is current track ID, value is parent ID
Framework includes.
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)
see below
simb::GeneratedParticleIndex_t GeneratedParticleIndex_t
void ParticleFilter(std::unique_ptr< util::PositionInVolumeFilter > &&filter)
Grabs a particle filter.
bool isGeneratedParticleIndex(GeneratedParticleIndex_t index)
Returns whether the specified one is an acceptable generator index.
Definition: simb.h:37
Monte Carlo Simulation.
ART objects.
std::unique_ptr< util::PositionInVolumeFilter > fFilter
filter for particles to be kept
bool isPrimary() const
Returns whether there is a particle.
cet::exempt_ptr< simb::MCParticle > particle
Object representing particle.
bool hasList() const
Returns whether a particle list is being kept.
static int fCurrentOrigTrackID
except for EM shower particles where it always shows the original track ID
bool hasParticle() const
Returns whether there is a particle.
Defines classes to filter particles based on their trajectory.
Common type definitions for data products (and a bit beyond).
std::map< int, GeneratedParticleIndex_t > const & GetPrimaryTruthMap() const
std::size_t GeneratedParticleIndex_t
Type of particle index in the generator truth record (simb::MCTruth).
Definition: simb.h:30