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

ProfileProjector.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 max() and min() missing from Microsoft Visual C++.
00017 #include "msdevstudio/MSconfig.h"
00018 #endif
00019 #endif
00020 
00021 #include "ProfileProjector.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 <algorithm>
00034 
00035 #include <cassert>
00036 
00037 using namespace hippodraw;
00038 
00039 #ifdef ITERATOR_MEMBER_DEFECT
00040 using namespace std;
00041 #else
00042 using std::list;
00043 using std::max;
00044 using std::string;
00045 using std::vector;
00046 #endif
00047 
00048 ProfileProjector::ProfileProjector( )
00049   : BinningProjector ( 1 ),
00050     NTupleProjector ( 2 )
00051 {
00052   m_binding_options.push_back ( "X" );
00053   m_binding_options.push_back ( "Y" );
00054   m_min_bindings = 2;
00055 
00056   BinnerAxisFactory * binner_factory = BinnerAxisFactory::instance ();
00057   BinnerAxis * binner = binner_factory -> create ( "BinnerLinear" );
00058 
00059   BinsFactory * factory = BinsFactory::instance();
00060   m_binner = factory -> create ( "Bins1DProfile" );
00061 
00062   m_binner->setBinnerOn ( binner, Axes::X );
00063   addPointReps();
00064 }
00065 
00066 ProfileProjector::ProfileProjector ( const ProfileProjector & projector )
00067   : BinningProjector ( projector ),
00068     NTupleProjector ( projector )
00069 {
00070   addPointReps();
00071 }
00072 
00073 ProfileProjector::~ProfileProjector()
00074 {
00075 }
00076 
00077 ProjectorBase * ProfileProjector::clone()
00078 {
00079   return new ProfileProjector( *this );
00080 }
00081 
00083 void ProfileProjector::changedNTuple()
00084 {
00085   unsigned int cols = m_ntuple->columns () - 1;
00086   if ( m_columns[0] > cols ) m_columns[0] = cols;
00087   if ( m_columns[1] > cols ) m_columns[1] = cols;
00088 
00089   m_binner->setDirty ( );
00090 }
00091 
00092 void ProfileProjector::execute ()
00093 {
00094   if ( m_ntuple->isNull () ) return;
00095 
00096   // Get the data and the optional weight column. 
00097   unsigned int & x_col = m_columns[0];
00098   unsigned int & y_col = m_columns[1];
00099   unsigned int size = m_ntuple -> rows ();
00100 
00101   // Use integer indexing to ensure that it will take everything from the
00102   // same row, including the cut values.
00103 
00104   m_binner->reset ();
00105 
00106   for ( unsigned int i = 0; i < size; i++ )
00107     {
00108       if ( acceptRow ( i ) == false ) continue;
00109 
00110       double x = m_ntuple -> valueAt ( i, x_col );
00111       double y = m_ntuple -> valueAt ( i, y_col );
00112 
00113       m_binner->accumulate( x, y );
00114     }
00115 }
00116 
00117 Range ProfileProjector::valueRange () const
00118 {
00119   return dataRangeOn ( Axes::Y );
00120 }
00121 
00122 namespace dp = hippodraw::DataPoint2DTuple;
00123 
00124 Range
00125 ProfileProjector::
00126 dataRangeOn ( hippodraw::Axes::Type axis ) const
00127 {
00128   assert ( axis == Axes::X || axis == Axes::Y );
00129 
00130   if ( axis == Axes::X ) {
00131     return dataRange ( m_columns[0] );
00132   }
00133 
00134   ProfileProjector * p = const_cast<ProfileProjector *> ( this );
00135   p->prepareValues ();
00136 
00137   // If no points are left due to cuts, then returns zero range.
00138   if ( m_proj_values -> empty () ) {
00139     return Range ( 0.0, 0.0 );
00140   }
00141   double max = DBL_MIN;
00142   double min = DBL_MAX;
00143 
00144   const vector < double > & values = m_proj_values -> getColumn ( dp::Y );
00145   const vector < double > & errors = m_proj_values -> getColumn ( dp::YERR );
00146   for ( unsigned int i = 0; i < values.size(); i++ ) {
00147     double hi = values[i] + errors[i];
00148     double lo = values[i] - errors[i];
00149     max = std::max ( max, hi );
00150     min = std::min ( min, lo );
00151   }
00152 
00153   return Range ( min, max );
00154 }
00155 
00156 double
00157 ProfileProjector::
00158 getPosOn ( hippodraw::Axes::Type axis ) const
00159 {
00160   assert ( axis == Axes::X || axis == Axes::Y );
00161 
00162   if ( axis == Axes::X ) {
00163     return getPos ( m_columns[0] );
00164   }
00165 
00166   // If no points are left due to cuts, then returns DBL_MAX.
00167   if ( m_proj_values -> empty() ) {
00168     return DBL_MAX;
00169   }
00170 
00171   double pos = DBL_MAX;
00172 
00173   const vector < double > & values = m_proj_values -> getColumn ( dp::Y );
00174   const vector < double > & errors = m_proj_values -> getColumn ( dp::YERR );
00175   for ( unsigned int i = 0; i < values.size (); i++ ) {
00176     double lo = values[i] - errors[i];
00177     if ( lo > 0.0 &&
00178          lo < pos ) pos = lo;
00179   }
00180 
00181   return pos;
00182 }
00183 
00184 /* virtual */
00185 bool ProfileProjector::isAxisBinned ( const std::string & axis ) const
00186 {
00187   if ( axis == m_binding_options[0] ) {
00188     return true;
00189   }
00190   return false;
00191 }
00192 
00193 void ProfileProjector::addPointReps()
00194 {
00195   m_pointreps.push_back ( "Symbol" );
00196 }
00197 
00198 void
00199 ProfileProjector::
00200 setRange ( hippodraw::Axes::Type axis, bool const_width )
00201 {
00202   assert ( m_binner );
00203   assert ( axis == Axes::X || axis == Axes::Y );
00204 
00205   if ( axis == Axes::X ) {
00206     const Range & range = m_x_axis->getRange( false );
00207     if( m_x_axis->isLog() ) {
00208       if( range.low() < 0.0 ) return;
00209       m_x_axis->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
00210       const Range & range2 = m_x_axis->getRange( false );
00211       setBinnerRange ( axis, range2, const_width );
00212     } 
00213     else {
00214       setBinnerRange ( axis, range, const_width );
00215 
00216     }
00217   }
00218 }
00219 
00220 void
00221 ProfileProjector::
00222 setBinnerRange ( hippodraw::Axes::Type axis,
00223                  const Range & range,
00224                  bool const_width )
00225 {
00226   m_binner -> setRange ( axis, range, const_width );
00227   checkScaling ();
00228 
00229   setDirty ( true );
00230 }
00231 
00232 void
00233 ProfileProjector::
00234 update ( const Observable * object )
00235 {
00236   const DataSource * datasource 
00237     = dynamic_cast < const DataSource * > ( object );
00238 
00239   if ( datasource != 0 ) {
00240     NTupleProjector::update ( object );
00241   }
00242   else {
00243     BinningProjector::update ( object );
00244   }
00245 }
00246 
00247 void
00248 ProfileProjector::
00249 willDelete ( const Observable * object )
00250 {
00251   const DataSource * datasource 
00252     = dynamic_cast < const DataSource * > ( object );
00253 
00254   if ( datasource != 0 ) {
00255     NTupleProjector::willDelete ( object );
00256   }
00257   else {
00258     BinningProjector::willDelete ( object );
00259   }
00260 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3