LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 1333 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 1452 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 1340 of file geo_vectors_utils.h.

1340 { 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 1351 of file geo_vectors_utils.h.

1352  {
1353  add(begin, end);
1354  }
void add(Point const &p)
Accumulates a point.
decltype(auto) begin(ROOT::Math::LorentzVector< CoordSystem > const &v)
decltype(auto) end(ROOT::Math::LorentzVector< CoordSystem > const &v)
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 1403 of file geo_vectors_utils.h.

References geo::vect::bindCoordManagers().

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

1404  {
1405  std::size_t ic = 0U;
1406  for (auto c : geo::vect::bindCoordManagers(p))
1407  fSums[ic++] += c();
1408  fW += 1.0;
1409  }
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 1418 of file geo_vectors_utils.h.

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

1419  {
1420  std::size_t ic = 0U;
1421  for (auto c : geo::vect::bindCoordManagers(p))
1422  fSums[ic++] += weight * c();
1423  fW += weight;
1424  }
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 1436 of file geo_vectors_utils.h.

1437  {
1438  std::for_each(begin, end, [this](auto const& p) { this->add(p); });
1439  }
void add(Point const &p)
Accumulates a point.
decltype(auto) begin(ROOT::Math::LorentzVector< CoordSystem > const &v)
decltype(auto) end(ROOT::Math::LorentzVector< CoordSystem > const &v)
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 1442 of file geo_vectors_utils.h.

1443  {
1444  fSums.fill(0.);
1445  fW = 0.0;
1446  }
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 1361 of file geo_vectors_utils.h.

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

1469  {
1470  return geo::vect::makeFromCoords<Point>(fSums);
1471  }
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 1455 of file geo_vectors_utils.h.

1456  {
1457  return {fSums.operator[](I)...};
1458  }
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 1476 of file geo_vectors_utils.h.

References w.

1477  {
1478  return makeWeightedPointImpl<Point>(w, IndexSequence_t{});
1479  }
std::make_index_sequence< Dim > IndexSequence_t
Float_t w
Definition: plot.C:20
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 1461 of file geo_vectors_utils.h.

1462  {
1463  return {(fSums.operator[](I) * w)...};
1464  }
std::array< Length_t, Dim > fSums
Sum of each of the point components.
Float_t w
Definition: plot.C:20
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 1386 of file geo_vectors_utils.h.

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

1386 { 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 1378 of file geo_vectors_utils.h.

1380  {
1381  return makeWeightedPoint<Point>(1.0 / fW);
1382  }
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 1364 of file geo_vectors_utils.h.

1364 { 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 1334 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 1335 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 1336 of file geo_vectors_utils.h.


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