00001
00012 #ifdef _MSC_VER
00013
00014 #include "msdevstudio/MSconfig.h"
00015 #endif //_MSC_VER
00016
00017 #include "DyHist2DProjector.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/NTuple.h"
00027
00028 #include <cassert>
00029
00030 using namespace hippodraw;
00031
00032 using std::list;
00033 using std::max;
00034 using std::string;
00035 using std::vector;
00036
00037 DyHist2DProjector::DyHist2DProjector( )
00038 : Hist2DProjImp (),
00039 NTupleProjector ( 3 )
00040 {
00041 m_binding_options.push_back ( "X" );
00042 m_binding_options.push_back ( "Y" );
00043 m_binding_options.push_back ( "Weight (optional)" );
00044 m_min_bindings = 2;
00045 }
00046
00051 DyHist2DProjector::
00052 DyHist2DProjector ( const DyHist2DProjector & projector )
00053 : ProjectorBase ( projector ),
00054 Hist2DProjImp ( projector ),
00055 NTupleProjector ( projector ),
00056 m_z_label_entries ( projector.m_z_label_entries ),
00057 m_z_label_density ( projector.m_z_label_density ),
00058 m_value_range( projector.m_value_range )
00059 {
00060 }
00061
00062 ProjectorBase * DyHist2DProjector::clone()
00063 {
00064 return new DyHist2DProjector( *this );
00065 }
00066
00067 void DyHist2DProjector::changedNTuple()
00068 {
00069 unsigned int cols = m_ntuple->columns () - 1;
00070 if ( m_columns[0] > cols ) m_columns[0] = cols;
00071 if ( m_columns[1] > cols ) m_columns[1] = cols;
00072
00073 m_binner->setDirty();
00074 }
00075
00076 void DyHist2DProjector::execute()
00077 {
00078 unsigned int x_col = m_columns[0];
00079 unsigned int y_col = m_columns[1];
00080 unsigned int w_col = m_columns[2];
00081
00082 bool have_weight = w_col < UINT_MAX;
00083
00084
00085
00086
00087 m_binner->reset();
00088 unsigned int size = m_ntuple -> rows ();
00089 for ( unsigned int i = 0; i < size; i++ )
00090 {
00091 if ( acceptRow ( i, m_cut_list ) == false ) continue;
00092
00093 double x = m_ntuple -> valueAt ( i, x_col );
00094 double y = m_ntuple -> valueAt ( i, y_col );
00095 double w = 1.0;
00096 if ( have_weight ) {
00097 w = m_ntuple -> valueAt ( i, w_col );
00098 }
00099 m_binner->accumulate( x, y, w );
00100 }
00101 }
00102
00103
00104 bool DyHist2DProjector::isAxisBinned ( const std::string & axis ) const
00105 {
00106 if ( axis == m_binding_options[0]
00107 || axis == m_binding_options[1] ) return true;
00108 return false;
00109 }
00110
00111 Range
00112 DyHist2DProjector::
00113 dataRangeOn ( hippodraw::Axes::Type axis ) const
00114 {
00115 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00116 if ( axis == Axes::X ) {
00117 return dataRange ( m_columns[0] );
00118 } else if ( axis == Axes::Y ) {
00119 return dataRange ( m_columns[1] );
00120 } else {
00121 return dataRangeOnValue ();
00122 }
00123 }
00124
00125 double
00126 DyHist2DProjector::
00127 getPosOn ( hippodraw::Axes::Type axis ) const
00128 {
00129 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00130 if ( axis == Axes::X ) {
00131 return getPos ( m_columns[0] );
00132 } else if( axis == Axes::Y ) {
00133 return getPos ( m_columns[1] );
00134 } else {
00135 return valueRange().pos();
00136 }
00137 }
00138
00139 const Range &
00140 DyHist2DProjector::
00141 setBinWidth ( Axes::Type axis,
00142 int parm,
00143 bool dragging )
00144 {
00145 double new_width = m_binner->calcBinWidth ( axis, parm, dragging );
00146
00147 return Hist2DProjImp::setBinWidth ( axis, new_width );
00148 }
00149
00150 void DyHist2DProjector::setOffset ( const std::string & axis,
00151 int parm,
00152 bool dragging )
00153 {
00154 Axes::Type at = Axes::convert ( axis );
00155 if ( at != Axes::X && at != Axes::Y ) return;
00156
00157 double new_offset = m_binner->calcOffset ( axis, parm, dragging );
00158
00159 if( new_offset == 0.0 ) return;
00160 if( !dragging )
00161 Hist2DProjImp::setOffset( at, 0.0 );
00162 else
00163 Hist2DProjImp::setOffset( at, new_offset );
00164
00165 setDirty ( true );
00166 }
00167
00168 void
00169 DyHist2DProjector::
00170 setBinnerRange ( hippodraw::Axes::Type axis,
00171 const Range & range,
00172 bool const_width )
00173 {
00174 m_binner -> setRange ( axis, range, const_width );
00175 checkScaling ();
00176
00177 setDirty ( true );
00178 }
00179
00180 void
00181 DyHist2DProjector::
00182 update ( const Observable * object )
00183 {
00184 const DataSource * datasource
00185 = dynamic_cast < const DataSource * > ( object );
00186
00187 if ( datasource != 0 ) {
00188 NTupleProjector::update ( object );
00189 }
00190 else {
00191 BinningProjector::update ( object );
00192 }
00193 }
00194
00195 void
00196 DyHist2DProjector::
00197 willDelete ( const Observable * object )
00198 {
00199 const DataSource * datasource
00200 = dynamic_cast < const DataSource * > ( object );
00201
00202 if ( datasource != 0 ) {
00203 NTupleProjector::willDelete ( object );
00204 }
00205 else {
00206 BinningProjector::willDelete ( object );
00207 }
00208 }