CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes | Friends
hitfit::Resolution Class Reference

#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 (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...
 
 Resolution (std::string s="")
 Constructor, initialize from a string. 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

@class Resolution

@brief 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 \f$p\f$, we calculate the uncertainty
in quantity \f$x\f$ as:

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

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

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

\verbatim

[-]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 98 of file Resolution.h.

Constructor & Destructor Documentation

◆ Resolution() [1/3]

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 82 of file Resolution.cc.

91  _inverse = false;
92  _constant_sigma = 0;
94  _noise_sigma = 0;
95 
96  // Skip spaces.
97  double x;
98  string::size_type i = 0;
99  while (i < s.size() && isspace(s[i]))
100  ++i;
101 
102  // Check for the inverse flag.
103  if (s[i] == '-') {
104  _inverse = true;
105  ++i;
106  } else if (s[i] == '+') {
107  ++i;
108  }
109 
110  // Get the constant term.
111  if (get_field(s, i, x))
112  _constant_sigma = x;
113  i = s.find(',', i);
114 
115  // Look for a resolution term.
116  if (i != string::npos) {
117  ++i;
118  if (get_field(s, i, x))
120 
121  // Look for a noise term.
122  i = s.find(',', i);
123  if (i != string::npos) {
124  if (get_field(s, i + 1, x))
125  _noise_sigma = x;
126  }
127  }
128  }

References _constant_sigma, _inverse, _noise_sigma, _resolution_sigma, mps_fire::i, and alignCSCRings::s.

◆ Resolution() [2/3]

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 130 of file Resolution.cc.

◆ Resolution() [3/3]

hitfit::Resolution::Resolution ( double  res,
bool  inverse = false 
)

Constructor to initialize a constant resolution.

Parameters
resThe resolution value.
inverseThe inverse flag.

Definition at line 133 of file Resolution.cc.

Member Function Documentation

◆ C()

double hitfit::Resolution::C ( ) const

Return the C term (constant term)

Definition at line 155 of file Resolution.cc.

155 { return _constant_sigma; }

References _constant_sigma.

◆ inverse()

bool hitfit::Resolution::inverse ( ) const

Return the setting of the inverse flag.

Definition at line 144 of file Resolution.cc.

151  {
152  return _inverse;
153  }

References _inverse.

◆ m()

double hitfit::Resolution::m ( ) const

Return the exponent factor in the resolution term.

Definition at line 159 of file Resolution.cc.

159 { return _resolution_exponent; }

References _resolution_exponent.

◆ N()

double hitfit::Resolution::N ( ) const

Return the N term (noise term)

Definition at line 161 of file Resolution.cc.

161 { return _noise_sigma; }

References _noise_sigma.

◆ pick()

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 181 of file Resolution.cc.

195  {
196  CLHEP::RandGauss gen(engine);
197  if (_inverse)
198  return 1 / gen.fire(1 / x, sigma(p));
199  else
200  return gen.fire(x, sigma(p));
201  }

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

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

◆ R()

double hitfit::Resolution::R ( ) const

Return the R term (resolution term)

Definition at line 157 of file Resolution.cc.

157 { return _resolution_sigma; }

References _resolution_sigma.

◆ sigma()

double hitfit::Resolution::sigma ( double  p) const

Return the uncertainty for a variable with magnitude p.

Parameters
pThe momentum.

Definition at line 163 of file Resolution.cc.

173  {
174  if (_inverse)
175  p = 1 / p;
176 
179  }

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

Friends And Related Function Documentation

◆ operator<<

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 211 of file Resolution.cc.

222  {
223  if (r._inverse)
224  s << "-";
225  s << r._constant_sigma << "," << r._resolution_sigma << "," << r._noise_sigma;
226  return s;
227  }

Member Data Documentation

◆ _constant_sigma

double hitfit::Resolution::_constant_sigma
private

The constant term.

Definition at line 202 of file Resolution.h.

Referenced by C(), and Resolution().

◆ _inverse

bool hitfit::Resolution::_inverse
private

The inverse flag.

Definition at line 222 of file Resolution.h.

Referenced by inverse(), and Resolution().

◆ _noise_sigma

double hitfit::Resolution::_noise_sigma
private

The noise term.

Definition at line 217 of file Resolution.h.

Referenced by N(), and Resolution().

◆ _resolution_exponent

double hitfit::Resolution::_resolution_exponent
private

The m exponential factor in the resolution term.

Definition at line 212 of file Resolution.h.

Referenced by m().

◆ _resolution_sigma

double hitfit::Resolution::_resolution_sigma
private

The resolution term.

Definition at line 207 of file Resolution.h.

Referenced by R(), and Resolution().

mps_fire.i
i
Definition: mps_fire.py:428
hitfit::Resolution::_noise_sigma
double _noise_sigma
Definition: Resolution.h:217
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
hitfit::Resolution::R
double R() const
Return the R term (resolution term)
Definition: Resolution.cc:157
DDAxes::x
hitfit::Resolution::N
double N() const
Return the N term (noise term)
Definition: Resolution.cc:161
hitfit::Resolution::_inverse
bool _inverse
Definition: Resolution.h:222
alignCSCRings.s
s
Definition: alignCSCRings.py:92
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
hitfit::Resolution::C
double C() const
Return the C term (constant term)
Definition: Resolution.cc:155
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
hitfit::Resolution::_resolution_sigma
double _resolution_sigma
Definition: Resolution.h:207
gen
Definition: PythiaDecays.h:13
hitfit::Resolution::inverse
bool inverse() const
Return the setting of the inverse flag.
Definition: Resolution.cc:144
res
Definition: Electron.h:6
alignCSCRings.r
r
Definition: alignCSCRings.py:93
hitfit::Resolution::_constant_sigma
double _constant_sigma
Definition: Resolution.h:202
hitfit::Resolution::_resolution_exponent
double _resolution_exponent
Definition: Resolution.h:212
relval_steps.gen
def gen(fragment, howMuch)
Production test section ####.
Definition: relval_steps.py:509
hitfit::Resolution::m
double m() const
Return the exponent factor in the resolution term.
Definition: Resolution.cc:159
hitfit::Resolution::sigma
double sigma(double p) const
Return the uncertainty for a variable with magnitude p.
Definition: Resolution.cc:163