LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
Track.h
Go to the documentation of this file.
1 
229 #ifndef LARDATA_RECOBASEPROXY_TRACK_H
230 #define LARDATA_RECOBASEPROXY_TRACK_H
231 
232 
233 // LArSoft libraries
234 #include "lardata/RecoBaseProxy/ProxyBase.h" // proxy namespace
238 #include "lardataobj/RecoBase/Hit.h"
240 
241 // framework libraries
243 
244 // range library
245 #include "range/v3/view/filter.hpp" // range::view::filter()
246 
247 namespace proxy {
248 
249  //----------------------------------------------------------------------------
250  // forward declarations
251  template <typename TrackProxy>
253 
254  template <typename Data>
256 
257  //----------------------------------------------------------------------------
258  namespace details {
259 
260  template <typename CollProxy>
262 
263  template <typename T>
264  struct isTrackProxy;
265 
266  template <typename Obj>
268 
269  template <typename Data>
270  struct StaticAsserts<TrackPointWrapper<Data>>: public std::true_type {
272 
273  static_assert(sizeof(Wrapper_t) == 1U, "Wrapper carries data!");
274 
275  static_assert(std::is_same<
276  std::decay_t<decltype(std::declval<Wrapper_t>().position())>,
278  >(),
279  "position() is not a recob::Track::Point_t"
280  );
281  static_assert(std::is_same<
282  std::decay_t<decltype(std::declval<Wrapper_t>().momentum())>,
284  >(),
285  "momentum() is not a recob::Track::Vector_t"
286  );
287  static_assert(std::is_same<
288  std::decay_t<decltype(std::declval<Wrapper_t>().flags())>,
290  >(),
291  "flags() is not a recob::Track::PointFlags_t"
292  );
293  static_assert(std::is_same<
294  std::decay_t<decltype(std::declval<Wrapper_t>().hitPtr())>,
296  >(),
297  "hit() is not a art::Ptr<recob::Hit>"
298  );
299  static_assert(std::is_same<
300  std::decay_t<decltype(std::declval<Wrapper_t>().index())>,
301  std::size_t
302  >(),
303  "index() is not a std::size_t"
304  );
305 
306  }; // StaticAsserts<TrackPointWrapper<Data>>
307 
308  } // namespace details
309 
310 
311  //----------------------------------------------------------------------------
312 
497  struct Tracks {
498 
500  using TrackDataProduct_t = std::vector<recob::Track>;
501 
504 
507 
510 
512  typedef enum {
515  NTypes
516  } TrackType_t;
517 
518  }; // struct Tracks
519 
520 
521 
522  //----------------------------------------------------------------------------
523  //--- track point information
524  //---
550  using TrackPointData = std::tuple<
551  recob::Track const*,
553  recob::TrackFitHitInfo const*,
554  std::size_t
555  >;
556 
585  template <typename Data>
586  class TrackPointWrapper {
588  using Wrapped_t = std::add_const_t<Data>;
589 
590  static constexpr std::size_t TrackIndex = 0;
591  static constexpr std::size_t HitIndex = 1;
592  static constexpr std::size_t FitHitInfoIndex = 2;
593  static constexpr std::size_t IndexIndex = 3;
594  static constexpr std::size_t NIndices = 4;
595 
596  static_assert(std::tuple_size<Data>::value == NIndices,
597  "Unexpected data size.");
598 
599  Wrapped_t const& base() const
600  { return reinterpret_cast<Wrapped_t const&>(*this); }
601 
602  template <std::size_t N>
603  auto get() const -> decltype(auto) { return std::get<N>(base()); }
604 
605  protected:
606  TrackPointWrapper() = default;
607  TrackPointWrapper(TrackPointWrapper const&) = default;
609  TrackPointWrapper& operator=(TrackPointWrapper const&) = default;
610  TrackPointWrapper& operator=(TrackPointWrapper&&) = default;
611 
612  public:
613 
615  recob::Track const& track() const
616  { return *get<TrackIndex>(); }
617 
620  auto position() const -> decltype(auto)
621  { return track().Trajectory().LocationAtPoint(index()); }
622 
625  auto momentum() const -> decltype(auto)
626  { return track().Trajectory().MomentumVectorAtPoint(index()); }
627 
633  auto flags() const -> decltype(auto)
636  { return track().Trajectory().FlagsAtPoint(index()); }
637 
644  bool isPointValid() const { return flags().isPointValid(); }
645 
647 
652  art::Ptr<recob::Hit> hitPtr() const { return get<HitIndex>(); }
653 
663  recob::TrackFitHitInfo const* fitInfoPtr() const
664  { return get<FitHitInfoIndex>(); }
665 
667  auto index() const -> decltype(auto) { return get<IndexIndex >(); }
668 
670  recob::Hit const* hit() const
671  { decltype(auto) ptr = hitPtr(); return ptr? ptr.get(): nullptr; }
672 
673  }; // TrackPointWrapper<>
674 
675 
683  struct TrackPoint
684  : private TrackPointData
685  , public TrackPointWrapper<TrackPointData>
686  {
688  TrackPoint(TrackPointData const& data): TrackPointData(data) {}
689  TrackPoint(TrackPointData&& data): TrackPointData(std::move(data)) {}
690 
691  private:
692  static constexpr bool asserts
694  }; // class TrackPoint
695 
696 
706  template <typename TrackProxy>
708  (TrackProxy const& track, std::size_t index)
709  {
710  static_assert(details::isTrackProxy<TrackProxy>(), "Not a proxy::Track!");
711  return {
712  &(track.track()),
713  track.hitAtPoint(index),
714  track.fitInfoAtPoint(index),
715  index
716  };
717  } // makeTrackPointData()
718 
719 
720  //--------------------------------------------------------------------------
729  template <typename CollProxy>
731  : public CollectionProxyElement<CollProxy>
732  {
734  using base_t::base_t; // inherit constructors
735 
738 
739  public:
742 
744  recob::Track const& track() const { return base_t::operator*(); }
745 
752  recob::TrackTrajectory const* operator()
753  (proxy::Tracks::TrackType_t type) const noexcept;
754 
755  // --- BEGIN Direct hit interface ------------------------------------------
781 
791  auto hits() const -> decltype(auto)
792  { return base_t::template get<Tracks::HitTag>(); }
793 
795  auto hitAtPoint(std::size_t index) const -> decltype(auto)
796  { return hits()[index]; }
797 
799  std::size_t nHits() const { return hits().size(); }
800 
802  // --- END Direct hit interface --------------------------------------------
803 
804 
806  recob::TrackFitHitInfo const* fitInfoAtPoint(std::size_t index) const;
807 
808 
809  // --- BEGIN Direct track trajectory interface -----------------------------
834 
838  { return !originalTrajectoryPtr().isNull(); }
839 
843  { return base_t::template get<Tracks::TrackTrajectoryTag>(); }
844 
855  { return *originalTrajectoryPtr(); }
856 
858  // --- END Direct track trajectory interface -------------------------------
859 
860 
861  // --- BEGIN Point-by-point iteration interface ----------------------------
886 
908  auto points() const
910 
949  template <typename Pred>
950  auto selectPoints(Pred&& pred) const;
951 
980  auto pointsWithFlags
982 
984  std::size_t nPoints() const { return track().NPoints(); }
985 
987  point_iterator beginPoint() const { return { *this, 0 }; }
988 
990  point_iterator endPoint() const { return { *this, nPoints() }; }
991 
994  TrackPoint point(std::size_t index) const
995  { return { makeTrackPointData(track(), index) }; }
996 
997  TrackPoint operator[](std::size_t index) const
998  { return point(index); }
999 
1001  // --- END Point-by-point iteration interface ------------------------------
1002 
1003 
1004  // --- BEGIN Additional utilities ------------------------------------------
1007 
1008 
1010  // --- END Additional utilities --------------------------------------------
1011 
1012  private:
1014  { return hasOriginalTrajectory()? &originalTrajectory(): nullptr; }
1015 
1016  }; // TrackCollectionProxyElement<>
1017 
1018 
1034  template <typename TrackCollProxy>
1036 
1037 
1038 
1039  // --- BEGIN Auxiliary data --------------------------------------------------
1063  inline auto withOriginalTrajectory(art::InputTag const& inputTag)
1064  {
1065  return proxy::withZeroOrOneAs
1067  }
1068 
1115  {
1116  return proxy::withZeroOrOneAs
1118  }
1119 
1120  //----------------------------------------------------------------------------
1132  inline auto withFitHitInfo(art::InputTag const& inputTag)
1133  {
1135  <std::vector<recob::TrackFitHitInfo>, Tracks::TrackFitHitInfoTag>
1136  (inputTag);
1137  }
1138 
1190  inline auto withFitHitInfo()
1191  {
1193  <std::vector<recob::TrackFitHitInfo>, Tracks::TrackFitHitInfoTag>();
1194  }
1195 
1197  // --- END Auxiliary data ----------------------------------------------------
1198 
1199  //----------------------------------------------------------------------------
1201  template <>
1203  : public CollectionProxyMakerTraits<Tracks::TrackDataProduct_t>
1204  {
1205  // default traits, plus a collection proxy class with a custom element:
1206  template <typename MainColl, typename... AuxColl>
1208  = CollectionProxyBase<Track, MainColl, AuxColl...>;
1209  };
1210 
1211 
1212  //----------------------------------------------------------------------------
1214  template <>
1216  : public CollectionProxyMakerBase<Tracks>
1217  {
1218 
1221 
1237  template <typename Event, typename... WithArgs>
1238  static auto make
1239  (Event const& event, art::InputTag const& tag, WithArgs&&... withArgs)
1240  {
1241  // automatically add associated hits with the same input tag;
1242  // IDEA: allow a withAssociated<recob::Hit>() from withArgs to override
1243  // this one; the pattern may be:
1244  // - if withArgs contains a withAssociated<recob::Hit>(), produce a new
1245  // withArgs with that one pushed first
1246  // - otherwise, produce a new withArgs with a new
1247  // withAssociated<recob::Hit>(tag) as first element
1248  // In principle there is no need for these hits to be first; code might
1249  // be simpler when assuming that though.
1250  return maker_base_t::make(
1251  event, tag,
1252  withAssociatedAs<recob::Hit, Tracks::HitTag>(),
1253  std::forward<WithArgs>(withArgs)...
1254  );
1255  } // make()
1256 
1257  }; // struct CollectionProxyMaker<>
1258 
1259 
1261  template <typename Data>
1262  auto wrapTrackPoint(Data const& wrappedData)
1263  {
1265  return reinterpret_cast<TrackPointWrapper<Data> const&>(wrappedData);
1266  }
1267 
1270  template <typename TrackProxy>
1271  class TrackPointIterator {
1272 
1273  /*
1274  * So, let's go through the list of iterator traits from cppreference.com:
1275  * [x] Iterator
1276  * [x] CopyConstructible
1277  * [x] CopyAssignable
1278  * [x] Destructible
1279  * [x] lvalues are Swappable
1280  * [x] value_type
1281  * [x] difference_type
1282  * [x] reference
1283  * [x] pointer
1284  * [x] iterator_category
1285  * [x] operator*()
1286  * [x] operator++()
1287  * [ ] InputIterator
1288  * [x] Iterator (above)
1289  * [x] EqualityComparable (operator== (A, B))
1290  * [x] operator!= ()
1291  * [ ] reference operator*() (convertible to value_type)
1292  * [ ] operator->()
1293  * [x] It& operator++()
1294  * [x] operator++(int)
1295  * [x] *i++ equivalent to { auto v = *i; ++i; return v; }
1296  * [ ] Forward Iterator
1297  * [ ] InputIterator (above)
1298  * [x] DefaultConstructible
1299  * [x] multipass guarantee: a == b => ++a == ++b
1300  * [ ] reference = value_type const&
1301  * [x] It operator++(int)
1302  * [ ] *i++ returns reference
1303  * That's it! :-|
1304  */
1305 
1306  using track_proxy_t = TrackProxy;
1307 
1308  track_proxy_t const* track = nullptr;
1310 
1311  public:
1312 
1315  using difference_type = std::ptrdiff_t;
1317  using pointer = TrackPoint const*;
1318  using reference = TrackPoint; // booo!
1319  // not quite an input iterator (see above)
1320  using iterator_category = std::input_iterator_tag;
1322 
1323  TrackPointIterator() = default;
1324 
1325  TrackPointIterator(track_proxy_t const& track, std::size_t index)
1326  : track(&track), index(index)
1327  {}
1328 
1329  TrackPointIterator& operator++() { ++index; return *this; }
1330 
1332  { auto it = *this; this->operator++(); return it; }
1333 
1334  // we make sure the return value is a temporary
1336  { return static_cast<value_type>(makeTrackPointData(*track, index)); }
1337 
1339  { return (index == other.index) && (track == other.track); }
1340 
1342  { return (index != other.index) || (track != other.track); }
1343 
1344  }; // class TrackPointIterator
1345 
1346 
1347 } // namespace proxy
1348 
1349 
1350 namespace proxy {
1351 
1352  //----------------------------------------------------------------------------
1353  namespace details {
1354 
1355  //--------------------------------------------------------------------------
1356  template <typename T>
1357  struct isTrackProxy: public std::false_type {};
1358 
1359  template <typename TrackCollProxy>
1360  struct isTrackProxy<Track<TrackCollProxy>>: public std::true_type {};
1361 
1362 
1363  //--------------------------------------------------------------------------
1365  template <typename CollProxy>
1366  struct TrackPointIteratorBox {
1369 
1370  TrackPointIteratorBox(track_proxy_t const& track): track(&track) {}
1371 
1373  { return track->beginPoint(); }
1374 
1376  { return track->endPoint(); }
1377 
1378  private:
1379  track_proxy_t const* track = nullptr;
1380 
1381  }; // TrackPointIteratorBox<>
1382 
1383 
1384  //--------------------------------------------------------------------------
1385 
1386  } // namespace details
1387 
1388  //----------------------------------------------------------------------------
1389  template <typename CollProxy>
1390  recob::TrackTrajectory const*
1392  (proxy::Tracks::TrackType_t type) const noexcept
1393  {
1394  switch (type) {
1395  case proxy::Tracks::Fitted:
1396  return &(track().Trajectory());
1398  return originalTrajectoryCPtr();
1399  default:
1400  return nullptr;
1401  } // switch
1402  } // TrackCollectionProxyElement<>::operator()
1403 
1404 
1405  //----------------------------------------------------------------------------
1406  template <typename CollProxy>
1407  recob::TrackFitHitInfo const*
1409  (std::size_t index) const
1410  {
1411  if (!base_t::template has<Tracks::TrackFitHitInfoTag>())
1412  return nullptr;
1413  auto&& fitInfo = base_t::template getIf<
1415  std::vector<recob::TrackFitHitInfo> const&
1416  >();
1417  return &(fitInfo[index]);
1418  } // TrackCollectionProxyElement<>::fitInfoAtPoint()
1419 
1420 
1421  //----------------------------------------------------------------------------
1422  template <typename CollProxy>
1423  template <typename Pred>
1425  { return util::filterRangeFor(points(), std::forward<Pred>(pred)); }
1426 
1427 
1428  //----------------------------------------------------------------------------
1429  template <typename CollProxy>
1432  {
1433  return
1434  selectPoints([mask](auto&& point) { return point.flags().match(mask); });
1435  } // TrackCollectionProxyElement<>::pointsWithFlags()
1436 
1437 
1438  //----------------------------------------------------------------------------
1439 
1440 } // namespace proxy
1441 
1442 
1443 #endif // LARDATA_RECOBASEPROXY_TRACK_H
auto hitAtPoint(std::size_t index) const -> decltype(auto)
Returns an art pointer to the hit associated with the specified point.
Definition: Track.h:795
TrackPointIterator operator++(int)
Definition: Track.h:1331
TrackProxy track_proxy_t
Definition: Track.h:1306
auto withOriginalTrajectory(art::InputTag const &inputTag)
Adds recob::TrackTrajectory information to the proxy.
Definition: Track.h:1063
std::size_t nPoints() const
Returns the number of trajectory points in the track.
Definition: Track.h:984
Collection of data type definitions for collection proxies.
recob::TrackFitHitInfo TrackFitHitInfoTag
Tag used for the "standard" track fit information.
Definition: Track.h:506
const_iterator begin() const
Definition: Track.h:1372
auto selectPoints(Pred &&pred) const
Returns an iterable range with only points matching the mask.
Definition: Track.h:1424
std::vector< recob::Track > TrackDataProduct_t
Type of the main collection.
Definition: Track.h:500
std::ptrdiff_t difference_type
Definition: Track.h:1315
art::Ptr< recob::TrackTrajectory > const & originalTrajectoryPtr() const
Definition: Track.h:842
art::Ptr< recob::Hit > hitPtr() const
Returns the hit associated with the trajectory point.
Definition: Track.h:652
Class to assemble the required proxy.
std::input_iterator_tag iterator_category
Definition: Track.h:1320
recob::TrackFitHitInfo const * fitInfoAtPoint(std::size_t index) const
Returns fit info for the specified point (nullptr if not available).
Definition: Track.h:1409
Declaration of signal hit object.
Proxy tag for a recob::Track collection proxy.
Definition: Track.h:497
auto withZeroOrOneAs(Args &&...args)
Definition: withZeroOrOne.h:81
bool isPointValid() const
Returns whether the trajectory point is valid.
Definition: Track.h:644
STL namespace.
auto position() const -> decltype(auto)
Definition: Track.h:620
Structure for range-for iteration.
Definition: Track.h:261
auto filterRangeFor(Range &&range, Pred &&pred) -> decltype(auto)
Provides iteration only through elements passing a condition.
Base utilities for the implementation of data product facades.
auto hits() const -> decltype(auto)
Returns a collection-like range of hits of this track, at point order.
Definition: Track.h:791
bool operator==(TrackPointIterator const &other) const
Definition: Track.h:1338
Class for track proxy elements.
Definition: Track.h:730
std::tuple< recob::Track const *, art::Ptr< recob::Hit >, recob::TrackFitHitInfo const *, std::size_t > TrackPointData
Container of track point information.
Definition: Track.h:555
Base representation of a collection of proxied objects.
TrackPointData makeTrackPointData(TrackProxy const &track, std::size_t index)
Returns an object with information about the specified track point.
Definition: Track.h:708
tracking::Vector_t Vector_t
Definition: Track.h:56
Type of track point information.
Definition: Track.h:683
A class containing a set of flags.
Definition: BitMask.h:420
Wrapper for a track data proxy.
Definition: Track.h:255
TrackPointIteratorBox(track_proxy_t const &track)
Definition: Track.h:1370
Int_t max
Definition: plot.C:27
void hits()
Definition: readHits.C:15
TrackPoint(TrackPointData const &data)
Definition: Track.h:688
TrackPointIterator(track_proxy_t const &track, std::size_t index)
Definition: Track.h:1325
recob::TrackTrajectory const * originalTrajectoryCPtr() const noexcept
Definition: Track.h:1013
A trajectory in space reconstructed from hits.
Object storing per-hit information from a track fit.
TrackPoint(TrackPointData &&data)
Definition: Track.h:689
const_iterator end() const
Definition: Track.h:1375
std::add_const_t< TrackPointData > Wrapped_t
Definition: Track.h:588
Class to assemble the required proxy.
TrackPoint operator[](std::size_t index) const
Returns an iterable range with point-by-point information.
Definition: Track.h:997
auto wrapTrackPoint(Data const &wrappedData)
"Converts" point data into a proxy::TrackPointWrapper.
Definition: Track.h:1262
Encloses LArSoft data product proxy objects and utilities.See this doxygen module for an introduction...
Data product for reconstructed trajectory in space.
auto index() const -> decltype(auto)
Returns the index of this point in the trajectory.
Definition: Track.h:667
Provides recob::Track data product.
std::size_t nHits() const
Returns the number of hits associated with this track.
Definition: Track.h:799
point_iterator endPoint() const
Returns the iterator past the last point.
Definition: Track.h:990
value_type operator*() const
Definition: Track.h:1335
An element of a collection proxy.
recob::TrackFitHitInfo const * fitInfoPtr() const
Returns fit info associated with the trajectory point.
Definition: Track.h:663
TrackPoint point(std::size_t index) const
Definition: Track.h:994
std::string value(boost::any const &)
recob::Hit const * hit() const
Returns a pointer to the hit on the trajectory point, if any.
Definition: Track.h:670
auto pointsWithFlags(recob::TrackTrajectory::PointFlags_t::Mask_t mask) const
Returns an iterable range with only points matching the mask.
Definition: Track.h:1431
typename track_proxy_t::point_iterator const_iterator
Definition: Track.h:1368
Represents a track trajectory before the final fit.
Definition: Track.h:513
track_proxy_t const * track
Definition: Track.h:1308
tracking::Point_t Point_t
Definition: Track.h:55
TrackType_t
Types of tracks and trajectories.
Definition: Track.h:512
Utilities to manipulate range for loops.
auto withFitHitInfo(art::InputTag const &inputTag)
Adds recob::TrackFitHitInfo information to the proxy.
Definition: Track.h:1132
point_iterator beginPoint() const
Returns the iterator to the data of the first point.
Definition: Track.h:987
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
Definition: Track.h:1035
bool hasOriginalTrajectory() const
Returns whether this track is associated to a trajectory.
Definition: Track.h:837
auto momentum() const -> decltype(auto)
Definition: Track.h:625
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
recob::TrackTrajectory const & originalTrajectory() const
Returns a reference to the associated trajectory.
Definition: Track.h:854
Represents a track trajectory from the final fit.
Definition: Track.h:514
auto points() const
Returns an iterable range with point-by-point information.
Definition: Track.h:908
QuadExpr operator*(double v, const QuadExpr &e)
Definition: QuadExpr.h:39
Float_t track
Definition: plot.C:34
TrackPoint const * pointer
Definition: Track.h:1317
recob::Track const & track() const
Returns the track this point belongs to.
Definition: Track.h:615
bool operator!=(TrackPointIterator const &other) const
Definition: Track.h:1341
Wrapped_t const & base() const
Definition: Track.h:599
Set of flags pertaining a point of the track.
TrackPointIterator & operator++()
Definition: Track.h:1329
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:51
Event finding and building.
recob::Track const & track() const
Returns the pointed track.
Definition: Track.h:744
auto withParallelDataAs(Args &&...args)
Helper function to merge an auxiliary data product into the proxy.