Hist1DProjImp.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 // Include max() and min() missing from Microsoft Visual C++.
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "Hist1DProjImp.h"
00018 
00019 #include "axes/AxisModelBase.h"
00020 
00021 #include "binners/BinsBase.h"
00022 #include "binners/BinsFactory.h"
00023 #include "binners/BinnerAxis.h"
00024 #include "binners/BinnerAxisFactory.h"
00025 
00026 #include "datasrcs/DataPointTuple.h"
00027 #include "datasrcs/NTuple.h"
00028 
00029 #include <cassert>
00030 
00031 using namespace hippodraw;
00032 
00033 #ifdef ITERATOR_MEMBER_DEFECT
00034 using namespace std;
00035 #else
00036 using std::list;
00037 using std::max;
00038 using std::string;
00039 using std::vector;
00040 #endif
00041 
00042 Hist1DProjImp::Hist1DProjImp( )
00043   : BinningProjector ( 1 )
00044 {
00045   BinnerAxisFactory * binner_factory = BinnerAxisFactory::instance ();
00046   BinnerAxis * binner = binner_factory -> create ( "BinnerLinear" );
00047 
00048   BinsFactory * factory = BinsFactory::instance ();
00049   m_binner = factory->create ( "Bins1DHist" );
00050 
00051   m_binner->setBinnerOn ( binner, Axes::X );
00052 
00053   m_y_label_entries = "Entries / bin";
00054   m_y_label_density = "Density";
00055 
00056   addPointReps();
00057 }
00058 
00063 Hist1DProjImp::
00064 Hist1DProjImp ( const Hist1DProjImp & projector )
00065   : BinningProjector ( projector ),
00066     m_y_label_entries ( projector.m_y_label_entries ),
00067     m_y_label_density ( projector.m_y_label_density )
00068 {
00069   addPointReps();
00070 }
00071 
00072 
00073 Hist1DProjImp::
00074 ~Hist1DProjImp()
00075 {
00076 }
00077 
00078 void
00079 Hist1DProjImp::
00080 addPointReps()
00081 {
00082   m_pointreps.push_back ( "Column" );
00083   m_pointreps.push_back ( "FilledColumn" );
00084   m_pointreps.push_back ( "Symbol" );
00085   m_pointreps.push_back ( "Line" );
00086 }
00087 
00088 void
00089 Hist1DProjImp::
00090 checkScaling ()
00091 {
00092   if ( m_y_axis == 0 ) return;
00093 
00094   bool yes = m_binner->hasEqualWidths ();
00095   if ( yes ) {
00096     double width = m_binner->scaleFactor ();
00097     m_y_axis->setScaleFactor ( width );
00098   }
00099   else {
00100     m_y_axis->setScaling ( false );
00101   }
00102 }
00103 
00104 bool
00105 Hist1DProjImp::
00106 isValueBinned () const
00107 {
00108   return true;
00109 }
00110 
00111 double 
00112 Hist1DProjImp::
00113 getPosOnValue () const
00114 {
00115   Range range = dataRangeOnValue ();
00116 
00117   return range.pos ();
00118 }
00119 
00120 Range
00121 Hist1DProjImp::
00122 preferredRange ( hippodraw::Axes::Type  axis ) const
00123 {
00124   Range range = dataRangeOn ( axis );
00125   if ( axis == Axes::Y ) {
00126     range.setLow ( 0.0 );
00127   }
00128 
00129   return range;
00130 }
00131 
00132 
00133 namespace dp = hippodraw::DataPoint2DTuple;
00134 
00135 Range
00136 Hist1DProjImp::
00137 dataRangeOnValue ( ) const
00138 {
00139   Hist1DProjImp * p = const_cast < Hist1DProjImp * > ( this );
00140   p->prepareValues ();
00141   if ( m_proj_values -> empty () ) {
00142     return Range ( 0.0, 1.0, 0.5 );
00143   }
00144 
00145   const vector < double > & values = m_proj_values -> getColumn( dp::Y );
00146   return  Range ( values );
00147 }
00148 
00150 void 
00151 Hist1DProjImp::
00152 setRange ( hippodraw::Axes::Type axis, bool const_width )
00153 {
00154   assert ( m_binner );
00155   assert ( axis == Axes::X || axis == Axes::Y );
00156 
00157   if ( axis == Axes::X ) {
00158     const Range & range = m_x_axis->getRange( false );
00159 
00160     if( m_x_axis->isLog() ) {
00161       if( range.low() < 0.0 ) return;
00162       m_x_axis->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
00163       const Range & range2 = m_x_axis->getRange( false );
00164       setBinnerRange ( axis, range2, const_width );
00165     } 
00166     else {
00167       setBinnerRange ( axis, range, const_width );
00168     }
00169   }
00170 }
00171 
00172 void 
00173 Hist1DProjImp::
00174 reset( )
00175 {
00176 }
00177 
00178 Range
00179 Hist1DProjImp::
00180 valueRange () const
00181 {
00182    return dataRangeOn ( Axes::Y );
00183 }
00184 
00185 bool
00186 Hist1DProjImp::
00187 wantsScaleFactor ( const std::string & axis ) const
00188 {
00189   return axis == "Y" || axis == "y";
00190 }

Generated for HippoDraw Class Library by doxygen