Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ErrorOfSigma.cc
Go to the documentation of this file.
1 #include "marlin/MarlinConfig.h" // defines MARLIN_CLHEP / MARLIN_AIDA
2 
3 #include "marlin/ErrorOfSigma.h"
4 
5 #include <iostream>
6 #include <cmath>
7 
8 namespace marlin{
9 
10  ErrorOfSigma::ErrorOfSigma( unsigned n ) :
11  _n( n ) {
12 
13  if( n < 30 ) { // FIXME - implement proper errors for small n
14 
15  std::cout << "ErrorOfSigma::ErrorOfSigma: errors will be inaccurate for n = " << n
16  << " - should be > 30 "
17  << std::endl ;
18  }
19 
20 
21 
22  }
23 
24  double ErrorOfSigma::lowerError( double sigma ) {
25 
26  return ( 1. - std::sqrt( _n - 1.0 ) / std::sqrt( getChiSquaredPlus() ) ) * sigma ;
27 
28  }
29 
30  double ErrorOfSigma::upperError( double sigma ) {
31 
32  return ( std::sqrt( _n - 1.0 ) / std::sqrt( getChiSquaredMinus() ) - 1. ) * sigma ;
33 
34  }
35 
36 
38 
39  // FIXME: only for n>30 ...
40  double t = 2./ ( 9. * _n ) ;
41  double chiPlus = _n * std::pow( ( 1. - t + std::sqrt( t) ) , 3. ) ;
42 
43 // std::cout << " getChiSquaredPlus( " << _n << ") :" << chiPlus << std::endl ;
44 
45 #ifdef MARLIN_CLHEP // only if CLHEP is available !
46  // here we can use CLHEP::CumulativeChiSquared to compute
47  // the exact chiPlus
48 #endif
49 
50 
51 
52  return chiPlus ;
53 
54  }
55 
57 
58 
59  // FIXME: only for n>30 ...
60  double t = 2./ ( 9. * _n ) ;
61  double chiMinus = _n * std::pow( ( 1. - t - std::sqrt( t) ) , 3. ) ;
62 
63 // std::cout << " getChiSquaredMinus( " << _n << ") :" << chiMinus << std::endl ;
64 
65 #ifdef MARLIN_CLHEP
66 
67  // here we can use CLHEP::CumulativeChiSquared to compute
68  // the exact chiMinus
69 #endif
70 
71  return chiMinus ;
72 
73  }
74 
75 }
76 
double upperError(double sigma)
The upper error of sigma.
Definition: ErrorOfSigma.cc:30
T endl(T...args)
virtual double getChiSquaredPlus()
Returns the chisquared value with P(chisquared) == 0.84.
Definition: ErrorOfSigma.cc:37
double lowerError(double sigma)
The lower error of sigma.
Definition: ErrorOfSigma.cc:24
unsigned _n
The number of degrees of freedom.
Definition: ErrorOfSigma.h:43
T pow(T...args)
T sqrt(T...args)
virtual double getChiSquaredMinus()
Returns the chisquared value with P(chisquared) == 0.16.
Definition: ErrorOfSigma.cc:56
ErrorOfSigma(unsigned n)
C&#39;tor takes the number of measured values.
Definition: ErrorOfSigma.cc:10