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

Axis.h

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/GaudiSvc/src/HistogramSvc/Axis.h,v 1.1.1.2 2001/04/18 18:32:49 tlindner Exp $
00002 #ifndef GAUDISVC_AXIS_H
00003 #define GAUDISVC_AXIS_H 1
00004 
00005 
00006 // Include files
00007 #include "GaudiKernel/IHistogram.h"
00008 #include "GaudiKernel/IAxis.h"
00009 
00010 #include "HTL/Histograms.h"
00011 
00012 
00013 //------------------------------------------------------------------------------
00014 //
00015 // ClassName:    Axis
00016 //  
00017 // Description:  Definition of the class Axis
00018 //
00019 //               Axis represents a binned histogram axis.
00020 //               A 1D histogram has one axis representing the X axis,
00021 //               a 2D histogram has two axes representing the X and Y Axis. 
00022 //
00023 // Authors:      Pavel Binko, Dino Ferrero Merlino, Andreas Pfeiffer
00024 // Date:         22/03/2000
00025 //
00026 //------------------------------------------------------------------------------
00027 
00028 
00029 class Axis : virtual public IAxis                                              {
00030 
00031 public:
00032 
00034   Axis( I_Histo* h, int axisNumber, int nBins, double low, double high )                                   {
00035     m_histogram = h;
00036     m_axisNumber = axisNumber;
00037     setEdgesAndBins( nBins, low, high );
00038   }
00039 
00040   Axis( I_Histo* h, int axisNumber, const std::vector<double>& edges )                                     {
00041     m_histogram = h;
00042     m_axisNumber = axisNumber;
00043     setEdgesAndBins( edges );
00044   }
00045 
00046   virtual ~Axis() {}
00047 
00051 
00053   virtual const std::vector<double>& edges() const                             {
00054     return m_edges;
00055   }
00056 
00058   virtual double lowerEdge() const                                             {
00059     return m_edges[0];
00060   }
00062   virtual double upperEdge() const                                             {
00063     return m_edges[m_bins];
00064   }
00065 
00066 
00070 
00073 
00075   virtual int bins() const                                                     {
00076     return m_bins;
00077   }
00078 
00081 
00083   virtual double binLowerEdge( int index ) const                               {
00084     int i = checkIndex( index );
00085     if( IHistogram::UNDERFLOW_BIN == i ) {
00086       // Should be negative infinity
00087       return -999999.999999;
00088     }
00089     else if ( IHistogram::OVERFLOW_BIN == i ) {
00090       return m_edges[m_bins];
00091     }
00092     // In-range bin
00093     return m_edges[i];
00094   }
00095 
00097   virtual double binUpperEdge( int index ) const                               {
00098     int i = checkIndex( index );
00099     if( IHistogram::UNDERFLOW_BIN == i ) {
00100       return m_edges[0];
00101     }
00102     else if ( IHistogram::OVERFLOW_BIN == i ) {
00103       // Should be positive infinity
00104       return +999999.999999;
00105     }
00106     // In-range bin
00107     return m_edges[i+1];
00108   }
00109 
00112 
00114   virtual double binWidth( int index ) const                                   {
00115     int i = checkIndex( index );
00116     return m_edges[i+1] - m_edges[i];
00117   }
00118 
00121 
00123   virtual double binCentre( int index ) const                                  {
00124     int i = checkIndex( index );
00125     // Only the arithmetic bin centre supported
00126     if( 1 == m_histogram->dim() ) {
00127       // Histogram 1D
00128       return HInfo::bin_center( *m_histogram, i );
00129     }
00130     else if( 2 == m_histogram->dim() ) {
00131       // Histogram 2D
00132       if( 0 == m_axisNumber ) {
00133         // X axis
00134         return HInfo::bin_center( *m_histogram, m_axisNumber, i, 0 );
00135       }
00136       else if( 1 == m_axisNumber ) {
00137         // Y axis
00138         return HInfo::bin_center( *m_histogram, m_axisNumber, 0, i );
00139       }
00140       std::cout << "Other axes than X or Y are not supported" << std::endl;
00141     }
00142     std::cout << "Other histograms than 1D or 2D are not supported" << std::endl;
00143     return 0.;
00144 //    // Geometrical bin centre would be
00145 //    return ( m_edges[i] + m_edges[i+1] ) / 2;
00146   }
00147 
00148 
00152 
00155   virtual int coordToIndex( double coord ) const                               {
00156     // Other possible implementation of fast coord to index conversion
00157     // Assuming histogram with right open bins
00158     if( lowerEdge() > coord ) {
00159       return IHistogram::UNDERFLOW_BIN;
00160     }
00161     if( upperEdge() <= coord ) {
00162       return IHistogram::OVERFLOW_BIN;
00163     }
00164     // Inside the histogram
00165     int begin   = 0;
00166     int end     = bins() - 1;
00167     int centre  = 0;
00168     while( begin != end ) {
00169       centre = ( begin + end ) / 2;
00170       if( binUpperEdge( centre ) <= coord  ) {
00171         begin = centre + 1;
00172       }
00173       else {
00174         end = centre;
00175       }
00176     }
00177     return begin;
00178   }
00179 
00180   
00184 
00187   virtual int checkIndex( int index ) const                                    {
00188     if( (index >= 0) && (index < m_bins) ) {
00189       return index;
00190     }
00191     else if( (IHistogram::OVERFLOW_BIN != index) && ((index < 0) || (index >= m_bins)) ) {
00192       return IHistogram::UNDERFLOW_BIN;
00193     }
00194     // Otherwise overflow
00195     return IHistogram::OVERFLOW_BIN;
00196   }
00197 
00198 
00199 protected:
00200 
00204 
00206   void setEdgesAndBins( const std::vector<double>& value )                     {
00207     m_edges = value;
00208     m_bins = m_edges.size() - 1;
00209   }
00211   void setEdgesAndBins( int nBins, double low, double high )                   {
00212     double siz  = ( high - low ) / nBins;
00213     double edge = low;
00214     for( int i=0; i<nBins; i++ ) {
00215       m_edges.push_back( edge );
00216       edge += siz;
00217     }
00218     m_edges.push_back( high );
00219     m_bins = nBins;
00220   }
00221 
00222 protected:
00223 
00225   int                      m_bins;
00226   
00228   std::vector<double>      m_edges;
00229 
00231   I_Histo*                 m_histogram;
00232 
00234   int                      m_axisNumber;
00235 
00236 };
00237 
00238 
00239 #endif    // GAUDISVC_AXIS_H
00240 
00241 
00242 
00243 
00244 
00245 

Generated at Wed Nov 21 12:22:29 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000