StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSvtHybridNoise.cc
1 #include <Stiostream.h>
2 #include <math.h>
3 #include <stdlib.h>
4 
5 #include "StSvtHybridNoise.hh"
6 
7 ClassImp(StSvtHybridNoise)
8 
9 StSvtHybridNoise::StSvtHybridNoise(int barrel, int ladder, int wafer, int hybrid):StSvtHybridPixelsC(barrel,ladder,wafer,hybrid)
10 { }
11 
12 //StSvtHybridNoise::~StSvtHybridNoise()
13 //{ }
14 
15 double StSvtHybridNoise::makeGausDev(double sigma,double mean)
16 {
17 
18  static int iset = 0;
19  static double v1,u;
20  double rsq,v2;
21 
22  //if(*idum < 0) iset = 0;
23  if(iset == 0)
24  {
25 
26  do {
27  v1 = 2.0*((float)rand()/(float)RAND_MAX) - 1.0;
28  v2 = 2.0*((float)rand()/(float)RAND_MAX) - 1.0;
29  rsq = v1*v1 + v2*v2;
30 
31  } while(rsq >= 1.0 || rsq == 0.0);
32 
33  u = ::sqrt(-2.0*::log(rsq)/rsq);
34 
35  iset = 1;
36  //return mean + sigma*v2*u;
37  return sigma*v2*u; // sigma*::sqrt(-2.0*::log(rsq))*(v1/::sqrt(rsq))
38  }
39  else
40  {
41  iset = 0;
42  // return mean + sigma*v1*u;
43  return v1*sigma*u;
44  }
45 
46  }
47 
48 double StSvtHybridNoise::prob(double sigma, double threshold)
49 {
50 
51  double num = 0, prob = 0;
52 
53  num = threshold/(M_SQRT2*sigma);
54  prob = 0.5*(1. - erf(num));
55 
56  return prob;
57  }
58 
59 double StSvtHybridNoise::maxDistValue(double sigma ,double threshold)
60 {
61  double num = 0, distValue = 0, coeff;
62 
63  num = threshold/(M_SQRT2*sigma);
64  coeff = 1.0/(sigma*M_PI);
65 
66  distValue = coeff*exp(-num*num);
67 
68  return distValue;
69 
70  }
71 
72 double StSvtHybridNoise::countAboveThreshold(double sigma, double randNum)
73 {
74 
75  double count = 0;
76 
77  count = sigma*::sqrt(2*M_PI)*randNum;
78  count =sigma*::sqrt( -2.0*::log(count));
79 
80  return count;
81  }