Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
Shower3DCylinderTrackHitFinder_tool.cc
Go to the documentation of this file.
1//############################################################################
2//### Name: Shower3DCylinderTrackHitFinder ###
3//### Author: Ed Tyley ###
4//### Date: 14.06.19 ###
5//### Description: Tool for finding the initial shower track using 3D ###
6//### spacepoints within a cylinder along the shower ###
7//### direction. fcl parameters define cylinder dimensions ###
8//############################################################################
9
10//Framework Includes
11#include "art/Utilities/ToolMacros.h"
12
13//LArSoft Includes
14#include "lardataobj/RecoBase/Hit.h"
15#include "lardataobj/RecoBase/PFParticle.h"
16#include "lardataobj/RecoBase/SpacePoint.h"
19
20namespace ShowerRecoTools {
21
23 public:
24 Shower3DCylinderTrackHitFinder(const fhicl::ParameterSet& pset);
25
26 //Generic Track Finder
27 int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
28 art::Event& Event,
29 reco::shower::ShowerElementHolder& ShowerEleHolder) override;
30
31 private:
32 std::vector<art::Ptr<recob::SpacePoint>> FindTrackSpacePoints(
33 std::vector<art::Ptr<recob::SpacePoint>>& spacePoints,
34 geo::Point_t const& showerStartPosition,
35 geo::Vector_t const& showerDirection) const;
36
37 //Fcl paramters
38 float fMaxProjectionDist; //Maximum projection along shower direction.
39 float fMaxPerpendicularDist; //Maximum perpendicular distance, radius of cylinder
40 bool fForwardHitsOnly; //Only take hits downstream of shower vertex
41 //(projection>0)
42
43 art::InputTag fPFParticleLabel;
45
50 };
51
53 : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
54 , fMaxProjectionDist(pset.get<float>("MaxProjectionDist"))
55 , fMaxPerpendicularDist(pset.get<float>("MaxPerpendicularDist"))
56 , fForwardHitsOnly(pset.get<bool>("ForwardHitsOnly"))
57 , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
58 , fVerbose(pset.get<int>("Verbose"))
59 , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
60 , fInitialTrackHitsOutputLabel(pset.get<std::string>("InitialTrackHitsOutputLabel"))
61 , fInitialTrackSpacePointsOutputLabel(
62 pset.get<std::string>("InitialTrackSpacePointsOutputLabel"))
63 , fShowerDirectionInputLabel(pset.get<std::string>("ShowerDirectionInputLabel"))
64 {}
65
67 const art::Ptr<recob::PFParticle>& pfparticle,
68 art::Event& Event,
69 reco::shower::ShowerElementHolder& ShowerEleHolder)
70 {
71
72 //This is all based on the shower vertex being known. If it is not lets not do the track
73 if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
74 if (fVerbose)
75 mf::LogError("Shower3DCylinderTrackHitFinder")
76 << "Start position not set, returning " << std::endl;
77 return 1;
78 }
79 if (!ShowerEleHolder.CheckElement("ShowerDirection")) {
80 if (fVerbose)
81 mf::LogError("Shower3DCylinderTrackHitFinder")
82 << "Direction not set, returning " << std::endl;
83 return 1;
84 }
85
86 geo::Point_t ShowerStartPosition = {-999, -999, -999};
87 ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, ShowerStartPosition);
88
89 geo::Vector_t ShowerDirection = {-999, -999, -999};
90 ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
91
92 // Get the assocated pfParicle Handle
93 auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
94
95 // Get the spacepoint - PFParticle assn
96 const art::FindManyP<recob::SpacePoint>& fmspp =
97 ShowerEleHolder.GetFindManyP<recob::SpacePoint>(pfpHandle, Event, fPFParticleLabel);
98
99 // Get the spacepoints
100 auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
101
102 // Get the hits associated with the space points
103 const art::FindManyP<recob::Hit>& fmhsp =
104 ShowerEleHolder.GetFindManyP<recob::Hit>(spHandle, Event, fPFParticleLabel);
105
106 // Get the SpacePoints
107 std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.key());
108
109 //We cannot progress with no spacepoints.
110 if (spacePoints.empty()) {
111 if (fVerbose)
112 mf::LogError("Shower3DCylinderTrackHitFinder")
113 << "No space points, returning " << std::endl;
114 return 1;
115 }
116
117 // Order the spacepoints
119 spacePoints, ShowerStartPosition, ShowerDirection);
120
121 // Get only the space points from the track
122 auto trackSpacePoints = FindTrackSpacePoints(spacePoints, ShowerStartPosition, ShowerDirection);
123
124 // Get the hits associated to the space points and seperate them by planes
125 std::vector<art::Ptr<recob::Hit>> trackHits;
126 for (auto const& spacePoint : trackSpacePoints) {
127 const art::Ptr<recob::Hit> hit = fmhsp.at(spacePoint.key()).front();
128 // const art::Ptr<recob::Hit> hit = fohsp.at(spacePoint.key());
129 trackHits.push_back(hit);
130 }
131
132 ShowerEleHolder.SetElement(trackHits, fInitialTrackHitsOutputLabel);
133 ShowerEleHolder.SetElement(trackSpacePoints, fInitialTrackSpacePointsOutputLabel);
134
135 return 0;
136 }
137
138 std::vector<art::Ptr<recob::SpacePoint>> Shower3DCylinderTrackHitFinder::FindTrackSpacePoints(
139 std::vector<art::Ptr<recob::SpacePoint>>& spacePoints,
140 geo::Point_t const& showerStartPosition,
141 geo::Vector_t const& showerDirection) const
142 {
143
144 // Make a vector to hold the output space points
145 std::vector<art::Ptr<recob::SpacePoint>> trackSpacePoints;
146
147 for (const auto& spacePoint : spacePoints) {
148 // Calculate the projection along direction and perpendicular distance
149 // from "axis" of shower TODO: change alg to return a pair for efficiency
151 spacePoint, showerStartPosition, showerDirection);
153 spacePoint, showerStartPosition, showerDirection, proj);
154
155 if (fForwardHitsOnly && proj < 0) continue;
156
157 if (std::abs(proj) < fMaxProjectionDist && std::abs(perp) < fMaxPerpendicularDist)
158 trackSpacePoints.push_back(spacePoint);
159 }
160 return trackSpacePoints;
161 }
162
163}
164
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition IShowerTool.h:82
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
std::vector< art::Ptr< recob::SpacePoint > > FindTrackSpacePoints(std::vector< art::Ptr< recob::SpacePoint > > &spacePoints, geo::Point_t const &showerStartPosition, geo::Vector_t const &showerDirection) const
int GetElement(const std::string &Name, T &Element) const
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
bool CheckElement(const std::string &Name) const
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint > > &showersps, geo::Point_t const &vertex, geo::Vector_t const &direction) const
double SpacePointPerpendicular(art::Ptr< recob::SpacePoint > const &sp, geo::Point_t const &vertex, geo::Vector_t const &direction) const
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, geo::Point_t const &vertex, geo::Vector_t const &direction) const