Public Member Functions | Private Attributes | List of all members
WireCell::Quantity Class Reference

#include <Quantity.h>

Public Member Functions

 Quantity ()
 
 Quantity (const double &mean, const double &sigma)
 
 Quantity (const double &mean)
 
 Quantity (const int &imean)
 
 Quantity (const Quantity &other)
 
 ~Quantity ()
 
Quantityoperator= (const Quantity &other)
 
 operator double () const
 
double mean () const
 
double sigma () const
 
Quantityoperator+= (const double &exact)
 
Quantityoperator-= (const double &exact)
 
Quantityoperator*= (const double &exact)
 
Quantityoperator/= (const double &exact)
 
Quantityoperator*= (const Quantity &other)
 
Quantityoperator/= (const Quantity &other)
 
Quantityoperator-= (const Quantity &other)
 
Quantityoperator+= (const Quantity &other)
 
bool operator< (const Quantity &other) const
 
bool operator> (const Quantity &other) const
 
bool operator== (const Quantity &other) const
 
bool operator!= (const Quantity &other) const
 

Private Attributes

double m_mean
 
double m_sigma
 

Detailed Description

Provide a quantity with a value and an uncertainty and all the little math operators.

Beware this assumes all quantities are uncorrelated!

Definition at line 16 of file Quantity.h.

Constructor & Destructor Documentation

WireCell::Quantity::Quantity ( )
inline

Definition at line 18 of file Quantity.h.

19  : m_mean(0.0), m_sigma(0.0)
20  { }
WireCell::Quantity::Quantity ( const double &  mean,
const double &  sigma 
)
inline

Definition at line 21 of file Quantity.h.

23  { }
double mean() const
Definition: Quantity.h:47
double sigma() const
Definition: Quantity.h:48
WireCell::Quantity::Quantity ( const double &  mean)
inline

Definition at line 24 of file Quantity.h.

25  : m_mean(mean), m_sigma(0.0)
26  { }
double mean() const
Definition: Quantity.h:47
WireCell::Quantity::Quantity ( const int &  imean)
inline

Definition at line 27 of file Quantity.h.

28  : m_mean((double)imean), m_sigma(0.0)
29  { }
WireCell::Quantity::Quantity ( const Quantity other)
inline

Definition at line 30 of file Quantity.h.

31  : m_mean(other.m_mean), m_sigma(other.m_sigma)
32  { }
WireCell::Quantity::~Quantity ( )
inline

Definition at line 35 of file Quantity.h.

35 {}

Member Function Documentation

double WireCell::Quantity::mean ( ) const
inline

Definition at line 47 of file Quantity.h.

47 { return m_mean; }
WireCell::Quantity::operator double ( ) const
inline

Definition at line 45 of file Quantity.h.

45 { return m_mean; }
bool WireCell::Quantity::operator!= ( const Quantity other) const
inline

Definition at line 121 of file Quantity.h.

121  {
122  return m_mean != other.m_mean;
123  }
Quantity& WireCell::Quantity::operator*= ( const double &  exact)
inline

Definition at line 63 of file Quantity.h.

64  {
65  m_mean *= exact;
66  m_sigma *= exact;
67  return *this;
68  }
Quantity& WireCell::Quantity::operator*= ( const Quantity other)
inline

Definition at line 78 of file Quantity.h.

78  {
79  // relative uncertainties
80  const double mrs = m_sigma/m_mean;
81  const double ors = other.m_sigma/other.m_mean;
82 
83  m_mean *= other.m_mean;
84  m_sigma = m_mean * std::hypot(mrs, ors);
85 
86  return *this;
87  }
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
Definition: hypot.h:60
Quantity& WireCell::Quantity::operator+= ( const double &  exact)
inline

Definition at line 51 of file Quantity.h.

52  {
53  m_mean += exact;
54  return *this;
55  }
Quantity& WireCell::Quantity::operator+= ( const Quantity other)
inline

Definition at line 105 of file Quantity.h.

105  {
106  m_mean += other.m_mean;
107  m_sigma = std::hypot(m_sigma, other.m_sigma);
108  return *this;
109  }
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
Definition: hypot.h:60
Quantity& WireCell::Quantity::operator-= ( const double &  exact)
inline

Definition at line 57 of file Quantity.h.

58  {
59  m_mean -= exact;
60  return *this;
61  }
Quantity& WireCell::Quantity::operator-= ( const Quantity other)
inline

Definition at line 100 of file Quantity.h.

100  {
101  m_mean -= other.m_mean;
102  m_sigma = std::hypot(m_sigma, other.m_sigma);
103  return *this;
104  }
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
Definition: hypot.h:60
Quantity& WireCell::Quantity::operator/= ( const double &  exact)
inline

Definition at line 70 of file Quantity.h.

71  {
72  m_mean /= exact;
73  m_sigma /= exact;
74  return *this;
75  }
Quantity& WireCell::Quantity::operator/= ( const Quantity other)
inline

Definition at line 89 of file Quantity.h.

89  {
90  // relative uncertainties
91  const double mrs = m_sigma/m_mean;
92  const double ors = other.m_sigma/other.m_mean;
93 
94  m_mean /= other.m_mean;
95  m_sigma = m_mean * std::hypot(mrs, ors);
96 
97  return *this;
98  }
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
Definition: hypot.h:60
bool WireCell::Quantity::operator< ( const Quantity other) const
inline

Definition at line 112 of file Quantity.h.

112  {
113  return m_mean < other.m_mean;
114  }
Quantity& WireCell::Quantity::operator= ( const Quantity other)
inline

Definition at line 37 of file Quantity.h.

38  {
39  if (this == &other) return *this;
40  m_mean = other.m_mean;
41  m_sigma = other.m_sigma;
42  return *this;
43  }
bool WireCell::Quantity::operator== ( const Quantity other) const
inline

Definition at line 118 of file Quantity.h.

118  {
119  return m_mean == other.m_mean;
120  }
bool WireCell::Quantity::operator> ( const Quantity other) const
inline

Definition at line 115 of file Quantity.h.

115  {
116  return m_mean > other.m_mean;
117  }
double WireCell::Quantity::sigma ( ) const
inline

Definition at line 48 of file Quantity.h.

48 { return m_sigma; }

Member Data Documentation

double WireCell::Quantity::m_mean
private

Definition at line 127 of file Quantity.h.

double WireCell::Quantity::m_sigma
private

Definition at line 127 of file Quantity.h.


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