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

A weighted counter. More...

#include <Counter.h>

Inheritance diagram for YODA::Counter:
YODA::AnalysisObject

Public Member Functions

Constructors
 Counter (const std::string &path="", const std::string &title="")
 Default constructor. More...
 
 Counter (const Dbn0D &dbn, const std::string &path="", const std::string &title="")
 Constructor accepting an explicit Dbn0D. More...
 
 Counter (double w, const std::string &path="", const std::string &title="")
 Constructor accepting a double (treated as the weight of a single fill). More...
 
 Counter (const Counter &c, const std::string &path="")
 Copy constructor with optional new path. More...
 
Counteroperator= (const Counter &c)
 Assignment operator. More...
 
Counter clone () const
 Make a copy on the stack. More...
 
Counternewclone () const
 Make a copy on the heap, via 'new'. More...
 
Modifiers
void fill (double weight=1.0)
 Fill histo by value and weight. More...
 
virtual void reset ()
 Reset the histogram. More...
 
void scaleW (double scalefactor)
 Rescale as if all fill weights had been different by factor scalefactor. More...
 
Data access
double numEntries () const
 Get the number of fills. More...
 
double effNumEntries () const
 Get the effective number of fills. More...
 
double sumW () const
 Get the sum of weights. More...
 
double sumW2 () const
 Get the sum of squared weights. More...
 
double val () const
 Get the value. More...
 
double err () const
 
double relErr () const
 
Adding and subtracting counters
Counteroperator+= (const Counter &toAdd)
 Add another counter to this. More...
 
Counteroperator-= (const Counter &toSubtract)
 Subtract another counter from this. More...
 
Counteroperator++ ()
 
Counteroperator-- ()
 
Counteroperator*= (double s)
 Scale by a double (syntactic sugar for scaleW(s)) More...
 
Counteroperator/= (double s)
 Inverse-scale by a double (syntactic sugar for scaleW(1/s)) 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...
 

Additional Inherited Members

- Public Types inherited from YODA::AnalysisObject
typedef std::map< std::string,
std::string > 
Annotations
 Collection type for annotations, as a string-string map. More...
 

Detailed Description

A weighted counter.

Definition at line 21 of file Counter.h.

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 28 of file Counter.h.

Referenced by clone(), and newclone().

29  : AnalysisObject("Counter", path, title)
30  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
YODA::Counter::Counter ( const Dbn0D dbn,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor accepting an explicit Dbn0D.

Intended both for internal persistency and user use.

Definition at line 36 of file Counter.h.

38  : AnalysisObject("Counter", path, title),
39  _dbn(dbn)
40  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
YODA::Counter::Counter ( double  w,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor accepting a double (treated as the weight of a single fill).

Intended for user convenience only, so Counter can be treated as a number.

Definition at line 46 of file Counter.h.

48  : AnalysisObject("Counter", path, title)
49  {
50  _dbn.fill(w);
51  }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
YODA::Counter::Counter ( const Counter c,
const std::string &  path = "" 
)

Copy constructor with optional new path.

Copy constructor with optional new path

Todo:
Don't copy the path?

Definition at line 16 of file Counter.cc.

17  : AnalysisObject("Counter", (path.size() == 0) ? c.path() : path, c, c.title())
18  {
19  _dbn = c._dbn;
20  }
AnalysisObject()
Default constructor.
const std::string path() const

Member Function Documentation

Counter YODA::Counter::clone ( ) const
inline

Make a copy on the stack.

Definition at line 68 of file Counter.h.

References Counter().

68  {
69  return Counter(*this);
70  }
Counter(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Counter.h:28
double YODA::Counter::effNumEntries ( ) const
inline

Get the effective number of fills.

Definition at line 115 of file Counter.h.

115 { return _dbn.effNumEntries(); }
double YODA::Counter::err ( ) const
inline

Get the uncertainty on the value

Todo:
Implement on Dbn0D and feed through to this and Dbn1D, 2D, etc.

Definition at line 129 of file Counter.h.

References sumW2().

Referenced by YODA::mkScatter(), relErr(), and YODA::WriterFLAT::writeCounter().

129 { return sqrt(sumW2()); }
double sumW2() const
Get the sum of squared weights.
Definition: Counter.h:121
void YODA::Counter::fill ( double  weight = 1.0)
inline

Fill histo by value and weight.

Definition at line 86 of file Counter.h.

86  {
87  _dbn.fill(weight);
88  }
Counter* YODA::Counter::newclone ( ) const
inlinevirtual

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

Implements YODA::AnalysisObject.

Definition at line 73 of file Counter.h.

References Counter().

73  {
74  return new Counter(*this);
75  }
Counter(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Counter.h:28
double YODA::Counter::numEntries ( ) const
inline

Get the number of fills.

Definition at line 112 of file Counter.h.

Referenced by YODA::efficiency(), and YODA::WriterYODA::writeCounter().

112 { return _dbn.numEntries(); }
Counter& YODA::Counter::operator*= ( double  s)
inline

Scale by a double (syntactic sugar for scaleW(s))

Definition at line 174 of file Counter.h.

References scaleW().

174  {
175  scaleW(s);
176  return *this;
177  }
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Counter.h:100
Counter& YODA::Counter::operator++ ( )
inline

Increment as if by a fill of weight = 1

Note
This is post-increment only, i.e. cn++ not ++cn

Definition at line 161 of file Counter.h.

161  {
162  *this += 1;
163  return *this;
164  }
Counter& YODA::Counter::operator+= ( const Counter toAdd)
inline

Add another counter to this.

Definition at line 148 of file Counter.h.

148  {
149  _dbn += toAdd._dbn;
150  return *this;
151  }
Counter& YODA::Counter::operator-- ( )
inline

Increment as if by a fill of weight = -1

Note
This is post-decrement only, i.e. cn– not –cn

Definition at line 168 of file Counter.h.

168  {
169  *this -= 1;
170  return *this;
171  }
Counter& YODA::Counter::operator-= ( const Counter toSubtract)
inline

Subtract another counter from this.

Definition at line 154 of file Counter.h.

154  {
155  _dbn -= toSubtract._dbn;
156  return *this;
157  }
Counter& YODA::Counter::operator/= ( double  s)
inline

Inverse-scale by a double (syntactic sugar for scaleW(1/s))

Definition at line 180 of file Counter.h.

References scaleW().

180  {
181  scaleW(1/s);
182  return *this;
183  }
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Counter.h:100
Counter& YODA::Counter::operator= ( const Counter c)
inline

Assignment operator.

Definition at line 60 of file Counter.h.

References YODA::AnalysisObject::path(), YODA::AnalysisObject::setPath(), YODA::AnalysisObject::setTitle(), and YODA::AnalysisObject::title().

60  {
61  setPath(c.path());
62  setTitle(c.title());
63  _dbn = c._dbn;
64  return *this;
65  }
void setPath(const std::string &path)
Set the AO path.
void setTitle(const std::string &title)
Set the AO title.
double YODA::Counter::relErr ( ) const
inline

Get the relative uncertainty on the value

Todo:
Implement on Dbn0D and feed through to this and Dbn1D, 2D, etc.
Todo:
Throw excp if sumW2 is 0?

Definition at line 134 of file Counter.h.

References err(), sumW(), and sumW2().

Referenced by YODA::divide().

134  {
136  return sumW2() != 0 ? err()/sumW() : 0;
137  }
double sumW2() const
Get the sum of squared weights.
Definition: Counter.h:121
double err() const
Definition: Counter.h:129
double sumW() const
Get the sum of weights.
Definition: Counter.h:118
virtual void YODA::Counter::reset ( )
inlinevirtual

Reset the histogram.

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

Implements YODA::AnalysisObject.

Definition at line 94 of file Counter.h.

94  {
95  _dbn.reset();
96  }
void YODA::Counter::scaleW ( double  scalefactor)
inline

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

Definition at line 100 of file Counter.h.

References YODA::AnalysisObject::setAnnotation().

Referenced by operator*=(), and operator/=().

100  {
101  setAnnotation("ScaledBy", annotation<double>("ScaledBy", 1.0) * scalefactor);
102  _dbn.scaleW(scalefactor);
103  }
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name.
double YODA::Counter::sumW ( ) const
inline

Get the sum of weights.

Definition at line 118 of file Counter.h.

Referenced by YODA::efficiency(), relErr(), val(), and YODA::WriterYODA::writeCounter().

118 { return _dbn.sumW(); }
double YODA::Counter::sumW2 ( ) const
inline

Get the sum of squared weights.

Definition at line 121 of file Counter.h.

Referenced by YODA::efficiency(), err(), relErr(), and YODA::WriterYODA::writeCounter().

121 { return _dbn.sumW2(); }
double YODA::Counter::val ( ) const
inline

Get the value.

Definition at line 124 of file Counter.h.

References sumW().

Referenced by YODA::divide(), YODA::mkScatter(), and YODA::WriterFLAT::writeCounter().

124 { return sumW(); }
double sumW() const
Get the sum of weights.
Definition: Counter.h:118

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