LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ParticleInventoryService.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 
28 
30 
33 #include "fhiclcpp/ParameterSet.h"
35 
36 namespace cheat {
37 
38  //----------------------------------------------------------------------
41  : ParticleInventory(config.ParticleInventoryTable())
42  {
43  // std::cout<<"Config Dump from ParticleInventoryService using fhicl Table\n";
44  // config.ParticleInventoryTable.print_allowed_configuration(std::cout);
46  }
47 
48  //----------------------------------------------------------------------
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).
59  {
61  }
62 
63  //----------------------------------------------------------------------
65  {
66  //fEvt=&evt;
68  if (!this->priv_CanRun(evt)) { return; }
69  this->priv_PrepParticleList(evt);
70  this->priv_PrepMCTruthList(evt);
72  //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.
73  }
74 
75  //----------------------------------------------------------------------
77  {
78  return ParticleInventory::CanRun(evt);
79  }
80 
81  //----------------------------------------------------------------------
83  {
84  if (!this->priv_CanRun(evt)) { throw; }
85  //if(!this->priv_CanRun(*fEvt)) {throw;}
86  if (this->priv_ParticleListReady()) { return; }
87  //try{ParticleInventory::PrepParticleList(*fEvt);}
88  try {
90  }
91  catch (...) {
92  mf::LogWarning("ParticleInventory")
93  << "Rebuild failed to get the MCParticles. This is expected when running on a generation "
94  "or simulation step.";
95  }
96  }
97 
99  {
100  if (!this->priv_CanRun(evt)) { throw; }
101  //if(!this->priv_CanRun(*fEvt)){throw;}
102  if (this->priv_TrackIdToMCTruthReady()) { return; }
103  //try{ParticleInventory::PrepTrackIdToMCTruthIndex(*fEvt);}
104  try {
106  }
107  catch (...) {
108  mf::LogWarning("ParticleInventory")
109  << "Rebuild failed to get the MCParticles. This is expected when running on a generation "
110  "or simulation step.";
111  }
112  } //End priv_PrepTrackIdToMCTruthIndexList
113 
115  {
116  // if(!this->priv_CanRun(*fEvt)){throw;}
117  if (!this->priv_CanRun(evt)) { throw; }
118  if (this->priv_MCTruthListReady()) {
119  return;
120  } //If the event is data or if the truth list is already built there is nothing for us to do.
121  try {
123  }
124  //try{ ParticleInventory::PrepMCTruthList(*fEvt); }
125  catch (...) {
126  mf::LogWarning("ParticleInventory")
127  << "Rebuild failed to get the MCParticles. This is expected when running on a generation "
128  "or simulation step.";
129  }
130  //ToDo. Find out exactly which exception is thrown and catch only that.
131 
132  } //End PrepMCTruthList
133 
134  //Loop Event and grab MCTruths. Quick and clean as possible.
135 
136  //deliverables
137 
139  {
140  // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
141  // Not used for non lazy functions
143  } //This should be replaced with a public struct so we can get away from the nutools dependency.
144 
145  const std::vector<art::Ptr<simb::MCTruth>>& ParticleInventoryService::MCTruthVector_Ps() const
146  {
147  //if(!this->priv_MCTruthListReady()){priv_PrepMCTruthList();}
148  // Not used for non-lazy mode
150  }
151 
152  //TrackIdToParticleP
153 
155  {
156  // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
157  // Not used for non-lazy mode
159  } //End TrackIdToParticle
160 
162  {
163  // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
164  // Not used for non-lazy mode
166  }
167 
169  {
170  // if(!this->priv_TrackIdToMCTruthReady()){this->priv_PrepTrackIdToMCTruthIndex();}
171  // Not used for non-lazy mode
173  }
174 
176  {
178  }
179 
181  const simb::MCParticle* p) const
182  {
183  // if(!this->priv_TrackIdToMCTruthReady()){this->priv_PrepTrackIdToMCTruthIndex();}
184  // Not used for non-lazy mode
185  return this->TrackIdToMCTruth_P(p->TrackId());
186  }
187 
188  std::vector<const simb::MCParticle*> ParticleInventoryService::MCTruthToParticles_Ps(
189  art::Ptr<simb::MCTruth> const& mct) const
190  {
191  // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
192  // if(!this->priv_MCTruthListReady()){this->priv_PrepMCTruthList();}
193  // Not used for non-lazy mode
195  }
196 
198  {
199  // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
200  // Not used for non-lazy mode
202  }
203 
205  {
206  // if(!this->priv_ParticleListReady()){this->priv_PrepParticleList();}
207  // Not used for non-lazy mode
209  }
210 
211 } //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
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 ...
int TrackId() const
Definition: MCParticle.h:211
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
T get(std::string const &key) const
Definition: ParameterSet.h:314
std::set< int > GetSetOfTrackIds() const
std::set< int > GetSetOfEveIds() const
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &, ScheduleContext)> sPreProcessEvent
const sim::ParticleList & ParticleList() const
void priv_PrepMCTruthList(const art::Event &evt)
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)
void Rebuild(const art::Event &evt)
ParticleInventory(const ParticleInventoryConfig &config)
TCEvent evt
Definition: DataStructs.cxx:8
const simb::MCParticle * TrackIdToMotherParticle_P(int id) const
void priv_PrepTrackIdToMCTruthIndex(const art::Event &evt)
Particle list in DetSim contains Monte Carlo particle information.
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