Go to the source code of this file.
|
template<class T > |
T | Prob (const T &rhs, int n) |
|
◆ Prob()
template<class T >
T Prob |
( |
const T & |
rhs, |
|
|
int |
n |
|
) |
| |
Upper Tail Probability of Chi-Squared Distribution. \begin{displaymath} Q(X|N) = \frac{1}{\sqrt{2^N}\Gamma(\frac{1}{2}N)} \int^\infty_X e^{-\frac{1}{2}t} t^{\frac{1}{2}N-1} dt \end{displaymath}
- Author
- T. Glebe
37 {
38
39
40 static T e, h;
41 static int i, m;
42 static T
s,
t, u,
w, fi;
43
44
45 u = rhs * .5;
46 if (n <= 0) {
47 h = 0.;
48
49 } else if (rhs < 0.) {
50 h = 0.;
51
52 } else if (rhs == 0. || (n / 20) > rhs) {
53 h = 1.;
54 } else if (n == 1) {
58 } else {
59 h = 0.;
60 }
61 } else if (n > 300) {
63 t =
s * .22222222222222221;
64 w = (pow(rhs*
s, 1./3.) - (1 -
t)) / sqrt(
t * 2);
66 h = 1.;
69 } else {
70 h = 0.;
71 }
72 } else {
73 m = n / 2;
74 if (u < 349.346 && rhs / n <= 100.) {
78 if (m << 1 == n) {
79 fi = 0.;
80 for (i = 1; i <= m-1; ++i) {
81 fi += 1;
84 }
86 } else {
87 fi = 1.;
88 for (i = 1; i <= m-1; ++i) {
89 fi += 2;
92 }
95 h =
w * 1.128379167095513 *
s * e +
erfc(
w);
96 } else {
97 h = 0.;
98 }
99 }
100 } else {
101 h = 0.;
102 }
103 }
104
105 if (h > 1e-30) {
106 return h;
107 } else {
108 return 0.;
109 }
110}
T erfc(const T &rhs)
Definition: Erf.hh:127
TTree * t
Definition: check_shower.C:4
s
Definition: check_shower.C:55
void w(int rid=2, int nviews=2)
Definition: test.C:27