1 #ifndef _utl_TimeDistribution_h_
2 #define _utl_TimeDistribution_h_
4 #include <utl/ErrorLogger.h>
5 #include <utl/AugerException.h>
6 #include <utl/IteratorRange.h>
8 #include <boost/tuple/tuple_io.hpp>
9 #include <boost/iterator/transform_iterator.hpp>
18 class TimeDistributionAlgorithm;
38 class TimeDistribution {
48 typedef boost::tuple<const int, const T>
Tuple;
52 {
return Tuple(pair.first, pair.second); }
70 typedef boost::transform_iterator<InternalMapFunctor,
86 if (
it->second == T()) {
97 AddTime(
const int slot,
const T weight = T(1))
104 const T w = (it->second += weight);
112 void AddTime(
const double time,
const T weight = T(1))
116 SetTime(
const int slot,
const T weight = T(1))
119 fData[slot] = weight;
122 if (it !=
fData.end())
127 void SetTime(
const double time,
const T weight = T(1))
141 static const T zero = T(0);
143 return it ==
fData.end() ? zero : it->second;
160 return it ==
fData.end() ? 0 : it->second;
163 T
At(
const double time)
const
173 for (
const auto& kv : td.fData)
175 val[kv.first] += kv.second;
178 const std::string msg =
"Cannot add two TimeDistributions with unequal binning.";
187 for (
const auto& kv : td.fData)
189 (*this)[kv.first] += kv.second;
192 const std::string msg =
"Cannot add two TimeDistributions with unequal binning.";
214 {
return fData.empty() ? 0 :
fData.rbegin()->first -
fData.begin()->first + 1; }
T At(const double time) const
int GetStart() const
First slot with data.
Tuple operator()(const InternalMapValue &pair) const
TimeDistribution(const double slotSize)
Constructor takes the bin size as an argument.
Base class for all exceptions used in the auger offline code.
void swap(utl::TabulatedFunction &t1, utl::TabulatedFunction &t2)
bool operator==(const TimeDistribution &td) const
Histogram class for time distributions with suppressed empty bins.
InternalMap::const_iterator InternalConstIterator
void Clear()
Remove contents of the TimeDistribution.
boost::tuple< const int, const T > Tuple
void SetTime(const double time, const T weight=T(1))
TimeDistribution< T > operator+(const TimeDistribution< T > &td) const
Add two traces. Adds only bins that have data in them.
const std::pair< InternalIterator, bool > ins
double GetBinning() const
Size of one slot.
const T & operator[](const int index) const
Return slot content.
T const
Query value without slot creation.
int GetStop() const
Last slot with data (1 less than First slot if no data)
T & operator[](const double time)
Return contents for slot containing the specified time.
std::map< int, T > InternalMap
#define OFFLINE_MAKE_CONST_ITERATOR_RANGE(_ConstIterator_, _NamePrefix_)
void Print(ostream &os, const TimeDistribution< T > &td)
bool operator!=(const TimeDistribution &td) const
SparseIterator SparseEnd() const
TimeDistribution< T > & operator+=(const TimeDistribution< T > &td)
T & operator[](const int index)
Return slot content.
int GetNumSlots() const
Number of slots from first slot with data up to last slot with data, including empty slots...
Utility class for returning properties of a TimeDistribution.
SparseIterator SparseBegin() const
Iterator over time slots with data in them (skips empty slots).
const T & operator[](const double time) const
#define ERROR(message)
Macro for logging error messages.
void AddTime(const double time, const T weight=T(1))
Add an entry (optionally weighted) for the given time. Slot will be computed.
InternalMap::value_type InternalMapValue
boost::transform_iterator< InternalMapFunctor, InternalConstIterator, Tuple > SparseIterator
InternalMap::iterator InternalIterator
int Purge()
Remove empty slots and return their number.