ParticleInventoryService_service.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 
27 //STL includes
28 //ROOT includes
29 //Framework includes
33 
34 //LArSoft includes
37 
38 namespace cheat{
39 
40  //----------------------------------------------------------------------
42  :ParticleInventory(config.ParticleInventoryTable())
43  {
44 // std::cout<<"Config Dump from ParticleInventoryService using fhicl Table\n";
45 // config.ParticleInventoryTable.print_allowed_configuration(std::cout);
47  }
48 
49  //----------------------------------------------------------------------
51  :ParticleInventory(pSet.get<fhicl::ParameterSet>("ParticleInventory"))
52  {
53 // std::cout<<"\n\n\n\nConfigDump from ParticleInventoryService using ParameterSet.\n"<<pSet.to_string()<<"\n\n\n\n";
55  }
56 
57  //_--Temporary Rebuild function (until the service can be lazy again).
60  }
61 
62  //----------------------------------------------------------------------
64  //fEvt=&evt;
66  if( ! this->priv_CanRun(evt) ) { return; }
67  this->priv_PrepParticleList(evt);
68  this->priv_PrepMCTruthList(evt);
70  //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.
71  }
72 
73  //----------------------------------------------------------------------
75  return ParticleInventory::CanRun(evt);
76  }
77 
78  //----------------------------------------------------------------------
80  if(!this->priv_CanRun(evt)) {throw;}
81  //if(!this->priv_CanRun(*fEvt)) {throw;}
82  if(this->priv_ParticleListReady()){ return; }
83  //try{ParticleInventory::PrepParticleList(*fEvt);}
85  catch(...){ mf::LogWarning("ParticleInventory") << "Rebuild failed to get the MCParticles. This is expected when running on a generation or simulation step.";}
86  }
87 
88 
90  if(!this->priv_CanRun(evt)){throw;}
91  //if(!this->priv_CanRun(*fEvt)){throw;}
92  if( this->priv_TrackIdToMCTruthReady()){ return; }
93  //try{ParticleInventory::PrepTrackIdToMCTruthIndex(*fEvt);}
95  catch(...){ mf::LogWarning("ParticleInventory") << "Rebuild failed to get the MCParticles. This is expected when running on a generation or simulation step.";}
96  }//End priv_PrepTrackIdToMCTruthIndexList
97 
99 // if(!this->priv_CanRun(*fEvt)){throw;}
100  if(!this->priv_CanRun(evt)){throw;}
101  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.
103  //try{ ParticleInventory::PrepMCTruthList(*fEvt); }
104  catch(...){ mf::LogWarning("ParticleInventory") << "Rebuild failed to get the MCParticles. This is expected when running on a generation or simulation step.";}
105  //ToDo. Find out exactly which exception is thrown and catch only that.
106 
107  }//End PrepMCTruthList
108 
109 
110  //Loop Event and grab MCTruths. Quick and clean as possible.
111 
112  //deliverables
113 
114  const sim::ParticleList& ParticleInventoryService::ParticleList() const {
115 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
116 // Not used for non lazy functions
118  } //This should be replaced with a public struct so we can get away from the nutools dependency.
119 
120  const std::vector< art::Ptr<simb::MCTruth> >& ParticleInventoryService::MCTruthVector_Ps() const {
121  //if(!this->priv_MCTruthListReady()){priv_PrepMCTruthList();}
122  // Not used for non-lazy mode
124  }
125 
126  //TrackIdToParticleP
127 
129 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
130 // Not used for non-lazy mode
132  }//End TrackIdToParticle
133 
134 
136  {
137 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
138 // Not used for non-lazy mode
140  }
141 
143  {
144 // if(!this->priv_TrackIdToMCTruthReady()){this->priv_PrepTrackIdToMCTruthIndex();}
145 // Not used for non-lazy mode
147  }
148 
150  {
152  }
153 
155  {
156 // if(!this->priv_TrackIdToMCTruthReady()){this->priv_PrepTrackIdToMCTruthIndex();}
157 // Not used for non-lazy mode
158  return this->TrackIdToMCTruth_P(p->TrackId());
159  }
160 
161  std::vector<const simb::MCParticle*> ParticleInventoryService::MCTruthToParticles_Ps(art::Ptr<simb::MCTruth> const& mct) const
162  {
163 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
164 // if(!this->priv_MCTruthListReady()){this->priv_PrepMCTruthList();}
165 // Not used for non-lazy mode
167  }
168 
170 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
171 // Not used for non-lazy mode
173  }
174 
176 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
177 // Not used for non-lazy mode
179  }
180 
182 
183 } //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
std::vector< const simb::MCParticle * > MCTruthToParticles_Ps(art::Ptr< simb::MCTruth > const &mct) const
Particle class.
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 ...
int TrackId() const
Definition: MCParticle.h:210
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
static Config * config
Definition: config.cpp:1054
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int id) const
const simb::MCParticle * TrackIdToParticle_P(int const &id) const
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::set< int > GetSetOfTrackIds() const
p
Definition: test.py:223
std::set< int > GetSetOfEveIds() const
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &, ScheduleContext)> sPreProcessEvent
const sim::ParticleList & ParticleList() const
#define DEFINE_ART_SERVICE(svc)
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:22
const simb::MCParticle * TrackIdToMotherParticle_P(int const &id) const
static ScheduleContext invalid()
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
ParticleInventoryService(const ParticleInventoryServiceConfig &config, art::ActivityRegistry &reg)
ParticleInventory(const ParticleInventoryConfig &config)
TCEvent evt
Definition: DataStructs.cxx:7
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