VTankResponse.cc
Go to the documentation of this file.
1 #include <tls/VTankResponse.h>
2 #include <utl/PoissonDistribution.h>
3 #include <utl/Math.h>
4 #include <utl/AugerException.h>
5 
6 using namespace std;
7 using namespace utl;
8 using namespace tls;
9 
10 typedef unsigned short ushort;
11 
12 static const double precision = 1e-10;
13 static const ushort kmax = 1000;
14 
15 double
16 VTankResponse::PoissonConvolvedPDF(const double signal,
17  const double theta,
18  const double r,
19  const double muons)
20  const
21 {
22  double psum = 0;
23  ushort k = 0;
24 
25  ulong nMuDown = ulong(muons);
26  ulong nMuUp = nMuDown+1;
27  for (double p = 0; k < kmax && (k < 5 || p >= precision*psum); ++k)
28  {
29  p = PoissonPDF(nMuUp, muons) * PDF(signal, theta, r, nMuUp);
30  ++nMuUp;
31 
32  if (nMuDown > 0)
33  {
34  p += PoissonPDF(nMuDown, muons) * PDF(signal, theta, r, nMuDown);
35  --nMuDown;
36  }
37 
38  psum += p;
39  }
40 
41  // ~if (k == kmax)
42  // ~{
43  // ~ostringstream msg;
44  // ~msg << "PoissonConvolvedPDF: iteration overflow, signal " << signal << " muons " << muons;
45  // ~WARNING(msg);
46  // ~}
47 
48  return psum;
49 }
50 
51 double
52 VTankResponse::PoissonConvolvedCDF(const double sThreshold,
53  const double theta,
54  const double r,
55  const double muons,
56  const bool complement)
57  const
58 {
59  double psum = 0.0;
60  ushort k = 0;
61 
62  if (complement) // saturation case
63  {
64  ulong nMuDown = ulong(muons);
65  ulong nMuUp = nMuDown+1;
66 
67  for (double p = 0; k < kmax && (k < 5 || p >= precision*psum); ++k)
68  {
69  p = PoissonPDF(nMuUp, muons) *
70  (1.0 - CDF(sThreshold, theta, r, nMuUp));
71  ++nMuUp;
72 
73  if (nMuDown > 0)
74  {
75  p += PoissonPDF(nMuDown, muons) *
76  (1.0 - CDF(sThreshold, theta, r, nMuDown));
77  --nMuDown;
78  }
79 
80  psum += p;
81  }
82  }
83  else // non-triggering case
84  {
85  // no muons: CDF(sThreshold) = 1 for sThreshold > 0
86  psum = PoissonPDF(0, muons);
87  k = 1;
88  for (double p = 0; k < kmax && (k < 5 || p >= precision*psum); ++k)
89  {
90  p = PoissonPDF(k, muons) * CDF(sThreshold, theta, r, k);
91  psum += p;
92  }
93  }
94 
95  // ~if (k == kmax)
96  // ~{
97  // ~ostringstream msg;
98  // ~msg << "PoissonConvolvedCDF: iteration overflow, sThr " << sThreshold << " muons " << muons;
99  // ~WARNING(msg);
100  // ~}
101 
102  return psum;
103 }
104 
105 void
106 VTankResponse::PoissonConvolvedMeanAndStDev(double& mean,
107  double& stDev,
108  const double theta,
109  const double r,
110  const double muons)
111  const
112 {
113  double cmom1 = 0;
114  double cmom2 = 0;
115  ushort k = 0;
116 
117  ulong nMuDown = ulong(muons);
118  ulong nMuUp = nMuDown+1;
119  for (double mom1 = 0; k < kmax && (k < 5 || mom1 >= precision*cmom1); ++k)
120  {
121  double mom2 = 0;
122  const double p = PoissonPDF(nMuUp,muons);
123  const double mean = Mean(theta,r,nMuUp);
124  const double sigma = StDev(theta,r,nMuUp);
125  mom1 = p * mean;
126  mom2 = p * (sigma*sigma + mean*mean);
127  ++nMuUp;
128 
129  if (nMuDown > 0) {
130  const double p = PoissonPDF(nMuDown,muons);
131  const double mean = Mean(theta,r,nMuDown);
132  const double sigma = StDev(theta,r,nMuDown);
133  mom1 += p * mean;
134  mom2 += p * (sigma*sigma + mean*mean);
135  --nMuDown;
136  }
137 
138  cmom1 += mom1;
139  cmom2 += mom2;
140  }
141 
142  // ~if (k == kmax)
143  // ~{
144  // ~ostringstream msg;
145  // ~msg << "PoissonConvolvedMeanAndStDev: iteration overflow";
146  // ~WARNING(msg);
147  // ~}
148 
149  mean = cmom1;
150  stDev = sqrt(cmom2 - cmom1*cmom1);
151 }
unsigned long ulong
Definition: VTankResponse.h:28
static const double precision
static const ushort kmax
unsigned short ushort
double Mean(const std::vector< double > &v)
Definition: Functions.h:31
unsigned long ulong
Definition: extractEvent.cc:36
double PoissonPDF(const ulong k, const double x)

, generated on Tue Sep 26 2023.