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