00001
00012 #ifdef _MSC_VER
00013
00014
00015 #endif //_MSC_VER
00016
00017 #include "Profile2DProjector.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 Profile2DProjector::Profile2DProjector( )
00039 : BinningProjector ( 2 ),
00040 NTupleProjector ( 4 )
00041 {
00042 m_binding_options.push_back ( "X" );
00043 m_binding_options.push_back ( "Y" );
00044 m_binding_options.push_back ( "Z" );
00045 m_min_bindings = 3;
00046
00047 BinnerAxisFactory * binner_factory = BinnerAxisFactory::instance();
00048 BinnerAxis * x = binner_factory -> create ( "BinnerLinear" );
00049 BinnerAxis * y = binner_factory -> create ( "BinnerLinear" );
00050
00051 BinsFactory * factory = BinsFactory::instance();
00052 m_binner = factory->create ( "Bins2DProfile" );
00053
00054 m_binner->setBinnerOn ( x, Axes::X );
00055 m_binner->setBinnerOn ( y, Axes::Y );
00056 addPointReps();
00057 }
00058
00063 Profile2DProjector::
00064 Profile2DProjector ( const Profile2DProjector & projector )
00065 : ProjectorBase ( projector ),
00066 BinningProjector ( projector ),
00067 NTupleProjector ( projector ),
00068 m_value_range( projector.m_value_range )
00069 {
00070 addPointReps();
00071 }
00072
00073 ProjectorBase * Profile2DProjector::clone()
00074 {
00075 return new Profile2DProjector( *this );
00076 }
00077
00078 void Profile2DProjector::changedNTuple()
00079 {
00080 unsigned int cols = m_ntuple->columns () - 1;
00081 if ( m_columns[0] > cols ) m_columns[0] = cols;
00082 if ( m_columns[1] > cols ) m_columns[1] = cols;
00083 if ( m_columns[2] > cols ) m_columns[2] = cols;
00084
00085 m_binner->setDirty();
00086 }
00087
00089 void Profile2DProjector::execute()
00090 {
00091 if ( m_ntuple->isNull () ) return;
00092 unsigned int ix = m_columns[0];
00093 unsigned int iy = m_columns[1];
00094 unsigned int iz = m_columns[2];
00095 unsigned int iw = m_columns[3];
00096 bool have_weight = false;
00097
00098
00099
00100
00101
00102
00103
00104
00105 m_binner->reset();
00106 unsigned int size = m_ntuple -> rows ();
00107 for ( unsigned int i = 0; i < size; i++ )
00108 {
00109 if ( acceptRow ( i, m_cut_list ) == false ) continue;
00110
00111 double x = m_ntuple -> valueAt ( i, ix );
00112 double y = m_ntuple -> valueAt ( i, iy );
00113 double z = m_ntuple -> valueAt ( i, iz );
00114
00115 double w = 1.0;
00116 if ( have_weight ) {
00117 w = m_ntuple -> valueAt ( i, iw );
00118 }
00119 m_binner->accumulate( x, y, z, w );
00120 }
00121 }
00122
00123
00124 bool Profile2DProjector::isAxisBinned ( const std::string & axis ) const
00125 {
00126 if ( axis == m_binding_options[0]
00127 || axis == m_binding_options[1] ) return true;
00128 return false;
00129 }
00130
00131 Range Profile2DProjector::valueRange() const
00132 {
00133 if ( isDirty () ) {
00134
00135 Profile2DProjector * p = const_cast <Profile2DProjector *> ( this );
00136 p->prepareValues ();
00137 }
00138
00139 return dataRangeOn ( Axes::Z );
00140 }
00141
00142 namespace dp = hippodraw::DataPoint3DTuple;
00143
00144 Range
00145 Profile2DProjector::
00146 dataRangeOn ( hippodraw::Axes::Type axis ) const
00147 {
00148 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00149 if ( axis == Axes::X ) {
00150 return dataRange ( m_columns[0] );
00151 }
00152 if ( axis == Axes::Y ) {
00153 return dataRange ( m_columns[1] );
00154 }
00155
00156 if ( isDirty () ) {
00157 Profile2DProjector * p = const_cast < Profile2DProjector * > ( this );
00158 p ->prepareValues ();
00159 p -> setDirty ( false );
00160 }
00161 const vector < double > & values = m_proj_values -> getColumn ( dp::Z );
00162
00163 return Range ( values );
00164 }
00165
00168 double
00169 Profile2DProjector::
00170 getPosOn ( hippodraw::Axes::Type axis ) const
00171 {
00172 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00173 if ( axis == Axes::X ) {
00174 return getPos ( m_columns[0] );
00175 }
00176 if ( axis == Axes::Y ) {
00177 return getPos ( m_columns[1] );
00178 }
00179 if ( axis == Axes::Z ) {
00180 return getPos ( m_columns[2] );
00181 }
00182 return DBL_MAX;
00183 }
00184
00186 void
00187 Profile2DProjector::
00188 setRange ( hippodraw::Axes::Type axis, bool const_width )
00189 {
00190 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00191
00192 AxisModelBase * model = 0;
00193 if ( axis == Axes::X ) {
00194 model = m_x_axis;
00195 } else if ( axis == Axes::Y ) {
00196 model = m_y_axis;
00197 }
00198
00199 if ( axis != Axes::Z ) {
00200 const Range & range = model->getRange (false);
00201 if( model->isLog() ) {
00202 if ( range.low() < 0.0 ) return;
00203 model->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
00204 const Range & range2 = model->getRange ( false );
00205 setBinnerRange ( axis, range2, const_width );
00206 } else {
00207 setBinnerRange ( axis, range, const_width );
00208 }
00209 }
00210
00211 setDirty ( true );
00212 }
00213
00215 const Range &
00216 Profile2DProjector::
00217 setBinWidth ( hippodraw::Axes::Type axis, double width )
00218 {
00219 assert ( axis == Axes::X || axis == Axes::Y );
00220
00221 const Range & range = m_binner->setBinWidth ( axis, width );
00222
00223 setDirty ( true );
00224
00225 return range;
00226 }
00227
00231
00232 const Range &
00233 Profile2DProjector::
00234 setBinWidth ( Axes::Type axis,
00235 int parm,
00236 bool dragging )
00237 {
00238 double new_width = m_binner->calcBinWidth ( axis, parm, dragging );
00239
00240 return setBinWidth ( axis, new_width );
00241 }
00242
00247 void Profile2DProjector::setOffset ( const std::string & axis,
00248 int parm,
00249 bool dragging )
00250 {
00251 if ( ( axis == "X" || axis == "Y" ) == false ) return;
00252
00253 double new_offset = m_binner->calcOffset ( axis, parm, dragging );
00254
00255 Axes::Type at;
00256 if ( axis == "X" ) {
00257 at = Axes::X;
00258 }
00259 else {
00260 at = Axes::Y;
00261 }
00262
00263 if( new_offset == 0.0 ) return;
00264 if( !dragging )
00265 setOffset( at, 0.0 );
00266 else
00267 setOffset( at, new_offset );
00268
00269 setDirty ( true );
00270 }
00271
00272
00273 void
00274 Profile2DProjector::
00275 setOffset ( hippodraw::Axes::Type axis, double offset )
00276 {
00277 if( axis == Axes::Z ) return;
00278 assert ( axis == Axes::X || axis == Axes::Y );
00279
00280 m_binner->setOffset ( axis, offset );
00281 if( axis == Axes::X )
00282 m_x_axis->setRange( m_binner->getRange ( Axes::X ), true );
00283 else
00284 m_y_axis->setRange( m_binner->getRange ( Axes::Y ), true );
00285
00286 setDirty ( true );
00287 }
00288
00289 const string & Profile2DProjector::getZLabel() const
00290 {
00291 return m_ntuple->getLabelAt( m_columns[2] );
00292 }
00293
00294 void Profile2DProjector::addPointReps()
00295 {
00296 m_pointreps.push_back ( "ColorBox" );
00297 m_pointreps.push_back ( "Contour" );
00298 }
00299
00300 void
00301 Profile2DProjector::
00302 setBinnerRange ( hippodraw::Axes::Type axis,
00303 const Range & range, bool const_width )
00304 {
00305 m_binner -> setRange ( axis, range, const_width );
00306 checkScaling ();
00307
00308 setDirty ( true );
00309 }
00310
00311 void
00312 Profile2DProjector::
00313 update ( const Observable * object )
00314 {
00315 const DataSource * datasource
00316 = dynamic_cast < const DataSource * > ( object );
00317
00318 if ( datasource != 0 ) {
00319 NTupleProjector::update ( object );
00320 }
00321 else {
00322 BinningProjector::update ( object );
00323 }
00324 }
00325
00326 void
00327 Profile2DProjector::
00328 willDelete ( const Observable * object )
00329 {
00330 const DataSource * datasource
00331 = dynamic_cast < const DataSource * > ( object );
00332
00333 if ( datasource != 0 ) {
00334 NTupleProjector::willDelete ( object );
00335 }
00336 else {
00337 BinningProjector::willDelete ( object );
00338 }
00339 }