LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
BackTracker.tcc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 //
3 // \file BackTracker.tcc
4 // \brief Template functions needed by the BackTracker service in order to connect truth information with reconstruction. Templates are for functions that require the event (as the "event" is different for art and Gallery).
5 //
6 // \author jason.stock@mines.sdsmt.edu
7 //
8 // Based on the original BackTracker by brebel@fnal.gov
9 //
10 ////////////////////////////////////////////////////////////////////////////
11 
12 namespace cheat{
13 
14  //--------------------------------------------------------------------
15  template<typename Evt> //DO NOT USE THIS FUNCTION FROM WITHIN ART! The BackTrackerService is designed to impliment these methods as cleanly as possible within the art framework. This is intended for gallery users.
16  void BackTracker::PrepEvent (const Evt& evt ){
17  if( !( this->CanRun( evt ) ) ){
18  throw cet::exception("BackTracker")
19  << "BackTracker cannot function. "
20  << "Is this file real data?";
21  }
22  fSimChannels.clear();
23  // fAllHitList.clear();
24  this->PrepSimChannels( evt );
25  //this->PrepAllHitList ( evt ); //This line temporarily commented out until I figure out how I want PrepAllHitList to work.
26 
27  }
28 
29  //--------------------------------------------------------------------
30  template<typename Evt>
31  void BackTracker::PrepSimChannels (const Evt& evt){
32  if(this->SimChannelsReady()){ return;}
33  //The SimChannels list needs to be built.
34  const auto& simChannelsHandle = evt.template getValidHandle<std::vector<sim::SimChannel>>(fG4ModuleLabel);
35  if(simChannelsHandle.failedToGet()){
36  /* mf::LogWarning("BackTracker") << "failed to get handle to simb::MCParticle from "
37  << fG4ModuleLabel
38  << ", return";*/ //This is now silent as it is expected to happen every generation run. It is also temporary while we wait for
39  return;
40  }
41 
42  art::fill_ptr_vector(fSimChannels, simChannelsHandle);
43 
44  auto comparesclambda = [](art::Ptr<sim::SimChannel> a, art::Ptr<sim::SimChannel> b) {return(a->Channel()<b->Channel());};
45  if (!std::is_sorted(fSimChannels.begin(),fSimChannels.end(),comparesclambda)) std::sort(fSimChannels.begin(),fSimChannels.end(),comparesclambda);
46 
47  return;
48 
49  }
50 
51  //--------------------------------------------------------------------
52  /* template<typename Evt>
53  void BackTracker::PrepAllHitList( const Evt& evt){
54  if(this->AllHitListReady()){return;}
55  const auto& allHitsHandle = evt.template getValidHandle<std::vector<recob::Hit>>(fHitLabel);
56  art::fill_ptr_vector(fAllHitList, allHitsHandle);
57  }
58  */
59  //--------------------------------------------------------------------
60  template<typename Evt>
61  const std::vector< art::Ptr< recob::Hit > > BackTracker::SpacePointToHits_Ps(art::Ptr<recob::SpacePoint> const& spt, const Evt& evt) const{
62  std::vector<art::Ptr<recob::SpacePoint>> spv; //This method needs to be rethought. For now I am directly implimenting it as found in the previous backtracker.
63  spv.push_back(spt);
64  art::FindManyP<recob::Hit> fmh(spv, evt, fHitLabel);
65  std::vector< art::Ptr<recob::Hit> > hitv = fmh.at(0);
66  return hitv;
67  }
68 
69  //--------------------------------------------------------------------
70  template<typename Evt>
71  const std::vector< double > BackTracker::SpacePointToXYZ( art::Ptr< recob::SpacePoint > const& spt, const Evt& evt ) const{
72  std::vector<art::Ptr<recob::Hit>> hits=this->SpacePointToHits_Ps(spt, evt);
73  return this->SpacePointHitsToWeightedXYZ(hits);
74  }
75 
76 }//end namespace