13 #include "msdevstudio/MSconfig.h"
29 using namespace hippodraw;
33 using std::max_element;
34 using std::min_element;
46 m_data( binner.m_data ),
47 m_variance( binner.m_variance ),
48 m_min_entries ( binner.m_min_entries )
65 m_data.resize ( number + 2 );
74 return *min_element (
m_data.begin() + 1,
m_data.end ( ) - 1 );
79 return *max_element (
m_data.begin () + 1,
m_data.end () - 1 );
94 return static_cast <
int > ( std::accumulate (
m_data.begin()+1,
100 int retval = static_cast <
int > (
m_data[i+1] );
107 return static_cast <
int > (
m_data[0] );
112 return static_cast <
int > ( *(
m_data.end()-1) );
118 if ( i > 0 && i <= static_cast < int > (
m_variance.size() ) ) {
141 namespace dp = hippodraw::DataPoint2DTuple;
150 double total = std::accumulate (
m_data.begin() + 1,
154 std::vector<double>::const_iterator dit =
m_data.begin() + 1;
155 std::vector<double>::const_iterator vit =
m_variance.begin();
156 std::vector<double>::const_iterator first_non_zero =
m_data.begin() + 1;
157 std::vector<double>::const_iterator last_non_zero =
m_data.end() - 2;
161 while ( (*first_non_zero) == 0 ) {
164 while ( (*last_non_zero) == 0 ) {
169 swap ( first_non_zero, last_non_zero );
176 if ( last_non_zero < first_non_zero ) {
177 for (;dit !=
m_data.end()-1; dit ++ ) {
179 double half_width = 0.5 * width;
180 double y = factor * ( *dit / width );
181 double yerr = factor * ( sqrt( *vit++ ) / width );
188 ntuple -> addRow ( row );
196 for ( ; dit != first_non_zero; dit++ ) {
198 double half_width = 0.5 * width;
199 double y = factor * ( *dit / width );
200 double yerr = factor * ( sqrt( *vit++ ) / width );
207 ntuple -> addRow ( row );
214 for( ; dit != last_non_zero+1; dit++ ) {
216 double entries = *dit;
218 double var = sqrt(*vit);
220 if (dit == last_non_zero)
break;
227 double half_width = 0.5 * width;
229 double y = factor * ( entries / width );
230 double yerr = factor * ( var / width );
235 unsigned int numOfRows = ntuple->
rows();
236 unsigned int lastIndex = numOfRows-1;
237 vector <double> lastRow = ntuple -> getRow( lastIndex );
239 x = lastRow[
dp::X] + half_width;
243 / ( width + lastRow[dp::XERR] * 2 ) ;
246 ntuple -> eraseRow ( lastIndex );
254 ntuple -> addRow ( row );
260 for ( ; dit !=
m_data.end()-1; dit++ ) {
262 double half_width = 0.5 * width;
263 double y = factor * ( *dit / width );
264 double yerr = factor * ( sqrt( *vit++ ) / width );
271 ntuple -> addRow ( row );
285 unsigned int size = ntuple -> rows ();
288 for (
unsigned int i = 0;
i <
size;
i++ ) {
289 const vector < double > & row = ntuple -> getRow (
i );
Bins1DHist()
The default constructor.
int m_min_entries
The minimum number of entries/bin.
The base class for the one-dimensional binner hierarchy.
virtual double getLow(hippodraw::Axes::Type axis) const
Returns the low value of the bins on the specified axis.
virtual void reset()
Resets the accumulation to zero.
virtual void setMinEntries(int entries)
Set the minimum entries/bin.
double maxBin()
Returns the value of the bin with the largest value.
double minBin()
Returns the value of the bin with the smallest value.
The class for the one-dimensional histogram binning.
virtual void fillDataSource(DataSource *ntuple) const
Fills the DataSource.
virtual NTuple * prepareNTuple(unsigned int rows) const
Prepares the NTuple.
void resize()
Resizes the internal arrays.
double m_moments[3]
The moments.
virtual NTuple * createNTuple() const
Creates a NTuple.
int binNumber(double x)
Returns the number of the bin in which the x value is situated.
hippodraw::NTuple class interface.
double binWidth(int i) const
Returns the width of each bin.
error on X or half bin width
virtual int getMinEntries()
Get the minimum entries/bin.
bool m_values_dirty
A flag to indicate that the objects in m_values are not correct.
intp size(numeric::array arr)
BinsBase * clone() const
The clone function returns an object of its own kind which is a copy of this object at this moment...
virtual ~Bins1DHist()
The destructor.
A DataSource class implemented with std::vector<double> to store the column data. ...
virtual unsigned int rows() const =0
Returns the number of rows.
virtual int getUnderflow() const
implementation from pure base
virtual void setBinContents(const DataSource *ntuple)
double m_scale_factor
The scale factor.
hippodraw::DataPointTuple namespace interface
bool m_is_scaling
A flag which is set true to enable scaling the output.
virtual int getNumberOfEntries() const
implementation from pure base
bool m_empty
A flag set to true, when no accumulation has yet occurred, otherwise is set false.
std::vector< double > m_variance
The accumulated square of the weights.
hippodraw::Bins1DHist class interface
std::vector< double > m_data
The array of binned data.
virtual void accumulate(double x, double w=1.0, double i1=0.0, double i2=0.0)
Accumulates a data point x into a bin with weight w.
virtual int getOverflow() const
implementation from pure base
The base class for the binner hierarchy.
Base class for DataSource.