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

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

1048 { 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 1059 of file geo_vectors_utils.h.

1061  { add(begin, end); }
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.
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.
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 1111 of file geo_vectors_utils.h.

1112  {
1113  std::size_t ic = 0U;
1114  for (auto c: geo::vect::bindCoordManagers(p)) fSums[ic++] += c();
1115  fW += 1.0;
1116  }
p
Definition: test.py:223
constexpr auto bindCoordManagers(Vector &v)
std::array< Length_t, Dim > fSums
Sum of each of the point components.
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 1125 of file geo_vectors_utils.h.

1126  {
1127  std::size_t ic = 0U;
1128  for (auto c: geo::vect::bindCoordManagers(p))
1129  fSums[ic++] += weight * c();
1130  fW += weight;
1131  }
double weight() const
Returns the total weight (number of points if all have weight 1).
p
Definition: test.py:223
constexpr auto bindCoordManagers(Vector &v)
std::array< Length_t, Dim > fSums
Sum of each of the point components.
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 1143 of file geo_vectors_utils.h.

1144  { std::for_each(begin, end, [this](auto const& p){ this->add(p); }); }
void add(Point const &p)
Accumulates a point.
decltype(auto) begin(ROOT::Math::LorentzVector< CoordSystem > const &v)
p
Definition: test.py:223
decltype(auto) end(ROOT::Math::LorentzVector< CoordSystem > const &v)
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  }
p
Definition: test.py:223
constexpr auto bindCoordManagers(Vector &v)
std::array< Length_t, Dim > fSums
Sum of each of the point components.
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  }
double weight() const
Returns the total weight (number of points if all have weight 1).
p
Definition: test.py:223
constexpr auto bindCoordManagers(Vector &v)
std::array< Length_t, Dim > fSums
Sum of each of the point components.
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); }); }
void add(Point const &p)
Accumulates a point.
decltype(auto) begin(ROOT::Math::LorentzVector< CoordSystem > const &v)
p
Definition: test.py:223
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 1147 of file geo_vectors_utils.h.

1147 { fSums.fill(0.); fW = 0.0; }
std::array< Length_t, Dim > fSums
Sum of each of the point components.
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 1069 of file geo_vectors_utils.h.

1069 { return fW == 0.0; }
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 1165 of file geo_vectors_utils.h.

1166  { 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 >
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 1156 of file geo_vectors_utils.h.

1157  { 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 , 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)... }; }
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 1171 of file geo_vectors_utils.h.

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

1161  { return { (fSums.operator[](I) * w)... }; }
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 >::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)... }; }
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 1092 of file geo_vectors_utils.h.

1093  { return middlePointAs<geo::Point_t>(); }
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 1086 of file geo_vectors_utils.h.

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

1072 { return 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>
static constexpr unsigned int geo::vect::MiddlePointAccumulatorDim< N >::Dim = N
staticprivate

Dimension of the points.

Definition at line 1042 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 1043 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 1044 of file geo_vectors_utils.h.


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