StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSvtTable.cc
1 #include <Stiostream.h>
2 #include <stdlib.h>
3 #include <math.h>
4 
5 #include "StSvtTable.hh"
6 
7 //ClassImp(StSvtTable)
8 
9 StSvtTable::StSvtTable()
10 {
11  /*
12  for(int j = 0; j < 1000; j++)
13  for(int k = 0; k < 2000; k++)
14  mFreq[j][k] = 0.0;
15  */
16 }
17 
18 StSvtTable::~StSvtTable()
19 {
20 
21 }
22 
23 void StSvtTable::setFreq(int i)
24 {
25  double num = 0.0, width = 0.0;
26 
27  for(int j = 0; j < 1000; j++)
28  {
29  num = j*0.001 + (double)i;
30  for(int k = 0; k < 2000; k++)
31  {
32  width = k*0.001;
33  if(!width)
34  mFreq[j][k] = 0.0;
35  else
36  mFreq[j][k] = prob1(num,width);
37  if(i == 1 && j == 33 && k == 132)
38  cout<<"mFreq"<<" ["<<j<<"]"<<" ["<<k<<"] = "<<mFreq[j][k]<<"\t";
39 
40  }
41  }
42 }
43 
44 double StSvtTable::getFreq(int j, int k)
45 {
46  double freq = mFreq[j][k];
47  return freq;
48 }
49 
50 
51 double StSvtTable::prob1(double num , double sigma)
52 {
53  num = num/(::sqrt(2)*sigma);
54 
55  double fraction = 0.5*(1 + erf(num));
56 
57  return fraction;
58 
59 }
60 
61 
62 double StSvtTable::prob2(double num , double sigma)
63 {
64  double mSum = 0, mErrf = 0;
65  double mFactorial = 0;
66  double mPowerTerm = 0;
67  double mPowerTermSquared = 0;
68  double mCountTerm = 0;
69 
70  if(fabs(num) < 5*sigma)
71  {
72  for(int j = 0; j<=120; j++)
73  {
74 
75  if(j==0)
76  {
77  mFactorial = 1.0;
78  mPowerTerm = fabs(num)/(::sqrt(2)*sigma);
79  mPowerTermSquared = mPowerTerm*mPowerTerm;
80  mCountTerm = mPowerTerm;
81  }
82 
83  else
84  {
85  mFactorial = (double)j*mFactorial;
86  mPowerTerm = (mPowerTermSquared)*(double)fabs(mPowerTerm);
87 
88  if(j%2 == 1)
89  mPowerTerm = (-1)*mPowerTerm;
90 
91  mCountTerm =(mPowerTerm /( mFactorial*(double)(2*j + 1)));
92 
93  }
94 
95  mSum += mCountTerm;
96 
97  }
98 
99  mErrf = (2.0/::sqrt(acos(-1.)))*mSum;
100 
101  if(num < 0.0)
102  mErrf = (-1.0)*mErrf;
103  }
104 
105  else if(num > 5*sigma)
106  mErrf = 1.0;
107  else
108  mErrf = -1.0;
109 
110  return 0.5*(1.0 + mErrf);
111 }
112