00001
00012 #ifdef _MSC_VER
00013
00014 #include "msdevstudio/MSconfig.h"
00015 #endif //_MSC_VER
00016
00017 #include "Hist2DProjImp.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 std::list;
00032 using std::max;
00033 using std::string;
00034 using std::vector;
00035
00036 namespace hippodraw {
00037
00038 Hist2DProjImp::Hist2DProjImp( )
00039 : BinningProjector ( 2 )
00040 {
00041 BinnerAxisFactory * binner_factory = BinnerAxisFactory::instance ();
00042 BinnerAxis * x = binner_factory -> create ( "BinnerLinear" );
00043 BinnerAxis * y = binner_factory -> create ( "BinnerLinear" );
00044
00045 BinsFactory * factory = BinsFactory::instance ();
00046 m_binner = factory->create ( "Bins2DHist" );
00047
00048 m_binner->setBinnerOn ( x, Axes::X );
00049 m_binner->setBinnerOn ( y, Axes::Y );
00050
00051 m_z_label_entries = "Entries / bin";
00052 m_z_label_density = "Density";
00053
00054 addPointReps();
00055 }
00056
00061 Hist2DProjImp::
00062 Hist2DProjImp ( const Hist2DProjImp & projector )
00063 : ProjectorBase ( projector ),
00064 BinningProjector ( projector ),
00065 m_z_label_entries ( projector.m_z_label_entries ),
00066 m_z_label_density ( projector.m_z_label_density ),
00067 m_value_range( projector.m_value_range )
00068 {
00069 addPointReps();
00070 }
00071
00075 Hist2DProjImp::~Hist2DProjImp()
00076 {
00077 }
00078
00079 bool Hist2DProjImp::isValueBinned () const
00080 {
00081 return true;
00082 }
00083
00084 double
00085 Hist2DProjImp::
00086 getPosOnValue () const
00087 {
00088 Range range = dataRangeOnValue ();
00089
00090 return range.pos ();
00091 }
00092
00093
00094 Range
00095 Hist2DProjImp::
00096 preferredRange ( hippodraw::Axes::Type axis ) const
00097 {
00098 Range range = dataRangeOn ( axis );
00099 if ( axis == Axes::Z ) {
00100 range.setLow ( 0.0 );
00101 }
00102
00103 return range;
00104 }
00105
00106 namespace dp = hippodraw::DataPoint3DTuple;
00107
00108 Range
00109 Hist2DProjImp::
00110 dataRangeOnValue () const
00111 {
00112 Hist2DProjImp * p = const_cast < Hist2DProjImp * > ( this );
00113 p->prepareValues ();
00114 if ( m_proj_values -> empty () ) {
00115 return Range ( 0.0, 1.0, 0.5 );
00116 }
00117
00118 const vector < double > & values = m_proj_values -> getColumn( dp::Z );
00119 return Range ( values );
00120 }
00121
00122 Range Hist2DProjImp::valueRange() const
00123 {
00124 return dataRangeOn ( Axes::Z );
00125 }
00126
00128 void
00129 Hist2DProjImp::
00130 setRange ( hippodraw::Axes::Type axis, bool const_width )
00131 {
00132 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00133
00134 AxisModelBase * model = 0;
00135 if ( axis == Axes::X ) {
00136 model = m_x_axis;
00137 } else if ( axis == Axes::Y ) {
00138 model = m_y_axis;
00139 }
00140 if ( axis != Axes::Z ) {
00141 const Range & range = model->getRange (false);
00142 if( model->isLog() ) {
00143 if( range.low() < 0.0 ) return;
00144 model->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
00145 const Range & range2 = model->getRange ( false );
00146 setBinnerRange ( axis, range2, const_width );
00147 } else {
00148 setBinnerRange ( axis, range, const_width );
00149 }
00150 }
00151 }
00152
00153 const Range &
00154 Hist2DProjImp::
00155 setBinWidth ( hippodraw::Axes::Type axis, double width )
00156 {
00157 assert ( axis == Axes::X || axis == Axes::Y );
00158
00159 const Range & range = m_binner->setBinWidth ( axis, width );
00160 checkScaling ();
00161
00162 setDirty ( true );
00163
00164 return range;
00165 }
00166
00167 void
00168 Hist2DProjImp::
00169 setOffset ( hippodraw::Axes::Type axis, double offset )
00170 {
00171 if ( axis == Axes::Z ) return;
00172 assert ( axis == Axes::X || axis == Axes::Y );
00173
00174 m_binner->setOffset ( axis, offset );
00175 if( axis == Axes::X )
00176 m_x_axis->setRange( m_binner->getRange ( Axes::X ), true );
00177 else
00178 m_y_axis->setRange( m_binner->getRange ( Axes::Y ), true );
00179
00180 setDirty ( true );
00181 }
00182
00183
00184 void Hist2DProjImp::setZLabel()
00185 {
00186 m_z_label_entries = "Entries / bin";
00187 }
00188
00189 const string & Hist2DProjImp::getZLabel() const
00190 {
00191 bool scaling = m_z_axis->isScaling ();
00192
00193 if ( scaling ) return m_z_label_entries;
00194 return m_z_label_density;
00195 }
00196
00197 bool Hist2DProjImp::hasZAxis() const
00198 {
00199 return true;
00200 }
00201
00202 void Hist2DProjImp::checkScaling ()
00203 {
00204 if ( m_z_axis == 0 ) return;
00205
00206 bool yes = m_binner->hasEqualWidths ();
00207
00208 if ( yes ) {
00209 double width = m_binner->scaleFactor ();
00210 m_z_axis->setScaleFactor ( width );
00211 }
00212 else {
00213 m_z_axis->setScaling ( false );
00214 }
00215
00216 }
00217
00218 void Hist2DProjImp::addPointReps()
00219 {
00220 m_pointreps.push_back ( "ColorBox" );
00221 m_pointreps.push_back ( "Contour" );
00222
00223 }
00224
00225 bool
00226 Hist2DProjImp::
00227 wantsScaleFactor ( const std::string & axis ) const
00228 {
00229 return axis == "Z" || axis == "z";
00230 }
00231
00232 }
00233