BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
ChisqConsistency.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: ChisqConsistency.cxx,v 1.1.1.1 2005/04/21 01:17:17 zhangy Exp $
4//
5// Description:
6//
7// Environment:
8// Software developed for the BaBar Detector at the SLAC B-Factory.
9//
10// Author List:
11// Bob Jacobsen, Ed Iskander
12//
13// Copyright Information:
14// Copyright (C) 1996 Lawrence Berkeley Laboratory
15//
16//------------------------------------------------------------------------
17
18//-----------------------
19// This Class's Header --
20//-----------------------
21//#include "BaBar/BaBar.hh"
23
24#include <iostream>
25#include <math.h>
26#include <float.h>
27
29
30//#include "ErrLogger/ErrLog.hh"
31
32// prototype the cernlib function
33extern "C" {
34 float chisin_(const float&, const int&);
35 double dgausn_(double& arg);
36}
37
39 _chisq(-1.0), _nDof(0)
40{}
41
42ChisqConsistency::ChisqConsistency(double chisq, double nDof) :
43 _chisq(chisq), _nDof(nDof)
44{
45 double z2 = 0.5*_chisq;
46 double n2 = 0.5*_nDof;
47
48 if (n2<=0 || z2<0) {
49 std::cout << "ErrMsg(warning)" << " Got unphysical values: chisq = " << chisq
50 << " #dof = " << nDof << std::endl;
51 _value=0;
54 return;
55 }
57
58// given that n2>0 && z2>=0, gammq will NOT abort
60
61 if (_chisq==0) {
62 _likelihood=1;
63 } else {
64 double loglike=(n2-1)*log(z2)-z2-NumRecipes::gammln(n2);
65 if ( loglike < DBL_MIN_EXP ) {
66 _likelihood = 0;
68 } else {
69 _likelihood = 0.5*exp(loglike);
70 }
71 }
72}
73
74
75
76ChisqConsistency::ChisqConsistency(unsigned nDof, double prob) :
77 _nDof(nDof)
78{
79 if(prob >= 0.0|| prob <= 1.0 || nDof < 0)
80 _value = prob;
81 else {
82 std::cout << "ErrMsg(warning)" << " Got unphysical values: prob = " << prob
83 << " #dof = " << nDof << std::endl;
84 _value=0;
87 return;
88 }
90 if(prob != 1.0){
91// use the cernlib function to get chisq. Note the funny convention on prob!!
92 float value = 1.0-float(_value);
93 int ndof = nDof;
94 if(value < 1.0)
95 _chisq = chisin_(value,ndof);
96 else
97 _chisq = log(double(FLT_MAX));
98// use the same algorithm as above to get loglikelihood
99 double z2 = 0.5*_chisq;
100 double n2 = 0.5*_nDof;
101 if (_chisq==0) {
102 _likelihood=1;
103 } else {
104 double loglike=(n2-1)*log(z2)-z2-NumRecipes::gammln(n2);
105 if ( loglike < DBL_MIN_EXP ) {
106 _likelihood = 0;
108 } else {
109 _likelihood = 0.5*exp(loglike);
110 }
111 }
112 }
113}
114
115
117 Consistency(other), _chisq(other._chisq), _nDof(other._nDof)
118{}
119
122 if(this != &other){
124 _chisq = other._chisq;
125 _nDof = other._nDof;
126 }
127 return *this;
128}
double dgausn_(double &arg)
float chisin_(const float &, const int &)
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
double arg(const EvtComplex &c)
Definition: EvtComplex.hh:227
int n2
Definition: SD0Tag.cxx:55
ChisqConsistency & operator=(const ChisqConsistency &)
void setStatus(ConsistentStatus s)
Definition: Consistency.h:107
double _value
Definition: Consistency.h:134
double _likelihood
Definition: Consistency.h:135
Consistency & operator=(const Consistency &rhs)
Definition: Consistency.cxx:72
static double gammq(double a, double x)
Definition: NumRecipes.cxx:72
static double gammln(double x)
Definition: NumRecipes.cxx:40