LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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
11 
12 //LArSoft Includes
17 
18 namespace ShowerRecoTools {
19 
21 
22  public:
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
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"))
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 
57  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  geo::Point_t 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 TrajPosition = InitialTrack.LocationAtPoint(traj);
106  geo::Point_t TrajPositionStart = InitialTrack.LocationAtPoint(0);
107 
108  //Ignore values with 0 mag from the start position
109  if ((TrajPosition - TrajPositionStart).R() == 0) { continue; }
110  if ((TrajPosition - ShowerStartPosition).R() == 0) { continue; }
111 
112  float MinDist = 9999;
113  unsigned int index = 999;
114  for (unsigned int sp = 0; sp < intitaltrack_sp.size(); ++sp) {
115  //Find the spacepoint closest to the trajectory point.
116  art::Ptr<recob::SpacePoint> spacepoint = intitaltrack_sp[sp];
117  auto const dist = (spacepoint->position() - TrajPosition).R();
118  if (dist < MinDist && dist < fMaxDist) {
119  MinDist = dist;
120  index = sp;
121  }
122  }
123 
124  if (index == 999) { continue; }
125  //Add the spacepoint to the track spacepoints.
126  new_intitaltrack_sp.push_back(intitaltrack_sp[index]);
127 
128  //Delete the spacepoint so it can not be used again.
129  intitaltrack_sp.erase(intitaltrack_sp.begin() + index);
130  }
131 
132  // Get the spacepoints
133  auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
134 
135  // Get the hits associated with the space points
136  const art::FindOneP<recob::Hit>& fohsp =
137  ShowerEleHolder.GetFindOneP<recob::Hit>(spHandle, Event, fPFParticleLabel);
138 
139  //Save the corresponding hits
140  std::vector<art::Ptr<recob::Hit>> trackHits;
141  for (auto const& spacePoint : new_intitaltrack_sp) {
142  //Get the hits
143  const art::Ptr<recob::Hit> hit = fohsp.at(spacePoint.key());
144  trackHits.push_back(hit);
145  }
146 
147  //Save the spacepoints.
148  ShowerEleHolder.SetElement(new_intitaltrack_sp, fInitialTrackSpacePointsOutputLabel);
149  ShowerEleHolder.SetElement(trackHits, fInitialTrackHitsOutputLabel);
150 
151  return 0;
152  }
153 
154 }
155 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h: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
Access to track position at different points.
Definition: Track.h:160
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
geo::Point_t position() const
Returns the position of the point in world coordinates [cm].
Definition: SpacePoint.h:91
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:136
STL namespace.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
parameter set interface
bool CheckElement(const std::string &Name) const
Provides recob::Track data product.
int GetElement(const std::string &Name, T &Element) const
Detector simulation of raw signals on wires.
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
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
Definition: MVAAlg.h:12
PointFlags_t const & FlagsAtPoint(size_t i) const
Access to i-th TrajectoryPoint or its Flags.
Definition: Track.h:152
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
const art::FindOneP< T1 > & GetFindOneP(const art::ValidHandle< std::vector< T2 >> &handle, const art::Event &evt, const art::InputTag &moduleTag)
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