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