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
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,
29  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
30 
31  private:
32  void InitialiseProducers() override;
33 
34  //Function to add the assoctions
36  art::Event& Event,
37  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
38 
39  // Define standard art tool interface.
41 
42  //fcl paramaters
43  int fVerbose;
44  float fSlidingFitHalfWindow; //To Describe
45  float fMinTrajectoryPoints; //Minimum number of trajectory point to say the track is good.
52  };
53 
55  const fhicl::ParameterSet& pset)
56  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
57  , fVerbose(pset.get<int>("Verbose"))
58  , fSlidingFitHalfWindow(pset.get<float>("SlidingFitHalfWindow"))
59  , fMinTrajectoryPoints(pset.get<float>("MinTrajectoryPoints"))
60  , fInitialTrackOutputLabel(pset.get<std::string>("InitialTrackOutputLabel"))
61  , fInitialTrackLengthOutputLabel(pset.get<std::string>("InitialTrackLengthOutputLabel"))
62  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
63  , fShowerDirectionInputLabel(pset.get<std::string>("ShowerDirectionInputLabel"))
64  , fInitialTrackSpacePointsInputLabel(pset.get<std::string>("InitialTrackSpacePointsInputLabel"))
65  , fInitialTrackHitsInputLabel(pset.get<std::string>("InitialTrackHitsInputLabel"))
66  {}
67 
68  void
70  {
71 
72  InitialiseProduct<std::vector<recob::Track>>(fInitialTrackOutputLabel);
73  InitialiseProduct<art::Assns<recob::Shower, recob::Track>>("ShowerTrackAssn");
74  InitialiseProduct<art::Assns<recob::Track, recob::Hit>>("ShowerTrackHitAssn");
75  }
76 
77  //This whole idea is stolen from PandoraTrackCreationModule so credit goes to the Pandora guys.
78  int
80  const art::Ptr<recob::PFParticle>& pfparticle,
81  art::Event& Event,
82  reco::shower::ShowerElementHolder& ShowerEleHolder)
83  {
84  //This is all based on the shower vertex being known. If it is not lets not do the track
85  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
86  if (fVerbose)
87  mf::LogError("ShowerPandoraSlidingFitTrackFinder")
88  << "Start position not set, returning " << std::endl;
89  return 1;
90  }
91  if (!ShowerEleHolder.CheckElement(fShowerDirectionInputLabel)) {
92  if (fVerbose)
93  mf::LogError("ShowerPandoraSlidingFitTrackFinder")
94  << "Direction not set, returning " << std::endl;
95  return 1;
96  }
97  if (!ShowerEleHolder.CheckElement(fInitialTrackSpacePointsInputLabel)) {
98  if (fVerbose)
99  mf::LogError("ShowerPandoraSlidingFitTrackFinder")
100  << "Initial Spacepoints not set, returning " << std::endl;
101  return 1;
102  }
103 
104  TVector3 ShowerStartPosition = {-999, -999, -999};
105  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, ShowerStartPosition);
106 
107  TVector3 ShowerDirection = {-999, -999, -999};
108  ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
109 
110  std::vector<art::Ptr<recob::SpacePoint>> spacepoints;
111  ShowerEleHolder.GetElement(fInitialTrackSpacePointsInputLabel, spacepoints);
112 
113  // The track fitter tries to create a traj point from each spacepoint so if we don't have enough
114  // spacepoints we will not get enough traj points, so let's not even try
115  if (spacepoints.size() < fMinTrajectoryPoints) {
116  if (fVerbose)
117  mf::LogWarning("ShowerPandoraSlidingFitTrackFinder")
118  << "Insufficient space points points to build track: " << spacepoints.size();
119  return 1;
120  }
122  // 'wirePitchW` is here used only to provide length scale for binning hits and performing sliding/local linear fits.
123  const float wirePitchW(detType->WirePitchW());
124 
125  const pandora::CartesianVector vertexPosition(
126  ShowerStartPosition.X(), ShowerStartPosition.Y(), ShowerStartPosition.Z());
127 
128  pandora::CartesianPointVector cartesianPointVector;
129  for (const art::Ptr<recob::SpacePoint> spacePoint : spacepoints)
130  cartesianPointVector.emplace_back(
131  pandora::CartesianVector(spacePoint->XYZ()[0], spacePoint->XYZ()[1], spacePoint->XYZ()[2]));
132 
133  lar_content::LArTrackStateVector trackStateVector;
134  pandora::IntVector indexVector;
135  try {
137  vertexPosition,
139  wirePitchW,
140  trackStateVector,
141  &indexVector);
142  }
143  catch (const pandora::StatusCodeException&) {
144  if (fVerbose)
145  mf::LogWarning("ShowerPandoraSlidingFitTrackFinder")
146  << "Unable to extract sliding fit trajectory" << std::endl;
147  return 1;
148  }
149  if (trackStateVector.size() < fMinTrajectoryPoints) {
150  if (fVerbose)
151  mf::LogWarning("ShowerPandoraSlidingFitTrackFinder")
152  << "Insufficient input trajectory points to build track: " << trackStateVector.size();
153  return 1;
154  }
155 
156  if (trackStateVector.empty())
157  throw cet::exception("ShowerPandoraSlidingFitTrackFinder")
158  << "BuildTrack - No input trajectory points provided " << std::endl;
159 
163 
164  for (const lar_content::LArTrackState& trackState : trackStateVector) {
165  xyz.emplace_back(recob::tracking::Point_t(trackState.GetPosition().GetX(),
166  trackState.GetPosition().GetY(),
167  trackState.GetPosition().GetZ()));
168  pxpypz.emplace_back(recob::tracking::Vector_t(trackState.GetDirection().GetX(),
169  trackState.GetDirection().GetY(),
170  trackState.GetDirection().GetZ()));
171 
172  // Set flag NoPoint if point has bogus coordinates, otherwise use clean flag set
173  if (std::fabs(trackState.GetPosition().GetX() - util::kBogusF) <
174  std::numeric_limits<float>::epsilon() &&
175  std::fabs(trackState.GetPosition().GetY() - util::kBogusF) <
176  std::numeric_limits<float>::epsilon() &&
177  std::fabs(trackState.GetPosition().GetZ() - util::kBogusF) <
178  std::numeric_limits<float>::epsilon()) {
181  }
182  else {
183  flags.emplace_back(recob::TrajectoryPointFlags());
184  }
185  }
186 
187  // note from gc: eventually we should produce a TrackTrajectory, not a Track with empty covariance matrix and bogus chi2, etc.
188  recob::Track InitialTrack = recob::Track(
189  recob::TrackTrajectory(std::move(xyz), std::move(pxpypz), std::move(flags), false),
195  pfparticle.key());
196 
197  ShowerEleHolder.SetElement(InitialTrack, fInitialTrackOutputLabel);
198 
199  TVector3 Start = {InitialTrack.Start().X(), InitialTrack.Start().Y(), InitialTrack.Start().Z()};
200  TVector3 End = {InitialTrack.End().X(), InitialTrack.End().Y(), InitialTrack.End().Z()};
201  float tracklength = (Start - End).Mag();
202 
203  ShowerEleHolder.SetElement(tracklength, fInitialTrackLengthOutputLabel);
204 
205  return 0;
206  }
207 
208  int
210  const art::Ptr<recob::PFParticle>& pfpPtr,
211  art::Event& Event,
212  reco::shower::ShowerElementHolder& ShowerEleHolder)
213  {
214 
215  //Check the track has been set
216  if (!ShowerEleHolder.CheckElement(fInitialTrackOutputLabel)) {
217  if (fVerbose)
218  mf::LogError("ShowerPandoraSlidingFitTrackFinderAddAssn")
219  << "Track not set so the assocation can not be made " << std::endl;
220  return 1;
221  }
222 
223  //Get the size of the ptr as it is.
224  int trackptrsize = GetVectorPtrSize(fInitialTrackOutputLabel);
225 
226  const art::Ptr<recob::Track> trackptr = GetProducedElementPtr<recob::Track>(
227  fInitialTrackOutputLabel, ShowerEleHolder, trackptrsize - 1);
228  const art::Ptr<recob::Shower> showerptr =
229  GetProducedElementPtr<recob::Shower>("shower", ShowerEleHolder);
230 
231  AddSingle<art::Assns<recob::Shower, recob::Track>>(showerptr, trackptr, "ShowerTrackAssn");
232 
233  std::vector<art::Ptr<recob::Hit>> TrackHits;
234  ShowerEleHolder.GetElement(fInitialTrackHitsInputLabel, TrackHits);
235 
236  for (auto const& TrackHit : TrackHits) {
237  AddSingle<art::Assns<recob::Track, recob::Hit>>(trackptr, TrackHit, "ShowerTrackHitAssn");
238  }
239 
240  return 0;
241  }
242 
243 }
244 
Header file for the pfo helper class.
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
static constexpr Flag_t NoPoint
The trajectory point is not defined.
std::string string
Definition: nybbler.cc:12
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
Definition: TrackingTypes.h:85
int GetVectorPtrSize(std::string Name)
Definition: IShowerTool.h:167
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.
STL namespace.
constexpr int kBogusI
obviously bogus integer value
std::vector< int > IntVector
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
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.
Definition: Track.h:123
A trajectory in space reconstructed from hits.
def move(depos, offset)
Definition: depos.py:107
key_type key() const noexcept
Definition: Ptr.h:216
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.
virtual float WirePitchW() const =0
The wire pitch of the mapped W view.
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
void End(void)
Definition: gXSecComp.cxx:210
int AddAssociations(const art::Ptr< recob::PFParticle > &pfpPtr, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
Definition: types.h:32
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Provides recob::Track data product.
Point_t const & End() const
Definition: Track.h:125
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
Definition: Track.h:1036
std::vector< LArTrackState > LArTrackStateVector
Definition: LArPfoObjects.h:67
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
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.
#define Start
Definition: config.cpp:1229
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)