LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PrimaryParticleInformation.h
Go to the documentation of this file.
1 //
31 
32 #ifndef G4BASE_PrimaryParticleInformation_h
33 #define G4BASE_PrimaryParticleInformation_h
34 
35 // nusimdata
36 #include "nusimdata/SimulationBase/simb.h" // simb::GeneratedParticleIndex_t
37 
38 // G4 Includes
39 #include "Geant4/G4VUserPrimaryParticleInformation.hh"
40 #include "Geant4/G4Allocator.hh"
41 
42 // ART Includes
45 
46 // C++ standard library
47 #include <limits> // std::numeric_limits<>
48 
49 // Forward declaration for this namespace.
50 namespace simb {
51  class MCTruth;
52  class MCParticle;
53 }
54 
55 namespace g4b {
56 
57  class PrimaryParticleInformation : public G4VUserPrimaryParticleInformation {
58 
59  public:
60 
63 
64  inline void* operator new(size_t);
65  inline void operator delete(void*);
66 
67  // Accessors:
68  const simb::MCTruth* GetMCTruth() const { return fMCTruth; }
69  size_t const& MCTruthIndex() const { return fMCTIndex; }
70 
83  { return fMCParticleIndex; }
84 
88  simb::MCParticle const* GetMCParticle() const;
89 
92  bool IsInMCTruth() const; // inline implementation below
93 
94  void SetMCTruth(const simb::MCTruth* m,
95  size_t idx=0,
97  );
98 
99  // Required by Geant4:
100  virtual void Print() const override;
101 
102  private:
103 
104  // The MCTruth object associated with the G4PrimaryParticle. If
105  // this is zero, then there is no MCTruth object for this
106  // particle (although in that case it's more likely that a
107  // G4Base::PrimaryParticleInformation object would not have been
108  // created in the first place.)
109  // The MCTIndex is the index of the MCTruth object in the vector
110  // of the ConvertMCTruthToG4 creating this object
111  const simb::MCTruth* fMCTruth = nullptr;
112  size_t fMCTIndex = 0;
115  };
116 
117  // It's not likely, but there could be memory issues with these
118  // PrimaryParticleInformation objects. To make things work more smoothly
119  // and quickly, use Geant4's memory allocation mechanism.
120 
121  extern G4Allocator<PrimaryParticleInformation> PrimaryParticleInformationAllocator;
122 
123  inline bool PrimaryParticleInformation::IsInMCTruth() const
124  { return MCParticleIndex() != simb::NoGeneratedParticleIndex; }
125 
126 
127  inline void PrimaryParticleInformation::SetMCTruth(
128  const simb::MCTruth* m,
129  size_t idx /* = 0 */,
130  GeneratedParticleIndex_t indexInTruth /* = simb::NoGeneratedParticleIndex */
131  )
132  {
133  fMCTruth = m;
134  fMCTIndex = idx;
135  fMCParticleIndex = indexInTruth;
136  }
137 
138  inline void* PrimaryParticleInformation::operator new(size_t)
139  {
140  void *aPrimaryParticleInformation;
141  aPrimaryParticleInformation = (void *) PrimaryParticleInformationAllocator.MallocSingle();
142  return aPrimaryParticleInformation;
143  }
144 
145  inline void PrimaryParticleInformation::operator delete(void *aPrimaryParticleInformation)
146  {
147  PrimaryParticleInformationAllocator.FreeSingle((PrimaryParticleInformation*) aPrimaryParticleInformation);
148  }
149 
150 }
151 
152 #endif // G4BASE_PrimaryParticleInformation_h
const simb::MCTruth * GetMCTruth() const
constexpr GeneratedParticleIndex_t NoGeneratedParticleIndex
Constant representing the absence of generator truth information.
Definition: simb.h:34
simb::GeneratedParticleIndex_t GeneratedParticleIndex_t
Type of the stored index of particle within the truth record.
G4Allocator< PrimaryParticleInformation > PrimaryParticleInformationAllocator
basic interface to Geant4 for ART-based software
void Print(G4Element &ele)
Definition: pyG4Element.cc:55
ART objects.
Event generator information.
Definition: MCTruth.h:32
Common type definitions for data products (and a bit beyond).
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