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