Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ProfileBin1D.cpp

Go to the documentation of this file.
00001 #include "ProfileBin1D.h"
00002 #include <cmath>
00003 
00004 
00005 Anaphe::AIDA_Histogram_native::ProfileBin1D::ProfileBin1D():
00006   m_entries( 0 ),
00007   m_sumOfWeights( 0 ),
00008   m_sumOfWeightTimesExtraCoordinate( 0 ),
00009   m_sumOfWeightTimesSquaredExtraCoordinate( 0 ),
00010   m_sumOfWeightTimesCoordinate( 0 )
00011 {}
00012 
00013 
00014 double
00015 Anaphe::AIDA_Histogram_native::ProfileBin1D::value() const
00016 {
00017   return ( ( m_sumOfWeights ==0 )? 0 : ( m_sumOfWeightTimesExtraCoordinate / m_sumOfWeights ) );
00018 }
00019 
00020 
00021 double
00022 Anaphe::AIDA_Histogram_native::ProfileBin1D::error() const
00023 {
00024   if ( m_sumOfWeights == 0 ) return 0;
00025   const double s = spread();
00026   if ( s == 0 ) return std::sqrt( m_sumOfWeightTimesExtraCoordinate / (m_sumOfWeights * m_sumOfWeights) );
00027   else return ( s / std::sqrt( m_sumOfWeights ) );
00028 }
00029 
00030 
00031 double
00032 Anaphe::AIDA_Histogram_native::ProfileBin1D::spread() const
00033 {
00034   if ( m_sumOfWeights == 0 ) return 0;
00035   const double hl = m_sumOfWeightTimesExtraCoordinate / m_sumOfWeights;
00036   const double hl2 = hl * hl;
00037   const double s = std::abs( m_sumOfWeightTimesSquaredExtraCoordinate / m_sumOfWeights - hl2 );
00038   if ( s == 0 ) return std::sqrt( std::abs( hl ) );
00039   else return std::sqrt( s );
00040 }
00041 
00042 
00043 bool
00044 Anaphe::AIDA_Histogram_native::ProfileBin1D::increment( const Anaphe::AIDA_Histogram_native::ProfileBin1D & bin )
00045 {
00046   m_entries += bin.m_entries;
00047   m_sumOfWeights += bin.m_sumOfWeights;
00048   m_sumOfWeightTimesExtraCoordinate += bin.m_sumOfWeightTimesExtraCoordinate;
00049   m_sumOfWeightTimesSquaredExtraCoordinate += bin.m_sumOfWeightTimesSquaredExtraCoordinate;
00050   m_sumOfWeightTimesCoordinate += bin.m_sumOfWeightTimesCoordinate;
00051   return true;
00052 }
00053 
00054 
00055 bool
00056 Anaphe::AIDA_Histogram_native::ProfileBin1D::increment( int extraEntries,
00057                                                         double extraValue,
00058                                                         double extraError,
00059                                                         double extraSpread,
00060                                                         double extraCentre )
00061 {
00062   Anaphe::AIDA_Histogram_native::ProfileBin1D temporaryBin;
00063   temporaryBin.set( extraEntries, extraValue, extraError, extraSpread, extraCentre );
00064   return this->increment( temporaryBin );
00065 }
00066 
00067 
00068 bool
00069 Anaphe::AIDA_Histogram_native::ProfileBin1D::set( int newEntries,
00070                                                   double newValue,
00071                                                   double newError,
00072                                                   double newSpread,
00073                                                   double newCentre )
00074 {
00075   m_entries = newEntries;
00076   m_sumOfWeights = m_sumOfWeightTimesExtraCoordinate = m_sumOfWeightTimesSquaredExtraCoordinate = m_sumOfWeightTimesCoordinate = 0;
00077   if ( m_entries !=0 && newValue != 0 && newError != 0 && newSpread != 0 ) {
00078      m_sumOfWeights = newSpread / newError;
00079      m_sumOfWeights *= m_sumOfWeights;
00080      m_sumOfWeightTimesExtraCoordinate = newValue * m_sumOfWeights;
00081      m_sumOfWeightTimesSquaredExtraCoordinate = m_sumOfWeightTimesExtraCoordinate / m_sumOfWeights;
00082      m_sumOfWeightTimesSquaredExtraCoordinate *= m_sumOfWeightTimesSquaredExtraCoordinate;
00083      m_sumOfWeightTimesSquaredExtraCoordinate += newSpread * newSpread;
00084      m_sumOfWeightTimesSquaredExtraCoordinate *= m_sumOfWeights;
00085      m_sumOfWeightTimesCoordinate = newCentre * m_sumOfWeights;
00086   }
00087   return true;
00088 }
00089 
00090 
00091 double
00092 Anaphe::AIDA_Histogram_native::ProfileBin1D::centreOfGravityX() const
00093 {
00094     return ( ( m_sumOfWeights == 0 ) ? 0 : ( m_sumOfWeightTimesCoordinate / m_sumOfWeights ) );
00095 }

Generated on Tue Nov 19 12:32:17 2002 for AIDA_Histogram_native by doxygen1.2.16