LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
BackTrackerService_service.cc
Go to the documentation of this file.
1 //
3 // \file BackTrackerService_service.cc
4 // \brief A service for backtracking reconstruction information to its truth information
5 //
6 // \author jason.stock@mines.sdsmt.edu
7 // Based on the original BackTracker by Brian Rebel (brebel@fnal.gov)
8 //
10 
11 #include <vector>
12 
13 #include "BackTrackerService.h"
14 
21 
22 namespace cheat{
23 
24  //---------------------------------------------------------------------
26  :BackTracker(
27  pSet.get<fhicl::ParameterSet>("BackTracker"),
29  lar::providerFrom<geo::Geometry>(),
30  lar::providerFrom<detinfo::DetectorClocksService>()
31  )
32  {
34  }
35 
36  //---------------------------------------------------------------------
38  :BackTracker(
39  config.BackTrackerTable(),
41  lar::providerFrom<geo::Geometry>(),
42  lar::providerFrom<detinfo::DetectorClocksService>()
43  )
44  {
45  //This line is only to be included until art/LArSoft discussion about lazy rebuild can be completed.
47  }
48 
49 
56 
57  //-----Temp rebuild function.
59  this->priv_PrepEvent(evt);
60  }
61 
62  //---------------------------------------------------------------------
64  fEvt=&evt;
66  if( ! this->priv_CanRun(evt) ){ return; }
67  this->priv_PrepSimChannels(evt);
68  fEvt=nullptr; //don't save the pointer because it will be useless after this anyways. I want to make sure calls at the wrong time crash.
69  }
70 
71  //---------------------------------------------------------------------
73  return BackTracker::CanRun(evt);
74  }
75 
76  //---------------------------------------------------------------------
78  throw cet::exception("BackTrackerService")
79  <<"The called Prep Function failed. This is most likely due "
80  <<"to a BackTracker function being used on a file that is real data.";
81  }
82 
83  //---------------------------------------------------------------------
85  if( !this->priv_CanRun(evt)) { this->priv_PrepFailed(); }
86  if( this->priv_SimChannelsReady()){ return; }
88  catch(...){ mf::LogWarning("BackTrackerService") << "Rebuild failed to get the SimChannels. This is expected when running on a gernation or simulation step.";}
89  }
90 
91  //---------------------------------------------------------------------
92  /* void BackTrackerService::priv_PrepAllHitList(){
93  if( !this->priv_CanRun(*fEvt)) { this->priv_PrepFailed(); }
94  if( this->priv_AllHitListReady() ){ return; }
95  BackTracker::PrepAllHitList(*fEvt);
96  }
97  */
99  // End of the Event Rebuild Implimentation //
101 
104  // This section contains the implimentation //
105  // of all BackTrackerService end user //
106  // functionality //
108 
109  //---------------------------------------------------------------------
110  const std::vector < art::Ptr < sim::SimChannel > >& BackTrackerService::SimChannels() {
111  //Removed until Lazy Rebuild works
112  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
113  return BackTracker::SimChannels();
114  }
115 
116  //---------------------------------------------------------------------
117  const std::vector < const sim::IDE* > BackTrackerService::TrackIdToSimIDEs_Ps(int const& id) {
118  //Removed until Lazy Rebuild works
119  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
121  }
122 
123  //---------------------------------------------------------------------
124  const std::vector < const sim::IDE* > BackTrackerService::TrackIdToSimIDEs_Ps(int const& id, const geo::View_t view) {
125  //Removed until Lazy Rebuild works
126  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
127  return BackTracker::TrackIdToSimIDEs_Ps(id, view);
128  }
129 
130  //---------------------------------------------------------------------
132  //Removed until Lazy Rebuild works
133  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
134  return BackTracker::FindSimChannel(channel);
135  }
136 
137  //---------------------------------------------------------------------
138  const std::vector < sim::TrackIDE > BackTrackerService::ChannelToTrackIDEs(raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time){
139  //Removed until Lazy Rebuild works
140  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
141  return BackTracker::ChannelToTrackIDEs(channel, hit_start_time, hit_end_time);
142  }
143 
144  //---------------------------------------------------------------------
145  const std::vector < sim::TrackIDE > BackTrackerService::HitToTrackIDEs(recob::Hit const& hit){
146  //Removed until Lazy Rebuild works
147  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
148  return BackTracker::HitToTrackIDEs(hit);
149  }
150 
151  //---------------------------------------------------------------------
152  const std::vector < sim::TrackIDE > BackTrackerService::HitToTrackIDEs(art::Ptr < recob::Hit > const& hit) {
153  //Removed until Lazy Rebuild works
154  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
155  return BackTracker::HitToTrackIDEs(hit);
156  }
157 
158  //---------------------------------------------------------------------
159  const std::vector < int > BackTrackerService::HitToTrackIds(recob::Hit const& hit) {
160  //Removed until Lazy Rebuild works
161  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
162  return BackTracker::HitToTrackIds(hit);
163  }
164 
165  //---------------------------------------------------------------------
166  const std::vector < sim::TrackIDE > BackTrackerService::HitToEveTrackIDEs(recob::Hit const& hit) {
167  //Removed until Lazy Rebuild works
168  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
169  return BackTracker::HitToEveTrackIDEs(hit);
170  }
171 
172  //---------------------------------------------------------------------
173  const std::vector < sim::TrackIDE > BackTrackerService::HitToEveTrackIDEs(art::Ptr < recob::Hit > const& hit) {
174  //Removed until Lazy Rebuild works
175  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
176  return BackTracker::HitToEveTrackIDEs(hit);
177  }
178 
179  //---------------------------------------------------------------------
180  const std::vector < art::Ptr < recob::Hit > > BackTrackerService::TrackIdToHits_Ps( const int& tkId, std::vector < art::Ptr < recob::Hit > > const& hitsIn ) {
181  //Removed until Lazy Rebuild works
182  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
183  return BackTracker::TrackIdToHits_Ps( tkId, hitsIn);
184  }
185 
186  //---------------------------------------------------------------------
187  /* const std::vector < art::Ptr < recob::Hit > > BackTrackerService::TrackIdToHits_Ps( const int& tkId ) {
188  //Removed until Lazy Rebuild works
189  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
190  // if(!this->priv_AllHitListReady()){this->priv_PrepAllHitList();}
191  return BackTracker::TrackIdToHits_Ps( tkId);
192  }*/ //I can't support this functino and caching all the hits without lazy implimentation
193 
194  //---------------------------------------------------------------------
195  const std::vector < std::vector < art::Ptr < recob::Hit > > > BackTrackerService::TrackIdsToHits_Ps( std::vector < int > const& tkIds, std:: vector < art::Ptr < recob::Hit > > const& hitsIn ) {
196  //Removed until Lazy Rebuild works
197  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
198  return BackTracker::TrackIdsToHits_Ps( tkIds, hitsIn);
199  }
200 
201  //---------------------------------------------------------------------
202  /* const std::vector < std::vector < art::Ptr < recob::Hit > > > BackTrackerService::TrackIdsToHits_Ps( std::vector < int > const& tkIds ) {
203  //Removed until Lazy Rebuild works
204  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
205  // if(!this->priv_AllHitListReady()){this->priv_PrepAllHitList();}
206  return BackTracker::TrackIdsToHits_Ps( tkIds);
207  }*/
208 
209  //---------------------------------------------------------------------
210  const std::vector< sim::IDE > BackTrackerService::HitToAvgSimIDEs ( recob::Hit const& hit) {
211  //Removed until Lazy Rebuild works
212  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
213  return BackTracker::HitToAvgSimIDEs(hit);
214  }
215 
216  //---------------------------------------------------------------------
218  //Removed until Lazy Rebuild works
219  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
220  return BackTracker::HitToAvgSimIDEs(hit);
221  }
222 
223  //---------------------------------------------------------------------
224  const std::vector< const sim::IDE* > BackTrackerService::HitToSimIDEs_Ps (recob::Hit const& hit) {
225  //Removed until Lazy Rebuild works
226  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
227  return BackTracker::HitToSimIDEs_Ps(hit);
228  }
229 
230  //---------------------------------------------------------------------
231  const std::vector< const sim::IDE* > BackTrackerService::HitToSimIDEs_Ps (art::Ptr< recob::Hit > const& hit) {
232  //Removed until Lazy Rebuild works
233  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
234  return BackTracker::HitToSimIDEs_Ps(hit);
235  }
236 
237  //---------------------------------------------------------------------
238  const std::vector<double> BackTrackerService::SimIDEsToXYZ( std::vector< sim::IDE > const& ides)
239  {
240  //Removed until Lazy Rebuild works
241  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
242  return BackTracker::SimIDEsToXYZ(ides);
243  }
244 
245 
246  //---------------------------------------------------------------------
247  const std::vector<double> BackTrackerService::SimIDEsToXYZ( std::vector< const sim::IDE* > const& ide_Ps)
248  {
249  //Removed until Lazy Rebuild works
250  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
251  return BackTracker::SimIDEsToXYZ(ide_Ps);
252  }
253 
254 
255 
256  //---------------------------------------------------------------------
257  const std::vector<double> BackTrackerService::HitToXYZ(const recob::Hit& hit)
258  {
259  //Removed until Lazy Rebuild works
260  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
261  return BackTracker::HitToXYZ(hit);
262  }
263 
264 
265  //---------------------------------------------------------------------
266  const std::vector<double> BackTrackerService::HitToXYZ(art::Ptr<recob::Hit> const& hit)
267  {
268  //Removed until Lazy Rebuild works
269  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
270  return HitToXYZ(*hit);
271  }
272 
273 
274 
275  //---------------------------------------------------------------------
276  const double BackTrackerService::HitCollectionPurity( std::set<int> const& trackIds, std::vector< art::Ptr<recob::Hit> > const& hits)
277  {
278  //Removed until Lazy Rebuild works
279  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
280  return BackTracker::HitCollectionPurity(trackIds, hits);
281  }
282 
283 
284  //---------------------------------------------------------------------
285  const double BackTrackerService::HitChargeCollectionPurity( std::set<int> const& trackIds, std::vector< art::Ptr<recob::Hit> > const& hits)
286  {
287  //Removed until Lazy Rebuild works
288  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
290  }
291 
292 
293 
294  //---------------------------------------------------------------------
295  const double BackTrackerService::HitCollectionEfficiency( std::set<int> const& trackIds, std::vector< art::Ptr<recob::Hit> > const& hits, std::vector< art::Ptr<recob::Hit> > const& allhits, geo::View_t const& view)
296  {
297  //Removed until Lazy Rebuild works
298  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
299  return BackTracker::HitCollectionEfficiency(trackIds, hits, allhits, view);
300  }
301 
302 
303 
304  //---------------------------------------------------------------------
305  const double BackTrackerService::HitChargeCollectionEfficiency( std::set<int> trackIds, std::vector< art::Ptr<recob::Hit> > const& hits, std::vector< art::Ptr<recob::Hit> > const& allhits, geo::View_t const& view)
306  {
307  //Removed until Lazy Rebuild works
308  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
309  return BackTracker::HitChargeCollectionEfficiency(trackIds, hits, allhits, view);
310  }
311 
312 
313 
314  //---------------------------------------------------------------------
316  {
317  //Removed until Lazy Rebuild works
318  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
320  }
321 
322 
323  //---------------------------------------------------------------------
324  const std::set<int> BackTrackerService::GetSetOfEveIds()
325  {
326  //Removed until Lazy Rebuild works
327  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
329  }
330 
331 
332 
333  //---------------------------------------------------------------------
335  {
336  //Removed until Lazy Rebuild works
337  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
339  }
340 
341 
342  //---------------------------------------------------------------------
344  {
345  //Removed until Lazy Rebuild works
346  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
348  }
349 
350  //---------------------------------------------------------------------
352  if( !this->priv_CanRun(*fEvt)) { this->priv_PrepFailed(); }
354  }
355 
356  //---------------------------------------------------------------------
357  const std::vector< art::Ptr< recob::Hit > > BackTrackerService::SpacePointToHits_Ps(art::Ptr<recob::SpacePoint> const& spt) {
358  //Note, this function is goofy in that it doesn't use the hits prepared by the module. That should likely be changed to make things more uniform.
359  if( !this->priv_CanRun(*fEvt)) { this->priv_PrepFailed(); }
361  }
362 
363  //---------------------------------------------------------------------
364  const std::vector< double > BackTrackerService::SpacePointToXYZ( art::Ptr< recob::SpacePoint > const& spt) {
365  if( !this->priv_CanRun(*fEvt)) { this->priv_PrepFailed(); }
366  return BackTracker::SpacePointToXYZ(spt, *fEvt);
367  }
368 
370 
371 
372 }//end namespace cheat
const std::vector< std::vector< art::Ptr< recob::Hit > > > TrackIdsToHits_Ps(std::vector< int > const &tkIds, std::vector< art::Ptr< recob::Hit > > const &hitsIn)
const std::vector< double > SpacePointHitsToWeightedXYZ(std::vector< art::Ptr< recob::Hit >> const &hits) const
Definition: BackTracker.cc:496
const std::vector< double > SimIDEsToXYZ(std::vector< sim::IDE > const &ides)
Utilities related to art service access.
void PrepSimChannels(const Evt &evt)
const double HitChargeCollectionEfficiency(std::set< int > trackIds, std::vector< art::Ptr< recob::Hit > > const &hits, std::vector< art::Ptr< recob::Hit > > const &allhits, geo::View_t const &view)
const std::vector< double > HitToXYZ(const recob::Hit &hit)
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
T::provider_type const * providerFrom()
Returns a constant pointer to the provider of specified service.
Definition: ServiceUtil.h:77
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
const std::set< int > GetSetOfEveIds() const
Definition: BackTracker.h:148
const std::vector< sim::TrackIDE > ChannelToTrackIDEs(raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time) const
Definition: BackTracker.cc:112
const std::set< int > GetSetOfEveIds()
const art::Ptr< sim::SimChannel > FindSimChannel(raw::ChannelID_t channel)
const std::vector< double > SpacePointToXYZ(art::Ptr< recob::SpacePoint > const &spt)
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit) const
Definition: BackTracker.cc:161
const std::vector< const sim::IDE * > HitToSimIDEs_Ps(recob::Hit const &hit)
const double HitCollectionEfficiency(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits, std::vector< art::Ptr< recob::Hit > > const &allhits, geo::View_t const &view) const
Definition: BackTracker.cc:406
const std::vector< int > HitToTrackIds(recob::Hit const &hit) const
Definition: BackTracker.cc:171
const std::set< int > GetSetOfTrackIds()
const double HitChargeCollectionPurity(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits)
const std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id)
bool CanRun(const Evt &evt)
Definition: BackTracker.h:71
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Access the description of detector geometry.
const std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
Definition: BackTracker.cc:57
const std::vector< art::Ptr< recob::Hit > > SpacePointToHits_Ps(art::Ptr< recob::SpacePoint > const &spt)
void hits()
Definition: readHits.C:15
const std::vector< int > HitToTrackIds(recob::Hit const &hit)
void Rebuild(const art::Event &evt)
BackTrackerService(const fhicl::ParameterSet &pSet, art::ActivityRegistry &reg)
art::Ptr< sim::SimChannel > FindSimChannel(raw::ChannelID_t channel) const
Definition: BackTracker.cc:99
parameter set interface
void priv_PrepSimChannels(const art::Event &evt)
const std::vector< art::Ptr< recob::Hit > > SpacePointToHits_Ps(art::Ptr< recob::SpacePoint > const &spt, const Evt &evt) const
const std::vector< double > HitToXYZ(const recob::Hit &hit) const
Definition: BackTracker.cc:367
std::vector< std::vector< art::Ptr< recob::Hit > > > TrackIdsToHits_Ps(std::vector< int > const &tkIds, std::vector< art::Ptr< recob::Hit > > const &hitsIn) const
Definition: BackTracker.cc:225
const double HitChargeCollectionPurity(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits) const
Definition: BackTracker.cc:389
const std::vector< const sim::IDE * > HitToSimIDEs_Ps(recob::Hit const &hit) const
Definition: BackTracker.cc:275
const std::vector< sim::TrackIDE > HitToEveTrackIDEs(recob::Hit const &hit) const
Definition: BackTracker.cc:181
General LArSoft Utilities.
const double HitCollectionEfficiency(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits, std::vector< art::Ptr< recob::Hit > > const &allhits, geo::View_t const &view)
const std::vector< double > SpacePointHitsToWeightedXYZ(std::vector< art::Ptr< recob::Hit >> const &hits)
Detector simulation of raw signals on wires.
const std::vector< art::Ptr< sim::SimChannel > > & SimChannels() const
Definition: BackTracker.h:89
bool priv_CanRun(const art::Event &evt)
void priv_PrepEvent(const art::Event &evt)
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:26
const std::vector< double > SpacePointToXYZ(art::Ptr< recob::SpacePoint > const &spt, const Evt &evt) const
const double HitChargeCollectionEfficiency(std::set< int > trackIds, std::vector< art::Ptr< recob::Hit > > const &hits, std::vector< art::Ptr< recob::Hit > > const &allhits, geo::View_t const &view) const
Definition: BackTracker.cc:438
const double HitCollectionPurity(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits)
LArSoft-specific namespace.
const std::vector< sim::TrackIDE > HitToEveTrackIDEs(recob::Hit const &hit)
const std::set< int > GetSetOfTrackIds() const
Definition: BackTracker.h:147
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
const std::vector< art::Ptr< recob::Hit > > TrackIdToHits_Ps(const int &tkId, std::vector< art::Ptr< recob::Hit > > const &hitsIn)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
const std::vector< sim::IDE > HitToAvgSimIDEs(recob::Hit const &hit) const
Definition: BackTracker.cc:263
const std::vector< double > SimIDEsToXYZ(std::vector< sim::IDE > const &ides) const
Definition: BackTracker.cc:338
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
Namespace collecting geometry-related classes utilities.
const std::vector< art::Ptr< sim::SimChannel > > & SimChannels()
std::vector< art::Ptr< recob::Hit > > TrackIdToHits_Ps(const int &tkId, std::vector< art::Ptr< recob::Hit > > const &hitsIn) const
Definition: BackTracker.cc:202
const std::vector< sim::TrackIDE > ChannelToTrackIDEs(raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time)
const double HitCollectionPurity(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits) const
Definition: BackTracker.cc:373
const std::vector< sim::IDE > HitToAvgSimIDEs(recob::Hit const &hit)
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33