1 ///////////////////////////////////////////////////////////////////////////
2 // \author jason.stock@mines.sdsmt.edu
4 // Based on the original BackTracker by brebel@fnal.gov
6 ////////////////////////////////////////////////////////////////////////////
8 #include "canvas/Persistency/Common/FindManyP.h"
9 #include "lardataobj/RecoBase/SpacePoint.h"
13 //--------------------------------------------------------------------
14 template <typename Evt> // DO NOT USE THIS FUNCTION FROM WITHIN ART! The
15 // BackTrackerService is designed to impliment these
16 // methods as cleanly as possible within the art
17 // framework. This is intended for gallery users.
18 void BackTracker::PrepEvent(const Evt& evt)
20 if (!(this->CanRun(evt))) {
21 throw cet::exception("BackTracker") << "BackTracker cannot function. "
22 << "Is this file real data?";
25 this->PrepSimChannels(evt);
26 //this->PrepAllHitList ( evt ); //This line temporarily commented out until I figure out how I want PrepAllHitList to work.
29 //--------------------------------------------------------------------
30 template <typename Evt>
31 void BackTracker::PrepSimChannels(const Evt& evt)
33 if (this->SimChannelsReady()) { return; }
34 // The SimChannels list needs to be built.
35 const auto& simChannelsHandle =
36 evt.template getValidHandle<std::vector<sim::SimChannel>>(fSimChannelModuleLabel);
38 art::fill_ptr_vector(fSimChannels, simChannelsHandle);
40 auto comparesclambda = [](art::Ptr<sim::SimChannel> a, art::Ptr<sim::SimChannel> b) {
41 return (a->Channel() < b->Channel());
43 if (!std::is_sorted(fSimChannels.begin(), fSimChannels.end(), comparesclambda))
44 std::sort(fSimChannels.begin(), fSimChannels.end(), comparesclambda);
47 //--------------------------------------------------------------------
48 /* template<typename Evt>
49 void BackTracker::PrepAllHitList( const Evt& evt){
50 if(this->AllHitListReady()){return;}
51 const auto& allHitsHandle = evt.template
52 getValidHandle<std::vector<recob::Hit>>(fHitLabel);
53 art::fill_ptr_vector(fAllHitList, allHitsHandle);
56 //--------------------------------------------------------------------
57 template <typename Evt>
58 std::vector<art::Ptr<recob::Hit>> BackTracker::SpacePointToHits_Ps(
59 art::Ptr<recob::SpacePoint> const& spt,
62 std::vector<art::Ptr<recob::SpacePoint>>
63 spv; // This method needs to be rethought. For now I am directly
64 // implimenting it as found in the previous backtracker.
66 art::FindManyP<recob::Hit> fmh(spv, evt, fHitLabel);
67 std::vector<art::Ptr<recob::Hit>> hitv = fmh.at(0);
71 //--------------------------------------------------------------------
72 template <typename Evt>
73 std::vector<double> BackTracker::SpacePointToXYZ(detinfo::DetectorClocksData const& clockData,
74 art::Ptr<recob::SpacePoint> const& spt,
77 std::vector<art::Ptr<recob::Hit>> hits = this->SpacePointToHits_Ps(spt, evt);
78 return this->SpacePointHitsToWeightedXYZ(clockData, hits);