All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowerPandoraSlidingFitTrackFinder_tool.cc
Go to the documentation of this file.
1 //#############################################################################
2 //### Name: ShowerPandoraSlidingFitTrackFinder ###
3 //### Author: Dominic Barker (dominic.barker@sheffield.ac.uk ###
4 //### Date: 30.07.19 ###
5 //### Description: Tool for finding the initial shower track using the ###
6 //### pandora sliding fit calculation. This method is derived ###
7 //### from the PandoraTrackCreationModule.cc ###
8 //#############################################################################
9 
10 //Framework Includes
11 #include "art/Utilities/ToolMacros.h"
12 
13 //LArSoft Includes
24 
25 namespace ShowerRecoTools {
26 
28  public:
29  ShowerPandoraSlidingFitTrackFinder(const fhicl::ParameterSet& pset);
30 
31  //Generic Track Finder
32  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
33  art::Event& Event,
34  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
35 
36  private:
37  void InitialiseProducers() override;
38 
39  //Function to add the assoctions
40  int AddAssociations(const art::Ptr<recob::PFParticle>& pfpPtr,
41  art::Event& Event,
42  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
43 
44  // Define standard art tool interface.
45  art::ServiceHandle<geo::Geometry> fGeom;
46 
47  //fcl paramaters
48  int fVerbose;
49  float fSlidingFitHalfWindow; //To Describe
50  float fMinTrajectoryPoints; //Minimum number of trajectory point to say the track is good.
57  };
58 
60  const fhicl::ParameterSet& pset)
61  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
62  , fVerbose(pset.get<int>("Verbose"))
63  , fSlidingFitHalfWindow(pset.get<float>("SlidingFitHalfWindow"))
64  , fMinTrajectoryPoints(pset.get<float>("MinTrajectoryPoints"))
65  , fInitialTrackOutputLabel(pset.get<std::string>("InitialTrackOutputLabel"))
66  , fInitialTrackLengthOutputLabel(pset.get<std::string>("InitialTrackLengthOutputLabel"))
67  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
68  , fShowerDirectionInputLabel(pset.get<std::string>("ShowerDirectionInputLabel"))
69  , fInitialTrackSpacePointsInputLabel(pset.get<std::string>("InitialTrackSpacePointsInputLabel"))
70  , fInitialTrackHitsInputLabel(pset.get<std::string>("InitialTrackHitsInputLabel"))
71  {}
72 
73  void
75  {
76 
77  InitialiseProduct<std::vector<recob::Track>>(fInitialTrackOutputLabel);
78  InitialiseProduct<art::Assns<recob::Shower, recob::Track>>("ShowerTrackAssn");
79  InitialiseProduct<art::Assns<recob::Track, recob::Hit>>("ShowerTrackHitAssn");
80  }
81 
82  //This whole idea is stolen from PandoraTrackCreationModule so credit goes to the Pandora guys.
83  int
85  const art::Ptr<recob::PFParticle>& pfparticle,
86  art::Event& Event,
87  reco::shower::ShowerElementHolder& ShowerEleHolder)
88  {
89  //This is all based on the shower vertex being known. If it is not lets not do the track
90  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
91  if (fVerbose)
92  mf::LogError("ShowerPandoraSlidingFitTrackFinder")
93  << "Start position not set, returning " << std::endl;
94  return 1;
95  }
96  if (!ShowerEleHolder.CheckElement(fShowerDirectionInputLabel)) {
97  if (fVerbose)
98  mf::LogError("ShowerPandoraSlidingFitTrackFinder")
99  << "Direction not set, returning " << std::endl;
100  return 1;
101  }
102  if (!ShowerEleHolder.CheckElement(fInitialTrackSpacePointsInputLabel)) {
103  if (fVerbose)
104  mf::LogError("ShowerPandoraSlidingFitTrackFinder")
105  << "Initial Spacepoints not set, returning " << std::endl;
106  return 1;
107  }
108 
109  TVector3 ShowerStartPosition = {-999, -999, -999};
110  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, ShowerStartPosition);
111 
112  TVector3 ShowerDirection = {-999, -999, -999};
113  ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
114 
115  std::vector<art::Ptr<recob::SpacePoint>> spacepoints;
116  ShowerEleHolder.GetElement(fInitialTrackSpacePointsInputLabel, spacepoints);
117 
118  // The track fitter tries to create a traj point from each spacepoint so if we don't have enough
119  // spacepoints we will not get enough traj points, so let's not even try
120  if (spacepoints.size() < fMinTrajectoryPoints) {
121  if (fVerbose)
122  mf::LogWarning("ShowerPandoraSlidingFitTrackFinder")
123  << "Insufficient space points points to build track: " << spacepoints.size();
124  return 1;
125  }
127  // 'wirePitchW` is here used only to provide length scale for binning hits and performing sliding/local linear fits.
128  const float wirePitchW(detType->WirePitchW());
129 
130  const pandora::CartesianVector vertexPosition(
131  ShowerStartPosition.X(), ShowerStartPosition.Y(), ShowerStartPosition.Z());
132 
133  pandora::CartesianPointVector cartesianPointVector;
134  for (const art::Ptr<recob::SpacePoint> spacePoint : spacepoints)
135  cartesianPointVector.emplace_back(
136  pandora::CartesianVector(spacePoint->XYZ()[0], spacePoint->XYZ()[1], spacePoint->XYZ()[2]));
137 
138  lar_content::LArTrackStateVector trackStateVector;
139  pandora::IntVector indexVector;
140  try {
142  vertexPosition,
144  wirePitchW,
145  trackStateVector,
146  &indexVector);
147  }
148  catch (const pandora::StatusCodeException&) {
149  if (fVerbose)
150  mf::LogWarning("ShowerPandoraSlidingFitTrackFinder")
151  << "Unable to extract sliding fit trajectory" << std::endl;
152  return 1;
153  }
154  if (trackStateVector.size() < fMinTrajectoryPoints) {
155  if (fVerbose)
156  mf::LogWarning("ShowerPandoraSlidingFitTrackFinder")
157  << "Insufficient input trajectory points to build track: " << trackStateVector.size();
158  return 1;
159  }
160 
161  if (trackStateVector.empty())
162  throw cet::exception("ShowerPandoraSlidingFitTrackFinder")
163  << "BuildTrack - No input trajectory points provided " << std::endl;
164 
168 
169  for (const lar_content::LArTrackState& trackState : trackStateVector) {
170  xyz.emplace_back(recob::tracking::Point_t(trackState.GetPosition().GetX(),
171  trackState.GetPosition().GetY(),
172  trackState.GetPosition().GetZ()));
173  pxpypz.emplace_back(recob::tracking::Vector_t(trackState.GetDirection().GetX(),
174  trackState.GetDirection().GetY(),
175  trackState.GetDirection().GetZ()));
176 
177  // Set flag NoPoint if point has bogus coordinates, otherwise use clean flag set
178  if (std::fabs(trackState.GetPosition().GetX() - util::kBogusF) <
179  std::numeric_limits<float>::epsilon() &&
180  std::fabs(trackState.GetPosition().GetY() - util::kBogusF) <
181  std::numeric_limits<float>::epsilon() &&
182  std::fabs(trackState.GetPosition().GetZ() - util::kBogusF) <
183  std::numeric_limits<float>::epsilon()) {
186  }
187  else {
188  flags.emplace_back(recob::TrajectoryPointFlags());
189  }
190  }
191 
192  // note from gc: eventually we should produce a TrackTrajectory, not a Track with empty covariance matrix and bogus chi2, etc.
193  recob::Track InitialTrack = recob::Track(
194  recob::TrackTrajectory(std::move(xyz), std::move(pxpypz), std::move(flags), false),
200  pfparticle.key());
201 
202  ShowerEleHolder.SetElement(InitialTrack, fInitialTrackOutputLabel);
203 
204  TVector3 Start = {InitialTrack.Start().X(), InitialTrack.Start().Y(), InitialTrack.Start().Z()};
205  TVector3 End = {InitialTrack.End().X(), InitialTrack.End().Y(), InitialTrack.End().Z()};
206  float tracklength = (Start - End).Mag();
207 
208  ShowerEleHolder.SetElement(tracklength, fInitialTrackLengthOutputLabel);
209 
210  return 0;
211  }
212 
213  int
215  const art::Ptr<recob::PFParticle>& pfpPtr,
216  art::Event& Event,
217  reco::shower::ShowerElementHolder& ShowerEleHolder)
218  {
219 
220  //Check the track has been set
221  if (!ShowerEleHolder.CheckElement(fInitialTrackOutputLabel)) {
222  if (fVerbose)
223  mf::LogError("ShowerPandoraSlidingFitTrackFinderAddAssn")
224  << "Track not set so the assocation can not be made " << std::endl;
225  return 1;
226  }
227 
228  //Get the size of the ptr as it is.
229  int trackptrsize = GetVectorPtrSize(fInitialTrackOutputLabel);
230 
231  const art::Ptr<recob::Track> trackptr = GetProducedElementPtr<recob::Track>(
232  fInitialTrackOutputLabel, ShowerEleHolder, trackptrsize - 1);
233  const art::Ptr<recob::Shower> showerptr =
234  GetProducedElementPtr<recob::Shower>("shower", ShowerEleHolder);
235 
236  AddSingle<art::Assns<recob::Shower, recob::Track>>(showerptr, trackptr, "ShowerTrackAssn");
237 
238  std::vector<art::Ptr<recob::Hit>> TrackHits;
239  ShowerEleHolder.GetElement(fInitialTrackHitsInputLabel, TrackHits);
240 
241  for (auto const& TrackHit : TrackHits) {
242  AddSingle<art::Assns<recob::Track, recob::Hit>>(trackptr, TrackHit, "ShowerTrackHitAssn");
243  }
244 
245  return 0;
246  }
247 
248 }
249 
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
Header file for the pfo helper class.
static constexpr Flag_t NoPoint
The trajectory point is not defined.
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
Definition: TrackingTypes.h:85
Declaration of signal hit object.
int GetVectorPtrSize(std::string Name)
Definition: IShowerTool.h:168
LArTrackState class.
Definition: LArPfoObjects.h:29
Empty interface to map pandora to specifics in the LArSoft geometry.
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
static void GetSlidingFitTrajectory(const pandora::CartesianPointVector &pointVector, const pandora::CartesianVector &vertexPosition, const unsigned int layerWindow, const float layerPitch, LArTrackStateVector &trackStateVector, pandora::IntVector *const pIndexVector=nullptr)
Apply 3D sliding fit to a set of 3D points and return track trajectory.
constexpr int kBogusI
obviously bogus integer value
std::vector< int > IntVector
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space. See recob::tracking::Coord_t for more details on the ...
Definition: TrackingTypes.h:29
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
Point_t const & Start() const
Access to track position at different points.
A trajectory in space reconstructed from hits.
virtual float WirePitchW() const =0
The wire pitch of the mapped W view.
bool CheckElement(const std::string &Name) const
std::vector< Vector_t > Momenta_t
Type of momentum list.
Definition: TrackingTypes.h:35
std::vector< PointFlags_t > Flags_t
Type of point flag list.
int GetElement(const std::string &Name, T &Element) const
static constexpr HitIndex_t InvalidHitIndex
Value marking an invalid hit index.
Provides recob::Track data product.
std::vector< Point_t > Positions_t
Type of trajectory point list.
Definition: TrackingTypes.h:32
LArPandoraDetectorType * GetDetectorType()
Factory class that returns the correct detector type interface.
constexpr float kBogusF
obviously bogus float value
int AddAssociations(const art::Ptr< recob::PFParticle > &pfpPtr, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
Point_t const & End() const
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
std::vector< LArTrackState > LArTrackStateVector
Definition: LArPfoObjects.h:67
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space. See recob::tracking::Coord_t for more detai...
Definition: TrackingTypes.h:26
Helper functions for extracting detector geometry for use in reconsruction.
Set of flags pertaining a point of the track.
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track: