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