LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TrackMaker.h
Go to the documentation of this file.
1 #ifndef TRACKMAKER_H
2 #define TRACKMAKER_H
3 
6 
15 
16 #include <memory>
17 #include <stdexcept>
18 #include <utility>
19 #include <vector>
20 
21 namespace detinfo {
22  class DetectorPropertiesData;
23 }
24 
25 namespace trkmkr {
26 
45  public:
47  void setTrackFitHitInfo(recob::TrackFitHitInfo&& aTrackFitHitInfo)
48  {
49  trackFitHitInfo = std::make_unique<recob::TrackFitHitInfo>(std::move(aTrackFitHitInfo));
50  }
51  void setTrackFitHitInfo(const recob::TrackFitHitInfo& aTrackFitHitInfo)
52  {
53  trackFitHitInfo = std::make_unique<recob::TrackFitHitInfo>(aTrackFitHitInfo);
54  }
56  bool isTrackFitInfoSet() { return bool(trackFitHitInfo); }
59  {
60  auto tmp = *trackFitHitInfo;
61  trackFitHitInfo.reset();
62  return tmp;
63  }
64  //
66  void setSpacePoint(recob::SpacePoint&& aSpacePoint)
67  {
68  spacePoint = std::make_unique<recob::SpacePoint>(aSpacePoint);
69  }
70  void setSpacePoint(const recob::SpacePoint& aSpacePoint)
71  {
72  spacePoint = std::make_unique<recob::SpacePoint>(aSpacePoint);
73  }
75  bool isSpacePointSet() { return bool(spacePoint); }
78  {
79  auto tmp = *spacePoint;
80  spacePoint.reset();
81  return tmp;
82  }
83 
84  private:
85  std::unique_ptr<recob::TrackFitHitInfo> trackFitHitInfo;
86  std::unique_ptr<recob::SpacePoint> spacePoint;
87  };
88 
109  public:
110  typedef std::pair<recob::SpacePoint, art::Ptr<recob::Hit>> SpHitPair;
111 
114  {
115  if (isTrackFitInfosInit() && ope.isTrackFitInfoSet()) {
116  outTrackFitHitInfos->push_back(ope.getTrackFitHitInfo());
117  }
118  }
121  {
122  if (isSpacePointsInit() && ope.isSpacePointSet()) {
123  outSpacePointHitPairs->emplace_back(ope.getSpacePoint(), hptr);
124  }
125  addPoint(ope);
126  }
128  void reset()
129  {
130  if (isTrackFitInfosInit()) {
131  outTrackFitHitInfos.reset();
132  initTrackFitInfos();
133  }
134  if (isSpacePointsInit()) {
135  outSpacePointHitPairs.reset();
136  initSpacePoints();
137  }
138  }
141  {
142  outTrackFitHitInfos = std::make_unique<std::vector<recob::TrackFitHitInfo>>();
143  }
145  void initSpacePoints() { outSpacePointHitPairs = std::make_unique<std::vector<SpHitPair>>(); }
147  bool isTrackFitInfosInit() { return bool(outTrackFitHitInfos); }
149  bool isSpacePointsInit() { return bool(outSpacePointHitPairs); }
151  std::vector<recob::TrackFitHitInfo> trackFitHitInfos()
152  {
153  if (!isTrackFitInfosInit())
154  throw std::logic_error("outTrackFitHitInfos is not available (any more?).");
155  auto tmp = *outTrackFitHitInfos;
156  outTrackFitHitInfos.reset();
157  return tmp;
158  }
160  std::vector<SpHitPair> spacePointHitPairs()
161  {
162  if (!isSpacePointsInit())
163  throw std::logic_error("outSpacePointHitPairs is not available (any more?).");
164  auto tmp = *outSpacePointHitPairs;
165  outSpacePointHitPairs.reset();
166  return tmp;
167  }
168 
169  private:
170  std::unique_ptr<std::vector<recob::TrackFitHitInfo>> outTrackFitHitInfos;
171  std::unique_ptr<std::vector<SpHitPair>> outSpacePointHitPairs;
172  };
173 
199  class TrackMaker {
200  public:
201  virtual ~TrackMaker() noexcept = default;
202 
204  virtual void initEvent(const art::Event&) {}
205 
209  const std::vector<art::Ptr<recob::Hit>>& inHits,
210  recob::Track& outTrack,
212  OptionalOutputs& optionals) const
213  {
214  return makeTrack(detProp, *ttraj, ttraj.key(), inHits, outTrack, outHits, optionals);
215  }
216 
219  virtual bool makeTrack(const detinfo::DetectorPropertiesData& detProp,
220  const recob::TrackTrajectory& ttraj,
221  const int tkID,
222  const std::vector<art::Ptr<recob::Hit>>& inHits,
223  recob::Track& outTrack,
225  OptionalOutputs& optionals) const = 0;
226 
228  bool makeTrack(const detinfo::DetectorPropertiesData& detProp,
232  const std::vector<art::Ptr<recob::Hit>>& inHits,
233  recob::Track& outTrack,
235  OptionalOutputs& optionals) const
236  {
237  return makeTrack(
238  detProp, track->Trajectory(), track.key(), inHits, outTrack, outHits, optionals);
239  }
241  };
242 }
243 
244 #endif
bool isTrackFitInfoSet()
check if the recob::TrackFitHitInfo unique_ptr is set
Definition: TrackMaker.h:56
Data product for reconstructed trajectory in space.
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
Definition: TrackMaker.h:140
void setTrackFitHitInfo(const recob::TrackFitHitInfo &aTrackFitHitInfo)
Definition: TrackMaker.h:51
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:132
recob::TrackFitHitInfo getTrackFitHitInfo()
get the recob::TrackFitHitInfo object, and reset the unique_ptr
Definition: TrackMaker.h:58
bool isSpacePointSet()
check if the recob::SpacePoint unique_ptr is set
Definition: TrackMaker.h:75
Declaration of signal hit object.
std::unique_ptr< recob::SpacePoint > spacePoint
Definition: TrackMaker.h:86
Float_t tmp
Definition: plot.C:35
std::unique_ptr< std::vector< recob::TrackFitHitInfo > > outTrackFitHitInfos
Definition: TrackMaker.h:170
std::unique_ptr< recob::TrackFitHitInfo > trackFitHitInfo
Definition: TrackMaker.h:85
Base abstract class for tools used to fit tracks.
Definition: TrackMaker.h:199
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
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:207
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:44
key_type key() const noexcept
Definition: Ptr.h:166
void setSpacePoint(const recob::SpacePoint &aSpacePoint)
Definition: TrackMaker.h:70
Provides recob::Track data product.
virtual void initEvent(const art::Event &)
per-event initialization; concrete classes may override this function to retrieve other products or a...
Definition: TrackMaker.h:204
Data product for reconstructed trajectory in space.
General LArSoft Utilities.
void addPoint(OptionalPointElement &ope, art::Ptr< recob::Hit > hptr)
add one OptionalPointElement and the corresponding hit
Definition: TrackMaker.h:120
Set of flags pertaining a point of the track.
std::unique_ptr< std::vector< SpHitPair > > outSpacePointHitPairs
Definition: TrackMaker.h:171
std::vector< SpHitPair > spacePointHitPairs()
get the output vector of SpHitPair by releasing and moving
Definition: TrackMaker.h:160
void reset()
reset the stored vectors
Definition: TrackMaker.h:128
recob::SpacePoint getSpacePoint()
get the recob::SpacePoint object, and release the unique_ptr
Definition: TrackMaker.h:77
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
Definition: TrackMaker.h:151
std::pair< recob::SpacePoint, art::Ptr< recob::Hit > > SpHitPair
Definition: TrackMaker.h:110
void addPoint(OptionalPointElement &ope)
add one OptionalPointElement
Definition: TrackMaker.h:113
bool isTrackFitInfosInit()
check initialization of the output vector of TrackFitHitInfos
Definition: TrackMaker.h:147
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:47
Float_t track
Definition: plot.C:35
void initSpacePoints()
initialize the output vector of SpHitPair
Definition: TrackMaker.h:145
Struct holding optional TrackMaker outputs.
Definition: TrackMaker.h:108
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:149