![]() |
Reference Documentation |
00001 #ifndef _FLOAT_WEIGHTED_BIN_H_ 00002 #define _FLOAT_WEIGHTED_BIN_H_ 1 00003 00004 #include <math.h> 00005 #include "HTL/I_Bin.h" 00006 #include "HTL/HTL_std.h" 00007 00008 #undef T_Value 00009 #define T_Value float 00010 00026 class Float_Weighted_Bin: public I_Bin { 00027 public: 00029 H_IID_IMPLEMENT( Float_Weighted_Bin ); 00030 public: 00031 typedef Float_Weighted_Bin Like_Current; 00032 typedef I_Bin Like_Parent; 00033 public: 00035 Float_Weighted_Bin(): I_Bin(), value_(0), error_(0), count_(0) {} 00037 ~Float_Weighted_Bin() {} 00038 public: // Inherited from I_Bin: 00040 double value( Index = 0 ) const { return value_; } 00041 00043 double error( Index = 0 ) const { return sqrt(error_); } 00044 00046 Size count() const { return count_; } 00047 00049 void set_value( double other, Index = 0 ){ value_ = T_Value(other); } 00050 00052 void set_error(double other, Index = 0){error_ = T_Value(other*other);} 00053 00055 void set_count( Size other ) { count_ = Size(other); } 00056 00058 void reset() { value_ = T_Value(0); error_ = T_Value(0); count_ = 0; } 00059 00061 00062 public: 00064 void put( T_Value a_weight ) 00065 { 00066 value_ += a_weight; 00067 error_ += a_weight * a_weight; 00068 count_ ++; 00069 } 00070 00072 00073 public: 00075 int operator==( const Like_Current &other ) const 00076 { 00077 return( 00078 (T_Value( value() ) == T_Value( other.value() )) && 00079 (T_Value( error() ) == T_Value( other.error() )) && 00080 (count() == other.count()) 00081 ); 00082 } 00083 00085 void make( const Like_Parent &other ) 00086 { 00087 value_ = T_Value( other.value() ); 00088 error_ = T_Value( other.error() * other.error() ); 00089 count_ = other.count(); 00090 } 00091 00093 void add( const Like_Parent &other ) 00094 { 00095 value_ = T_Value( value_ + other.value() ); 00096 error_ = T_Value( other.error() * other.error() + error_ ); 00097 count_ += other.count(); 00098 } 00099 00101 void sub( const Like_Parent &other ) 00102 { 00103 value_ = T_Value( value_ - other.value() ); 00104 error_ = T_Value( other.error() * other.error() + error_ ); 00105 count_ += other.count(); 00106 } 00107 00109 void mul( const Like_Parent &other ) 00110 { 00111 value_ = T_Value( other.value() * value_ ); 00112 error_ = T_Value( error_ * other.value()*other.value() + 00113 other.error()*other.error() * value_*value_ ) ; 00114 count_ += other.count(); 00115 } 00116 00121 void div( const Like_Parent &other ) 00122 { 00123 T_Value e = T_Value( other.error() ); 00124 e = T_Value( e*e * e*e * e*e * e*e ); 00125 if( T_Value(other.value()) == T_Value(0.) ) { 00126 HTL_ERR( "WARNING: Division by 0 in Float_Weighted_Bin: value" ); 00127 value_ = T_Value(0.); 00128 } else { 00129 value_ = T_Value( value_ / other.value() ); 00130 } 00131 error_ = T_Value( error_ * other.value()*other.value() + 00132 other.error()*other.error() * value_*value_ ) ; 00133 if( e == T_Value(0.) ) { 00134 HTL_ERR( "WARNING: Division by 0 in Float_Weighted_Bin: value" ); 00135 error_ = T_Value(0.); 00136 } else { 00137 error_ = T_Value( error_/e ); 00138 } 00139 count_ += other.count(); 00140 } 00141 00146 void binomial_div( const Like_Parent &other ) 00147 { 00148 if( T_Value(other.value()) == T_Value(0.) ) { 00149 HTL_ERR( "WARNING: Division by 0 in Weighted_Bin" ); 00150 value_ = T_Value(0.); 00151 } else { 00152 value_ = T_Value( value_ / other.value() ); 00153 } 00154 T_Value e = T_Value( other.error() ); 00155 if( e == T_Value(0.) ) { 00156 HTL_ERR( "WARNING: Division by 0 in Weighted_Bin" ); 00157 error_ = T_Value(0.); 00158 } else { 00159 e = e * e; 00160 error_ = sqrt( error_ / e ); 00161 error_ = error_ * (1-error_); 00162 error_ = error_ * error_; 00163 error_ = T_Value( error_ / e ); 00164 } 00165 count_ += other.count(); 00166 } 00167 00169 void add( double x ) { value_ = T_Value( value_ + x ); } 00171 void sub( double x ) { value_ = T_Value( value_ - x ); } 00173 void mul( double x ) { value_ = T_Value( value_ * x ); } 00175 void div( double x ) 00176 { 00177 if( x != 0. ) { 00178 value_ = T_Value( value_ / x ); 00179 return; 00180 } 00181 HTL_ERR( "WARNING: Division by 0 in Float_Weighted_Bin: div(x)" ); 00182 value_ = T_Value(0.); 00183 } 00184 00185 private: 00186 T_Value value_; // *Real* error. 00187 T_Value error_; // Square of the *real* error. 00188 Size count_; 00189 }; 00190 00191 #undef T_Value 00192 00193 #endif // _FLOAT_WEIGHTED_BIN_H_ 00194 00195 /* 00196 00197 September, 1998: 00198 00199 This class does not need to be friend of itself for the assignment operator, 00200 because, as for Gravity_Bin_1D, the value and the error are directly stored 00201 in the bin and can be accessed from the interface methods. 00202 For the assignment operator we could have used I_Histo instead of 00203 Like_Parent. We use the last one because of Profile_Bin. 00204 00205 */ 00206
Anaphe documentation generated by Doxygen (www.doxygen.org) |