Calculate and represent resolution for a physical quantity. More...
#include <Resolution.h>
Public Member Functions | |
double | C () const |
Return the C term (constant term) | |
bool | inverse () const |
Return the setting of the inverse flag. | |
double | m () const |
Return the exponent factor in the resolution term. | |
double | N () const |
Return the N term (noise term) | |
double | pick (double x, double p, CLHEP::HepRandomEngine &engine) const |
Generate random value from a Gaussian distribution described by this resolution. Given a value , measured for an object with momentum , pick a new value from a Gaussian distribution described by this resolution: with mean and width . | |
double | R () const |
Return the R term (resolution term) | |
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. | |
Resolution (std::string s="") | |
Constructor, initialize from a string. | |
Resolution (double res, bool inverse=false) | |
Constructor to initialize a constant resolution. | |
double | sigma (double p) const |
Return the uncertainty for a variable with magnitude p. | |
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. |
Calculate and represent resolution for a physical quantity.
This class calculate resolutions for some quantity. In general we have three parameters:
Given a physical quantitiy , we calculate the uncertainty in quantity as:
In addition, we also have an inverse flag. If the flag is set, we take the inverse of before doing the calculations. Therefore is regarded as actually .
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.
hitfit::Resolution::Resolution | ( | std::string | s = "" | ) |
Constructor, initialize from a string.
s | A 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.
:_resolution_exponent(0) { _inverse = false; _constant_sigma = 0; _resolution_sigma = 0; _noise_sigma = 0; // Skip spaces. double x; string::size_type i = 0; while (i < s.size() && isspace (s[i])) ++i; // Check for the inverse flag. if (s[i] == '-') { _inverse = true; ++i; } else if (s[i] == '+') { ++i; } // Get the constant term. if (get_field (s, i, x)) _constant_sigma = x; i = s.find (',', i); // Look for a resolution term. if (i != string::npos) { ++i; if (get_field (s, i, x)) _resolution_sigma = x; // Look for a noise term. i = s.find (',', i); if (i != string::npos) { if (get_field (s, i+1, x)) _noise_sigma = x; } } }
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.
C | The constant term |
R | The resolution term |
m | The exponent factor term |
N | The noise term |
inverse | The inverse flag. |
Definition at line 139 of file Resolution.cc.
: _constant_sigma (C), _resolution_sigma (R), _resolution_exponent(m), _noise_sigma (N), _inverse (inverse) { }
hitfit::Resolution::Resolution | ( | double | res, |
bool | inverse = false |
||
) |
Constructor to initialize a constant resolution.
res | The resolution value. |
inverse | The inverse flag. |
Definition at line 153 of file Resolution.cc.
: _constant_sigma (0), _resolution_sigma (0), _resolution_exponent(0), _noise_sigma (res), _inverse (inverse) { }
double hitfit::Resolution::C | ( | ) | const |
Return the C term (constant term)
Definition at line 184 of file Resolution.cc.
References _constant_sigma.
{ return _constant_sigma; }
bool hitfit::Resolution::inverse | ( | ) | const |
Return the setting of the inverse flag.
Definition at line 172 of file Resolution.cc.
References _inverse.
{ return _inverse; }
double hitfit::Resolution::m | ( | ) | const |
Return the exponent factor in the resolution term.
Definition at line 196 of file Resolution.cc.
References _resolution_exponent.
{ return _resolution_exponent; }
double hitfit::Resolution::N | ( | ) | const |
Return the N term (noise term)
Definition at line 202 of file Resolution.cc.
References _noise_sigma.
{ return _noise_sigma; }
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 , measured for an object with momentum , pick a new value from a Gaussian distribution described by this resolution: with mean and width .
x | The quantity value (distributed mean). |
p | The momentum, for calculating the width. |
engine | The underlying random number generator. |
Definition at line 228 of file Resolution.cc.
References cmsDownloadME::gen, and AlCaHLTBitMon_ParallelJobs::p.
Referenced by hitfit::Lepjets_Event::smear().
double hitfit::Resolution::R | ( | ) | const |
Return the R term (resolution term)
Definition at line 190 of file Resolution.cc.
References _resolution_sigma.
{ return _resolution_sigma; }
double hitfit::Resolution::sigma | ( | double | p | ) | const |
Return the uncertainty for a variable with magnitude p.
p | The momentum. |
Definition at line 208 of file Resolution.cc.
References AlCaHLTBitMon_ParallelJobs::p, and mathSSE::sqrt().
{ if (_inverse) p = 1 / p; return sqrt ((_constant_sigma*_constant_sigma*p + _resolution_sigma*_resolution_sigma)*p + _noise_sigma*_noise_sigma); }
std::ostream& operator<< | ( | std::ostream & | s, |
const Resolution & | r | ||
) | [friend] |
Output stream operator, print the content of this Resolution to an output stream.
s | The stream to which to write. |
r | The instance of Resolution to be printed. |
Definition at line 259 of file Resolution.cc.
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().