00001 00012 #ifdef _MSC_VER 00013 // Include max() and min() missing from MicroSoft Visual C++. 00014 #include "msdevstudio/MSconfig.h" 00015 #endif 00016 00017 #include "StHist1DProjector.h" 00018 00019 #include "ProjectorHelper.h" 00020 00021 #include "axes/AxisModelBase.h" 00022 00023 #include "binners/BinsBase.h" 00024 #include "binners/BinsFactory.h" 00025 00026 #include <cassert> 00027 00028 using namespace hippodraw; 00029 00030 #ifdef ITERATOR_MEMBER_DEFECT 00031 using namespace std; 00032 #else 00033 using std::list; 00034 using std::max; 00035 using std::string; 00036 using std::vector; 00037 #endif 00038 00039 StHist1DProjector::StHist1DProjector( ) 00040 : Hist1DProjImp ( ) 00041 { 00042 m_y_label = "Entries / bin"; 00043 } 00044 00050 StHist1DProjector:: 00051 StHist1DProjector ( const StHist1DProjector & projector ) 00052 : ProjectorBase ( projector ), 00053 Hist1DProjImp ( projector ), 00054 m_title ( projector.m_title ), 00055 m_x_label ( projector.m_x_label ), 00056 m_y_label ( projector.m_y_label ) 00057 { 00058 } 00059 00060 ProjectorBase * StHist1DProjector::clone() 00061 { 00062 return new StHist1DProjector ( *this ); 00063 } 00064 00065 /* virtual */ 00066 bool StHist1DProjector::isAxisBinned ( const std::string & axis ) const 00067 { 00068 return axis == "x" || axis == "X"; 00069 } 00070 00074 double 00075 StHist1DProjector:: 00076 getPosOn ( hippodraw::Axes::Type axis ) const 00077 { 00078 assert ( axis == Axes::X || axis == Axes::Y ); 00079 00080 return getPosOnValue (); 00081 } 00082 00083 Range 00084 StHist1DProjector:: 00085 dataRangeOn ( hippodraw::Axes::Type axis ) const 00086 { 00087 assert ( axis == Axes::X || axis == Axes::Y ); 00088 00089 if ( axis == Axes::X ) { 00090 return m_binner->getRange ( axis ); 00091 } 00092 00093 // Y 00094 return dataRangeOnValue (); 00095 } 00096 00097 const string & StHist1DProjector::getXLabel() const 00098 { 00099 return m_x_label; 00100 } 00101 00102 void StHist1DProjector::setYLabel() 00103 { 00104 m_y_label = m_y_label_entries; 00105 } 00106 00107 const string & StHist1DProjector::getYLabel ( bool ) const 00108 { 00109 return m_y_label; 00110 } 00111 00112 double 00113 StHist1DProjector:: 00114 getAverage ( hippodraw::Axes::Type axis ) const 00115 { 00116 StHist1DProjector * p = const_cast < StHist1DProjector * > ( this ); 00117 p -> prepareValues (); // might yet be done. 00118 00119 ProjectorHelper helper( getProjectedValues () ); 00120 00121 double mean = 0.0; 00122 00123 if ( axis == Axes::X ) { 00124 mean = helper.meanCoord(); 00125 } 00126 else if ( axis == Axes::Y ) { 00127 mean = helper.meanValue() * m_y_axis->getScaleFactor(); 00128 } 00129 p -> setDirty ( true ); 00130 return mean; 00131 } 00132 00133 /* virtual */ 00134 const std::string & StHist1DProjector::getTitle () const 00135 { 00136 return m_title; 00137 } 00138 00139 int 00140 StHist1DProjector:: 00141 getNumberOfEntries () const 00142 { 00143 double sum = m_binner->getNumberOfEntries (); 00144 00145 return static_cast < int > ( sum ); 00146 } 00147 00148 int 00149 StHist1DProjector:: 00150 getUnderflow () const 00151 { 00152 int underflow = m_binner->getUnderflow (); 00153 return underflow; 00154 } 00155 00156 int 00157 StHist1DProjector:: 00158 getOverflow () const 00159 { 00160 int overflow = m_binner->getOverflow (); 00161 return overflow; 00162 } 00163 00164 00165 void 00166 StHist1DProjector:: 00167 addValues ( const std::vector < double > & v ) 00168 { 00169 double x = v[0]; 00170 double w = v.size() == 2 ? v[1] : 1.0; 00171 00172 m_binner -> accumulate ( x, w ); 00173 setDirty (); 00174 00175 notifyObservers (); 00176 } 00177 00178 bool 00179 StHist1DProjector:: 00180 isEmpty () const 00181 { 00182 return false; 00183 } 00184 00185 void 00186 StHist1DProjector:: 00187 setBinnerRange ( hippodraw::Axes::Type axis, 00188 const Range & range, 00189 bool const_width ) 00190 { 00191 if ( m_binner -> isEmpty () ) { 00192 m_binner -> setRange ( axis, range, const_width ); 00193 checkScaling (); 00194 } 00195 setDirty ( true ); 00196 } 00197 00198 void 00199 StHist1DProjector:: 00200 reset () 00201 { 00202 m_binner -> reset (); 00203 setDirty( true ); 00204 } 00205