FEDRA emulsion software from the OPERA Collaboration
Prob.hh
Go to the documentation of this file.
1#ifndef __PROB_HH
2#define __PROB_HH
3// ********************************************************************
4//
5// source:
6//
7// type: source code
8//
9// created: 19. Apr 2001
10//
11// author: Thorsten Glebe
12// HERA-B Collaboration
13// Max-Planck-Institut fuer Kernphysik
14// Saupfercheckweg 1
15// 69117 Heidelberg
16// Germany
17// E-mail: T.Glebe@mpi-hd.mpg.de
18//
19// Description: Upper Tail Probability of Chi-Squared Distribution
20//
21// changes:
22// 19 Apr 2001 (TG) creation
23//
24// ********************************************************************
25//#include <cmath>
26#include "Erf.hh"
27
36template <class T>
37T Prob(const T& rhs, int n) {
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
111#endif
T erfc(const T &rhs)
Definition: Erf.hh:127
T Prob(const T &rhs, int n)
Definition: Prob.hh:37
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