All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
19 
20 namespace 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  TVector3& showerStartPosition,
35  TVector3& showerDirection);
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;
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"))
61  , fInitialTrackSpacePointsOutputLabel(
62  pset.get<std::string>("InitialTrackSpacePointsOutputLabel"))
63  , fShowerDirectionInputLabel(pset.get<std::string>("ShowerDirectionInputLabel"))
64  {}
65 
66  int
68  const art::Ptr<recob::PFParticle>& pfparticle,
69  art::Event& Event,
70  reco::shower::ShowerElementHolder& ShowerEleHolder)
71  {
72 
73  //This is all based on the shower vertex being known. If it is not lets not do the track
74  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
75  if (fVerbose)
76  mf::LogError("Shower3DCylinderTrackHitFinder")
77  << "Start position not set, returning " << std::endl;
78  return 1;
79  }
80  if (!ShowerEleHolder.CheckElement("ShowerDirection")) {
81  if (fVerbose)
82  mf::LogError("Shower3DCylinderTrackHitFinder")
83  << "Direction not set, returning " << std::endl;
84  return 1;
85  }
86 
87  TVector3 ShowerStartPosition = {-999, -999, -999};
88  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, ShowerStartPosition);
89 
90  TVector3 ShowerDirection = {-999, -999, -999};
91  ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
92 
93  // Get the assocated pfParicle Handle
94  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
95 
96  // Get the spacepoint - PFParticle assn
97  const art::FindManyP<recob::SpacePoint>& fmspp =
98  ShowerEleHolder.GetFindManyP<recob::SpacePoint>(pfpHandle, Event, fPFParticleLabel);
99 
100  // Get the spacepoints
101  auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
102 
103  // Get the hits associated with the space points
104  const art::FindManyP<recob::Hit>& fmhsp =
105  ShowerEleHolder.GetFindManyP<recob::Hit>(spHandle, Event, fPFParticleLabel);
106 
107  // Get the SpacePoints
108  std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.key());
109 
110  //We cannot progress with no spacepoints.
111  if (spacePoints.empty()) {
112  if (fVerbose)
113  mf::LogError("Shower3DCylinderTrackHitFinder")
114  << "No space points, returning " << std::endl;
115  return 1;
116  }
117 
118  // Order the spacepoints
120  spacePoints, ShowerStartPosition, ShowerDirection);
121 
122  // Get only the space points from the track
123  std::vector<art::Ptr<recob::SpacePoint>> trackSpacePoints;
124  trackSpacePoints = FindTrackSpacePoints(spacePoints, ShowerStartPosition, ShowerDirection);
125 
126  // Get the hits associated to the space points and seperate them by planes
127  std::vector<art::Ptr<recob::Hit>> trackHits;
128  for (auto const& spacePoint : trackSpacePoints) {
129  const art::Ptr<recob::Hit> hit = fmhsp.at(spacePoint.key()).front();
130  // const art::Ptr<recob::Hit> hit = fohsp.at(spacePoint.key());
131  trackHits.push_back(hit);
132  }
133 
134  ShowerEleHolder.SetElement(trackHits, fInitialTrackHitsOutputLabel);
135  ShowerEleHolder.SetElement(trackSpacePoints, fInitialTrackSpacePointsOutputLabel);
136 
137  return 0;
138  }
139 
140  std::vector<art::Ptr<recob::SpacePoint>>
142  std::vector<art::Ptr<recob::SpacePoint>>& spacePoints,
143  TVector3& showerStartPosition,
144  TVector3& showerDirection)
145  {
146 
147  // Make a vector to hold the output space points
148  std::vector<art::Ptr<recob::SpacePoint>> trackSpacePoints;
149 
150  for (const auto& spacePoint : spacePoints) {
151  // Calculate the projection along direction and perpendicular distance
152  // from "axis" of shower TODO: change alg to return a pair for efficiency
154  spacePoint, showerStartPosition, showerDirection);
156  spacePoint, showerStartPosition, showerDirection, proj);
157 
158  if (fForwardHitsOnly && proj < 0) continue;
159 
161  trackSpacePoints.push_back(spacePoint);
162  }
163  return trackSpacePoints;
164  }
165 
166 }
167 
std::vector< art::Ptr< recob::SpacePoint > > FindTrackSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &spacePoints, TVector3 &showerStartPosition, TVector3 &showerDirection)
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &showersps, TVector3 const &vertex, TVector3 const &direction) const
Declaration of signal hit object.
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
static constexpr bool
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
process_name hit
Definition: cheaterreco.fcl:51
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:265
T abs(T value)
walls no front
Definition: selectors.fcl:105
bool CheckElement(const std::string &Name) const
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const
int GetElement(const std::string &Name, T &Element) const
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:88
double SpacePointPerpendicular(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48