FEDRA emulsion software from the OPERA Collaboration
Prob.hh File Reference
#include "Erf.hh"
Include dependency graph for Prob.hh:

Go to the source code of this file.

Functions

template<class T >
Prob (const T &rhs, int n)
 

Function Documentation

◆ 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  /* Local variables */
40  static T e, h;
41  static int i, m;
42  static T s, t, u, w, fi;
43 
44  // maximum chi2 per df for df >= 2., if chi2/df > chipdf prob=0.
45  u = rhs * .5;
46  if (n <= 0) {
47  h = 0.;
48  // error
49  } else if (rhs < 0.) {
50  h = 0.;
51  // error
52  } else if (rhs == 0. || (n / 20) > rhs) {
53  h = 1.;
54  } else if (n == 1) {
55  w = sqrt(u);
56  if (w < 24.) {
57  h = erfc(w);
58  } else {
59  h = 0.;
60  }
61  } else if (n > 300) {
62  s = 1. / n;
63  t = s * .22222222222222221;
64  w = (pow(rhs*s, 1./3.) - (1 - t)) / sqrt(t * 2);
65  if (w < -24.) {
66  h = 1.;
67  } else if (w < 24.) {
68  h = erfc(w) * .5;
69  } else {
70  h = 0.;
71  }
72  } else {
73  m = n / 2;
74  if (u < 349.346 && rhs / n <= 100.) {
75  s = exp(u * -.5);
76  t = s;
77  e = s;
78  if (m << 1 == n) {
79  fi = 0.;
80  for (i = 1; i <= m-1; ++i) {
81  fi += 1;
82  t = u * t / fi;
83  s += t;
84  }
85  h = s * e;
86  } else {
87  fi = 1.;
88  for (i = 1; i <= m-1; ++i) {
89  fi += 2;
90  t = t * rhs / fi;
91  s += t;
92  }
93  w = sqrt(u);
94  if (w < 24.) {
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 } // Prob
T erfc(const T &rhs)
Definition: Erf.hh:127
TTree * t
Definition: check_shower.C:4
void w(int rid=2, int nviews=2)
Definition: test.C:27
EdbSegP * s
Definition: tlg2pattern.C:32