00001 #include "EvenBinAxis.h" 00002 #include <cmath> 00003 00004 #ifdef NONUMERICLIMITS 00005 static const double positive_infinity = 1.7976931348623157e+308; 00006 static const double negative_infinity = -1.7976931348623157e+308; 00007 #else 00008 #include <limits> 00009 static const double positive_infinity = std::numeric_limits<double>::max(); 00010 static const double negative_infinity = -positive_infinity; 00011 #endif 00012 00013 Anaphe::AIDA_Histogram_native::EvenBinAxis::EvenBinAxis( int nBins, 00014 double lowEdge, 00015 double highEdge ): 00016 m_bins( nBins ), 00017 m_lowEdge( lowEdge ), 00018 m_highEdge( highEdge ), 00019 m_binSize( ( m_highEdge - m_lowEdge ) / m_bins ) 00020 {} 00021 00022 double 00023 Anaphe::AIDA_Histogram_native::EvenBinAxis::binLowerEdge( int index ) const 00024 { 00025 if ( index >= 0 && index <= m_bins ) { 00026 return m_lowEdge + index * m_binSize; 00027 } 00028 if ( index > m_bins || index == static_cast< int >( AIDA::IAxis::OVERFLOW_BIN ) ) return m_highEdge; 00029 else return negative_infinity; 00030 } 00031 00032 double 00033 Anaphe::AIDA_Histogram_native::EvenBinAxis::binUpperEdge( int index ) const 00034 { 00035 if ( index >= 0 && index < m_bins ) { 00036 return m_lowEdge + ( index + 1 ) * m_binSize; 00037 } 00038 if ( index > m_bins || index == static_cast< int >( AIDA::IAxis::OVERFLOW_BIN ) ) return positive_infinity; 00039 else return m_lowEdge; 00040 } 00041 00042 int 00043 Anaphe::AIDA_Histogram_native::EvenBinAxis::coordToIndex( double coord ) const 00044 { 00045 if ( coord < m_lowEdge ) return static_cast< int >( AIDA::IAxis::UNDERFLOW_BIN ); 00046 else if ( coord >= m_highEdge ) return static_cast< int >( AIDA::IAxis::OVERFLOW_BIN ); 00047 else return static_cast< int >( std::floor( ( coord - m_lowEdge ) / m_binSize ) ); 00048 }