ChisqConsistency Class Reference

#include <ChisqConsistency.h>

Inheritance diagram for ChisqConsistency:

Consistency List of all members.

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 &)
ChisqConsistencyoperator= (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 ConsistencybadMeasurement ()

Protected Attributes

double _chisq
double _nDof
ConsistentStatus _stat
ConsistentSign _sign
double _value
double _likelihood

Detailed Description

Definition at line 27 of file ChisqConsistency.h.


Member Enumeration Documentation

enum Consistency::ConsistentSign [inherited]

Enumerator:
left 
unknown 
right 

Definition at line 114 of file Consistency.h.

00114 { left=-1, unknown=0, right=1 };

enum Consistency::ConsistentStatus [inherited]

Enumerator:
OK 
noMeasure 
underFlow 
unPhysical 

Definition at line 94 of file Consistency.h.

00094 { OK=0, noMeasure, underFlow, unPhysical };


Constructor & Destructor Documentation

ChisqConsistency::ChisqConsistency (  ) 

Definition at line 38 of file ChisqConsistency.cxx.

00038                                    :
00039   _chisq(-1.0), _nDof(0)
00040 {}

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  ) 

Definition at line 116 of file ChisqConsistency.cxx.

00116                                                                 :
00117   Consistency(other), _chisq(other._chisq), _nDof(other._nDof)
00118 {}

virtual ChisqConsistency::~ChisqConsistency (  )  [inline, virtual]

Definition at line 44 of file ChisqConsistency.h.

00044 {}


Member Function Documentation

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]

Definition at line 46 of file ChisqConsistency.h.

References _chisq.

00046 { return _chisq; }

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]

Definition at line 132 of file Consistency.cxx.

00133 {
00134   return 0;
00135 }

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]

Definition at line 47 of file ChisqConsistency.h.

References _nDof.

00047 { return _nDof; }

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]

Definition at line 123 of file Consistency.cxx.

00124 {
00125   // ghm
00126   if( *this==rhs ) return false;
00127   return( ! (*this<rhs) );
00128 }

virtual void Consistency::print ( std::ostream  )  const [virtual, inherited]

void Consistency::setSign ( ConsistentSign  s  )  [inline, inherited]

Definition at line 118 of file Consistency.h.

References Consistency::_sign.

00118 { _sign = s; }

void Consistency::setStatus ( ConsistentStatus  s  )  [inline, inherited]

Definition at line 107 of file Consistency.h.

References Consistency::_stat.

Referenced by Consistency::badMeasurement(), and ChisqConsistency().

00107 { _stat = s; }

ConsistentSign Consistency::sign (  )  const [inline, inherited]

Definition at line 117 of file Consistency.h.

References Consistency::_sign.

00117 {return _sign; }

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]

Definition at line 106 of file Consistency.h.

References Consistency::_stat.

00106 {return _stat;}


Member Data Documentation

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().


Generated on Tue Nov 29 23:18:07 2016 for BOSS_7.0.2 by  doxygen 1.4.7