LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ParticleInventoryService_service.cc
Go to the documentation of this file.
1 //
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).
26 
27 //STL includes
28 #include <map>
29 //ROOT includes
30 //Framework includes
34 
35 //LArSoft includes
42 
43 
44 namespace cheat{
45 
46  //----------------------------------------------------------------------
48  :ParticleInventory(config.ParticleInventoryTable())
49  {
50 // std::cout<<"Config Dump from ParticleInventoryService using fhicl Table\n";
51 // config.ParticleInventoryTable.print_allowed_configuration(std::cout);
53  }
54 
55  //----------------------------------------------------------------------
57  :ParticleInventory(pSet.get<fhicl::ParameterSet>("ParticleInventory"))
58  {
59 // std::cout<<"\n\n\n\nConfigDump from ParticleInventoryService using ParameterSet.\n"<<pSet.to_string()<<"\n\n\n\n";
61  }
62 
63  //_--Temporary Rebuild function (until the service can be lazy again).
65  this->priv_PrepEvent(evt);
66  }
67 
68  //----------------------------------------------------------------------
70  //fEvt=&evt;
72  if( ! this->priv_CanRun(evt) ) { return; }
73  this->priv_PrepParticleList(evt);
74  this->priv_PrepMCTruthList(evt);
76  //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.
77  }
78 
79  //----------------------------------------------------------------------
81  return ParticleInventory::CanRun(evt);
82  }
83 
84  //----------------------------------------------------------------------
86  if(!this->priv_CanRun(evt)) {throw;}
87  //if(!this->priv_CanRun(*fEvt)) {throw;}
88  if(this->priv_ParticleListReady()){ return; }
89  //try{ParticleInventory::PrepParticleList(*fEvt);}
91  catch(...){ mf::LogWarning("ParticleInventory") << "Rebuild failed to get the MCParticles. This is expected when running on a gernation or simulation step.";}
92  }
93 
94 
96  if(!this->priv_CanRun(evt)){throw;}
97  //if(!this->priv_CanRun(*fEvt)){throw;}
98  if( this->priv_TrackIdToMCTruthReady()){ return; }
99  //try{ParticleInventory::PrepTrackIdToMCTruthIndex(*fEvt);}
101  catch(...){ mf::LogWarning("ParticleInventory") << "Rebuild failed to get the MCParticles. This is expected when running on a gernation or simulation step.";}
102  }//End priv_PrepTrackIdToMCTruthIndexList
103 
105 // if(!this->priv_CanRun(*fEvt)){throw;}
106  if(!this->priv_CanRun(evt)){throw;}
107  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.
109  //try{ ParticleInventory::PrepMCTruthList(*fEvt); }
110  catch(...){ mf::LogWarning("ParticleInventory") << "Rebuild failed to get the MCParticles. This is expected when running on a gernation or simulation step.";}
111  //ToDo. Find out exactly which exception is thrown and catch only that.
112 
113  }//End PrepMCTruthList
114 
115 
116  //Loop Event and grab MCTruths. Quick and clean as possible.
117 
118  //deliverables
119 
121 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
122 // Not used for non lazy functions
124  } //This should be replaced with a public struct so we can get away from the nutools dependency.
125 
126  const std::vector< art::Ptr<simb::MCTruth> >& ParticleInventoryService::MCTruthVector_Ps() {
127  //if(!this->priv_MCTruthListReady()){priv_PrepMCTruthList();}
128  // Not used for non-lazy mode
130  }
131 
132  //TrackIdToParticleP
133 
135 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
136 // Not used for non-lazy mode
138  }//End TrackIdToParticle
139 
140 
142  {
143 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
144 // Not used for non-lazy mode
146  }
147 
149  {
150 // if(!this->priv_TrackIdToMCTruthReady()){this->priv_PrepTrackIdToMCTruthIndex();}
151 // Not used for non-lazy mode
153  }
154 
156  {
158  }
159 
161  {
162 // if(!this->priv_TrackIdToMCTruthReady()){this->priv_PrepTrackIdToMCTruthIndex();}
163 // Not used for non-lazy mode
164  return this->TrackIdToMCTruth_P(p->TrackId());
165  }
166 
167  const std::vector<const simb::MCParticle*> ParticleInventoryService::MCTruthToParticles_Ps(art::Ptr<simb::MCTruth> const& mct)
168  {
169 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
170 // if(!this->priv_MCTruthListReady()){this->priv_PrepMCTruthList();}
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 // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
183 // Not used for non-lazy mode
185  }
186 
188 
189 } //namespace
190 
191 
192 
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 simb::MCParticle * TrackIdToParticle_P(int const &id)
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p)
Particle class.
const std::vector< art::Ptr< simb::MCTruth > > & MCTruthVector_Ps()
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:214
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.
const simb::MCParticle * TrackIdToParticle_P(int const &id) const
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::set< int > GetSetOfTrackIds() const
std::set< int > GetSetOfEveIds() const
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:26
Utility object to perform functions of association.
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...
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
ParticleInventoryService(const ParticleInventoryServiceConfig &config, art::ActivityRegistry &reg)
ParticleInventory(const ParticleInventoryConfig &config)
TCEvent evt
Definition: DataStructs.cxx:5
void priv_PrepTrackIdToMCTruthIndex(const art::Event &evt)
const simb::MCParticle * TrackIdToMotherParticle_P(int const &id)
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
Tools and modules for checking out the basics of the Monte Carlo.
const std::vector< const simb::MCParticle * > MCTruthToParticles_Ps(art::Ptr< simb::MCTruth > const &mct) const
const sim::ParticleList & ParticleList() const
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int const &id)
const std::vector< const simb::MCParticle * > MCTruthToParticles_Ps(art::Ptr< simb::MCTruth > const &mct)