LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ParticleInventory.h
Go to the documentation of this file.
1 // ParticleInventory.h
3 // Provide a single interface for building and accessing truth information from events for backtracking services.
4 //
5 // author jason.stock@mines.sdsmt.edu
6 // Based on the original BackTracker by Brian Rebel (brebel@fnal.gov)
7 //
8 // This module may look strange at first glance beacause of the mutable
9 // object in const functions whose sole purpose is to change the mutable
10 // objects.
11 // This is done because the returns from the ParticleInventory really
12 // should be const, and anything called from them must then also be const,
13 // and finally we get to the mutables. These are cached objects to prevent
14 // repeated and costly access to objects in the event.
15 //
17 
19 //DOXYGEN DOCUMENTATION
21 
154 #ifndef CHEAT_PARTICLEINVENTORY_H
155 #define CHEAT_PARTICLEINVENTORY_H
156 
157 #include <vector>
158 
160 
162 
166 
167 #include "fhiclcpp/types/Atom.h"
168 #include "fhiclcpp/ParameterSet.h"
174 
175 
176 
177 namespace cheat{
179  {
180  public:
183  fhicl::Name("G4ModuleLabel"),
184  fhicl::Comment("The label of the LArG4 module used to produce the art file we will be examining"),
185  "largeant"};
186  };
187 
188  //using provider_type = ParticleInventory;
189  //cheat::ParticleInventory const* provider() const
190  //{ return static_cast<cheat::ParticleInventory const*>(this); }
191 
195  ParticleInventory(ParticleInventory const&) = delete;
196 
197  template<typename Evt> //Template must be decalred and defined outside of the .cpp file.
198  void PrepEvent ( const Evt& evt );
199 
200  bool ParticleListReady() const { return !( fParticleList.empty() ); }
201  bool MCTruthListReady() const { return !( (fMCTObj.fMCTruthList).empty() ); }
202  bool TrackIdToMCTruthReady() const { return !(fMCTObj.fTrackIdToMCTruthIndex.empty());}
203 
204  template<typename Evt>
205  void PrepParticleList (const Evt& evt ) const;
206  template<typename Evt>
207  void PrepTrackIdToMCTruthIndex(const Evt& evt ) const;
208  template<typename Evt>
209  void PrepMCTruthList (const Evt& evt ) const;
210  template<typename Evt>
211  void PrepMCTruthListAndTrackIdToMCTruthIndex(const Evt& evt ) const ;
212  template<typename Evt>
213  bool CanRun(const Evt& evt) const;
214 
215  const sim::ParticleList& ParticleList() const { return fParticleList; }
217 
218  const std::vector< art::Ptr<simb::MCTruth> >& MCTruthList() const { return fMCTObj.fMCTruthList;}
219 
220  const std::map< int, int >& TrackIdToMCTruthIndex() const {return fMCTObj.fTrackIdToMCTruthIndex;}
221 
222  void ClearEvent();
223 
224  const simb::MCParticle* TrackIdToParticle_P(int const& id) const;
225  simb::MCParticle TrackIdToParticle(int const& id) const
226  { return *(this->TrackIdToParticle_P(id)); }//Users are encouraged to use TrackIdToParticleP
227 
228  const simb::MCParticle* TrackIdToMotherParticle_P(int const& id) const;
229  simb::MCParticle TrackIdToMotherParticle(int const& id) const//Users are encouraged to use TrackIdToMotherParticleP
230  { return *(this->TrackIdToMotherParticle_P(id)); }
231 
232  const art::Ptr<simb::MCTruth>& TrackIdToMCTruth_P(int const& id) const;
233  simb::MCTruth TrackIdToMCTruth (int const& id) const//Users are encouraged to use TrackIdToMCTruthP
234  { return *(this->TrackIdToMCTruth_P(id)); }
235 
236  //New Functions go here.
237  //TrackIdToEveId.
238  int TrackIdToEveTrackId(const int& tid) const { return fParticleList.EveId(tid);}
239 
240  const art::Ptr<simb::MCTruth>& ParticleToMCTruth_P(const simb::MCParticle* p) const; //Users are encouraged to use ParticleToMCTruthP
242  { return *(this->ParticleToMCTruth_P(p)); }
243 
244  const std::vector< art::Ptr<simb::MCTruth> >& MCTruthVector_Ps() const; //I don't want this to be able to return a vector of copies. Too much chance of significant memory usage.
245 
246  const std::vector<const simb::MCParticle*> MCTruthToParticles_Ps(art::Ptr<simb::MCTruth> const& mct) const; //I don't want this to be able to return a vector of copies. Too much chance of significant memory usage.
247 
248  std::set<int> GetSetOfTrackIds() const;
249  std::set<int> GetSetOfEveIds() const;
250 
251 
252  private:
254  struct MCTObjects{
255  std::vector< art::Ptr<simb::MCTruth> > fMCTruthList; //there is some optimization that can be done here.
256  std::map< int, int > fTrackIdToMCTruthIndex;
257  };
259  //For fhicl validation, makea config struct
261 
262 
263 
264 
265 
266  };//class ParticleInventory
267 
268 }//namespace
269 
270 #include "ParticleInventory.tcc"
271 
272 #endif //CHEAT_PARTICLEINVENTORY_H
273 
void PrepParticleList(const Evt &evt) const
A function to load the ParticleList and cache it This function will find the particle list and load i...
simb::MCParticle TrackIdToParticle(int const &id) const
sim::ParticleList fParticleList
bool empty() const
Definition: ParticleList.h:314
const std::map< int, int > & TrackIdToMCTruthIndex() const
bool MCTruthListReady() const
A simple check to determine if the MCTruthList has already been prepared and cached or not...
FHICL Validation Object This struct is used for loading the fhicl configuration.
bool TrackIdToMCTruthReady() const
A simple check to determine if the TrackIdToMCTruth map has been prepared or not. ...
fhicl::Atom< art::InputTag > G4ModuleLabel
An atom. FHICL Atom for retreiving the module label to be used in retreiving information from the art...
simb::MCParticle TrackIdToMotherParticle(int const &id) const
void PrepEvent(const Evt &evt)
Function to set up the ParticleInventory state for an event. This is a function to tell the ParticleI...
int EveId(const int trackID) const
Particle class.
bool CanRun(const Evt &evt) const
A short function to check if use of the backtracker is appropriate or not based on the type of input ...
const std::vector< art::Ptr< simb::MCTruth > > & MCTruthVector_Ps() const
void PrepTrackIdToMCTruthIndex(const Evt &evt) const
A function to prepare and cache a map of TrackIds and MCTruth object indicies from fMCTruthList...
void PrepMCTruthList(const Evt &evt) const
A function to load and cache the MCTruthList of the event.
void SetEveIdCalculator(sim::EveIdCalculator *ec)
void PrepMCTruthListAndTrackIdToMCTruthIndex(const Evt &evt) const
A function to make both PrepTrackIdToMCTruthIndex and PrepMCTruthList run when both are needed...
A simple struct to contain the MC Truth information.
const simb::MCParticle * TrackIdToParticle_P(int const &id) const
std::set< int > GetSetOfTrackIds() const
std::set< int > GetSetOfEveIds() const
Interface for calculating the "ultimate mother" of a particle in a simulated event.
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p) const
simb::MCTruth TrackIdToMCTruth(int const &id) const
simb::MCTruth ParticleToMCTruth(const simb::MCParticle *p) const
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:26
const simb::MCParticle * TrackIdToMotherParticle_P(int const &id) const
Example routine for calculating the "ultimate e-m mother" of a particle in a simulated event...
bool ParticleListReady() const
A simple check to determine if the ParticleList has already been prepared for this event or not...
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
ParticleInventory(const ParticleInventoryConfig &config)
Event generator information.
Definition: MCTruth.h:30
Particle list in DetSim contains Monte Carlo particle information.
static void AdoptEveIdCalculator(EveIdCalculator *)
int TrackIdToEveTrackId(const int &tid) const
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int const &id) const
const std::vector< const simb::MCParticle * > MCTruthToParticles_Ps(art::Ptr< simb::MCTruth > const &mct) const
const std::vector< art::Ptr< simb::MCTruth > > & MCTruthList() const
const sim::ParticleList & ParticleList() const