00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef SimEvent_SimStatistic_H
00016 #define SimEvent_SimStatistic_H 1
00017
00018
00019 #include "GaudiKernel/boost_allocator.h"
00020 #include <cmath>
00021 #include <map>
00022 #include <ostream>
00023
00024
00025
00026 namespace DayaBay
00027 {
00028
00029
00030 class SimStatistic;
00031
00032
00042 class SimStatistic
00043 {
00044 public:
00045
00047 SimStatistic() : m_count(0),
00048 m_sum(0),
00049 m_squaredsum(0) {}
00050
00052 virtual ~SimStatistic() {}
00053
00055 double mean() const;
00056
00058 double rms() const;
00059
00061 void increment(double x);
00062
00064 SimStatistic& operator+=(const DayaBay::SimStatistic& rhs);
00065
00067 SimStatistic operator+(const DayaBay::SimStatistic& rhs) const;
00068
00070 std::ostream& fillStream(std::ostream& s) const;
00071
00074 double count() const;
00075
00078 void setCount(double value);
00079
00082 double sum() const;
00083
00086 void setSum(double value);
00087
00090 double squaredsum() const;
00091
00094 void setSquaredsum(double value);
00095
00096
00097 #ifndef GOD_NOALLOC
00099 static void* operator new ( size_t size )
00100 {
00101 return ( sizeof(SimStatistic) == size ?
00102 boost::singleton_pool<SimStatistic, sizeof(SimStatistic)>::malloc() :
00103 ::operator new(size) );
00104 }
00105
00109 static void* operator new ( size_t size, void* pObj )
00110 {
00111 return ::operator new (size,pObj);
00112 }
00113
00115 static void operator delete ( void* p )
00116 {
00117 boost::singleton_pool<SimStatistic, sizeof(SimStatistic)>::is_from(p) ?
00118 boost::singleton_pool<SimStatistic, sizeof(SimStatistic)>::free(p) :
00119 ::operator delete(p);
00120 }
00121
00124 static void operator delete ( void* p, void* pObj )
00125 {
00126 ::operator delete (p, pObj);
00127 }
00128 #endif
00129 protected:
00130
00131 private:
00132
00133 double m_count;
00134 double m_sum;
00135 double m_squaredsum;
00136
00137 };
00138
00139 inline std::ostream& operator<< (std::ostream& str, const SimStatistic& obj)
00140 {
00141 return obj.fillStream(str);
00142 }
00143
00144 }
00145
00146
00147
00148
00149
00150
00151
00152 inline double DayaBay::SimStatistic::count() const
00153 {
00154 return m_count;
00155 }
00156
00157 inline void DayaBay::SimStatistic::setCount(double value)
00158 {
00159 m_count = value;
00160 }
00161
00162 inline double DayaBay::SimStatistic::sum() const
00163 {
00164 return m_sum;
00165 }
00166
00167 inline void DayaBay::SimStatistic::setSum(double value)
00168 {
00169 m_sum = value;
00170 }
00171
00172 inline double DayaBay::SimStatistic::squaredsum() const
00173 {
00174 return m_squaredsum;
00175 }
00176
00177 inline void DayaBay::SimStatistic::setSquaredsum(double value)
00178 {
00179 m_squaredsum = value;
00180 }
00181
00182 inline double DayaBay::SimStatistic::mean() const
00183 {
00184
00185 return m_sum/m_count;
00186
00187 }
00188
00189 inline double DayaBay::SimStatistic::rms() const
00190 {
00191
00192 return sqrt((m_squaredsum - m_sum*m_sum/m_count)/(m_count));
00193
00194 }
00195
00196 inline void DayaBay::SimStatistic::increment(double x)
00197 {
00198
00199 m_count+=1.0;
00200 m_sum += x;
00201 m_squaredsum += x*x;
00202
00203 }
00204
00205 inline DayaBay::SimStatistic& DayaBay::SimStatistic::operator+=(const DayaBay::SimStatistic& rhs)
00206 {
00207
00208 m_count+=rhs.m_count;
00209 m_sum += rhs.m_sum;
00210 m_squaredsum += rhs.m_squaredsum;
00211 return *this;
00212
00213 }
00214
00215 inline DayaBay::SimStatistic DayaBay::SimStatistic::operator+(const DayaBay::SimStatistic& rhs) const
00216 {
00217
00218 SimStatistic res;
00219 res.m_count = m_count + rhs.m_count;
00220 res.m_sum = m_sum + rhs.m_sum;
00221 res.m_squaredsum = m_squaredsum + rhs.m_squaredsum;
00222 return res;
00223
00224 }
00225
00226
00227 #endif