All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowerTrackTrajToSpacePoint_tool.cc
Go to the documentation of this file.
1 //############################################################################
2 //### Name: ShowerTrackTrajToSpacePoint ###
3 //### Author: Dominic Barker ###
4 //### Date: 01.10.19 ###
5 //### Description: Tool to associate the initial track trajectory points ###
6 //### to the spacepoints ###
7 //############################################################################
8 
9 //Framework Includes
10 #include "art/Utilities/ToolMacros.h"
11 
12 //LArSoft Includes
17 
18 namespace ShowerRecoTools {
19 
21 
22  public:
23  ShowerTrackTrajToSpacePoint(const fhicl::ParameterSet& pset);
24 
25  //Match trajectory points to the spacepoints
26  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
27  art::Event& Event,
28  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
29 
30  private:
31  float fMaxDist; //Max distance that a spacepoint can be from a trajectory
32  //point to be matched
33  art::InputTag fPFParticleLabel;
34  int fVerbose;
35 
38  std::string fInitialTrackInputTag;
41  };
42 
44  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
45  , fMaxDist(pset.get<float>("MaxDist"))
46  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
47  , fVerbose(pset.get<int>("Verbose"))
48  , fInitialTrackSpacePointsOutputLabel(
49  pset.get<std::string>("InitialTrackSpacePointsOutputLabel"))
50  , fInitialTrackHitsOutputLabel(pset.get<std::string>("InitialTrackHitsOutputLabel"))
51  , fInitialTrackInputTag(pset.get<std::string>("InitialTrackInputTag"))
52  , fShowerStartPositionInputTag(pset.get<std::string>("ShowerStartPositionInputTag"))
53  , fInitialTrackSpacePointsInputTag(pset.get<std::string>("InitialTrackSpacePointsInputTag"))
54  {}
55 
56  int
57  ShowerTrackTrajToSpacePoint::CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
58  art::Event& Event,
59  reco::shower::ShowerElementHolder& ShowerEleHolder)
60  {
61 
62  //Check the Track has been defined
63  if (!ShowerEleHolder.CheckElement(fInitialTrackInputTag)) {
64  if (fVerbose)
65  mf::LogError("ShowerTrackTrajToSpacePoint") << "Initial track not set" << std::endl;
66  return 0;
67  }
68 
69  //Check the start position is set.
70  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputTag)) {
71  if (fVerbose)
72  mf::LogError("ShowerTrackTrajToSpacePoint")
73  << "Start position not set, returning " << std::endl;
74  return 0;
75  }
76 
77  //Check the Track Hits has been defined
78  if (!ShowerEleHolder.CheckElement(fInitialTrackSpacePointsInputTag)) {
79  if (fVerbose)
80  mf::LogError("ShowerTrackTrajToSpacePoint")
81  << "Initial track spacepoints not set" << std::endl;
82  return 0;
83  }
84 
85  //Get the start poistion
86  TVector3 ShowerStartPosition = {-999, -999, -999};
87  ShowerEleHolder.GetElement(fShowerStartPositionInputTag, ShowerStartPosition);
88 
89  //Get the initial track hits.
90  std::vector<art::Ptr<recob::SpacePoint>> intitaltrack_sp;
91  ShowerEleHolder.GetElement(fInitialTrackSpacePointsInputTag, intitaltrack_sp);
92 
93  //Get the track
94  recob::Track InitialTrack;
95  ShowerEleHolder.GetElement(fInitialTrackInputTag, InitialTrack);
96 
97  std::vector<art::Ptr<recob::SpacePoint>> new_intitaltrack_sp;
98  //Loop over the trajectory points
99  for (unsigned int traj = 0; traj < InitialTrack.NumberTrajectoryPoints(); ++traj) {
100 
101  //ignore bogus info.
102  auto flags = InitialTrack.FlagsAtPoint(traj);
103  if (flags.isSet(recob::TrajectoryPointFlagTraits::NoPoint)) { continue; }
104 
105  geo::Point_t TrajPositionPoint = InitialTrack.LocationAtPoint(traj);
106  TVector3 TrajPosition = {TrajPositionPoint.X(), TrajPositionPoint.Y(), TrajPositionPoint.Z()};
107 
108  geo::Point_t TrajPositionStartPoint = InitialTrack.LocationAtPoint(0);
109  TVector3 TrajPositionStart = {
110  TrajPositionStartPoint.X(), TrajPositionStartPoint.Y(), TrajPositionStartPoint.Z()};
111 
112  //Ignore values with 0 mag from the start position
113  if ((TrajPosition - TrajPositionStart).Mag() == 0) { continue; }
114  if ((TrajPosition - ShowerStartPosition).Mag() == 0) { continue; }
115 
116  float MinDist = 9999;
117  unsigned int index = 999;
118  for (unsigned int sp = 0; sp < intitaltrack_sp.size(); ++sp) {
119  //Find the spacepoint closest to the trajectory point.
120  art::Ptr<recob::SpacePoint> spacepoint = intitaltrack_sp[sp];
121  TVector3 pos =
122  IShowerTool::GetLArPandoraShowerAlg().SpacePointPosition(spacepoint) - TrajPosition;
123  if (pos.Mag() < MinDist && pos.Mag() < fMaxDist) {
124  MinDist = pos.Mag();
125  index = sp;
126  }
127  }
128 
129  if (index == 999) { continue; }
130  //Add the spacepoint to the track spacepoints.
131  new_intitaltrack_sp.push_back(intitaltrack_sp[index]);
132 
133  //Delete the spacepoint so it can not be used again.
134  intitaltrack_sp.erase(intitaltrack_sp.begin() + index);
135  }
136 
137  // Get the spacepoints
138  auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
139 
140  // Get the hits associated with the space points
141  const art::FindOneP<recob::Hit>& fohsp =
142  ShowerEleHolder.GetFindOneP<recob::Hit>(spHandle, Event, fPFParticleLabel);
143 
144  //Save the corresponding hits
145  std::vector<art::Ptr<recob::Hit>> trackHits;
146  for (auto const& spacePoint : new_intitaltrack_sp) {
147  //Get the hits
148  const art::Ptr<recob::Hit> hit = fohsp.at(spacePoint.key());
149  trackHits.push_back(hit);
150  }
151 
152  //Save the spacepoints.
153  ShowerEleHolder.SetElement(new_intitaltrack_sp, fInitialTrackSpacePointsOutputLabel);
154  ShowerEleHolder.SetElement(trackHits, fInitialTrackHitsOutputLabel);
155 
156  return 0;
157  }
158 
159 }
160 
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
static constexpr Flag_t NoPoint
The trajectory point is not defined.
Declaration of signal hit object.
Point_t const & LocationAtPoint(size_t i) const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
const art::FindOneP< T1 > & GetFindOneP(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
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
Provides recob::Track data product.
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:88
PointFlags_t const & FlagsAtPoint(size_t i) const
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
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:184
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track:
TVector3 SpacePointPosition(art::Ptr< recob::SpacePoint > const &sp) const