00001
00012 #ifdef _MSC_VER
00013
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016
00017 #include "StHist2DProjector.h"
00018
00019 #include "axes/AxisModelBase.h"
00020
00021 #include "binners/BinsBase.h"
00022 #include "binners/BinsFactory.h"
00023
00024 #include "datasrcs/DataPointTuple.h"
00025 #include "datasrcs/DataSource.h"
00026
00027 #include <numeric>
00028
00029 #include <cassert>
00030
00031 using namespace hippodraw;
00032
00033 #ifdef ITERATOR_MEMBER_DEFECT
00034 using namespace std;
00035 #else
00036 using std::accumulate;
00037 using std::inner_product;
00038 using std::list;
00039 using std::max;
00040 using std::string;
00041 using std::vector;
00042 #endif
00043
00044 StHist2DProjector::StHist2DProjector( )
00045 : Hist2DProjImp ( )
00046 {
00047 m_z_label = "Entries / bin";
00048 }
00049
00055 StHist2DProjector::
00056 StHist2DProjector ( const StHist2DProjector & projector )
00057 : ProjectorBase ( projector ),
00058 Hist2DProjImp ( projector ),
00059 m_title ( projector.m_title ),
00060 m_x_label ( projector.m_x_label ),
00061 m_y_label ( projector.m_y_label ),
00062 m_z_label ( projector.m_y_label )
00063 {
00064 }
00065
00066 ProjectorBase * StHist2DProjector::clone()
00067 {
00068 return new StHist2DProjector ( *this );
00069 }
00070
00075 bool StHist2DProjector::isAxisBinned ( const std::string & axis ) const
00076 {
00077 return axis == "x" ||
00078 axis == "X" ||
00079 axis == "y" ||
00080 axis == "Y";
00081 }
00082
00083 double
00084 StHist2DProjector::
00085 getPosOn( hippodraw::Axes::Type axis ) const
00086 {
00087 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00088
00089 return getPosOnValue ();
00090 }
00091
00092 Range
00093 StHist2DProjector::
00094 dataRangeOn (hippodraw:: Axes::Type axis ) const
00095 {
00096 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00097
00098 if ( axis == Axes::X ) {
00099 return m_binner->getRange ( axis );
00100 }
00101 if ( axis == Axes::Y ) {
00102 return m_binner->getRange ( axis );
00103 }
00104
00105 return dataRangeOnValue ();
00106 }
00107
00108 const string & StHist2DProjector::getXLabel() const
00109 {
00110 return m_x_label;
00111 }
00112
00113 const string & StHist2DProjector::getYLabel ( bool ) const
00114 {
00115 return m_y_label;
00116 }
00117
00118 const string & StHist2DProjector::getZLabel ( bool ) const
00119 {
00120 return m_z_label;
00121 }
00122
00123 namespace dp = hippodraw::DataPoint3DTuple;
00124
00125 double
00126 StHist2DProjector::
00127 getAverage ( hippodraw::Axes::Type axis ) const
00128 {
00129 StHist2DProjector * p = const_cast < StHist2DProjector * > ( this );
00130 p -> prepareValues ();
00131
00132 unsigned int col = 3;
00133 switch ( axis ) {
00134
00135 case Axes::X:
00136 col = dp::X;
00137 break;
00138
00139 case Axes::Y:
00140 col = dp::Y;
00141 break;
00142
00143 case Axes::Z:
00144 col = dp::Z;
00145 break;
00146
00147 default:
00148 break;
00149 }
00150 assert ( col < 3 );
00151
00152 double result = 0.0;
00153 const DataSource * ntuple = getProjectedValues ();
00154 const vector < double > & value = ntuple -> getColumn ( dp::Z );
00155
00156 if ( col < 2 ) {
00157 const vector < double > & data = ntuple -> getColumn ( col );
00158
00159 double sumXV = 0.0;
00160
00161 sumXV = std::inner_product ( data.begin(), data.end(),
00162 value.begin(), sumXV );
00163
00164 double sumV = 0.0;
00165 sumV = accumulate ( value.begin(), value.end(), sumV );
00166
00167 result = sumXV / sumV;
00168 }
00169 else {
00170 double sumV = 0.0;
00171 sumV = accumulate ( value.begin(), value.end (), sumV );
00172 result = ( sumV / value.size () ) * m_z_axis -> getScaleFactor ();
00173 }
00174 p -> setDirty ( true );
00175
00176 return result;
00177 }
00178
00179
00180 const std::string & StHist2DProjector::getTitle () const
00181 {
00182 return m_title;
00183 }
00184
00185 int
00186 StHist2DProjector::
00187 getNumberOfEntries () const
00188 {
00189 double sum = m_binner->getNumberOfEntries ();
00190
00191 return static_cast < int > ( sum );
00192 }
00193
00194 int
00195 StHist2DProjector::
00196 getUnderflow () const
00197 {
00198 return m_binner->getUnderflow ();
00199 }
00200
00201 int
00202 StHist2DProjector::
00203 getOverflow () const
00204 {
00205 return m_binner->getOverflow ();
00206 }
00207
00208 void
00209 StHist2DProjector::
00210 addValues ( const std::vector < double > & v )
00211 {
00212 double x = v[0];
00213 double y = v[1];
00214 double w = v.size() == 3 ? v[2] : 1.0;
00215
00216 m_binner -> accumulate ( x, y, w );
00217 setDirty ();
00218
00219 notifyObservers ();
00220 }
00221
00222 bool
00223 StHist2DProjector::
00224 isEmpty () const
00225 {
00226 return false;
00227 }
00228
00229 void
00230 StHist2DProjector::
00231 setBinnerRange ( hippodraw::Axes::Type axis,
00232 const Range & range,
00233 bool const_width )
00234 {
00235 if ( m_binner -> isEmpty () ) {
00236 m_binner -> setRange ( axis, range, const_width );
00237 checkScaling ();
00238 }
00239 setDirty ( true );
00240 }