BackTrackerService_service.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // \file BackTrackerService_service.cc
4 // \brief A service for backtracking reconstruction information to its truth
5 // information
6 //
7 // \author jason.stock@mines.sdsmt.edu
8 // Based on the original BackTracker by Brian Rebel (brebel@fnal.gov)
9 //
10 ////////////////////////////////////////////////////////////////////////////////////////
11 
12 #include <vector>
13 
15 
20 
23 
24 namespace cheat {
25 
26  //---------------------------------------------------------------------
29  : BackTracker(pSet.get<fhicl::ParameterSet>("BackTracker"),
31  lar::providerFrom<geo::Geometry>())
32  {
34  }
35 
36  //---------------------------------------------------------------------
38  : BackTracker(config.BackTrackerTable(),
40  lar::providerFrom<geo::Geometry>())
41  {
42  // This line is only to be included until art/LArSoft discussion about lazy
43  // rebuild can be completed.
45  }
46 
47  ////////////////////////////////////////////////
48  //////////Event Rebuild Implimentation//////////
49  /// This section contains the implimentation ///
50  /// of all Prep templates from the service ///
51  /// provider. ///
52  ////////////////////////////////////////////////
53 
54  //-----Temp rebuild function.
55  void
57  {
59  }
60 
61  //---------------------------------------------------------------------
62  void
64  {
65  fEvt = &evt;
67  if (!this->priv_CanRun(evt)) { return; }
68  this->priv_PrepSimChannels(evt);
69  fEvt = nullptr; // don't save the pointer because it will be useless after this
70  // anyways. I want to make sure calls at the wrong time crash.
71  }
72 
73  //---------------------------------------------------------------------
74  bool
76  {
77  return BackTracker::CanRun(evt);
78  }
79 
80  //---------------------------------------------------------------------
81  void
83  {
84  throw cet::exception("BackTrackerService")
85  << "The called Prep Function failed. This is most likely due "
86  << "to a BackTracker function being used on a file that is real data.";
87  }
88 
89  //---------------------------------------------------------------------
90  void
92  {
93  if (!this->priv_CanRun(evt)) { this->priv_PrepFailed(); }
94  if (this->priv_SimChannelsReady()) { return; }
95  try {
97  }
98  catch (...) {
99  mf::LogWarning("BackTrackerService")
100  << "Rebuild failed to get the SimChannels. This is expected when running on a generation "
101  "or simulation step.";
102  }
103  }
104 
105  //---------------------------------------------------------------------
106  /* void BackTrackerService::priv_PrepAllHitList(){
107  if( !this->priv_CanRun(*fEvt)) { this->priv_PrepFailed(); }
108  if( this->priv_AllHitListReady() ){ return; }
109  BackTracker::PrepAllHitList(*fEvt);
110  }
111  */
112  /////////////////////////////////////////////
113  // End of the Event Rebuild Implimentation //
114  /////////////////////////////////////////////
115 
116  ///////////////////////////////////////////////
117  /////BackTracking Functions Implimentation/////
118  // This section contains the implimentation //
119  // of all BackTrackerService end user //
120  // functionality //
121  ///////////////////////////////////////////////
122 
123  //---------------------------------------------------------------------
124  const std::vector<art::Ptr<sim::SimChannel>>&
126  {
127  // Removed until Lazy Rebuild works
128  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
129  return BackTracker::SimChannels();
130  }
131 
132  //---------------------------------------------------------------------
133  std::vector<const sim::IDE*>
135  {
136  // Removed until Lazy Rebuild works
137  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
139  }
140 
141  //---------------------------------------------------------------------
142  std::vector<const sim::IDE*>
143  BackTrackerService::TrackIdToSimIDEs_Ps(int const& id, const geo::View_t view) const
144  {
145  // Removed until Lazy Rebuild works
146  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
147  return BackTracker::TrackIdToSimIDEs_Ps(id, view);
148  }
149 
150  //---------------------------------------------------------------------
153  {
154  // Removed until Lazy Rebuild works
155  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
156  return BackTracker::FindSimChannel(channel);
157  }
158 
159  //---------------------------------------------------------------------
160  std::vector<sim::TrackIDE>
163  const double hit_start_time,
164  const double hit_end_time) const
165  {
166  // Removed until Lazy Rebuild works
167  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
168  return BackTracker::ChannelToTrackIDEs(clockData, channel, hit_start_time, hit_end_time);
169  }
170 
171  //---------------------------------------------------------------------
172  std::vector<sim::TrackIDE>
174  recob::Hit const& hit) const
175  {
176  // Removed until Lazy Rebuild works
177  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
178  return BackTracker::HitToTrackIDEs(clockData, hit);
179  }
180 
181  //---------------------------------------------------------------------
182  std::vector<sim::TrackIDE>
184  art::Ptr<recob::Hit> const& hit) const
185  {
186  // Removed until Lazy Rebuild works
187  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
188  return BackTracker::HitToTrackIDEs(clockData, hit);
189  }
190 
191  //---------------------------------------------------------------------
192  std::vector<int>
194  recob::Hit const& hit) const
195  {
196  // Removed until Lazy Rebuild works
197  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
198  return BackTracker::HitToTrackIds(clockData, hit);
199  }
200 
201  //---------------------------------------------------------------------
202  std::vector<sim::TrackIDE>
204  recob::Hit const& hit) const
205  {
206  // Removed until Lazy Rebuild works
207  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
208  return BackTracker::HitToEveTrackIDEs(clockData, hit);
209  }
210 
211  //---------------------------------------------------------------------
212  std::vector<sim::TrackIDE>
214  art::Ptr<recob::Hit> const& hit) const
215  {
216  // Removed until Lazy Rebuild works
217  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
218  return BackTracker::HitToEveTrackIDEs(clockData, hit);
219  }
220 
221  //---------------------------------------------------------------------
222  std::vector<art::Ptr<recob::Hit>>
224  const int tkId,
225  std::vector<art::Ptr<recob::Hit>> const& hitsIn) const
226  {
227  // Removed until Lazy Rebuild works
228  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
229  return BackTracker::TrackIdToHits_Ps(clockData, tkId, hitsIn);
230  }
231 
232  //---------------------------------------------------------------------
233  /* const std::vector < art::Ptr < recob::Hit > >
234  BackTrackerService::TrackIdToHits_Ps( const int& tkId ) {
235  //Removed until Lazy Rebuild works
236  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
237  // if(!this->priv_AllHitListReady()){this->priv_PrepAllHitList();}
238  return BackTracker::TrackIdToHits_Ps( tkId);
239  }*/ //I can't support this functino and caching all the hits without lazy implimentation
240 
241  //---------------------------------------------------------------------
242  std::vector<std::vector<art::Ptr<recob::Hit>>>
244  std::vector<int> const& tkIds,
245  std::vector<art::Ptr<recob::Hit>> const& hitsIn) const
246  {
247  // Removed until Lazy Rebuild works
248  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
249  return BackTracker::TrackIdsToHits_Ps(clockData, tkIds, hitsIn);
250  }
251 
252  //---------------------------------------------------------------------
253  std::vector<sim::IDE>
255  recob::Hit const& hit) const
256  {
257  // Removed until Lazy Rebuild works
258  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
259  return BackTracker::HitToAvgSimIDEs(clockData, hit);
260  }
261 
262  //---------------------------------------------------------------------
263  std::vector<sim::IDE>
266  {
267  // Removed until Lazy Rebuild works
268  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
269  return BackTracker::HitToAvgSimIDEs(clockData, hit);
270  }
271 
272  //---------------------------------------------------------------------
273  std::vector<const sim::IDE*>
275  recob::Hit const& hit) const
276  {
277  //Removed until Lazy Rebuild works
278  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
279  return BackTracker::HitToSimIDEs_Ps(clockData, hit);
280  }
281 
282  //---------------------------------------------------------------------
283  std::vector<const sim::IDE*>
285  art::Ptr<recob::Hit> const& hit) const
286  {
287  //Removed until Lazy Rebuild works
288  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
289  return BackTracker::HitToSimIDEs_Ps(clockData, hit);
290  }
291 
292  //---------------------------------------------------------------------
293  std::vector<double>
294  BackTrackerService::SimIDEsToXYZ(std::vector<sim::IDE> const& ides) const
295  {
296  // Removed until Lazy Rebuild works
297  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
298  return BackTracker::SimIDEsToXYZ(ides);
299  }
300 
301  //---------------------------------------------------------------------
302  std::vector<double>
303  BackTrackerService::SimIDEsToXYZ(std::vector<const sim::IDE*> const& ide_Ps) const
304  {
305  // Removed until Lazy Rebuild works
306  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
307  return BackTracker::SimIDEsToXYZ(ide_Ps);
308  }
309 
310  //---------------------------------------------------------------------
311  std::vector<double>
313  const recob::Hit& hit) const
314  {
315  // Removed until Lazy Rebuild works
316  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
317  return BackTracker::HitToXYZ(clockData, hit);
318  }
319 
320  //---------------------------------------------------------------------
321  std::vector<double>
323  art::Ptr<recob::Hit> const& hit) const
324  {
325  // Removed until Lazy Rebuild works
326  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
327  return HitToXYZ(clockData, *hit);
328  }
329 
330  //---------------------------------------------------------------------
331  double
333  std::set<int> const& trackIds,
334  std::vector<art::Ptr<recob::Hit>> const& hits) const
335  {
336  // Removed until Lazy Rebuild works
337  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
338  return BackTracker::HitCollectionPurity(clockData, trackIds, hits);
339  }
340 
341  //---------------------------------------------------------------------
342  double
344  std::set<int> const& trackIds,
345  std::vector<art::Ptr<recob::Hit>> const& hits) const
346  {
347  // Removed until Lazy Rebuild works
348  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
349  return BackTracker::HitChargeCollectionPurity(clockData, trackIds, hits);
350  }
351 
352  //---------------------------------------------------------------------
353  double
355  std::set<int> const& trackIds,
356  std::vector<art::Ptr<recob::Hit>> const& hits,
357  std::vector<art::Ptr<recob::Hit>> const& allhits,
358  geo::View_t const& view) const
359  {
360  // Removed until Lazy Rebuild works
361  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
362  return BackTracker::HitCollectionEfficiency(clockData, trackIds, hits, allhits, view);
363  }
364 
365  //---------------------------------------------------------------------
366  double
368  detinfo::DetectorClocksData const& clockData,
369  std::set<int> const& trackIds,
370  std::vector<art::Ptr<recob::Hit>> const& hits,
371  std::vector<art::Ptr<recob::Hit>> const& allhits,
372  geo::View_t const& view) const
373  {
374  //Removed until Lazy Rebuild works
375  //if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
376  return BackTracker::HitChargeCollectionEfficiency(clockData, trackIds, hits, allhits, view);
377  }
378 
379  //---------------------------------------------------------------------
380  std::set<int>
382  {
383  // Removed until Lazy Rebuild works
384  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
386  }
387 
388  //---------------------------------------------------------------------
389  std::set<int>
391  {
392  // Removed until Lazy Rebuild works
393  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
395  }
396 
397  //---------------------------------------------------------------------
398  std::set<int>
400  std::vector<art::Ptr<recob::Hit>> const& hits) const
401  {
402  // Removed until Lazy Rebuild works
403  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
404  return BackTracker::GetSetOfTrackIds(clockData, hits);
405  }
406 
407  //---------------------------------------------------------------------
408  std::set<int>
410  std::vector<art::Ptr<recob::Hit>> const& hits) const
411  {
412  // Removed until Lazy Rebuild works
413  // if(!this->priv_SimChannelsReady()){this->priv_PrepSimChannels();}
414  return BackTracker::GetSetOfEveIds(clockData, hits);
415  }
416 
417  //---------------------------------------------------------------------
418  std::vector<double>
420  detinfo::DetectorClocksData const& clockData,
421  std::vector<art::Ptr<recob::Hit>> const& hits) const
422  {
423  // if( !this->priv_CanRun(*fEvt)) { this->priv_PrepFailed(); }
424  return BackTracker::SpacePointHitsToWeightedXYZ(clockData, hits);
425  }
426 
427  //---------------------------------------------------------------------
428  std::vector<art::Ptr<recob::Hit>>
430  {
431  // Note, this function is goofy in that it doesn't use the hits prepared by
432  // the module. That should likely be changed to make things more uniform.
433  // if( !this->priv_CanRun(*fEvt)) { this->priv_PrepFailed(); }
434  if (!fEvt) {
435  throw cet::exception("BackTrackerService")
436  << "This function is not yet implimented pending the implimentation of "
437  "backtracker lazy loading.";
438  }
440  }
441 
442  //---------------------------------------------------------------------
443  std::vector<double>
445  art::Ptr<recob::SpacePoint> const& spt) const
446  {
447  // if( !this->priv_CanRun(*fEvt)) { this->priv_PrepFailed(); }
448  if (!fEvt) {
449  throw cet::exception("BackTrackerService")
450  << "This function is not yet implimented pending the implimentation of "
451  "backtracker lazy loading.";
452  }
453  return BackTracker::SpacePointToXYZ(clockData, spt, *fEvt);
454  }
455 
457 
458 } // end namespace cheat
void PrepSimChannels(const Evt &evt)
std::vector< art::Ptr< recob::Hit > > TrackIdToHits_Ps(detinfo::DetectorClocksData const &clockData, int tkId, std::vector< art::Ptr< recob::Hit >> const &hitsIn) const
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
std::vector< std::vector< art::Ptr< recob::Hit > > > TrackIdsToHits_Ps(detinfo::DetectorClocksData const &clockData, std::vector< int > const &tkIds, std::vector< art::Ptr< recob::Hit >> const &hitsIn) const
Definition: BackTracker.cc:262
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::vector< art::Ptr< recob::Hit > > SpacePointToHits_Ps(art::Ptr< recob::SpacePoint > const &spt) const
double HitChargeCollectionPurity(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits) const
std::vector< sim::TrackIDE > HitToEveTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
Definition: BackTracker.cc:201
std::vector< double > SpacePointToXYZ(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::SpacePoint > const &spt, const Evt &evt) const
double HitCollectionEfficiency(detinfo::DetectorClocksData const &clockData, 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
struct vector vector
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
uint8_t channel
Definition: CRTFragment.hh:201
std::vector< double > HitToXYZ(detinfo::DetectorClocksData const &clockData, const recob::Hit &hit) const
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
Definition: BackTracker.cc:178
art framework interface to geometry description
std::vector< int > HitToTrackIds(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
std::vector< art::Ptr< recob::Hit > > SpacePointToHits_Ps(art::Ptr< recob::SpacePoint > const &spt, const Evt &evt) const
bool CanRun(const Evt &evt)
Definition: BackTracker.h:94
art::Ptr< sim::SimChannel > FindSimChannel(raw::ChannelID_t channel) const
void Rebuild(const art::Event &evt)
std::set< int > GetSetOfTrackIds() const
std::vector< double > HitToXYZ(detinfo::DetectorClocksData const &clockData, const recob::Hit &hit) const
Definition: BackTracker.cc:409
BackTrackerService(const fhicl::ParameterSet &pSet, art::ActivityRegistry &reg)
static Config * config
Definition: config.cpp:1054
art::Ptr< sim::SimChannel > FindSimChannel(raw::ChannelID_t channel) const
Returns the cached sim::SimChannel on the specified channel.
Definition: BackTracker.cc:122
double HitCollectionPurity(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits) const
std::vector< art::Ptr< recob::Hit > > TrackIdToHits_Ps(detinfo::DetectorClocksData const &clockData, int tkId, std::vector< art::Ptr< recob::Hit >> const &hitsIn) const
Definition: BackTracker.cc:235
void priv_PrepSimChannels(const art::Event &evt)
std::set< int > GetSetOfTrackIds() const
Definition: BackTracker.h:242
double HitCollectionPurity(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits) const
Definition: BackTracker.cc:417
std::vector< std::vector< art::Ptr< recob::Hit > > > TrackIdsToHits_Ps(detinfo::DetectorClocksData const &clockData, std::vector< int > const &tkIds, std::vector< art::Ptr< recob::Hit >> const &hitsIn) const
void priv_PrepEvent(const art::Event &evt, art::ScheduleContext)
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &, ScheduleContext)> sPreProcessEvent
Detector simulation of raw signals on wires.
const std::vector< art::Ptr< sim::SimChannel > > & SimChannels() const
Definition: BackTracker.h:120
std::set< int > GetSetOfEveIds() const
bool priv_CanRun(const art::Event &evt)
double HitChargeCollectionEfficiency(detinfo::DetectorClocksData const &clockData, 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
#define DEFINE_ART_SERVICE(svc)
std::vector< sim::TrackIDE > ChannelToTrackIDEs(detinfo::DetectorClocksData const &clockData, raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time) const
Definition: BackTracker.cc:131
std::set< int > GetSetOfEveIds() const
Definition: BackTracker.h:247
double HitChargeCollectionPurity(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits) const
Definition: BackTracker.cc:437
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:22
LArSoft-specific namespace.
Contains all timing reference information for the detector.
std::vector< int > HitToTrackIds(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
Definition: BackTracker.cc:188
std::vector< sim::IDE > HitToAvgSimIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
static ScheduleContext invalid()
std::vector< double > SpacePointHitsToWeightedXYZ(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit >> const &hits) const
std::vector< sim::TrackIDE > HitToEveTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double HitCollectionEfficiency(detinfo::DetectorClocksData const &clockData, 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:458
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
Definition: BackTracker.cc:63
std::vector< double > SimIDEsToXYZ(std::vector< sim::IDE > const &ides) const
const std::vector< art::Ptr< sim::SimChannel > > & SimChannels() const
T::provider_type const * providerFrom()
Returns a constant pointer to the provider of specified service.
Definition: ServiceUtil.h:63
std::vector< const sim::IDE * > HitToSimIDEs_Ps(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
std::vector< sim::IDE > HitToAvgSimIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
Definition: BackTracker.cc:305
LArSoft geometry interface.
Definition: ChannelGeo.h:16
std::vector< double > SpacePointToXYZ(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::SpacePoint > const &spt) const
std::vector< double > SimIDEsToXYZ(std::vector< sim::IDE > const &ides) const
Definition: BackTracker.cc:376
double HitChargeCollectionEfficiency(detinfo::DetectorClocksData const &clockData, 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:497
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::vector< sim::TrackIDE > ChannelToTrackIDEs(detinfo::DetectorClocksData const &clockData, raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time) const
std::vector< const sim::IDE * > HitToSimIDEs_Ps(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
Definition: BackTracker.cc:320
std::vector< double > SpacePointHitsToWeightedXYZ(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit >> const &hits) const
Definition: BackTracker.cc:566