LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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
12 
13 //LArSoft Includes
19 
20 namespace ShowerRecoTools {
21 
23  public:
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(
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 
44  int fVerbose;
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"))
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
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(
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 
158  trackSpacePoints.push_back(spacePoint);
159  }
160  return trackSpacePoints;
161  }
162 
163 }
164 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:160
Declaration of signal hit object.
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
constexpr auto abs(T v)
Returns the absolute value of the argument.
STL namespace.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
double SpacePointPerpendicular(art::Ptr< recob::SpacePoint > const &sp, geo::Point_t const &vertex, geo::Vector_t const &direction) const
parameter set interface
key_type key() const noexcept
Definition: Ptr.h:166
bool CheckElement(const std::string &Name) const
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
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, geo::Point_t const &vertex, geo::Vector_t const &direction) const
Detector simulation of raw signals on wires.
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:82
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &showersps, geo::Point_t const &vertex, geo::Vector_t const &direction) const
Float_t proj
Definition: plot.C:35
Definition: MVAAlg.h:12
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 >> &handle, const art::Event &evt, const art::InputTag &moduleTag)