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