All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
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 1246 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 1358 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 1253 of file geo_vectors_utils.h.

1253 { 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 1264 of file geo_vectors_utils.h.

1266  { add(begin, end); }
void add(Point const &p)
Accumulates a point.
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
MiddlePointAccumulatorDim()
Default constructor: starts with no accumulated point.

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 1316 of file geo_vectors_utils.h.

1317  {
1318  std::size_t ic = 0U;
1319  for (auto c: geo::vect::bindCoordManagers(p)) fSums[ic++] += c();
1320  fW += 1.0;
1321  }
pdgs p
Definition: selectors.fcl:22
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 1330 of file geo_vectors_utils.h.

1331  {
1332  std::size_t ic = 0U;
1333  for (auto c: geo::vect::bindCoordManagers(p))
1334  fSums[ic++] += weight * c();
1335  fW += weight;
1336  }
pdgs p
Definition: selectors.fcl:22
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 1348 of file geo_vectors_utils.h.

1349  { std::for_each(begin, end, [this](auto const& p){ this->add(p); }); }
pdgs p
Definition: selectors.fcl:22
void add(Point const &p)
Accumulates a point.
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
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 1352 of file geo_vectors_utils.h.

1352 { 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 1274 of file geo_vectors_utils.h.

1274 { 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 1370 of file geo_vectors_utils.h.

1371  { 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 1361 of file geo_vectors_utils.h.

1362  { return { fSums.operator[](I)... }; }
see a below echo or echo I(indirect symbol).'echo" If the symbol is local (non-external)
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 1376 of file geo_vectors_utils.h.

1377  { return makeWeightedPointImpl<Point>(w, IndexSequence_t{}); }
std::make_index_sequence< Dim > IndexSequence_t
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 1365 of file geo_vectors_utils.h.

1366  { return { (fSums.operator[](I) * w)... }; }
see a below echo or echo I(indirect symbol).'echo" If the symbol is local (non-external)
std::array< Length_t, Dim > fSums
Sum of each of the point components.
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 1297 of file geo_vectors_utils.h.

1298  { 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 1291 of file geo_vectors_utils.h.

1293  { 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 1277 of file geo_vectors_utils.h.

1277 { 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 1247 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 1248 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 1249 of file geo_vectors_utils.h.


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