All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleInventoryService.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 //
3 // ParticleInventoryService.cc
4 // Author: JStock
5 // EMail: jason.stock@mines.sdsmt.edu
6 // 2017-09-12
7 //
8 // Maintinence Notes: When the ParticleInventory is initialized, none of the prep work (previously
9 // the BackTracker rebuild stage) will be done. Each function needs to check and make sure the
10 // needed data products have been loaded. To see what objects a function uses, you will have to
11 // check the appropriate part of ParticleInventory. After this, you will need to manually write the check
12 // into whatever function you are writing. You will also want to include a call to prepare the needed items
13 // if your check fails.
14 //
15 // Example:
16 // std::set<int> ParticleInventoryService::GetSetOfTrackIds(){
17 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();} //The GetTrackIds in ParticleInventory needs the ParticleList.
18 // So, we check if it's ready, and if it isn't we ready it.
19 // return ParticleInventory::GetSetOfTrackIds();
20 // }
21 //
22 // If you have any questions about how to incorperate something in here, let me know. I know this is a rather odd
23 // use model. The rationale is to allow the BackTracker service to be lazy, while at the same time allowing gallery
24 // to use backtracker functions (the gallery implimentation is not lazy).
25 ////////////////////////////////////////////////////////////////////////////
26 
28 
29 #include "nug4/ParticleNavigation/ParticleList.h"
30 
31 #include "art/Framework/Principal/Event.h"
32 #include "art/Framework/Services/Registry/ActivityRegistry.h"
33 #include "messagefacility/MessageLogger/MessageLogger.h"
34 #include "fhiclcpp/ParameterSet.h"
35 
36 namespace cheat{
37 
38  //----------------------------------------------------------------------
40  :ParticleInventory(config.ParticleInventoryTable())
41  {
42 // std::cout<<"Config Dump from ParticleInventoryService using fhicl Table\n";
43 // config.ParticleInventoryTable.print_allowed_configuration(std::cout);
44  reg.sPreProcessEvent.watch(this, &ParticleInventoryService::priv_PrepEvent);
45  }
46 
47  //----------------------------------------------------------------------
48  ParticleInventoryService::ParticleInventoryService(const fhicl::ParameterSet& pSet, art::ActivityRegistry& reg)
49  :ParticleInventory(pSet.get<fhicl::ParameterSet>("ParticleInventory"))
50  {
51 // std::cout<<"\n\n\n\nConfigDump from ParticleInventoryService using ParameterSet.\n"<<pSet.to_string()<<"\n\n\n\n";
52  reg.sPreProcessEvent.watch(this, &ParticleInventoryService::priv_PrepEvent);
53  }
54 
55  //_--Temporary Rebuild function (until the service can be lazy again).
56  void ParticleInventoryService::Rebuild( const art::Event& evt){
57  this->priv_PrepEvent(evt, art::ScheduleContext::invalid());
58  }
59 
60  //----------------------------------------------------------------------
61  void ParticleInventoryService::priv_PrepEvent(const art::Event& evt, art::ScheduleContext){
62  //fEvt=&evt;
64  if( ! this->priv_CanRun(evt) ) { return; }
65  this->priv_PrepParticleList(evt);
66  this->priv_PrepMCTruthList(evt);
68  //fEvt=nullptr; //dont keep the cached pointer since it will expire right after this, and I want to make sure bad calls to prep functions fail.
69  }
70 
71  //----------------------------------------------------------------------
72  bool ParticleInventoryService::priv_CanRun(const art::Event& evt) const{
73  return ParticleInventory::CanRun(evt);
74  }
75 
76  //----------------------------------------------------------------------
78  if(!this->priv_CanRun(evt)) {throw;}
79  //if(!this->priv_CanRun(*fEvt)) {throw;}
80  if(this->priv_ParticleListReady()){ return; }
81  //try{ParticleInventory::PrepParticleList(*fEvt);}
83  catch(...){ mf::LogWarning("ParticleInventory") << "Rebuild failed to get the MCParticles. This is expected when running on a generation or simulation step.";}
84  }
85 
86 
88  if(!this->priv_CanRun(evt)){throw;}
89  //if(!this->priv_CanRun(*fEvt)){throw;}
90  if( this->priv_TrackIdToMCTruthReady()){ return; }
91  //try{ParticleInventory::PrepTrackIdToMCTruthIndex(*fEvt);}
93  catch(...){ mf::LogWarning("ParticleInventory") << "Rebuild failed to get the MCParticles. This is expected when running on a generation or simulation step.";}
94  }//End priv_PrepTrackIdToMCTruthIndexList
95 
97 // if(!this->priv_CanRun(*fEvt)){throw;}
98  if(!this->priv_CanRun(evt)){throw;}
99  if(this->priv_MCTruthListReady( ) ){ return;} //If the event is data or if the truth list is already built there is nothing for us to do.
101  //try{ ParticleInventory::PrepMCTruthList(*fEvt); }
102  catch(...){ mf::LogWarning("ParticleInventory") << "Rebuild failed to get the MCParticles. This is expected when running on a generation or simulation step.";}
103  //ToDo. Find out exactly which exception is thrown and catch only that.
104 
105  }//End PrepMCTruthList
106 
107 
108  //Loop Event and grab MCTruths. Quick and clean as possible.
109 
110  //deliverables
111 
112  const sim::ParticleList& ParticleInventoryService::ParticleList() const {
113 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
114 // Not used for non lazy functions
116  } //This should be replaced with a public struct so we can get away from the nutools dependency.
117 
118  const std::vector< art::Ptr<simb::MCTruth> >& ParticleInventoryService::MCTruthVector_Ps() const {
119  //if(!this->priv_MCTruthListReady()){priv_PrepMCTruthList();}
120  // Not used for non-lazy mode
122  }
123 
124  //TrackIdToParticleP
125 
126  const simb::MCParticle* ParticleInventoryService::TrackIdToParticle_P(int const id) const {
127 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
128 // Not used for non-lazy mode
130  }//End TrackIdToParticle
131 
132 
133  const simb::MCParticle* ParticleInventoryService::TrackIdToMotherParticle_P(int const id) const
134  {
135 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
136 // Not used for non-lazy mode
138  }
139 
140  const art::Ptr<simb::MCTruth>& ParticleInventoryService::TrackIdToMCTruth_P(int const id) const
141  {
142 // if(!this->priv_TrackIdToMCTruthReady()){this->priv_PrepTrackIdToMCTruthIndex();}
143 // Not used for non-lazy mode
145  }
146 
148  {
150  }
151 
152  const art::Ptr<simb::MCTruth>& ParticleInventoryService::ParticleToMCTruth_P(const simb::MCParticle* p) const
153  {
154 // if(!this->priv_TrackIdToMCTruthReady()){this->priv_PrepTrackIdToMCTruthIndex();}
155 // Not used for non-lazy mode
156  return this->TrackIdToMCTruth_P(p->TrackId());
157  }
158 
159  std::vector<const simb::MCParticle*> ParticleInventoryService::MCTruthToParticles_Ps(art::Ptr<simb::MCTruth> const& mct) const
160  {
161 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
162 // if(!this->priv_MCTruthListReady()){this->priv_PrepMCTruthList();}
163 // Not used for non-lazy mode
165  }
166 
168 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
169 // Not used for non-lazy mode
171  }
172 
174 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
175 // Not used for non-lazy mode
177  }
178 
179 } //namespace
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...
const std::vector< art::Ptr< simb::MCTruth > > & MCTruthVector_Ps() const
const simb::MCParticle * TrackIdToParticle_P(int id) const
pdgs p
Definition: selectors.fcl:22
std::vector< const simb::MCParticle * > MCTruthToParticles_Ps(art::Ptr< simb::MCTruth > const &mct) const
void priv_PrepParticleList(const art::Event &evt)
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p) const
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 priv_PrepEvent(const art::Event &evt, art::ScheduleContext)
std::vector< const simb::MCParticle * > MCTruthToParticles_Ps(art::Ptr< simb::MCTruth > const &mct) const
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int id) const
const simb::MCParticle * TrackIdToParticle_P(int const &id) const
std::set< int > GetSetOfTrackIds() const
std::set< int > GetSetOfEveIds() const
const sim::ParticleList & ParticleList() const
void priv_PrepMCTruthList(const art::Event &evt)
const simb::MCParticle * TrackIdToMotherParticle_P(int const &id) const
ParticleInventoryService(const ParticleInventoryServiceConfig &config, art::ActivityRegistry &reg)
void Rebuild(const art::Event &evt)
TCEvent evt
Definition: DataStructs.cxx:8
const simb::MCParticle * TrackIdToMotherParticle_P(int id) const
void priv_PrepTrackIdToMCTruthIndex(const art::Event &evt)
int TrackIdToEveTrackId(const int &tid) const
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int const &id) const
bool priv_CanRun(const art::Event &evt) const
const sim::ParticleList & ParticleList() const