LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 <map>
158 #include <vector>
159 
162 #include "fhiclcpp/types/Atom.h"
163 namespace fhicl {
164  class ParameterSet;
165 }
166 
167 namespace simb {
168  class MCParticle;
169 }
172 
173 namespace cheat {
175  public:
178  fhicl::Name("G4ModuleLabel"),
180  "The label of the LArG4 module used to produce the art file we will be examining"),
181  "largeant"};
182  fhicl::Atom<std::string> EveIdCalculator{
183  fhicl::Name("EveIdCalculator"),
184  fhicl::Comment("For selecting which EveID caclulator to use at initialization."),
185  "EmEveIdCalculator"};
186  fhicl::Atom<bool> OverrideRealData{
187  fhicl::Name("OverrideRealData"),
188  fhicl::Comment("Option when overlaying simulation on real data, to tell the backtracker to "
189  "continue even if event looks like data."),
190  false};
191  };
192 
193  //using provider_type = ParticleInventory;
194  //cheat::ParticleInventory const* provider() const
195  //{ return static_cast<cheat::ParticleInventory const*>(this); }
196 
200  ParticleInventory(ParticleInventory const&) = delete;
201 
202  template <typename Evt> //Template must be decalred and defined outside of the .cpp file.
203  void PrepEvent(const Evt& evt);
204 
205  bool ParticleListReady() const { return !(fParticleList.empty()); }
206  bool MCTruthListReady() const { return !((fMCTObj.fMCTruthList).empty()); }
207  bool TrackIdToMCTruthReady() const { return !(fMCTObj.fTrackIdToMCTruthIndex.empty()); }
208 
209  template <typename Evt>
210  void PrepParticleList(const Evt& evt) const;
211  template <typename Evt>
212  void PrepTrackIdToMCTruthIndex(const Evt& evt) const;
213  template <typename Evt>
214  void PrepMCTruthList(const Evt& evt) const;
215  template <typename Evt>
216  void PrepMCTruthListAndTrackIdToMCTruthIndex(const Evt& evt) const;
217  template <typename Evt>
218  bool CanRun(const Evt& evt) const;
219 
220  const sim::ParticleList& ParticleList() const { return fParticleList; }
221  void SetEveIdCalculator(sim::EveIdCalculator* ec) { fParticleList.AdoptEveIdCalculator(ec); }
222 
223  const std::vector<art::Ptr<simb::MCTruth>>& MCTruthList() const { return fMCTObj.fMCTruthList; }
224 
225  const std::map<int, int>& TrackIdToMCTruthIndex() const
226  {
227  return fMCTObj.fTrackIdToMCTruthIndex;
228  }
229 
230  void ClearEvent();
231 
232  const simb::MCParticle* TrackIdToParticle_P(int const& id) const;
233  simb::MCParticle TrackIdToParticle(int const& id) const
234  {
235  return *(this->TrackIdToParticle_P(id));
236  } //Users are encouraged to use TrackIdToParticleP
237 
238  const simb::MCParticle* TrackIdToMotherParticle_P(int const& id) const;
240  int const& id) const //Users are encouraged to use TrackIdToMotherParticleP
241  {
242  return *(this->TrackIdToMotherParticle_P(id));
243  }
244 
245  const art::Ptr<simb::MCTruth>& TrackIdToMCTruth_P(int const& id) const;
247  int const& id) const //Users are encouraged to use TrackIdToMCTruthP
248  {
249  return *(this->TrackIdToMCTruth_P(id));
250  }
251 
252  //New Functions go here.
253  //TrackIdToEveId.
254  int TrackIdToEveTrackId(const int& tid) const { return fParticleList.EveId(tid); }
255 
256  const art::Ptr<simb::MCTruth>& ParticleToMCTruth_P(
257  const simb::MCParticle* p) const; //Users are encouraged to use ParticleToMCTruthP
259  {
260  return *(this->ParticleToMCTruth_P(p));
261  }
262 
263  const std::vector<art::Ptr<simb::MCTruth>>& MCTruthVector_Ps()
264  const; //I don't want this to be able to return a vector of copies. Too much chance of significant memory usage.
265 
266  std::vector<const simb::MCParticle*> MCTruthToParticles_Ps(art::Ptr<simb::MCTruth> const& mct)
267  const; //I don't want this to be able to return a vector of copies. Too much chance of significant memory usage.
268 
269  std::set<int> GetSetOfTrackIds() const;
270  std::set<int> GetSetOfEveIds() const;
271 
272  private:
274  struct MCTObjects {
275  std::vector<art::Ptr<simb::MCTruth>>
276  fMCTruthList; //there is some optimization that can be done here.
277  std::map<int, int> fTrackIdToMCTruthIndex;
278  };
280  //For fhicl validation, makea config struct
282  //std::string fEveIdCalculatorName;
283  //enum EveIdCalculator
284  //{
285  // EmEveIdCalculator,
286  // EveIdCalculator
287  //}
288  std::string fEveIdCalculator;
290 
291  }; //class ParticleInventory
292 
293 } //namespace
294 
295 #include "ParticleInventory.tcc"
296 
297 #endif //CHEAT_PARTICLEINVENTORY_H
simb::MCParticle TrackIdToParticle(int const &id) const
sim::ParticleList fParticleList
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. ...
simb::MCParticle TrackIdToMotherParticle(int const &id) const
void SetEveIdCalculator(sim::EveIdCalculator *ec)
const std::map< int, int > & TrackIdToMCTruthIndex() const
A simple struct to contain the MC Truth information.
parameter set interface
ART objects.
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:22
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.
TCEvent evt
Definition: DataStructs.cxx:8
Event generator information.
Definition: MCTruth.h:32
Particle list in DetSim contains Monte Carlo particle information.
int TrackIdToEveTrackId(const int &tid) const
const std::vector< art::Ptr< simb::MCTruth > > & MCTruthList() const
const sim::ParticleList & ParticleList() const
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109