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