10#include <tracking/trackingUtilities/numerics/WithWeight.h>
22 namespace TrackFindingCDC {
24 template <
class T,
class AItem>
50 return std::accumulate(
begin(),
52 static_cast<TrackingUtilities::Weight
>(0.0),
54 return accumulatedWeight + weightedItem.
getWeight();
59 template <
class APredicate>
71 void insert(
const AItem& item, TrackingUtilities::Weight weight = 1.0)
79 template <
class AMeasure>
82 for (AItem item : items.m_items) {
83 const TrackingUtilities::Weight weight = measure(item);
84 if (not std::isnan(weight)) {
91 typename std::vector<TrackingUtilities::WithWeight<AItem>>::iterator
begin()
97 typename std::vector<TrackingUtilities::WithWeight<AItem>>::const_iterator
begin()
const
103 typename std::vector<TrackingUtilities::WithWeight<AItem>>::iterator
end()
109 typename std::vector<TrackingUtilities::WithWeight<AItem>>::const_iterator
end()
const
117 return std::distance(
begin(),
end());
126 Super& super = *
this;
127 TrackingUtilities::clearIfApplicable(super);
132 std::vector<TrackingUtilities::WithWeight<AItem>>
m_items;
135 typename std::vector<TrackingUtilities::WithWeight<AItem>>::iterator
m_itEnd{
m_items.end()};
WithWeightedItems< T, AItem > This
Type of this class.
std::vector< TrackingUtilities::WithWeight< AItem > >::const_iterator end() const
End iterator of the contained items.
size_t size() const
Getter for the number of items.
std::vector< TrackingUtilities::WithWeight< AItem > > m_items
Memory for the weighted items.
TrackingUtilities::Weight getWeight() const
Cumulated weight of the contained items.
void insert(const AItem &item, TrackingUtilities::Weight weight=1.0)
Add an item with weight.
void eraseIf(const APredicate &predicate)
Erase items from this node that satisfy the predicate.
T Super
Type of the base class.
WithWeightedItems(const T &t)
Also forward the copy constructor form the base class object.
std::vector< TrackingUtilities::WithWeight< AItem > >::const_iterator begin() const
Begin iterator of the contained items.
std::vector< TrackingUtilities::WithWeight< AItem > >::iterator end()
End iterator of the contained items.
std::vector< TrackingUtilities::WithWeight< AItem > >::iterator begin()
Begin iterator of the contained items.
void insert(const This &items, AMeasure &measure)
Add the items from another item range assigning a weight from the predicate.
void clear()
Clear the contained items.
std::vector< TrackingUtilities::WithWeight< AItem > >::iterator m_itEnd
Memory for the end of the items that are not erased.
A mixin class to attach a weight to an object.
Weight getWeight() const
Getter for the weight.
Abstract base class for different kinds of events.