CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes | Friends
hitfit::Resolution Class Reference

Calculate and represent resolution for a physical quantity. More...

#include <Resolution.h>

Public Member Functions

double C () const
 Return the C term (constant term) More...
 
bool inverse () const
 Return the setting of the inverse flag. More...
 
double m () const
 Return the exponent factor in the resolution term. More...
 
double N () const
 Return the N term (noise term) More...
 
double pick (double x, double p, CLHEP::HepRandomEngine &engine) const
 Generate random value from a Gaussian distribution described by this resolution. Given a value $x$, measured for an object with momentum $p$, pick a new value from a Gaussian distribution described by this resolution: with mean $x$ and width $\sigma(p)$. More...
 
double R () const
 Return the R term (resolution term) More...
 
 Resolution (std::string s="")
 Constructor, initialize from a string. More...
 
 Resolution (double C, double R, double m, double N, bool inverse=false)
 Constructor to initialize with four values for C, R, m, N, and the boolean for inverse. More...
 
 Resolution (double res, bool inverse=false)
 Constructor to initialize a constant resolution. More...
 
double sigma (double p) const
 Return the uncertainty for a variable with magnitude p. More...
 

Private Attributes

double _constant_sigma
 
bool _inverse
 
double _noise_sigma
 
double _resolution_exponent
 
double _resolution_sigma
 

Friends

std::ostream & operator<< (std::ostream &s, const Resolution &r)
 Output stream operator, print the content of this Resolution to an output stream. More...
 

Detailed Description

Calculate and represent resolution for a physical quantity.

This class calculate resolutions for some quantity.  In general we have
three parameters:
- <b>C</b> constant term.
- <b>R</b> resolution term.
- <b>N</b> noise term.

Given a physical quantitiy \form#30, we calculate the uncertainty
in quantity \form#33 as:

\[ \sigma(x) = \sqrt{C^{2}p^{2} + R^{2}p + N^{2}} \]

In addition, we also have an inverse flag. If the flag is set, we take the inverse of $p$ before doing the calculations. Therefore $\sigma(x)$ is regarded as actually $\sigma(1/x)$.

We encode he resolution parameters into a string, from which these objects get initialized. The format is

[-]C[,R[,N]]

where parameters within the brackets are optional. If the leading minus is present, the inverse flag is turned on. Omitted parameters are set to 0.

Definition at line 103 of file Resolution.h.

Constructor & Destructor Documentation

hitfit::Resolution::Resolution ( std::string  s = "")

Constructor, initialize from a string.

Parameters
sA string encoding the resolution parameters, as described in the class description.

Definition at line 91 of file Resolution.cc.

References _constant_sigma, _inverse, _noise_sigma, _resolution_sigma, i, and x.

100 {
101  _inverse = false;
102  _constant_sigma = 0;
103  _resolution_sigma = 0;
104  _noise_sigma = 0;
105 
106  // Skip spaces.
107  double x;
108  string::size_type i = 0;
109  while (i < s.size() && isspace (s[i]))
110  ++i;
111 
112  // Check for the inverse flag.
113  if (s[i] == '-') {
114  _inverse = true;
115  ++i;
116  }
117  else if (s[i] == '+') {
118  ++i;
119  }
120 
121  // Get the constant term.
122  if (get_field (s, i, x)) _constant_sigma = x;
123  i = s.find (',', i);
124 
125  // Look for a resolution term.
126  if (i != string::npos) {
127  ++i;
128  if (get_field (s, i, x)) _resolution_sigma = x;
129 
130  // Look for a noise term.
131  i = s.find (',', i);
132  if (i != string::npos) {
133  if (get_field (s, i+1, x)) _noise_sigma = x;
134  }
135  }
136 }
int i
Definition: DBlmapReader.cc:9
uint16_t size_type
double _resolution_exponent
Definition: Resolution.h:222
double _resolution_sigma
Definition: Resolution.h:217
Definition: DDAxes.h:10
double _constant_sigma
Definition: Resolution.h:212
hitfit::Resolution::Resolution ( double  C,
double  R,
double  m,
double  N,
bool  inverse = false 
)

Constructor to initialize with four values for C, R, m, N, and the boolean for inverse.

Parameters
CThe constant term
RThe resolution term
mThe exponent factor term
NThe noise term
inverseThe inverse flag.

Definition at line 139 of file Resolution.cc.

144  : _constant_sigma (C),
147  _noise_sigma (N),
148  _inverse (inverse)
149 {
150 }
double R() const
Return the R term (resolution term)
Definition: Resolution.cc:190
double m() const
Return the exponent factor in the resolution term.
Definition: Resolution.cc:196
bool inverse() const
Return the setting of the inverse flag.
Definition: Resolution.cc:172
double _resolution_exponent
Definition: Resolution.h:222
double _resolution_sigma
Definition: Resolution.h:217
double N() const
Return the N term (noise term)
Definition: Resolution.cc:202
double C() const
Return the C term (constant term)
Definition: Resolution.cc:184
double _constant_sigma
Definition: Resolution.h:212
hitfit::Resolution::Resolution ( double  res,
bool  inverse = false 
)

Constructor to initialize a constant resolution.

Parameters
resThe resolution value.
inverseThe inverse flag.

Definition at line 153 of file Resolution.cc.

163  : _constant_sigma (0),
164  _resolution_sigma (0),
166  _noise_sigma (res),
167  _inverse (inverse)
168 {
169 }
bool inverse() const
Return the setting of the inverse flag.
Definition: Resolution.cc:172
double _resolution_exponent
Definition: Resolution.h:222
double _resolution_sigma
Definition: Resolution.h:217
double _constant_sigma
Definition: Resolution.h:212

Member Function Documentation

double hitfit::Resolution::C ( ) const

Return the C term (constant term)

Definition at line 184 of file Resolution.cc.

References _constant_sigma.

185 {
186  return _constant_sigma;
187 }
double _constant_sigma
Definition: Resolution.h:212
bool hitfit::Resolution::inverse ( ) const

Return the setting of the inverse flag.

Definition at line 172 of file Resolution.cc.

References _inverse.

179 {
180  return _inverse;
181 }
double hitfit::Resolution::m ( ) const

Return the exponent factor in the resolution term.

Definition at line 196 of file Resolution.cc.

References _resolution_exponent.

197 {
198  return _resolution_exponent;
199 }
double _resolution_exponent
Definition: Resolution.h:222
double hitfit::Resolution::N ( ) const

Return the N term (noise term)

Definition at line 202 of file Resolution.cc.

References _noise_sigma.

203 {
204  return _noise_sigma;
205 }
double hitfit::Resolution::pick ( double  x,
double  p,
CLHEP::HepRandomEngine &  engine 
) const

Generate random value from a Gaussian distribution described by this resolution. Given a value $x$, measured for an object with momentum $p$, pick a new value from a Gaussian distribution described by this resolution: with mean $x$ and width $\sigma(p)$.

Parameters
xThe quantity value (distributed mean).
pThe momentum, for calculating the width.
engineThe underlying random number generator.

Definition at line 228 of file Resolution.cc.

References relval_steps::gen(), and AlCaHLTBitMon_ParallelJobs::p.

Referenced by hitfit::Lepjets_Event::smear().

242 {
243  CLHEP::RandGauss gen (engine);
244  if (_inverse)
245  return 1 / gen.fire (1 / x, sigma (p));
246  else
247  return gen.fire (x, sigma (p));
248 }
double sigma(double p) const
Return the uncertainty for a variable with magnitude p.
Definition: Resolution.cc:208
Definition: DDAxes.h:10
double hitfit::Resolution::R ( ) const

Return the R term (resolution term)

Definition at line 190 of file Resolution.cc.

References _resolution_sigma.

191 {
192  return _resolution_sigma;
193 }
double _resolution_sigma
Definition: Resolution.h:217
double hitfit::Resolution::sigma ( double  p) const

Return the uncertainty for a variable with magnitude p.

Parameters
pThe momentum.

Definition at line 208 of file Resolution.cc.

References AlCaHLTBitMon_ParallelJobs::p, and mathSSE::sqrt().

218 {
219  if (_inverse)
220  p = 1 / p;
221 
225 }
T sqrt(T t)
Definition: SSEVec.h:48
double _resolution_sigma
Definition: Resolution.h:217
double _constant_sigma
Definition: Resolution.h:212

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  s,
const Resolution r 
)
friend

Output stream operator, print the content of this Resolution to an output stream.

Parameters
sThe stream to which to write.
rThe instance of Resolution to be printed.

Definition at line 259 of file Resolution.cc.

270 {
271  if (r._inverse) s << "-";
272  s << r._constant_sigma << ","
273  << r._resolution_sigma << ","
274  << r._noise_sigma;
275  return s;
276 }

Member Data Documentation

double hitfit::Resolution::_constant_sigma
private

The constant term.

Definition at line 212 of file Resolution.h.

Referenced by C(), hitfit::operator<<(), and Resolution().

bool hitfit::Resolution::_inverse
private

The inverse flag.

Definition at line 232 of file Resolution.h.

Referenced by inverse(), hitfit::operator<<(), and Resolution().

double hitfit::Resolution::_noise_sigma
private

The noise term.

Definition at line 227 of file Resolution.h.

Referenced by N(), hitfit::operator<<(), and Resolution().

double hitfit::Resolution::_resolution_exponent
private

The m exponential factor in the resolution term.

Definition at line 222 of file Resolution.h.

Referenced by m().

double hitfit::Resolution::_resolution_sigma
private

The resolution term.

Definition at line 217 of file Resolution.h.

Referenced by hitfit::operator<<(), R(), and Resolution().