LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
geo::vect::MiddlePointAccumulatorDim< N > Class Template Reference

Helper class to compute the middle point in a point set. More...

#include "geo_vectors_utils.h"

Public Member Functions

 MiddlePointAccumulatorDim ()
 Default constructor: starts with no accumulated point. More...
 
template<typename BeginIter , typename EndIter >
 MiddlePointAccumulatorDim (BeginIter begin, EndIter end)
 Constructor: starts with accumulating a sequence of points. More...
 
Result query
bool empty () const
 Returns whether the total weight is zero (usually means no points). More...
 
double weight () const
 Returns the total weight (number of points if all have weight 1). More...
 
template<typename Point >
Point middlePointAs () const
 Returns the middle point, NaN components if no point. More...
 
geo::Point_t middlePoint () const
 
Addition of points
template<typename Point >
void add (Point const &p)
 Accumulates a point. More...
 
template<typename Point >
void add (Point const &p, double weight)
 Accumulates a point. More...
 
template<typename BeginIter , typename EndIter >
void add (BeginIter begin, EndIter end)
 Adds a sequence of points. More...
 
void clear ()
 Resets the status of the object to no accumulated points. More...
 

Private Types

using IndexSequence_t = std::make_index_sequence< Dim >
 

Private Member Functions

template<typename Point , std::size_t... I>
Point makePointImpl (std::index_sequence< I... >) const
 
template<typename Point , std::size_t... I>
Point makeWeightedPointImpl (double w, std::index_sequence< I... >) const
 
template<typename Point >
Point makePoint () const
 Converts the internal sums into a Point. More...
 
template<typename Point >
Point makeWeightedPoint (double w) const
 

Private Attributes

std::array< Length_t, DimfSums
 Sum of each of the point components. More...
 
double fW = 0.0
 Total weight. More...
 

Static Private Attributes

static constexpr unsigned int Dim = N
 Dimension of the points. More...
 

Detailed Description

template<unsigned int N = 3U>
class geo::vect::MiddlePointAccumulatorDim< N >

Helper class to compute the middle point in a point set.


Template Parameters
N_(default: 3)_ dimension of the points

This class accumulates cartesian points and returns their middle point when asked.

In the following example, only the points from a list (points) which have y coordinate larger than 0 are averaged, all with the same weight:

std::array<geo::Point_t, 4> const points = {
geo::Point_t{ 0.0, 1.0, 2.0 },
geo::Point_t{ 0.0, -1.0, 2.0 },
geo::Point_t{ 0.0, 1.0, -2.0 },
geo::Point_t{ 0.0, -1.0, -2.0 }
};
for (auto const& point: points)
if (point.Y() > 0.0) pointsAboveGround.add(point);
if (pointsAboveGround.empty())
throw std::runtime_error("No point above ground!");
auto middleAboveGround = pointsAboveGround.middlePoint();

Note the check to make sure that there are points that fulfil the requirement.

Definition at line 1042 of file geo_vectors_utils.h.

Member Typedef Documentation

template<unsigned int N = 3U>
using geo::vect::MiddlePointAccumulatorDim< N >::IndexSequence_t = std::make_index_sequence<Dim>
private

Definition at line 1154 of file geo_vectors_utils.h.

Constructor & Destructor Documentation

template<unsigned int N = 3U>
geo::vect::MiddlePointAccumulatorDim< N >::MiddlePointAccumulatorDim ( )
inline

Default constructor: starts with no accumulated point.

Definition at line 1049 of file geo_vectors_utils.h.

1049 { fSums.fill(0.); }
std::array< Length_t, Dim > fSums
Sum of each of the point components.
template<unsigned int N = 3U>
template<typename BeginIter , typename EndIter >
geo::vect::MiddlePointAccumulatorDim< N >::MiddlePointAccumulatorDim ( BeginIter  begin,
EndIter  end 
)
inline

Constructor: starts with accumulating a sequence of points.

Template Parameters
BeginItertype of iterator to a point type compatible with add()
EndItertype of end iterator
Parameters
beginiterator to the first point to be added
enditerator after the last point to be added
See also
add()

Definition at line 1060 of file geo_vectors_utils.h.

1062  { add(begin, end); }
void add(Point const &p)
Accumulates a point.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
MiddlePointAccumulatorDim()
Default constructor: starts with no accumulated point.
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)

Member Function Documentation

template<unsigned int N = 3U>
template<typename Point >
void geo::vect::MiddlePointAccumulatorDim< N >::add ( Point const &  p)
inline

Accumulates a point.

Template Parameters
Pointpoint type, required to have X(), Y() and Z() accessors
Parameters
ppoint to be included

The point is added with weight 1.

Definition at line 1112 of file geo_vectors_utils.h.

References geo::vect::bindCoordManagers().

Referenced by trkf::TrajectoryMCSFitter::linearRegression().

1113  {
1114  std::size_t ic = 0U;
1115  for (auto c: geo::vect::bindCoordManagers(p)) fSums[ic++] += c();
1116  fW += 1.0;
1117  }
std::array< Length_t, Dim > fSums
Sum of each of the point components.
constexpr auto bindCoordManagers(Vector &v)
template<unsigned int N = 3U>
template<typename Point >
void geo::vect::MiddlePointAccumulatorDim< N >::add ( Point const &  p,
double  weight 
)
inline

Accumulates a point.

Template Parameters
Pointpoint type, required to have X(), Y() and Z() accessors
Parameters
ppoint to be included
weightthe relative weight of this point

Definition at line 1126 of file geo_vectors_utils.h.

References geo::vect::bindCoordManagers(), and weight.

1127  {
1128  std::size_t ic = 0U;
1129  for (auto c: geo::vect::bindCoordManagers(p))
1130  fSums[ic++] += weight * c();
1131  fW += weight;
1132  }
double weight() const
Returns the total weight (number of points if all have weight 1).
std::array< Length_t, Dim > fSums
Sum of each of the point components.
constexpr auto bindCoordManagers(Vector &v)
template<unsigned int N = 3U>
template<typename BeginIter , typename EndIter >
void geo::vect::MiddlePointAccumulatorDim< N >::add ( BeginIter  begin,
EndIter  end 
)
inline

Adds a sequence of points.

Template Parameters
BeginItertype of iterator to a point type compatible with add()
EndItertype of end iterator
Parameters
beginiterator to the first point to be added
enditerator after the last point to be added

Each point is added with weight 1.0.

Definition at line 1144 of file geo_vectors_utils.h.

1145  { std::for_each(begin, end, [this](auto const& p){ this->add(p); }); }
void add(Point const &p)
Accumulates a point.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
template<unsigned int N = 3U>
void geo::vect::MiddlePointAccumulatorDim< N >::clear ( )
inline

Resets the status of the object to no accumulated points.

Definition at line 1148 of file geo_vectors_utils.h.

1148 { fSums.fill(0.); fW = 0.0; }
std::array< Length_t, Dim > fSums
Sum of each of the point components.
template<unsigned int N = 3U>
bool geo::vect::MiddlePointAccumulatorDim< N >::empty ( ) const
inline

Returns whether the total weight is zero (usually means no points).

Definition at line 1070 of file geo_vectors_utils.h.

1070 { return fW == 0.0; }
template<unsigned int N = 3U>
template<typename Point >
Point geo::vect::MiddlePointAccumulatorDim< N >::makePoint ( ) const
inlineprivate

Converts the internal sums into a Point.

Definition at line 1166 of file geo_vectors_utils.h.

1167  { return geo::vect::makeFromCoords<Point>(fSums); }
std::array< Length_t, Dim > fSums
Sum of each of the point components.
template<unsigned int N = 3U>
template<typename Point , std::size_t... I>
Point geo::vect::MiddlePointAccumulatorDim< N >::makePointImpl ( std::index_sequence< I... >  ) const
inlineprivate

Definition at line 1157 of file geo_vectors_utils.h.

1158  { return { fSums.operator[](I)... }; }
std::array< Length_t, Dim > fSums
Sum of each of the point components.
template<unsigned int N = 3U>
template<typename Point >
Point geo::vect::MiddlePointAccumulatorDim< N >::makeWeightedPoint ( double  w) const
inlineprivate

Converts the internal sums into a Point with components scaled by w.

Definition at line 1172 of file geo_vectors_utils.h.

References w.

1173  { return makeWeightedPointImpl<Point>(w, IndexSequence_t{}); }
std::make_index_sequence< Dim > IndexSequence_t
Float_t w
Definition: plot.C:23
template<unsigned int N = 3U>
template<typename Point , std::size_t... I>
Point geo::vect::MiddlePointAccumulatorDim< N >::makeWeightedPointImpl ( double  w,
std::index_sequence< I... >   
) const
inlineprivate

Definition at line 1161 of file geo_vectors_utils.h.

1162  { return { (fSums.operator[](I) * w)... }; }
std::array< Length_t, Dim > fSums
Sum of each of the point components.
Float_t w
Definition: plot.C:23
template<unsigned int N = 3U>
geo::Point_t geo::vect::MiddlePointAccumulatorDim< N >::middlePoint ( ) const
inline

Returns the middle point as a geo::Point_t, NaN components if no point.

Definition at line 1093 of file geo_vectors_utils.h.

Referenced by trkf::TrajectoryMCSFitter::linearRegression().

1094  { return middlePointAs<geo::Point_t>(); }
template<unsigned int N = 3U>
template<typename Point >
Point geo::vect::MiddlePointAccumulatorDim< N >::middlePointAs ( ) const
inline

Returns the middle point, NaN components if no point.

Template Parameters
Pointtype of the output point

The type of return point must be specified as template argument, e.g.

auto mp = accumulator.middlePointAs<TVector3>();

The Point type is required to have a constructor with the three cartesian components as arguments.

Definition at line 1087 of file geo_vectors_utils.h.

1089  { return makeWeightedPoint<Point>(1.0 / fW); }
template<unsigned int N = 3U>
double geo::vect::MiddlePointAccumulatorDim< N >::weight ( ) const
inline

Returns the total weight (number of points if all have weight 1).

Definition at line 1073 of file geo_vectors_utils.h.

1073 { return fW; }

Member Data Documentation

template<unsigned int N = 3U>
constexpr unsigned int geo::vect::MiddlePointAccumulatorDim< N >::Dim = N
staticprivate

Dimension of the points.

Definition at line 1043 of file geo_vectors_utils.h.

template<unsigned int N = 3U>
std::array<Length_t, Dim> geo::vect::MiddlePointAccumulatorDim< N >::fSums
private

Sum of each of the point components.

Definition at line 1044 of file geo_vectors_utils.h.

template<unsigned int N = 3U>
double geo::vect::MiddlePointAccumulatorDim< N >::fW = 0.0
private

Total weight.

Definition at line 1045 of file geo_vectors_utils.h.


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