LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
proxy::TrackCollectionProxyElement< CollProxy > Struct Template Reference

Class for track proxy elements. More...

#include "Track.h"

Inheritance diagram for proxy::TrackCollectionProxyElement< CollProxy >:
proxy::CollectionProxyElement< CollProxy >

Public Types

using base_t = CollectionProxyElement< CollProxy >
 Base type. More...
 
using track_proxy_t = TrackCollectionProxyElement< CollProxy >
 This type. More...
 
using point_iterator = TrackPointIterator< track_proxy_t >
 Iterator for trajectory point information. More...
 
using collection_proxy_t = CollProxy
 
using main_element_t = typename collection_proxy_t::main_element_t
 
using aux_elements_t = typename details::SubstituteWithAuxList< typename collection_proxy_t::aux_collections_t >::type
 Tuple of elements (expected to be tagged types). More...
 

Public Member Functions

recob::Track const & track () const
 Returns the pointed track. More...
 
recob::TrackTrajectory const * operator() (proxy::Tracks::TrackType_t type) const noexcept
 Returns the requested trajectory from the proxy. More...
 
recob::TrackFitHitInfo const * fitInfoAtPoint (std::size_t index) const
 Returns fit info for the specified point (nullptr if not available). More...
 
main_element_t const * operator-> () const
 Returns a pointer to the main element. More...
 
main_element_t const & operator* () const
 Returns a reference to the main element. More...
 
std::size_t index () const
 Returns the index of this element in the collection. More...
 
template<typename Tag >
auto get () const -> decltype(auto)
 Returns the auxiliary data specified by type (Tag). More...
 
template<typename Tag , typename T = Tag const&>
auto getIf () const -> decltype(auto)
 Returns the auxiliary data specified by type (Tag). More...
 
Direct hit interface.

The track prescription requires one hit per trajectory point.

Note
Remember that in particular cases there might be a hit without point of vice versa. In those cases, the point will have a dummy value, or the hit pointer will have isNull() true. In the former case, the point flag isPointValid() should be unset.

The interface at track proxy level allows for both access to the whole sequence of hits, or to the hit of a specific point:

assert(track.nHits() > 0);
auto const& hits = track.hits();
art::Ptr<recob::Hit> maxHit = hits[0]; // direct access
for (art::Ptr<recob::Hit> const& hit: hits) {
if (hit.isNull()) continue;
if (maxHit.isNull() || maxHit->Charge() < hit->Charge())
maxHit = hit;
} // for
art::Ptr<recob::Hit> lastHit = track.hitAtPoint(track.nHits() - 1U);
auto hits () const -> decltype(auto)
 Returns a collection-like range of hits of this track, at point order. More...
 
auto hitAtPoint (std::size_t index) const -> decltype(auto)
 Returns an art pointer to the hit associated with the specified point. More...
 
std::size_t nHits () const
 Returns the number of hits associated with this track. More...
 
Direct track trajectory interface
See also
proxy::TrackPoint

The interface allows to check if this track has a trajectory associated with it, and to obtain a reference to it or its art pointer.

bool hasTraj = proxy.hasOriginalTrajectory();
if (hasTraj) {
recob::TrackTrajectory const& trajectory = proxy.originalTrajectory();
// ...
}
= proxy.originalTrajectoryPtr();
if (!trajectoryPtr.isNull()) {
recob::TrackTrajectory const& trajectory = *trajectoryPtr;
// ...
}
Note
This interface can't be used if the track trajectory information has not been merged into the proxy (typically via proxy::withOriginalTrajectory()).
bool hasOriginalTrajectory () const
 Returns whether this track is associated to a trajectory. More...
 
art::Ptr< recob::TrackTrajectory > const & originalTrajectoryPtr () const
 
recob::TrackTrajectory const & originalTrajectory () const
 Returns a reference to the associated trajectory. More...
 
Point-by-point iteration interface

The points on track can be accessed individually with a special, non-extensible proxy.

In this example, points are accessed via iteration:

unsigned int nPoints = track.nPoints();
unsigned int nValidHits = 0;
for (auto point: track.points()) {
if (!point.hit().isNull()) ++nValidHits;
}
unsigned int nValidPoints = std::count_if
(track.beginPoint(), track.endPoint(), &TrackPoint::isPointValid);

Random (index-based) access is also available:

if (track.nPoints() > 1) {
auto point = track.point(1); // or track[1]
// ...
}
auto points () const
 Returns an iterable range with point-by-point information. More...
 
template<typename Pred >
auto selectPoints (Pred &&pred) const
 Returns an iterable range with only points matching the mask. More...
 
auto pointsWithFlags (recob::TrackTrajectory::PointFlags_t::Mask_t mask) const
 Returns an iterable range with only points matching the mask. More...
 
std::size_t nPoints () const
 Returns the number of trajectory points in the track. More...
 
point_iterator beginPoint () const
 Returns the iterator to the data of the first point. More...
 
point_iterator endPoint () const
 Returns the iterator past the last point. More...
 
TrackPoint point (std::size_t index) const
 
TrackPoint operator[] (std::size_t index) const
 Returns an iterable range with point-by-point information. More...
 

Static Public Member Functions

template<typename Tag >
static constexpr bool has ()
 Returns whether this class knowns about the specified type (Tag). More...
 

Private Member Functions

recob::TrackTrajectory const * originalTrajectoryCPtr () const noexcept
 

Detailed Description

template<typename CollProxy>
struct proxy::TrackCollectionProxyElement< CollProxy >

Class for track proxy elements.

Template Parameters
CollProxytype of track proxy collection to get data from
See also
proxy::TrackPoint, proxy::TrackPointWrapper

For details on the track point interface see proxy::TrackPoint.

Definition at line 730 of file Track.h.

Member Typedef Documentation

template<typename CollProxy >
using proxy::CollectionProxyElement< CollProxy >::aux_elements_t = typename details::SubstituteWithAuxList <typename collection_proxy_t::aux_collections_t>::type
inherited

Tuple of elements (expected to be tagged types).

Definition at line 170 of file CollectionProxyElement.h.

template<typename CollProxy >
using proxy::TrackCollectionProxyElement< CollProxy >::base_t = CollectionProxyElement<CollProxy>

Base type.

Definition at line 733 of file Track.h.

template<typename CollProxy >
using proxy::CollectionProxyElement< CollProxy >::collection_proxy_t = CollProxy
inherited

Definition at line 165 of file CollectionProxyElement.h.

template<typename CollProxy >
using proxy::CollectionProxyElement< CollProxy >::main_element_t = typename collection_proxy_t::main_element_t
inherited

Definition at line 166 of file CollectionProxyElement.h.

template<typename CollProxy >
using proxy::TrackCollectionProxyElement< CollProxy >::point_iterator = TrackPointIterator<track_proxy_t>

Iterator for trajectory point information.

Definition at line 741 of file Track.h.

template<typename CollProxy >
using proxy::TrackCollectionProxyElement< CollProxy >::track_proxy_t = TrackCollectionProxyElement<CollProxy>

This type.

Definition at line 737 of file Track.h.

Member Function Documentation

template<typename CollProxy >
point_iterator proxy::TrackCollectionProxyElement< CollProxy >::beginPoint ( ) const
inline

Returns the iterator to the data of the first point.

Definition at line 987 of file Track.h.

987 { return { *this, 0 }; }
template<typename CollProxy >
point_iterator proxy::TrackCollectionProxyElement< CollProxy >::endPoint ( ) const
inline

Returns the iterator past the last point.

Definition at line 990 of file Track.h.

990 { return { *this, nPoints() }; }
std::size_t nPoints() const
Returns the number of trajectory points in the track.
Definition: Track.h:984
template<typename CollProxy >
recob::TrackFitHitInfo const * proxy::TrackCollectionProxyElement< CollProxy >::fitInfoAtPoint ( std::size_t  index) const

Returns fit info for the specified point (nullptr if not available).

Definition at line 1409 of file Track.h.

Referenced by proxy::TrackCollectionProxyElement< CollProxy >::operator()().

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()
recob::TrackFitHitInfo TrackFitHitInfoTag
Tag used for the "standard" track fit information.
Definition: Track.h:506
std::size_t index() const
Returns the index of this element in the collection.
auto getIf() const -> decltype(auto)
Returns the auxiliary data specified by type (Tag).
template<typename CollProxy >
template<typename Tag >
auto proxy::CollectionProxyElement< CollProxy >::get ( ) const -> decltype(auto)
inlineinherited

Returns the auxiliary data specified by type (Tag).

Definition at line 190 of file CollectionProxyElement.h.

191  { return std::get<util::index_of_tag_v<Tag, aux_elements_t>>(fAuxData); }
aux_elements_t fAuxData
Data associated to the main object.
template<typename CollProxy >
template<typename Tag , typename T >
auto proxy::CollectionProxyElement< CollProxy >::getIf ( ) const -> decltype(auto)
inherited

Returns the auxiliary data specified by type (Tag).

Template Parameters
Tagtag of the data to fetch (usually, its type)
Ttype to return (by default, a constant reference to Tag)
Returns
the auxiliary data specified by type (Tag).
Exceptions
std::logic_errorif the tag is not available.
See also
get(), has()

This method is a get() which forgives when the requested type is not available (because this proxy was configured not to hold it).

The difference with get() is the following:

decltype(auto) elem = tracks[0];
if (elem.has<recob::Hit>()) {
auto hits = elem.get<recob::Hit>();
// ...
}
if (elem.has<recob::SpacePoint>()) {
auto spacepoints = elem.getIf<recob::SpacePoint>();
// ...
}

If the proxy tracks has not been coded with recob::Hit data, the code snippet will not compile, because get() will not compile for tags that were not coded in. On the other end, if recob::Hit is coded in tracks but recob::SpacePoint is not, the snippet will compile. In that case, if the has() check had been omitted, getIt() would throw a std::logic_error exception when executed. With C++17, this will not be necessary any more by using "constexpr if":

decltype(auto) elem = tracks[0];
if constexpr (elem.has<recob::Hit>()) {
auto hits = elem.get<recob::Hit>();
// ...
}
if constexpr (elem.has<recob::SpacePoint>()) {
auto spacepoints = elem.get<recob::SpacePoint>();
// ...
}
Note
The second template argument contains the exact type returned by the function. That information is needed because this method needs to return the same type (or compatible types) whether the required tag is present or not, in order for user code like
if (elem.has<recob::SpacePoint>()) {
recob::SpacePoint const* spacepoints
= elem.getIf<recob::SpacePoint>(); // won't do
// ...
}
to work; it becomes:
if (elem.has<recob::SpacePoint>()) {
recob::SpacePoint const* spacepoints
= elem.getIf<recob::SpacePoint, recob::SpacePoint const*>();
// ...
}
This is necessary because when the tag (in the example, recob::SpacePoint) is not registered in the proxy, getIf() has no clue of what the return value should be ("which is the type of the data that does not exist?").

Definition at line 359 of file CollectionProxyElement.h.

References proxy::CollectionProxyElement< CollProxy >::getIfHas().

360  { return getIfHas<Tag, T>(util::bool_constant<has<Tag>()>{}); }
std::integral_constant< bool, Value > bool_constant
Definition: MetaUtils.h:168
template<typename CollProxy >
template<typename Tag >
static constexpr bool proxy::CollectionProxyElement< CollProxy >::has ( )
inlinestaticinherited

Returns whether this class knowns about the specified type (Tag).

Definition at line 267 of file CollectionProxyElement.h.

267 { return util::has_tag_v<Tag, aux_elements_t>; }
template<typename CollProxy >
bool proxy::TrackCollectionProxyElement< CollProxy >::hasOriginalTrajectory ( ) const
inline

Returns whether this track is associated to a trajectory.

Definition at line 837 of file Track.h.

838  { return !originalTrajectoryPtr().isNull(); }
art::Ptr< recob::TrackTrajectory > const & originalTrajectoryPtr() const
Definition: Track.h:842
template<typename CollProxy >
auto proxy::TrackCollectionProxyElement< CollProxy >::hitAtPoint ( std::size_t  index) const -> decltype(auto)
inline

Returns an art pointer to the hit associated with the specified point.

Definition at line 795 of file Track.h.

References hits().

796  { return hits()[index]; }
auto hits() const -> decltype(auto)
Returns a collection-like range of hits of this track, at point order.
Definition: Track.h:791
std::size_t index() const
Returns the index of this element in the collection.
template<typename CollProxy >
auto proxy::TrackCollectionProxyElement< CollProxy >::hits ( ) const -> decltype(auto)
inline

Returns a collection-like range of hits of this track, at point order.

Returns
a range of art pointers to hits

One hit is expected per trajectory point. Hits can be missing, in which case the art pointer will have isNull() as true.

Definition at line 791 of file Track.h.

792  { return base_t::template get<Tracks::HitTag>(); }
template<typename CollProxy >
std::size_t proxy::CollectionProxyElement< CollProxy >::index ( ) const
inlineinherited

Returns the index of this element in the collection.

Definition at line 186 of file CollectionProxyElement.h.

186 { return fIndex; };
std::size_t fIndex
Index of this element in the proxy.
template<typename CollProxy >
std::size_t proxy::TrackCollectionProxyElement< CollProxy >::nHits ( ) const
inline

Returns the number of hits associated with this track.

Definition at line 799 of file Track.h.

References hits().

799 { return hits().size(); }
auto hits() const -> decltype(auto)
Returns a collection-like range of hits of this track, at point order.
Definition: Track.h:791
template<typename CollProxy >
std::size_t proxy::TrackCollectionProxyElement< CollProxy >::nPoints ( ) const
inline

Returns the number of trajectory points in the track.

Definition at line 984 of file Track.h.

References track.

984 { return track().NPoints(); }
size_t NPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:106
recob::Track const & track() const
Returns the pointed track.
Definition: Track.h:744
template<typename CollProxy >
recob::TrackTrajectory const * proxy::TrackCollectionProxyElement< CollProxy >::operator() ( proxy::Tracks::TrackType_t  type) const
noexcept

Returns the requested trajectory from the proxy.

Parameters
typetype of the track trajectory to be returned
Returns
a reference to the requested track trajectory

Definition at line 1392 of file Track.h.

References proxy::TrackCollectionProxyElement< CollProxy >::fitInfoAtPoint(), proxy::Tracks::Fitted, track, and proxy::Tracks::Unfitted.

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()
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:101
recob::TrackTrajectory const * originalTrajectoryCPtr() const noexcept
Definition: Track.h:1013
Represents a track trajectory before the final fit.
Definition: Track.h:513
Represents a track trajectory from the final fit.
Definition: Track.h:514
recob::Track const & track() const
Returns the pointed track.
Definition: Track.h:744
template<typename CollProxy >
main_element_t const& proxy::CollectionProxyElement< CollProxy >::operator* ( ) const
inlineinherited

Returns a reference to the main element.

Definition at line 183 of file CollectionProxyElement.h.

183 { return *fMain; }
main_element_t const * fMain
Pointer to the main object of the element.
template<typename CollProxy >
main_element_t const* proxy::CollectionProxyElement< CollProxy >::operator-> ( ) const
inlineinherited

Returns a pointer to the main element.

Definition at line 180 of file CollectionProxyElement.h.

180 { return fMain; }
main_element_t const * fMain
Pointer to the main object of the element.
template<typename CollProxy >
TrackPoint proxy::TrackCollectionProxyElement< CollProxy >::operator[] ( std::size_t  index) const
inline

Returns an iterable range with point-by-point information.

See also
proxy::TrackPoint, proxy::TrackPointWrapper

The interface of the elements is documented in TrackPointWrapper. Example:

for (auto const& pointInfo: track.points()) {
if (!pointInfo.flags().isPointValid()) continue;
auto const& pos = pointInfo.position();
// ...
} // for point

will iterate through all points (including the invalid ones, hence the check).

Definition at line 997 of file Track.h.

998  { return point(index); }
std::size_t index() const
Returns the index of this element in the collection.
TrackPoint point(std::size_t index) const
Definition: Track.h:994
template<typename CollProxy >
recob::TrackTrajectory const& proxy::TrackCollectionProxyElement< CollProxy >::originalTrajectory ( ) const
inline

Returns a reference to the associated trajectory.

Returns
the associated trajectory as a constant reference
See also
originalTrajectoryPtr(), hasOriginalTrajectory()

If the track is not associated to any trajectory, the return value is undefined. This condition should be checked beforehand, e.g. with hasTrajectory().

Definition at line 854 of file Track.h.

855  { return *originalTrajectoryPtr(); }
art::Ptr< recob::TrackTrajectory > const & originalTrajectoryPtr() const
Definition: Track.h:842
template<typename CollProxy >
recob::TrackTrajectory const* proxy::TrackCollectionProxyElement< CollProxy >::originalTrajectoryCPtr ( ) const
inlineprivatenoexcept

Definition at line 1013 of file Track.h.

1014  { return hasOriginalTrajectory()? &originalTrajectory(): nullptr; }
bool hasOriginalTrajectory() const
Returns whether this track is associated to a trajectory.
Definition: Track.h:837
recob::TrackTrajectory const & originalTrajectory() const
Returns a reference to the associated trajectory.
Definition: Track.h:854
template<typename CollProxy >
art::Ptr<recob::TrackTrajectory> const& proxy::TrackCollectionProxyElement< CollProxy >::originalTrajectoryPtr ( ) const
inline

Returns an art pointer to the associated trajectory.

Returns
pointer to the associated trajectory (isNull() true if none)

Definition at line 842 of file Track.h.

843  { return base_t::template get<Tracks::TrackTrajectoryTag>(); }
template<typename CollProxy >
TrackPoint proxy::TrackCollectionProxyElement< CollProxy >::point ( std::size_t  index) const
inline

Extracts information from the specified point.

Definition at line 994 of file Track.h.

References proxy::makeTrackPointData(), and track.

995  { return { makeTrackPointData(track(), index) }; }
TrackPointData makeTrackPointData(TrackProxy const &track, std::size_t index)
Returns an object with information about the specified track point.
Definition: Track.h:708
std::size_t index() const
Returns the index of this element in the collection.
recob::Track const & track() const
Returns the pointed track.
Definition: Track.h:744
template<typename CollProxy >
auto proxy::TrackCollectionProxyElement< CollProxy >::points ( ) const
inline

Returns an iterable range with point-by-point information.

See also
proxy::TrackPoint, proxy::TrackPointWrapper

The interface of the elements is documented in TrackPointWrapper. Example:

for (auto const& pointInfo: track.points()) {
if (!pointInfo.flags().isPointValid()) continue;
auto const& pos = pointInfo.position();
// ...
} // for point

will iterate through all points (including the invalid ones, hence the check).

Definition at line 908 of file Track.h.

909  { return details::TrackPointIteratorBox<CollProxy>(*this); }
template<typename CollProxy >
auto proxy::TrackCollectionProxyElement< CollProxy >::pointsWithFlags ( recob::TrackTrajectory::PointFlags_t::Mask_t  mask) const

Returns an iterable range with only points matching the mask.

Parameters
maskpoint flag mask to be matched
Returns
an object that can be forward-iterated
See also
points(), util::flags::BitMask::match()

This methods is used in a way similar to points(), with the addition of specifying a mask of flags. The iteration will happen only through the points which match the mask. that is for which pointInfo.flags().match(mask) is true.

The interface of the elements is documented in TrackPointWrapper. Example:

for (auto const& pointInfo
)
{
auto const& pos = pointInfo.position();
// ...
} // for point

will iterate through only the points which do not have the NoPoint flag set (which have in fact a valid position).

Definition at line 1431 of file Track.h.

Referenced by proxy::TrackCollectionProxyElement< CollProxy >::selectPoints().

1432  {
1433  return
1434  selectPoints([mask](auto&& point) { return point.flags().match(mask); });
1435  } // TrackCollectionProxyElement<>::pointsWithFlags()
auto selectPoints(Pred &&pred) const
Returns an iterable range with only points matching the mask.
Definition: Track.h:1424
auto flags() const -> decltype(auto)
Definition: Track.h:635
TrackPoint point(std::size_t index) const
Definition: Track.h:994
template<typename CollProxy >
template<typename Pred >
auto proxy::TrackCollectionProxyElement< CollProxy >::selectPoints ( Pred &&  pred) const

Returns an iterable range with only points matching the mask.

Template Parameters
Predtype of predicate to test on points
Parameters
predpredicate to be fulfilled by the points
Returns
an object that can be forward-iterated
See also
points(), pointsWithFlags()

This methods is used in a way similar to points(), with the addition of specifying a criterium (predicate) defining the selected points. The iteration will happen only through the points which fulfil the predicate.

The interface of the elements is documented in TrackPointWrapper. Example:

auto farPoints = [](auto const& pointInfo)
{ return pointInfo.isPointValid() && pointInfo.position().Z() > 50.; };
for (auto const& pointInfo: track.selectPoints(farPoints)) {
auto const& pos = pointInfo.position();
// ...
} // for point

will iterate through all points which are valid and whose position is at z absolute coordinate larger than 50 centimeters (whatever it means).

Requirements

  • Pred is a unary function object which can accept a TrackPoint object as its sole argument and which returns a value convertible to bool

Definition at line 1424 of file Track.h.

References util::filterRangeFor(), and proxy::TrackCollectionProxyElement< CollProxy >::pointsWithFlags().

1425  { return util::filterRangeFor(points(), std::forward<Pred>(pred)); }
auto filterRangeFor(Range &&range, Pred &&pred) -> decltype(auto)
Provides iteration only through elements passing a condition.
auto points() const
Returns an iterable range with point-by-point information.
Definition: Track.h:908
template<typename CollProxy >
recob::Track const& proxy::TrackCollectionProxyElement< CollProxy >::track ( ) const
inline

Returns the pointed track.

Definition at line 744 of file Track.h.

References operator*().

744 { return base_t::operator*(); }
main_element_t const & operator*() const
Returns a reference to the main element.

The documentation for this struct was generated from the following file: