YODA is hosted by Hepforge, IPPP Durham
YODA::Histo1D Class Reference

A one-dimensional histogram. More...

#include <Histo1D.h>

Inheritance diagram for YODA::Histo1D:
YODA::AnalysisObject

Public Types

typedef Histo1DAxis Axis
 Convenience typedefs. More...
 
typedef Axis::Bins Bins
 
typedef HistoBin1D Bin
 
- Public Types inherited from YODA::AnalysisObject
typedef std::map< std::string,
std::string > 
Annotations
 Collection type for annotations, as a string-string map. More...
 

Public Member Functions

Constructors
 Histo1D (const std::string &path="", const std::string &title="")
 Default constructor. More...
 
 Histo1D (size_t nbins, double lower, double upper, const std::string &path="", const std::string &title="")
 Constructor giving range and number of bins. More...
 
 Histo1D (const std::vector< double > &binedges, const std::string &path="", const std::string &title="")
 Constructor giving explicit bin edges. More...
 
 Histo1D (const std::vector< Bin > &bins, const std::string &path="", const std::string &title="")
 Constructor accepting an explicit collection of bins. More...
 
 Histo1D (const Histo1D &h, const std::string &path="")
 Copy constructor with optional new path. More...
 
 Histo1D (const Scatter2D &s, const std::string &path="")
 Constructor from a Scatter2D's binning, with optional new path. More...
 
 Histo1D (const Profile1D &p, const std::string &path="")
 Constructor from a Profile1D's binning, with optional new path. More...
 
 Histo1D (const std::vector< HistoBin1D > &bins, const Dbn1D &dbn_tot, const Dbn1D &dbn_uflow, const Dbn1D &dbn_oflow, const std::string &path="", const std::string &title="")
 State-setting constructor. More...
 
Histo1Doperator= (const Histo1D &h1)
 Assignment operator. More...
 
Histo1D clone () const
 Make a copy on the stack. More...
 
Histo1Dnewclone () const
 Make a copy on the heap, via 'new'. More...
 
Modifiers
virtual void reset ()
 Reset the histogram. More...
 
void fill (double x, double weight=1.0)
 Fill histo by value and weight. More...
 
void fillBin (size_t i, double weight=1.0)
 Fill histo bin i with the given weight. More...
 
void scaleW (double scalefactor)
 Rescale as if all fill weights had been different by factor scalefactor. More...
 
void normalize (double normto=1.0, bool includeoverflows=true)
 
void mergeBins (size_t from, size_t to)
 Merge together the bin range with indices from from to to, inclusive. More...
 
void rebin (int n)
 Merge every group of n bins, starting from the LHS. More...
 
Bin accessors
size_t numBins () const
 Number of bins on this axis (not counting under/overflow) More...
 
double xMin () const
 Low edge of this histo's axis. More...
 
double xMax () const
 High edge of this histo's axis. More...
 
std::vector< YODA::HistoBin1D > & bins ()
 Access the bin vector. More...
 
const std::vector
< YODA::HistoBin1D > & 
bins () const
 Access the bin vector (const version) More...
 
HistoBin1Dbin (size_t index)
 Access a bin by index (non-const version) More...
 
const HistoBin1Dbin (size_t index) const
 Access a bin by index (const version) More...
 
int binIndexAt (double x)
 Access a bin index by coordinate. More...
 
const HistoBin1DbinAt (double x) const
 Access a bin by coordinate (const version) More...
 
Dbn1DtotalDbn ()
 Access summary distribution, including gaps and overflows (non-const version) More...
 
const Dbn1DtotalDbn () const
 Access summary distribution, including gaps and overflows (const version) More...
 
Dbn1Dunderflow ()
 Access underflow (non-const version) More...
 
const Dbn1Dunderflow () const
 Access underflow (const version) More...
 
Dbn1Doverflow ()
 Access overflow (non-const version) More...
 
const Dbn1Doverflow () const
 Access overflow (const version) More...
 
void addBin (double from, double to)
 Add a new bin specifying its lower and upper bound. More...
 
void addBins (std::vector< double > edges)
 Add a new bin specifying a vector of edges. More...
 
void eraseBin (size_t index)
 Remove a bin. More...
 
Whole histo data
double integral (bool includeoverflows=true) const
 Get the total area of the histogram. More...
 
double integral (size_t binindex1, size_t binindex2) const
 Get the integrated area of the histogram between bins binindex1 and binindex2. More...
 
double integral (size_t binindex, bool includeunderflow=true) const
 Get the integrated area of the histogram up to bin binindex. More...
 
double numEntries () const
 
double effNumEntries () const
 
double sumW (bool includeoverflows=true) const
 Get sum of weights in histo. More...
 
double sumW2 (bool includeoverflows=true) const
 Get sum of squared weights in histo. More...
 
double xMean (bool includeoverflows=true) const
 Get the mean. More...
 
double xVariance (bool includeoverflows=true) const
 Get the variance. More...
 
double xStdDev (bool includeoverflows=true) const
 Get the standard deviation. More...
 
double xStdErr (bool includeoverflows=true) const
 Get the standard error. More...
 
Adding and subtracting histograms
Histo1Doperator+= (const Histo1D &toAdd)
 Add another histogram to this one. More...
 
Histo1Doperator-= (const Histo1D &toSubtract)
 Subtract another histogram from this one. More...
 
- Public Member Functions inherited from YODA::AnalysisObject
 AnalysisObject ()
 Default constructor. More...
 
 AnalysisObject (const std::string &type, const std::string &path, const std::string &title="")
 Constructor giving a type, a path and an optional title. More...
 
 AnalysisObject (const std::string &type, const std::string &path, const AnalysisObject &ao, const std::string &title="")
 Constructor giving a type, a path, another AO to copy annotation from, and an optional title. More...
 
virtual ~AnalysisObject ()
 Default destructor. More...
 
virtual AnalysisObjectoperator= (const AnalysisObject &ao)
 Default copy assignment operator. More...
 
const std::vector< std::string > annotations () const
 Get all the annotation names. More...
 
bool hasAnnotation (const std::string &name) const
 Check if an annotation is defined. More...
 
const std::string & annotation (const std::string &name) const
 Get an annotation by name (as a string) More...
 
const std::string & annotation (const std::string &name, const std::string &defaultreturn) const
 Get an annotation by name (as a string) with a default in case the annotation is not found. More...
 
template<typename T >
const T annotation (const std::string &name) const
 Get an annotation by name (copied to another type) More...
 
template<typename T >
const T annotation (const std::string &name, const T &defaultreturn) const
 Get an annotation by name (copied to another type) with a default in case the annotation is not found. More...
 
template<typename T >
void setAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name. More...
 
void setAnnotations (const Annotations &anns)
 Set all annotations at once. More...
 
template<typename T >
void addAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name. More...
 
void rmAnnotation (const std::string &name)
 Delete an annotation by name. More...
 
void clearAnnotations ()
 Delete an annotation by name. More...
 
const std::string title () const
 
void setTitle (const std::string &title)
 Set the AO title. More...
 
const std::string path () const
 
void setPath (const std::string &path)
 Set the AO path. More...
 
virtual std::string type () const
 Get name of the analysis object type, for persistency. More...
 

Protected Member Functions

HistoBin1DbinAt (double x)
 Access a bin by coordinate (non-const version) More...
 

Detailed Description

A one-dimensional histogram.

Definition at line 27 of file Histo1D.h.

Member Typedef Documentation

Convenience typedefs.

Definition at line 31 of file Histo1D.h.

Definition at line 33 of file Histo1D.h.

Definition at line 32 of file Histo1D.h.

Constructor & Destructor Documentation

YODA::Histo1D::Histo1D ( const std::string &  path = "",
const std::string &  title = "" 
)
inline

Default constructor.

Definition at line 40 of file Histo1D.h.

Referenced by clone(), and newclone().

41  : AnalysisObject("Histo1D", path, title),
42  _axis()
43  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
YODA::Histo1D::Histo1D ( size_t  nbins,
double  lower,
double  upper,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor giving range and number of bins.

Definition at line 47 of file Histo1D.h.

49  : AnalysisObject("Histo1D", path, title),
50  _axis(nbins, lower, upper)
51  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
YODA::Histo1D::Histo1D ( const std::vector< double > &  binedges,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor giving explicit bin edges.

For n bins, binedges.size() == n+1, the last one being the upper bound of the last bin

Definition at line 58 of file Histo1D.h.

60  : AnalysisObject("Histo1D", path, title),
61  _axis(binedges)
62  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
YODA::Histo1D::Histo1D ( const std::vector< Bin > &  bins,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor accepting an explicit collection of bins.

Definition at line 66 of file Histo1D.h.

68  : AnalysisObject("Histo1D", path, title),
69  _axis(bins)
70  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
YODA::Histo1D::Histo1D ( const Histo1D h,
const std::string &  path = "" 
)

Copy constructor with optional new path.

Copy constructor with optional new path

Todo:
Also allow title setting from the constructor?

Definition at line 108 of file Histo1D.cc.

109  : AnalysisObject("Histo1D", (path.size() == 0) ? h.path() : path, h, h.title())
110  {
111  _axis = h._axis;
112  }
AnalysisObject()
Default constructor.
const std::string path() const
YODA::Histo1D::Histo1D ( const Scatter2D s,
const std::string &  path = "" 
)

Constructor from a Scatter2D's binning, with optional new path.

Constructor from a Scatter2D's binning, with optional new path

Todo:
Also allow title setting from the constructor?

Definition at line 116 of file Histo1D.cc.

References bins(), YODA::Scatter2D::points(), YODA::Point2D::xMax(), and YODA::Point2D::xMin().

117  : AnalysisObject("Histo1D", (path.size() == 0) ? s.path() : path, s, s.title())
118  {
119  std::vector<HistoBin1D> bins;
120  BOOST_FOREACH (const Scatter2D::Point& p, s.points()) {
121  bins.push_back(HistoBin1D(p.xMin(), p.xMax()));
122  }
123  _axis = Histo1DAxis(bins);
124  }
AnalysisObject()
Default constructor.
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:186
Axis1D< HistoBin1D, Dbn1D > Histo1DAxis
Convenience typedef.
Definition: Histo1D.h:23
Point2D Point
Type of the native Point2D collection.
Definition: Scatter2D.h:27
const std::string path() const
YODA::Histo1D::Histo1D ( const Profile1D p,
const std::string &  path = "" 
)

Constructor from a Profile1D's binning, with optional new path.

Constructor from a Profile1D's binning, with optional new path

Todo:
Also allow title setting from the constructor?

Definition at line 128 of file Histo1D.cc.

References bins(), YODA::Profile1D::bins(), YODA::Bin1D< DBN >::xMax(), and YODA::Bin1D< DBN >::xMin().

129  : AnalysisObject("Histo1D", (path.size() == 0) ? p.path() : path, p, p.title())
130  {
131  std::vector<HistoBin1D> bins;
132  BOOST_FOREACH (const ProfileBin1D& b, p.bins()) {
133  bins.push_back(HistoBin1D(b.xMin(), b.xMax()));
134  }
135  _axis = Histo1DAxis(bins);
136  }
AnalysisObject()
Default constructor.
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:186
Axis1D< HistoBin1D, Dbn1D > Histo1DAxis
Convenience typedef.
Definition: Histo1D.h:23
const std::string path() const
YODA::Histo1D::Histo1D ( const std::vector< HistoBin1D > &  bins,
const Dbn1D dbn_tot,
const Dbn1D dbn_uflow,
const Dbn1D dbn_oflow,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

State-setting constructor.

Intended principally for internal persistency use.

Definition at line 91 of file Histo1D.h.

94  : AnalysisObject("Histo1D", path, title),
95  _axis(bins, dbn_tot, dbn_uflow, dbn_oflow)
96  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const

Member Function Documentation

void YODA::Histo1D::addBin ( double  from,
double  to 
)
inline

Add a new bin specifying its lower and upper bound.

Definition at line 225 of file Histo1D.h.

225 { _axis.addBin(from, to); }
void YODA::Histo1D::addBins ( std::vector< double >  edges)
inline

Add a new bin specifying a vector of edges.

Definition at line 228 of file Histo1D.h.

228 { _axis.addBins(edges); }
HistoBin1D& YODA::Histo1D::bin ( size_t  index)
inline

Access a bin by index (non-const version)

Definition at line 192 of file Histo1D.h.

Referenced by YODA::chi2(), YODA::efficiency(), integral(), YODA::toIntegralHisto(), and YODA::toTH1D().

192 { return _axis.bins()[index]; }
const HistoBin1D& YODA::Histo1D::bin ( size_t  index) const
inline

Access a bin by index (const version)

Definition at line 194 of file Histo1D.h.

194 { return _axis.bins()[index]; }
const HistoBin1D& YODA::Histo1D::binAt ( double  x) const
inline

Access a bin by coordinate (const version)

Definition at line 203 of file Histo1D.h.

Referenced by YODA::toTH1D().

203 { return _axis.binAt(x); }
HistoBin1D& YODA::Histo1D::binAt ( double  x)
inlineprotected

Access a bin by coordinate (non-const version)

Definition at line 355 of file Histo1D.h.

355 { return _axis.binAt(x); }
int YODA::Histo1D::binIndexAt ( double  x)
inline

Access a bin index by coordinate.

Definition at line 198 of file Histo1D.h.

198  {
199  return _axis.binIndexAt(x);
200  }
std::vector<YODA::HistoBin1D>& YODA::Histo1D::bins ( )
inline

Access the bin vector.

Definition at line 186 of file Histo1D.h.

Referenced by Histo1D(), YODA::mkScatter(), numBins(), YODA::Profile1D::Profile1D(), and YODA::WriterYODA::writeHisto1D().

186 { return _axis.bins(); }
const std::vector<YODA::HistoBin1D>& YODA::Histo1D::bins ( ) const
inline

Access the bin vector (const version)

Definition at line 188 of file Histo1D.h.

188 { return _axis.bins(); }
Histo1D YODA::Histo1D::clone ( ) const
inline

Make a copy on the stack.

Definition at line 107 of file Histo1D.h.

References Histo1D().

107  {
108  return Histo1D(*this);
109  }
Histo1D(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Histo1D.h:40
double YODA::Histo1D::effNumEntries ( ) const
inline

Get the effective number of fills

Todo:
Add an includeoverflows argument

Definition at line 281 of file Histo1D.h.

References YODA::Dbn1D::effNumEntries(), and totalDbn().

281 { return totalDbn().effNumEntries(); }
double effNumEntries() const
Effective number of entries .
Definition: Dbn1D.h:147
Dbn1D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo1D.h:207
void YODA::Histo1D::eraseBin ( size_t  index)
inline

Remove a bin.

Definition at line 236 of file Histo1D.h.

236 { _axis.eraseBin(index); }
void YODA::Histo1D::fill ( double  x,
double  weight = 1.0 
)

Fill histo by value and weight.

Unify this with Profile1D's version, when binning and inheritance are reworked

Todo:
Replace try block with a check that there is a bin at x

Definition at line 17 of file Histo1D.cc.

References YODA::inRange().

17  {
18  if ( std::isnan(x) ) throw RangeError("X is NaN");
19 
20  // Fill the overall distribution
21  _axis.totalDbn().fill(x, weight);
22 
23  // Fill the bins and overflows
25  if (inRange(x, _axis.xMin(), _axis.xMax())) {
26  try {
28  binAt(x).fill(x, weight);
29  } catch (const RangeError& re) { }
30  } else if (x < _axis.xMin()) {
31  _axis.underflow().fill(x, weight);
32  } else if (x >= _axis.xMax()) {
33  _axis.overflow().fill(x, weight);
34  }
35 
36  // Lock the axis now that a fill has happened
37  _axis._setLock(true);
38  }
bool inRange(NUM value, NUM low, NUM high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
Determine if value is in the range low to high, for floating point numbers.
Definition: MathUtils.h:151
const HistoBin1D & binAt(double x) const
Access a bin by coordinate (const version)
Definition: Histo1D.h:203
void fill(double x, double weight=1.0)
Definition: HistoBin1D.h:72
void YODA::Histo1D::fillBin ( size_t  i,
double  weight = 1.0 
)

Fill histo bin i with the given weight.

Definition at line 41 of file Histo1D.cc.

41  {
42  fill(bin(i).xMid(), weight);
43  }
HistoBin1D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo1D.h:192
void fill(double x, double weight=1.0)
Fill histo by value and weight.
Definition: Histo1D.cc:17
double YODA::Histo1D::integral ( bool  includeoverflows = true) const
inline

Get the total area of the histogram.

Definition at line 245 of file Histo1D.h.

References sumW().

Referenced by integral(), normalize(), YODA::toIntegralEfficiencyHisto(), and YODA::WriterYODA::writeHisto1D().

245 { return sumW(includeoverflows); }
double sumW(bool includeoverflows=true) const
Get sum of weights in histo.
Definition: Histo1D.cc:50
double YODA::Histo1D::integral ( size_t  binindex1,
size_t  binindex2 
) const
inline

Get the integrated area of the histogram between bins binindex1 and binindex2.

Note
The area of bin binindex2 is not included in the returned value. To include the underflow and overflow areas, you should add them explicitly with the underflow() and overflow() methods.
Todo:
Allow int bin index args for type compatibility with binIndexAt()?

Definition at line 254 of file Histo1D.h.

References bin(), numBins(), and YODA::Bin1D< DBN >::sumW().

254  {
255  assert(binindex2 >= binindex1);
256  if (binindex1 >= numBins()) throw RangeError("binindex1 is out of range");
257  if (binindex2 > numBins()) throw RangeError("binindex2 is out of range");
258  double rtn = 0;
259  for (size_t i = binindex1; i < binindex2; ++i) {
260  rtn += bin(i).sumW();
261  }
262  return rtn;
263  }
size_t numBins() const
Number of bins on this axis (not counting under/overflow)
Definition: Histo1D.h:176
double sumW() const
The sum of weights.
Definition: Bin1D.h:212
HistoBin1D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo1D.h:192
double YODA::Histo1D::integral ( size_t  binindex,
bool  includeunderflow = true 
) const
inline

Get the integrated area of the histogram up to bin binindex.

Note
The area of bin binindex is not included in the returned value. To not include the underflow, set includeunderflow=false.

Definition at line 269 of file Histo1D.h.

References integral(), YODA::Dbn1D::sumW(), and underflow().

269  {
270  double rtn = includeunderflow ? underflow().sumW() : 0;
271  rtn += integral(0, binindex);
272  return rtn;
273  }
double sumW() const
The sum of weights.
Definition: Dbn1D.h:152
Dbn1D & underflow()
Access underflow (non-const version)
Definition: Histo1D.h:213
double integral(bool includeoverflows=true) const
Get the total area of the histogram.
Definition: Histo1D.h:245
void YODA::Histo1D::mergeBins ( size_t  from,
size_t  to 
)
inline

Merge together the bin range with indices from from to to, inclusive.

Definition at line 157 of file Histo1D.h.

157  {
158  _axis.mergeBins(from, to);
159  }
Histo1D* YODA::Histo1D::newclone ( ) const
inlinevirtual

Make a copy on the heap, via 'new'.

Implements YODA::AnalysisObject.

Definition at line 112 of file Histo1D.h.

References Histo1D().

112  {
113  return new Histo1D(*this);
114  }
Histo1D(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Histo1D.h:40
void YODA::Histo1D::normalize ( double  normto = 1.0,
bool  includeoverflows = true 
)
inline

Normalize the (visible) histo area to the normto value.

If includeoverflows is true, the original normalisation is computed with the overflow bins included, so that the resulting visible normalisation can be less than normto. This is probably what you want.

Todo:
Check that this is the desired behaviour

Definition at line 148 of file Histo1D.h.

References integral(), and scaleW().

148  {
149  const double oldintegral = integral(includeoverflows);
150  if (oldintegral == 0) throw WeightError("Attempted to normalize a histogram with null area");
152  scaleW(normto / oldintegral);
153  }
double integral(bool includeoverflows=true) const
Get the total area of the histogram.
Definition: Histo1D.h:245
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Histo1D.h:137
size_t YODA::Histo1D::numBins ( ) const
inline

Number of bins on this axis (not counting under/overflow)

Definition at line 176 of file Histo1D.h.

References bins().

Referenced by YODA::chi2(), YODA::efficiency(), integral(), YODA::mkScatter(), YODA::toIntegralHisto(), and YODA::toTH1D().

176 { return bins().size(); }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:186
double YODA::Histo1D::numEntries ( ) const
inline

Get the number of fills

Todo:
Add an includeoverflows argument

Definition at line 277 of file Histo1D.h.

References YODA::Dbn1D::numEntries(), and totalDbn().

277 { return totalDbn().numEntries(); }
unsigned long numEntries() const
Number of entries (number of times fill was called, ignoring weights)
Definition: Dbn1D.h:142
Dbn1D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo1D.h:207
Histo1D& YODA::Histo1D::operator+= ( const Histo1D toAdd)
inline

Add another histogram to this one.

Note
Adding histograms will unset any ScaledBy attribute from prevous calls to scaleW or normalize.
Todo:
What about if one histo sets ScaledBy, and the other doesn't?!? Aaaargh

Definition at line 313 of file Histo1D.h.

References YODA::AnalysisObject::hasAnnotation(), and YODA::AnalysisObject::rmAnnotation().

313  {
314  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
315  _axis += toAdd._axis;
316  return *this;
317 
318  // if (!hasAnnotation("ScaledBy") && !toAdd.hasAnnotation("ScaledBy")) {
319  // _axis += toAdd._axis;
320  // } else {
321  // // Undo scaling of both histograms
322  // double scaledBy = annotation<double>("ScaledBy", 1.0);
323  // _axis.scaleW(1.0/scaledBy);
324 
325  // double toAddScaledBy = toAdd.annotation<double>("ScaledBy", 1.0);
326  // Axis1D<HistoBin1D, Dbn1D> toAddAxis = toAdd._axis;
327  // toAddAxis.scaleW(1.0/toAddScaledBy);
328 
329  // _axis += toAddAxis;
330 
331  // // Re-apply combined scaling
332  // double newScaledBy = scaledBy*toAddScaledBy/(scaledBy+toAddScaledBy);
333  // _axis.scaleW(newScaledBy);
334  // setAnnotation("ScaledBy", newScaledBy);
335  // }
337  // return *this;
338  }
void rmAnnotation(const std::string &name)
Delete an annotation by name.
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.
Histo1D& YODA::Histo1D::operator-= ( const Histo1D toSubtract)
inline

Subtract another histogram from this one.

Note
Subtracting histograms will unset any ScaledBy attribute from prevous calls to scaleW or normalize.

Definition at line 343 of file Histo1D.h.

References YODA::AnalysisObject::hasAnnotation(), and YODA::AnalysisObject::rmAnnotation().

343  {
344  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
345  _axis -= toSubtract._axis;
346  return *this;
347  }
void rmAnnotation(const std::string &name)
Delete an annotation by name.
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.
Histo1D& YODA::Histo1D::operator= ( const Histo1D h1)
inline

Assignment operator.

Definition at line 100 of file Histo1D.h.

References YODA::AnalysisObject::operator=().

100  {
101  AnalysisObject::operator = (h1); //< AO treatment of paths etc.
102  _axis = h1._axis;
103  return *this;
104  }
virtual AnalysisObject & operator=(const AnalysisObject &ao)
Default copy assignment operator.
Dbn1D& YODA::Histo1D::overflow ( )
inline

Access overflow (non-const version)

Definition at line 219 of file Histo1D.h.

Referenced by YODA::toIntegralEfficiencyHisto(), YODA::toTH1D(), and YODA::WriterYODA::writeHisto1D().

219 { return _axis.overflow(); }
const Dbn1D& YODA::Histo1D::overflow ( ) const
inline

Access overflow (const version)

Definition at line 221 of file Histo1D.h.

221 { return _axis.overflow(); }
void YODA::Histo1D::rebin ( int  n)
inline

Merge every group of n bins, starting from the LHS.

Definition at line 163 of file Histo1D.h.

163  {
164  _axis.rebin(n);
165  }
virtual void YODA::Histo1D::reset ( )
inlinevirtual

Reset the histogram.

Keep the binning but set all bin contents and related quantities to zero

Implements YODA::AnalysisObject.

Definition at line 125 of file Histo1D.h.

125  {
126  _axis.reset();
127  }
void YODA::Histo1D::scaleW ( double  scalefactor)
inline

Rescale as if all fill weights had been different by factor scalefactor.

Definition at line 137 of file Histo1D.h.

References YODA::AnalysisObject::setAnnotation().

Referenced by normalize().

137  {
138  setAnnotation("ScaledBy", annotation<double>("ScaledBy", 1.0) * scalefactor);
139  _axis.scaleW(scalefactor);
140  }
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name.
double YODA::Histo1D::sumW ( bool  includeoverflows = true) const

Get sum of weights in histo.

Todo:
Improve/centralise this statistical aggregation by exposing the Dbn1D/2D objects in the bins and using their native += operators to do the aggregation.

Definition at line 50 of file Histo1D.cc.

References YODA::Bin1D< DBN >::sumW().

Referenced by integral().

50  {
51  if (includeoverflows) return _axis.totalDbn().sumW();
52  double sumw = 0;
53  BOOST_FOREACH (const Bin& b, bins()) {
54  sumw += b.sumW();
55  }
56  return sumw;
57  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:186
HistoBin1D Bin
Definition: Histo1D.h:33
double YODA::Histo1D::sumW2 ( bool  includeoverflows = true) const

Get sum of squared weights in histo.

Definition at line 60 of file Histo1D.cc.

References YODA::Bin1D< DBN >::sumW2().

60  {
61  if (includeoverflows) return _axis.totalDbn().sumW2();
62  double sumw2 = 0;
63  BOOST_FOREACH (const Bin& b, bins()) {
64  sumw2 += b.sumW2();
65  }
66  return sumw2;
67  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:186
HistoBin1D Bin
Definition: Histo1D.h:33
Dbn1D& YODA::Histo1D::totalDbn ( )
inline

Access summary distribution, including gaps and overflows (non-const version)

Definition at line 207 of file Histo1D.h.

Referenced by effNumEntries(), numEntries(), and YODA::WriterYODA::writeHisto1D().

207 { return _axis.totalDbn(); }
const Dbn1D& YODA::Histo1D::totalDbn ( ) const
inline

Access summary distribution, including gaps and overflows (const version)

Definition at line 209 of file Histo1D.h.

209 { return _axis.totalDbn(); }
Dbn1D& YODA::Histo1D::underflow ( )
inline

Access underflow (non-const version)

Definition at line 213 of file Histo1D.h.

Referenced by integral(), YODA::toIntegralHisto(), YODA::toTH1D(), and YODA::WriterYODA::writeHisto1D().

213 { return _axis.underflow(); }
const Dbn1D& YODA::Histo1D::underflow ( ) const
inline

Access underflow (const version)

Definition at line 215 of file Histo1D.h.

215 { return _axis.underflow(); }
double YODA::Histo1D::xMax ( ) const
inline

High edge of this histo's axis.

Definition at line 182 of file Histo1D.h.

182 { return _axis.xMax(); }
double YODA::Histo1D::xMean ( bool  includeoverflows = true) const

Get the mean.

Definition at line 70 of file Histo1D.cc.

References YODA::Bin1D< DBN >::sumW(), and YODA::Bin1D< DBN >::sumWX().

Referenced by YODA::WriterYODA::writeHisto1D().

70  {
71  if (includeoverflows) return _axis.totalDbn().xMean();
72  double sumwx = 0;
73  double sumw = 0;
74  BOOST_FOREACH (const Bin& b, bins()) {
75  sumwx += b.sumWX();
76  sumw += b.sumW();
77  }
78  if ( sumw == 0 ) {
79  throw LowStatsError("Requested mean of a Histo1D with no net fill weights");
80  }
81  return sumwx/sumw;
82  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:186
HistoBin1D Bin
Definition: Histo1D.h:33
double YODA::Histo1D::xMin ( ) const
inline

Low edge of this histo's axis.

Definition at line 179 of file Histo1D.h.

179 { return _axis.xMin(); }
double YODA::Histo1D::xStdDev ( bool  includeoverflows = true) const
inline

Get the standard deviation.

Definition at line 296 of file Histo1D.h.

References xVariance().

296  {
297  if (includeoverflows) return _axis.totalDbn().xStdDev();
298  return std::sqrt(xVariance(includeoverflows));
299  }
double xVariance(bool includeoverflows=true) const
Get the variance.
Definition: Histo1D.cc:85
double YODA::Histo1D::xStdErr ( bool  includeoverflows = true) const

Get the standard error.

Definition at line 97 of file Histo1D.cc.

97  {
98  if (includeoverflows) return _axis.totalDbn().xStdErr();
99  const double effNumEntries = sumW(false)*sumW(false)/sumW2(false);
100  return std::sqrt(xVariance(false) / effNumEntries);
101  }
double effNumEntries() const
Definition: Histo1D.h:281
double xVariance(bool includeoverflows=true) const
Get the variance.
Definition: Histo1D.cc:85
double sumW2(bool includeoverflows=true) const
Get sum of squared weights in histo.
Definition: Histo1D.cc:60
double sumW(bool includeoverflows=true) const
Get sum of weights in histo.
Definition: Histo1D.cc:50
double YODA::Histo1D::xVariance ( bool  includeoverflows = true) const

Get the variance.

Definition at line 85 of file Histo1D.cc.

References YODA::mean(), YODA::Bin1D< DBN >::sumW(), and YODA::Bin1D< DBN >::xFocus().

Referenced by xStdDev().

85  {
86  if (includeoverflows) return _axis.totalDbn().xVariance();
87  double sigma2 = 0;
88  const double mean = this->xMean();
89  BOOST_FOREACH (const HistoBin1D& b, bins()) {
90  const double diff = b.xFocus() - mean;
91  sigma2 += diff * diff * b.sumW();
92  }
93  return sigma2/sumW();
94  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:186
double xMean(bool includeoverflows=true) const
Get the mean.
Definition: Histo1D.cc:70
double sumW(bool includeoverflows=true) const
Get sum of weights in histo.
Definition: Histo1D.cc:50
double mean(const std::vector< int > &sample)
Calculate the mean of a sample.
Definition: MathUtils.h:312

The documentation for this class was generated from the following files: