LArSoft  v07_13_02
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  //failedToGet for a valid handle will always be false.
36 // if(simChannelsHandle.failedToGet()){
37 // /* mf::LogWarning("BackTracker") << "failed to get handle to simb::MCParticle from "
38 // << fG4ModuleLabel
39 // << ", return";*/ //This is now silent as it is expected to happen every generation run. It is also temporary while we wait for
40 // return;
41 // }
42 
43  art::fill_ptr_vector(fSimChannels, simChannelsHandle);
44 
45  auto comparesclambda = [](art::Ptr<sim::SimChannel> a, art::Ptr<sim::SimChannel> b) {return(a->Channel()<b->Channel());};
46  if (!std::is_sorted(fSimChannels.begin(),fSimChannels.end(),comparesclambda)) std::sort(fSimChannels.begin(),fSimChannels.end(),comparesclambda);
47 
48  return;
49 
50  }
51 
52  //--------------------------------------------------------------------
53  /* template<typename Evt>
54  void BackTracker::PrepAllHitList( const Evt& evt){
55  if(this->AllHitListReady()){return;}
56  const auto& allHitsHandle = evt.template getValidHandle<std::vector<recob::Hit>>(fHitLabel);
57  art::fill_ptr_vector(fAllHitList, allHitsHandle);
58  }
59  */
60  //--------------------------------------------------------------------
61  template<typename Evt>
62  const std::vector< art::Ptr< recob::Hit > > BackTracker::SpacePointToHits_Ps(art::Ptr<recob::SpacePoint> const& spt, const Evt& evt) const{
63  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.
64  spv.push_back(spt);
65  art::FindManyP<recob::Hit> fmh(spv, evt, fHitLabel);
66  std::vector< art::Ptr<recob::Hit> > hitv = fmh.at(0);
67  return hitv;
68  }
69 
70  //--------------------------------------------------------------------
71  template<typename Evt>
72  const std::vector< double > BackTracker::SpacePointToXYZ( art::Ptr< recob::SpacePoint > const& spt, const Evt& evt ) const{
73  std::vector<art::Ptr<recob::Hit>> hits=this->SpacePointToHits_Ps(spt, evt);
74  return this->SpacePointHitsToWeightedXYZ(hits);
75  }
76 
77 }//end namespace