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

BinningProjector.cxx

Go to the documentation of this file.
00001 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #else
00015 #ifdef _MSC_VER
00016 #include "msdevstudio/MSconfig.h"
00017 #endif
00018 #endif
00019 
00020 #include "BinningProjector.h"
00021 
00022 #include "axes/AxisModelBase.h"
00023 #include "binners/BinsBase.h"
00024 #include "datasrcs/NTuple.h"
00025 
00026 #include <cassert>
00027 
00028 using namespace hippodraw;
00029 
00030 #ifdef ITERATOR_MEMBER_DEFECT
00031 using namespace std;
00032 #else
00033 using std::string;
00034 using std::list;
00035 using std::vector;
00036 #endif
00037 
00038 BinningProjector::BinningProjector ( unsigned int axes )
00039   : m_binner_dim ( axes ),
00040     m_binner ( 0 )
00041 {
00042 }
00043 
00044 BinningProjector::BinningProjector ( const BinningProjector & projector )
00045   : ProjectorBase ( projector ),
00046     m_binner_dim ( projector.m_binner_dim ),
00047     m_binner ( 0 )
00048 {
00049   if ( projector.m_binner != 0 ) {
00050     m_binner = projector.m_binner->clone ();
00051   } 
00052   m_proj_values = m_binner -> createNTuple ();
00053 
00054   fillDataSource ( m_proj_values );
00055 }
00056 
00057 BinningProjector::~BinningProjector ()
00058 {
00059   if ( m_binner != 0 ) {
00060     delete m_binner;
00061   }
00062 }
00063 
00064 void
00065 BinningProjector::
00066 setAxisModel ( hippodraw::Axes::Type axis, AxisModelBase * model )
00067 {
00068   ProjectorBase::setAxisModel ( axis, model );
00069   checkScaling ();
00070 }
00071 
00072 void BinningProjector::prepareValues()
00073 {
00074   bool is_dirty = isDirty();
00075   if ( is_dirty ) {
00076     execute();
00077     fillDataSource ( m_proj_values );
00078     setDirty ( false );
00079   }
00080 }
00081 
00082 const DataSource *
00083 BinningProjector::
00084 createOldStyleNTuple () const
00085 {
00086   bool is_dirty = isDirty ();
00087   if ( is_dirty ) {
00088     BinningProjector * projector = const_cast < BinningProjector * > ( this );
00089     projector -> execute ();
00090   }
00091   DataSource * ds = m_binner -> createNTuple ();
00092   fillProjectedValues ( ds );
00093 
00094   return ds;
00095 }
00096 
00097 const BinsBase *
00098 BinningProjector::
00099 getBinner ( ) const
00100 {
00101   return m_binner;
00102 }
00103 
00104 void
00105 BinningProjector::
00106 setBinner ( BinsBase * bins )
00107 {
00108   if ( m_binner != 0 ) delete m_binner;
00109   m_binner = bins;
00110   if ( m_proj_values != 0 ) delete m_proj_values;
00111   m_proj_values = m_binner -> createNTuple ();
00112 }
00113 
00116 void
00117 BinningProjector::
00118 setBinnerOn ( BinnerAxis * binner,
00119               hippodraw::Axes::Type type )
00120 {
00121   string axis;
00122   if ( type == Axes::X ) axis = "X";
00123   else if ( type == Axes::Y ) axis = "Y";
00124   else axis = "Z";
00125 
00126   bool yes = isAxisBinned ( axis );
00127   if ( ! yes ) return;
00128 
00129   m_binner->setBinnerOn ( binner, type );
00130   checkScaling ();
00131 
00132   setDirty ( true );
00133 }
00134 
00135 int
00136 BinningProjector::
00137 getNumberOfBins ( hippodraw::Axes::Type axis ) const
00138 {
00139   assert ( m_binner );
00140 
00141   if ( axis == Axes::X || 
00142        ( m_binner_dim == 2 && axis == Axes::Y ) ) {
00143     return m_binner->numberOfBins ( axis );
00144   }
00145 
00146   return ProjectorBase::getNumberOfBins ( axis );
00147 }
00148 
00149 void
00150 BinningProjector::
00151 setRange ( hippodraw::Axes::Type axis, const Range & range, bool const_width )
00152 {
00153   assert ( axis == Axes::X || axis == Axes::Y );
00154 
00155   m_binner->setRange ( axis, range, const_width );
00156 }
00157 
00162 void
00163 BinningProjector::
00164 setBinWidth ( hippodraw::Axes::Type axis, double width )
00165 {
00166   if ( axis == Axes::Y ) return;
00167 
00168   assert ( axis == Axes::X && width > 0. );
00169 
00170   m_binner->setBinWidth ( Axes::X, width );
00171   checkScaling ();
00172 
00173   setDirty ( true );
00174 }
00175 
00176 /* virtual */
00177 void 
00178 BinningProjector::
00179 setBinWidth ( const std::string & axis, 
00180               int parm, 
00181               bool dragging )
00182 {
00183   if ( axis != "X" ) return;
00184 
00185   double new_width = m_binner->calcBinWidth ( axis, parm, dragging );
00186   setBinWidth ( Axes::X, new_width );
00187 }
00188 
00189 /* virtual */
00190 void BinningProjector::setOffset ( const std::string & axis, 
00191                                    int parm, 
00192                                    bool dragging )
00193 {
00194   if ( axis != "X" ) return;
00195   
00196   double new_offset = m_binner->calcOffset ( axis, parm, dragging );
00197 //   if ( new_offset != 0.0 ) {
00198     setOffset ( Axes::X, new_offset );
00199     setDirty ( true );
00200 //   }
00201 }
00202 
00203 /* virtual */
00204 void
00205 BinningProjector::
00206 setOffset ( hippodraw::Axes::Type axis, double offset )
00207 {
00208   if ( axis == Axes::Y ) return;
00209 
00210   m_binner->setOffset ( Axes::X, offset );
00211   m_x_axis->setRange( m_binner->getRange ( Axes::X ), true );
00212 
00213   setDirty ( true );
00214 }
00215 
00216 
00217 void BinningProjector:: reset ( )
00218 {
00219 }
00220 
00221 double
00222 BinningProjector::
00223 getOffset ( hippodraw::Axes::Type axis ) const
00224 {
00225   assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00226 
00227   if ( axis == Axes::X ||
00228        ( axis == Axes::Y && m_binner_dim == 2 ) ) {
00229     return m_binner->getOffset ( axis );
00230   }
00231 
00232   // else Z
00233   return 0.0;
00234 }
00235 
00236 double
00237 BinningProjector::
00238 getBinWidth (hippodraw:: Axes::Type axis ) const
00239 {
00240   assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00241 
00242   if ( axis == Axes::X ||
00243        ( axis == Axes::Y && m_binner_dim == 2 ) ) {
00244     return m_binner->binWidth ( axis );
00245   }
00246 
00247   // else Z
00248   return 0.0;
00249 }
00250 
00251 /* virtual */
00253 void BinningProjector::execute ()
00254 {
00255 }
00256 
00257 /* virtual */
00258 void BinningProjector::checkScaling ()
00259 {
00260   // does nothing
00261 }
00262 
00263 double BinningProjector::getZValue ( double x, double y ) const
00264 {
00265   return m_binner->getZValue ( x, y );
00266 }
00267 
00270 DataSource *
00271 BinningProjector::
00272 createNTuple () const
00273 {
00274   return m_binner->createNTuple ();
00275 }
00276 
00277 void
00278 BinningProjector::
00279 fillProjectedValues ( DataSource * ntuple, bool all ) const
00280 {
00281   m_binner -> fillProjectedValues ( ntuple );
00282 }
00283 
00284 void
00285 BinningProjector::
00286 fillDataSource ( DataSource * ntuple, bool all ) const
00287 {
00288   m_binner -> fillDataSource ( ntuple );
00289 }
00290 
00291 void
00292 BinningProjector::
00293 normalizeTo ( double number )
00294 {
00295   m_binner -> scaleNumberOfEntries ( number );
00296 }
00297 
00298 void
00299 BinningProjector::
00300 setNormalizing ( bool on )
00301 {
00302   m_binner -> setEntriesScaling ( on );
00303 }
00304 
00307 void
00308 BinningProjector::
00309 normalizeTo ( const ProjectorBase * target )
00310 {
00311   if ( target != 0 ) {
00312     if ( target -> isValueBinned ( ) ) {
00313       m_target = target;
00314       ProjectorBase * t = const_cast < ProjectorBase * > ( target );
00315       t -> addObserver ( this );
00316       setNormalizing ( true );
00317       normalize ();
00318     }
00319   }
00320   else {
00321     if ( m_target != 0 ) {
00322       ProjectorBase * t = const_cast < ProjectorBase * > ( m_target );
00323       t -> removeObserver ( this );
00324       setNormalizing ( false );
00325     }
00326     m_target = 0;
00327   }
00328 }
00329 
00330 void
00331 BinningProjector::
00332 normalize ()
00333 {
00334   int number = m_target ->getNumberOfEntries ();
00335   double norm = number;
00336   normalizeTo ( norm );
00337 
00338   setDirty ( true );
00339 }
00340 
00341 void
00342 BinningProjector::
00343 update ( const Observable * object )
00344 {
00345   if ( object == m_target ) {
00346     normalize ();
00347   }
00348 
00349   else notifyObservers ();
00350 }
00351 
00352 void
00353 BinningProjector::
00354 willDelete ( const Observable * object )
00355 {
00356   if ( object == m_target ) {
00357     m_target = 0;
00358     setNormalizing ( false );
00359     setDirty ( true );
00360   }
00361 }
00362 
00363 void
00364 BinningProjector::
00365 setBinContents ( const DataSource * source )
00366 {
00367   m_binner -> setBinContents ( source );
00368 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3