BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
NumRecipes.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: NumRecipes.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// #include "BaBar/BaBar.hh"
18
19//-----------------------
20// This Class's Header --
21//-----------------------
22#include "ProbTools/NumRecipes.h"
23
24//-------------
25// C Headers --
26//-------------
27extern "C" {
28#include <assert.h>
29#include <math.h>
30#include <stdlib.h>
31}
32
33//---------------
34// C++ Headers --
35//---------------
36#include <iostream>
37// #include "ErrLogger/ErrLog.hh"
38using std::endl;
39
40double NumRecipes::gammln( double xx ) {
41 double x, y, tmp, ser;
42 static double cof[6] = { 76.18009172947146, -86.50532032941677, 24.01409824083091,
43 -1.231739572450155, 0.1208650973866179e-2, -0.5395239384953e-5 };
44 int j;
45
46 y = x = xx;
47 tmp = x + 5.5;
48 tmp -= ( x + 0.5 ) * log( tmp );
49 ser = 1.000000000190015;
50 for ( j = 0; j <= 5; j++ ) ser += cof[j] / ++y;
51 return -tmp + log( 2.5066282746310005 * ser / x );
52}
53
54double NumRecipes::gammp( double a, double x ) {
55 double gamser, gammcf, gln;
56
57 if ( x < 0.0 || a <= 0.0 )
58 std::cout << "ErrMsg(error)"
59 << " Invalid arguments in routine gammp x=" << x << " a=" << a << endl;
60 if ( x < ( a + 1.0 ) )
61 {
62 gser( &gamser, a, x, &gln );
63 return gamser;
64 }
65 else
66 {
67 gcf( &gammcf, a, x, &gln );
68 return 1.0 - gammcf;
69 }
70}
71
72double NumRecipes::gammq( double a, double x ) {
73 double gamser, gammcf, gln;
74
75 if ( x < 0.0 || a <= 0.0 ) recipesErr( " Invalid arguments in routine GAMMQ" );
76 if ( x < ( a + 1.0 ) )
77 {
78 gser( &gamser, a, x, &gln );
79 return 1.0 - gamser;
80 }
81 else
82 {
83 gcf( &gammcf, a, x, &gln );
84 return gammcf;
85 }
86}
87
88void NumRecipes::gcf( double* gammcf, double a, double x, double* gln ) {
89 int n;
90 double gold = 0.0, g, fac = 1.0, b1 = 1.0;
91 double b0 = 0.0, anf, ana, an, a1, a0 = 1.0;
92
93 *gln = gammln( a );
94 a1 = x;
95 for ( n = 1; n <= NUMREC_ITMAX; n++ )
96 {
97 an = (double)n;
98 ana = an - a;
99 a0 = ( a1 + a0 * ana ) * fac;
100 b0 = ( b1 + b0 * ana ) * fac;
101 anf = an * fac;
102 a1 = x * a0 + anf * a1;
103 b1 = x * b0 + anf * b1;
104 if ( a1 )
105 {
106 fac = 1.0 / a1;
107 g = b1 * fac;
108 if ( fabs( ( g - gold ) / g ) < NUMREC_EPS )
109 {
110 *gammcf = exp( -x + a * log( x ) - ( *gln ) ) * g;
111 return;
112 }
113 gold = g;
114 }
115 }
116 recipesErr( " a too large, NUMREC_ITMAX too small in routine GCF" );
117}
118
119void NumRecipes::gser( double* gamser, double a, double x, double* gln ) {
120 int n;
121 double sum, del, ap;
122
123 *gln = gammln( a );
124 if ( x <= 0.0 )
125 {
126 if ( x < 0.0 ) recipesErr( " x less than 0 in routine GSER" );
127 *gamser = 0.0;
128 return;
129 }
130 else
131 {
132 ap = a;
133 del = sum = 1.0 / a;
134 for ( n = 1; n <= NUMREC_ITMAX; n++ )
135 {
136 ap += 1.0;
137 del *= x / ap;
138 sum += del;
139 if ( fabs( del ) < fabs( sum ) * NUMREC_EPS )
140 {
141 *gamser = sum * exp( -x + a * log( x ) - ( *gln ) );
142 return;
143 }
144 }
145 recipesErr( " a too large, NUMREC_ITMAX too small in routine GSER" );
146 return;
147 }
148}
149
150void NumRecipes::recipesErr( const char* c ) {
151 std::cout << "ErrMsg(fatal)"
152 << " Numerical Recipes run-time error...\n"
153 << c << "\n ...now exiting to system..." << std::endl;
154 ::abort();
155}
const Int_t n
character *LEPTONflag integer iresonances real zeta5 real a0
EvtComplex exp(const EvtComplex &c)
static double gammq(double a, double x)
static void gser(double *gamser, double a, double x, double *gln)
static double gammln(double x)
static void gcf(double *gammcf, double a, double x, double *gln)
static double gammp(double a, double x)