All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackMaker.h
Go to the documentation of this file.
1 #ifndef TRACKMAKER_H
2 #define TRACKMAKER_H
3 
4 namespace art {
5  class Event;
6 }
7 
8 #include "canvas/Persistency/Common/Ptr.h"
9 
18 
19 #include <stdexcept>
20 #include <memory>
21 #include <utility>
22 #include <vector>
23 
24 namespace detinfo {
25  class DetectorPropertiesData;
26 }
27 
28 namespace trkmkr {
29 
30  /**
31  * @file larreco/TrackFinder/TrackMaker.h
32  * @struct trkmkr::OptionalPointElement
33  *
34  * @brief Struct holding point-by-point elements used in OptionalOutputs.
35  *
36  * This struct holds the elements of OptionalOutputs that are added for each point (i.e. each hit).
37  *
38  * It stores a unique_ptr to each optional output object element.
39  * Functions are provided to set the unique_ptr and to check if it set.
40  * When the elements are returned, the unique_ptr is reset.
41  *
42  * @author G. Cerati (FNAL, MicroBooNE)
43  * @date 2017
44  * @version 1.0
45  */
46 
48  public:
49  /// set the recob::TrackFitHitInfo unique_ptr
50  void
52  {
53  trackFitHitInfo = std::make_unique<recob::TrackFitHitInfo>(std::move(aTrackFitHitInfo));
54  }
55  void
56  setTrackFitHitInfo(const recob::TrackFitHitInfo& aTrackFitHitInfo)
57  {
58  trackFitHitInfo = std::make_unique<recob::TrackFitHitInfo>(aTrackFitHitInfo);
59  }
60  /// check if the recob::TrackFitHitInfo unique_ptr is set
61  bool
63  {
64  return bool(trackFitHitInfo);
65  }
66  /// get the recob::TrackFitHitInfo object, and reset the unique_ptr
69  {
70  auto tmp = *trackFitHitInfo;
71  trackFitHitInfo.reset();
72  return tmp;
73  }
74  //
75  /// set the recob::SpacePoint unique_ptr
76  void
78  {
79  spacePoint = std::make_unique<recob::SpacePoint>(aSpacePoint);
80  }
81  void
82  setSpacePoint(const recob::SpacePoint& aSpacePoint)
83  {
84  spacePoint = std::make_unique<recob::SpacePoint>(aSpacePoint);
85  }
86  /// check if the recob::SpacePoint unique_ptr is set
87  bool
89  {
90  return bool(spacePoint);
91  }
92  /// get the recob::SpacePoint object, and release the unique_ptr
95  {
96  auto tmp = *spacePoint;
97  spacePoint.reset();
98  return tmp;
99  }
100 
101  private:
102  std::unique_ptr<recob::TrackFitHitInfo> trackFitHitInfo;
103  std::unique_ptr<recob::SpacePoint> spacePoint;
104  };
105 
106  /**
107  * @file larreco/TrackFinder/TrackMaker.h
108  * @struct trkmkr::OptionalOutputs
109  *
110  * @brief Struct holding optional TrackMaker outputs.
111  *
112  * This struct holds the optional outputs of track making and hides their details to the actual track making tools.
113  * In this way, adding a new optional output will affect only those tools that produce such new ouput.
114  *
115  * It stores a unique_ptr to the vector of each optional output object (meant to be per-track).
116  * Track making tools need to init the outional outputs they will produce, so that only the unique_ptrs that are needed are actually created.
117  * Functions are provided (called addPoint) to add point-by-point elements (see OptionalPointElement).
118  * When the output objects are returned, the unique_ptr is reset, so that no new elements should be added and a new initialization is needed.
119  *
120  * @author G. Cerati (FNAL, MicroBooNE)
121  * @date 2017
122  * @version 1.0
123  */
124 
126  public:
127  typedef std::pair<recob::SpacePoint, art::Ptr<recob::Hit>> SpHitPair;
128 
129  /// add one OptionalPointElement
130  void
132  {
133  if (isTrackFitInfosInit() && ope.isTrackFitInfoSet()) {
134  outTrackFitHitInfos->push_back(ope.getTrackFitHitInfo());
135  }
136  }
137  /// add one OptionalPointElement and the corresponding hit
138  void
139  addPoint(OptionalPointElement& ope, art::Ptr<recob::Hit> hptr)
140  {
141  if (isSpacePointsInit() && ope.isSpacePointSet()) {
142  outSpacePointHitPairs->emplace_back(ope.getSpacePoint(), hptr);
143  }
144  addPoint(ope);
145  }
146  /// reset the stored vectors
147  void
149  {
150  if (isTrackFitInfosInit()) {
151  outTrackFitHitInfos.reset();
153  }
154  if (isSpacePointsInit()) {
155  outSpacePointHitPairs.reset();
156  initSpacePoints();
157  }
158  }
159  /// initialize the output vector of TrackFitHitInfos
160  void
162  {
163  outTrackFitHitInfos = std::make_unique<std::vector<recob::TrackFitHitInfo>>();
164  }
165  /// initialize the output vector of SpHitPair
166  void
168  {
169  outSpacePointHitPairs = std::make_unique<std::vector<SpHitPair>>();
170  }
171  /// check initialization of the output vector of TrackFitHitInfos
172  bool
174  {
175  return bool(outTrackFitHitInfos);
176  }
177  /// check initialization of the output vector of SpHitPair
178  bool
180  {
181  return bool(outSpacePointHitPairs);
182  }
183  /// get the output vector of TrackFitHitInfos by releasing and moving
184  std::vector<recob::TrackFitHitInfo>
186  {
187  if (!isTrackFitInfosInit())
188  throw std::logic_error("outTrackFitHitInfos is not available (any more?).");
189  auto tmp = *outTrackFitHitInfos;
190  outTrackFitHitInfos.reset();
191  return tmp;
192  }
193  /// get the output vector of SpHitPair by releasing and moving
194  std::vector<SpHitPair>
196  {
197  if (!isSpacePointsInit())
198  throw std::logic_error("outSpacePointHitPairs is not available (any more?).");
199  auto tmp = *outSpacePointHitPairs;
200  outSpacePointHitPairs.reset();
201  return tmp;
202  }
203 
204  private:
205  std::unique_ptr<std::vector<recob::TrackFitHitInfo>> outTrackFitHitInfos;
206  std::unique_ptr<std::vector<SpHitPair>> outSpacePointHitPairs;
207  };
208 
209  /**
210  * @file larreco/TrackFinder/TrackMaker.h
211  * @class trkmkr::TrackMaker
212  *
213  * @brief Base abstract class for tools used to fit tracks.
214  *
215  * The virtual function makeTrack comes in different versions, one for each possible input (Trajectory, TrackTrajectory, Track), both using const references and art pointers as input).
216  * The functions return a bool corresponding to the success or failure status of the fit.
217  *
218  * The only purely virtual function is the one for input Trajectories (by default the other two just forward the call to it).
219  * Its arguments are the const inputs (Trajectory, TrajectoryPointFlags, track ID)
220  * and the non-const ouputs (mandatory: outTrack and outHits; optional outputs stored in OptionalOutputs).
221  *
222  * In case other products are needed from the event (e.g. associations to the input), they can be retrieved overriding the initEvent function.
223  *
224  * The tool is not meant to put collections in the event.
225  *
226  * Requirements are that a Track has at least 2 points, that it has the same number of Points and Momenta,
227  * that TrajectoryPoints and Hit have a 1-1 correspondance (same number and same order).
228  *
229  * @author G. Cerati (FNAL, MicroBooNE)
230  * @date 2017
231  * @version 1.0
232  */
233 
234  class TrackMaker {
235  public:
236  virtual ~TrackMaker() noexcept = default;
237 
238  /// per-event initialization; concrete classes may override this function to retrieve other products or associations from the event.
239  virtual void
240  initEvent(const art::Event& e)
241  {}
242 
243  //@{
244  /// makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory using a dummy flags vector.
245  virtual bool
247  const recob::Trajectory& traj,
248  const std::vector<recob::TrajectoryPointFlags>& flags,
249  const int tkID,
250  const std::vector<art::Ptr<recob::Hit>>& inHits,
251  recob::Track& outTrack,
252  std::vector<art::Ptr<recob::Hit>>& outHits,
253  OptionalOutputs& optionals) const
254  {
255  return makeTrack(
256  detProp,
258  tkID,
259  inHits,
260  outTrack,
261  outHits,
262  optionals);
263  }
264  virtual bool
266  const art::Ptr<recob::Trajectory> traj,
267  const std::vector<recob::TrajectoryPointFlags>& flags,
268  const std::vector<art::Ptr<recob::Hit>>& inHits,
269  recob::Track& outTrack,
270  std::vector<art::Ptr<recob::Hit>>& outHits,
271  OptionalOutputs& optionals) const
272  {
273  return makeTrack(
274  detProp,
276  traj.key(),
277  inHits,
278  outTrack,
279  outHits,
280  optionals);
281  }
282  //@}
283 
284  /// makeTrack functions with art::Ptr<recob::TrackTrajectory>; calls the purely virtual version with const recob::TrackTrajectory reference as argument.
285  virtual bool
287  const art::Ptr<recob::TrackTrajectory> ttraj,
288  const std::vector<art::Ptr<recob::Hit>>& inHits,
289  recob::Track& outTrack,
290  std::vector<art::Ptr<recob::Hit>>& outHits,
291  OptionalOutputs& optionals) const
292  {
293  return makeTrack(detProp, *ttraj, ttraj.key(), inHits, outTrack, outHits, optionals);
294  }
295 
296  /// makeTrack functions with const recob::TrackTrajectory reference as
297  /// argument: purely virtual, to be implemented in concrete classes.
299  const recob::TrackTrajectory& ttraj,
300  const int tkID,
301  const std::vector<art::Ptr<recob::Hit>>& inHits,
302  recob::Track& outTrack,
303  std::vector<art::Ptr<recob::Hit>>& outHits,
304  OptionalOutputs& optionals) const = 0;
305 
306  //@{
307  /// makeTrack functions with recob::Track as argument; calls the version
308  /// with recob::TrackTrajectory.
309  virtual bool
311  const art::Ptr<recob::Track> track,
312  const std::vector<art::Ptr<recob::Hit>>& inHits,
313  recob::Track& outTrack,
314  std::vector<art::Ptr<recob::Hit>>& outHits,
315  OptionalOutputs& optionals) const
316  {
317  return makeTrack(
318  detProp, track->Trajectory(), track.key(), inHits, outTrack, outHits, optionals);
319  }
320 
321  virtual bool
323  const recob::Track& track,
324  const std::vector<art::Ptr<recob::Hit>>& inHits,
325  recob::Track& outTrack,
326  std::vector<art::Ptr<recob::Hit>>& outHits,
327  OptionalOutputs& optionals) const
328  {
329  return makeTrack(
330  detProp, track.Trajectory(), track.ID(), inHits, outTrack, outHits, optionals);
331  }
332  //@}
333  };
334 }
335 
336 #endif
virtual bool makeTrack(const detinfo::DetectorPropertiesData &detProp, const art::Ptr< recob::TrackTrajectory > ttraj, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const
makeTrack functions with art::Ptr&lt;recob::TrackTrajectory&gt;; calls the purely virtual version with cons...
Definition: TrackMaker.h:286
bool isTrackFitInfoSet()
check if the recob::TrackFitHitInfo unique_ptr is set
Definition: TrackMaker.h:62
Data product for reconstructed trajectory in space.
virtual bool makeTrack(const detinfo::DetectorPropertiesData &detProp, const recob::Track &track, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const
Definition: TrackMaker.h:322
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
Definition: TrackMaker.h:161
void setTrackFitHitInfo(const recob::TrackFitHitInfo &aTrackFitHitInfo)
Definition: TrackMaker.h:56
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
recob::TrackFitHitInfo getTrackFitHitInfo()
get the recob::TrackFitHitInfo object, and reset the unique_ptr
Definition: TrackMaker.h:68
bool isSpacePointSet()
check if the recob::SpacePoint unique_ptr is set
Definition: TrackMaker.h:88
Declaration of signal hit object.
std::unique_ptr< recob::SpacePoint > spacePoint
Definition: TrackMaker.h:103
static constexpr bool
process_name use argoneut_mc_hitfinder track
std::unique_ptr< std::vector< recob::TrackFitHitInfo > > outTrackFitHitInfos
Definition: TrackMaker.h:205
std::unique_ptr< recob::TrackFitHitInfo > trackFitHitInfo
Definition: TrackMaker.h:102
virtual bool makeTrack(const detinfo::DetectorPropertiesData &detProp, const art::Ptr< recob::Track > track, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const
Definition: TrackMaker.h:310
Base abstract class for tools used to fit tracks.
Definition: TrackMaker.h:234
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:167
A trajectory in space reconstructed from hits.
Object storing per-hit information from a track fit.
Struct holding point-by-point elements used in OptionalOutputs.
Definition: TrackMaker.h:47
void setSpacePoint(const recob::SpacePoint &aSpacePoint)
Definition: TrackMaker.h:82
virtual bool makeTrack(const detinfo::DetectorPropertiesData &detProp, const recob::Trajectory &traj, const std::vector< recob::TrajectoryPointFlags > &flags, const int tkID, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const
makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory...
Definition: TrackMaker.h:246
Data product for reconstructed trajectory in space.
std::vector< PointFlags_t > Flags_t
Type of point flag list.
void addPoint(OptionalPointElement &ope, art::Ptr< recob::Hit > hptr)
add one OptionalPointElement and the corresponding hit
Definition: TrackMaker.h:139
Set of flags pertaining a point of the track.
Provides recob::Track data product.
std::unique_ptr< std::vector< SpHitPair > > outSpacePointHitPairs
Definition: TrackMaker.h:206
std::vector< SpHitPair > spacePointHitPairs()
get the output vector of SpHitPair by releasing and moving
Definition: TrackMaker.h:195
void reset()
reset the stored vectors
Definition: TrackMaker.h:148
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:67
virtual void initEvent(const art::Event &e)
per-event initialization; concrete classes may override this function to retrieve other products or a...
Definition: TrackMaker.h:240
recob::SpacePoint getSpacePoint()
get the recob::SpacePoint object, and release the unique_ptr
Definition: TrackMaker.h:94
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
Definition: TrackMaker.h:185
std::pair< recob::SpacePoint, art::Ptr< recob::Hit > > SpHitPair
Definition: TrackMaker.h:127
void addPoint(OptionalPointElement &ope)
add one OptionalPointElement
Definition: TrackMaker.h:131
do i e
bool isTrackFitInfosInit()
check initialization of the output vector of TrackFitHitInfos
Definition: TrackMaker.h:173
void setSpacePoint(recob::SpacePoint &&aSpacePoint)
set the recob::SpacePoint unique_ptr
Definition: TrackMaker.h:77
void setTrackFitHitInfo(recob::TrackFitHitInfo &&aTrackFitHitInfo)
set the recob::TrackFitHitInfo unique_ptr
Definition: TrackMaker.h:51
virtual ~TrackMaker() noexcept=default
virtual bool makeTrack(const detinfo::DetectorPropertiesData &detProp, const art::Ptr< recob::Trajectory > traj, const std::vector< recob::TrajectoryPointFlags > &flags, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const
Definition: TrackMaker.h:265
void initSpacePoints()
initialize the output vector of SpHitPair
Definition: TrackMaker.h:167
Struct holding optional TrackMaker outputs.
Definition: TrackMaker.h:125
auto const detProp
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track:
bool isSpacePointsInit()
check initialization of the output vector of SpHitPair
Definition: TrackMaker.h:179