#include <ChisqConsistency.h>
Inheritance diagram for ChisqConsistency:
Public Types | |
OK = 0 | |
noMeasure | |
underFlow | |
unPhysical | |
left = -1 | |
unknown = 0 | |
right = 1 | |
enum | ConsistentStatus { OK = 0, noMeasure, underFlow, unPhysical } |
enum | ConsistentSign { left = -1, unknown = 0, right = 1 } |
Public Member Functions | |
ChisqConsistency () | |
ChisqConsistency (double chisq, double nDof) | |
ChisqConsistency (unsigned nDof, double consistency) | |
ChisqConsistency (const ChisqConsistency &) | |
ChisqConsistency & | operator= (const ChisqConsistency &) |
virtual | ~ChisqConsistency () |
const double & | chisqValue () const |
const double & | nDOF () const |
bool | operator== (const Consistency &rhs) const |
bool | operator< (const Consistency &rhs) const |
bool | operator> (const Consistency &rhs) const |
double | significanceLevel () const |
double | likelihood () const |
double | consistency () const |
ConsistentStatus | status () const |
void | setStatus (ConsistentStatus s) |
ConsistentSign | sign () const |
void | setSign (ConsistentSign s) |
virtual const ConsistencySet * | genealogy () const |
virtual void | print (std::ostream &) const |
Static Public Member Functions | |
static const Consistency & | badMeasurement () |
Protected Attributes | |
double | _chisq |
double | _nDof |
ConsistentStatus | _stat |
ConsistentSign | _sign |
double | _value |
double | _likelihood |
Definition at line 27 of file ChisqConsistency.h.
enum Consistency::ConsistentSign [inherited] |
enum Consistency::ConsistentStatus [inherited] |
ChisqConsistency::ChisqConsistency | ( | ) |
ChisqConsistency::ChisqConsistency | ( | double | chisq, | |
double | nDof | |||
) |
Definition at line 42 of file ChisqConsistency.cxx.
References _chisq, Consistency::_likelihood, _nDof, Consistency::_value, exp(), NumRecipes::gammln(), NumRecipes::gammq(), n2, Consistency::OK, Consistency::setStatus(), Consistency::underFlow, and Consistency::unPhysical.
00042 : 00043 _chisq(chisq), _nDof(nDof) 00044 { 00045 double z2 = 0.5*_chisq; 00046 double n2 = 0.5*_nDof; 00047 00048 if (n2<=0 || z2<0) { 00049 std::cout << "ErrMsg(warning)" << " Got unphysical values: chisq = " << chisq 00050 << " #dof = " << nDof << std::endl; 00051 _value=0; 00052 _likelihood=0; 00053 setStatus(Consistency::unPhysical); 00054 return; 00055 } 00056 setStatus(Consistency::OK); 00057 00058 // given that n2>0 && z2>=0, gammq will NOT abort 00059 _value = NumRecipes::gammq(n2,z2); 00060 00061 if (_chisq==0) { 00062 _likelihood=1; 00063 } else { 00064 double loglike=(n2-1)*log(z2)-z2-NumRecipes::gammln(n2); 00065 if ( loglike < DBL_MIN_EXP ) { 00066 _likelihood = 0; 00067 setStatus(Consistency::underFlow); 00068 } else { 00069 _likelihood = 0.5*exp(loglike); 00070 } 00071 } 00072 }
ChisqConsistency::ChisqConsistency | ( | unsigned | nDof, | |
double | consistency | |||
) |
Definition at line 76 of file ChisqConsistency.cxx.
References _chisq, Consistency::_likelihood, _nDof, Consistency::_value, chisin_(), exp(), NumRecipes::gammln(), n2, Consistency::OK, Consistency::setStatus(), Consistency::underFlow, and Consistency::unPhysical.
00076 : 00077 _nDof(nDof) 00078 { 00079 if(prob >= 0.0|| prob <= 1.0 || nDof < 0) 00080 _value = prob; 00081 else { 00082 std::cout << "ErrMsg(warning)" << " Got unphysical values: prob = " << prob 00083 << " #dof = " << nDof << std::endl; 00084 _value=0; 00085 _likelihood=0; 00086 setStatus(Consistency::unPhysical); 00087 return; 00088 } 00089 setStatus(Consistency::OK); 00090 if(prob != 1.0){ 00091 // use the cernlib function to get chisq. Note the funny convention on prob!! 00092 float value = 1.0-float(_value); 00093 int ndof = nDof; 00094 if(value < 1.0) 00095 _chisq = chisin_(value,ndof); 00096 else 00097 _chisq = log(double(FLT_MAX)); 00098 // use the same algorithm as above to get loglikelihood 00099 double z2 = 0.5*_chisq; 00100 double n2 = 0.5*_nDof; 00101 if (_chisq==0) { 00102 _likelihood=1; 00103 } else { 00104 double loglike=(n2-1)*log(z2)-z2-NumRecipes::gammln(n2); 00105 if ( loglike < DBL_MIN_EXP ) { 00106 _likelihood = 0; 00107 setStatus(Consistency::underFlow); 00108 } else { 00109 _likelihood = 0.5*exp(loglike); 00110 } 00111 } 00112 } 00113 }
ChisqConsistency::ChisqConsistency | ( | const ChisqConsistency & | ) |
virtual ChisqConsistency::~ChisqConsistency | ( | ) | [inline, virtual] |
const Consistency & Consistency::badMeasurement | ( | ) | [static, inherited] |
Definition at line 172 of file Consistency.cxx.
References Consistency::noMeasure, and Consistency::setStatus().
00173 { 00174 static Consistency bad(1.,1.); 00175 bad.setStatus(noMeasure); 00176 00177 return bad; 00178 }
const double& ChisqConsistency::chisqValue | ( | ) | const [inline] |
double Consistency::consistency | ( | ) | const [inline, inherited] |
Definition at line 91 of file Consistency.h.
References Consistency::_value.
00091 { return _value; }
const ConsistencySet * Consistency::genealogy | ( | ) | const [virtual, inherited] |
double Consistency::likelihood | ( | ) | const [inline, inherited] |
Definition at line 86 of file Consistency.h.
References Consistency::_likelihood.
00086 { return _likelihood;}
const double& ChisqConsistency::nDOF | ( | ) | const [inline] |
bool Consistency::operator< | ( | const Consistency & | rhs | ) | const [inherited] |
Definition at line 98 of file Consistency.cxx.
References Consistency::_stat, Consistency::_value, and Consistency::OK.
00099 { 00100 // 00101 // this is not unique... 00102 // 00103 00104 bool answer = false; 00105 if (_stat == OK && rhs._stat == OK ) { 00106 // 00107 // Dare to use consistency for comparison. 00108 // Likelihood may give a different answer 00109 // 00110 if (_value < rhs._value) { 00111 answer = true; 00112 } 00113 } else { 00114 if (rhs._stat == OK) { 00115 answer = true; 00116 } 00117 } 00118 00119 return answer; 00120 }
ChisqConsistency & ChisqConsistency::operator= | ( | const ChisqConsistency & | ) |
Definition at line 121 of file ChisqConsistency.cxx.
References _chisq, _nDof, Consistency::operator=(), and EvtCyclic3::other().
00121 { 00122 if(this != &other){ 00123 Consistency::operator =(other); 00124 _chisq = other._chisq; 00125 _nDof = other._nDof; 00126 } 00127 return *this; 00128 }
bool Consistency::operator== | ( | const Consistency & | rhs | ) | const [inherited] |
Definition at line 84 of file Consistency.cxx.
References Consistency::_likelihood, Consistency::_sign, Consistency::_stat, and Consistency::_value.
00085 { 00086 bool answer = false; 00087 if (_stat == rhs._stat && 00088 _value == rhs._value && 00089 _likelihood == rhs._likelihood && 00090 _sign == rhs._sign) { 00091 answer = true; 00092 } 00093 00094 return answer; 00095 }
bool Consistency::operator> | ( | const Consistency & | rhs | ) | const [inherited] |
virtual void Consistency::print | ( | std::ostream & | ) | const [virtual, inherited] |
void Consistency::setSign | ( | ConsistentSign | s | ) | [inline, inherited] |
void Consistency::setStatus | ( | ConsistentStatus | s | ) | [inline, inherited] |
Definition at line 107 of file Consistency.h.
References Consistency::_stat.
Referenced by Consistency::badMeasurement(), and ChisqConsistency().
ConsistentSign Consistency::sign | ( | ) | const [inline, inherited] |
double Consistency::significanceLevel | ( | ) | const [inline, inherited] |
Definition at line 85 of file Consistency.h.
References Consistency::_value.
00085 { return _value; }
ConsistentStatus Consistency::status | ( | void | ) | const [inline, inherited] |
double ChisqConsistency::_chisq [protected] |
Definition at line 50 of file ChisqConsistency.h.
Referenced by ChisqConsistency(), chisqValue(), and operator=().
double Consistency::_likelihood [protected, inherited] |
Definition at line 135 of file Consistency.h.
Referenced by ChisqConsistency(), Consistency::likelihood(), Consistency::operator=(), and Consistency::operator==().
double ChisqConsistency::_nDof [protected] |
Definition at line 51 of file ChisqConsistency.h.
Referenced by ChisqConsistency(), nDOF(), and operator=().
ConsistentSign Consistency::_sign [protected, inherited] |
Definition at line 133 of file Consistency.h.
Referenced by Consistency::operator=(), Consistency::operator==(), Consistency::setSign(), and Consistency::sign().
ConsistentStatus Consistency::_stat [protected, inherited] |
Definition at line 132 of file Consistency.h.
Referenced by Consistency::operator<(), Consistency::operator=(), Consistency::operator==(), Consistency::setStatus(), and Consistency::status().
double Consistency::_value [protected, inherited] |
Definition at line 134 of file Consistency.h.
Referenced by ChisqConsistency(), Consistency::consistency(), Consistency::operator<(), Consistency::operator=(), Consistency::operator==(), and Consistency::significanceLevel().