Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Hist2DProjImp.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 // for max() and min() missing from Microsoft Visual C++.
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 namespace hippodraw;
00032 
00033 using std::list;
00034 using std::max;
00035 using std::string;
00036 using std::vector;
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 
00057 Hist2DProjImp::Hist2DProjImp ( const Hist2DProjImp & projector )
00058   : BinningProjector ( projector ),
00059     m_z_label_entries ( projector.m_z_label_entries ),
00060     m_z_label_density ( projector.m_z_label_density ),
00061     m_value_range( projector.m_value_range )
00062 {
00063   addPointReps();
00064 }
00065 
00066 Hist2DProjImp::~Hist2DProjImp()
00067 {
00068 }
00069 
00070 bool Hist2DProjImp::isValueBinned () const
00071 {
00072   return true;
00073 }
00074 
00075 double 
00076 Hist2DProjImp::
00077 getPosOnValue () const
00078 {
00079   Range range = dataRangeOnValue ();
00080 
00081   return range.pos ();
00082 }
00083 
00084 
00085 Range
00086 Hist2DProjImp::
00087 preferredRange ( hippodraw::Axes::Type  axis ) const
00088 {
00089   Range range = dataRangeOn ( axis );
00090   if ( axis == Axes::Z ) {
00091     range.setLow ( 0.0 );
00092   }
00093 
00094   return range;
00095 }
00096 
00097 namespace dp = hippodraw::DataPoint3DTuple;
00098 
00099 Range
00100 Hist2DProjImp::
00101 dataRangeOnValue () const
00102 {
00103   Hist2DProjImp * p = const_cast < Hist2DProjImp * > ( this );
00104   p->prepareValues ();
00105   if ( m_proj_values -> empty () ) {
00106     return Range ( 0.0, 1.0, 0.5 );
00107   }
00108 
00109   const vector < double > & values = m_proj_values -> getColumn( dp::Z );
00110   return  Range ( values );
00111 }
00112 
00113 Range Hist2DProjImp::valueRange() const
00114 {
00115   return dataRangeOn ( Axes::Z );
00116 }
00117 
00119 void
00120 Hist2DProjImp::
00121 setRange ( hippodraw::Axes::Type axis, bool const_width )
00122 {
00123   assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00124 
00125   AxisModelBase * model = 0;
00126   if ( axis == Axes::X ) {
00127     model = m_x_axis;
00128   } else if ( axis == Axes::Y ) {
00129     model = m_y_axis;
00130   }
00131   if ( axis != Axes::Z ) {
00132     const Range & range = model->getRange (false);
00133     if( model->isLog() ) {
00134       if( range.low() < 0.0 ) return;
00135       model->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
00136       const Range & range2 = model->getRange ( false );
00137       setBinnerRange ( axis, range2, const_width );
00138     } else {
00139       setBinnerRange ( axis, range, const_width );
00140     }
00141   }
00142 }
00143 
00144 void
00145 Hist2DProjImp::
00146 setBinWidth ( hippodraw::Axes::Type axis, double width )
00147 {
00148   if( axis == Axes::Z ) return;
00149   assert ( axis == Axes::X || axis == Axes::Y );
00150 
00151   m_binner->setBinWidth ( axis, width );
00152   checkScaling ();
00153 
00154   setDirty ( true );
00155 }
00156 
00157 void
00158 Hist2DProjImp::
00159 setOffset ( hippodraw::Axes::Type axis, double offset )
00160 {
00161   if ( axis == Axes::Z ) return;
00162   assert ( axis == Axes::X || axis == Axes::Y );
00163 
00164   m_binner->setOffset ( axis, offset );
00165   if( axis == Axes::X )
00166     m_x_axis->setRange( m_binner->getRange ( Axes::X ), true );
00167   else
00168     m_y_axis->setRange( m_binner->getRange ( Axes::Y ), true );
00169 
00170   setDirty ( true );
00171 }
00172 
00173 
00174 void Hist2DProjImp::setZLabel()
00175 {
00176   m_z_label_entries = "Entries / bin";
00177 }
00178 
00179 const string & Hist2DProjImp::getZLabel() const
00180 {
00181   bool scaling = m_z_axis->isScaling ();
00182 
00183   if ( scaling ) return m_z_label_entries;
00184   return m_z_label_density;
00185 }
00186 
00187 bool Hist2DProjImp::hasZAxis() const
00188 {
00189   return true;
00190 }
00191 
00192 void Hist2DProjImp::checkScaling ()
00193 {
00194   if ( m_z_axis == 0 ) return;
00195 
00196   bool yes = m_binner->hasEqualWidths ();
00197 
00198   if ( yes ) {
00199     double width = m_binner->scaleFactor ();
00200     m_z_axis->setScaleFactor ( width );
00201   }
00202   else {
00203     m_z_axis->setScaling ( false );
00204   }
00205 
00206 }
00207 
00208 void Hist2DProjImp::addPointReps()
00209 {
00210   m_pointreps.push_back ( "ColorBox" );
00211   m_pointreps.push_back ( "Contour" );
00212 }
00213 
00214 bool
00215 Hist2DProjImp::
00216 wantsScaleFactor ( const std::string & axis ) const
00217 {
00218   return axis == "Z" || axis == "z";
00219 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3