3 #include <utl/AugerException.h>
4 #include <utl/Reader.h>
5 #include <utl/Branch.h>
6 #include <utl/AugerUnits.h>
19 #include <boost/lexical_cast.hpp>
21 using namespace TabularTankResponseNS;
24 using namespace boost;
28 inline double sqrt(
const size_t x) {
return sqrt(
double(x)); }
32 Trafo(
size_t& i,
double&z,
const double x,
const size_t n,
const double x0,
const double dx)
52 i =
static_cast<size_t>(z);
82 const double nan = numeric_limits<double>::quiet_NaN();
85 double xrange[2] = { nan, nan };
86 double yrange[2] = { nan, nan };
94 const double x = lexical_cast<
double>(am[
"x"])*
degree;
95 const double y = lexical_cast<
double>(am[
"y"])+log10(
meter);
96 fDS = lexical_cast<
double>(am[
"ds"]);
98 if (std::isnan(xrange[0]) || x < xrange[0] || xrange[1] < x)
101 if (x < xrange[0] || std::isnan(xrange[0])) xrange[0] = x;
102 if (x > xrange[1] || std::isnan(xrange[1])) xrange[1] = x;
105 if (std::isnan(yrange[0]) || y < yrange[0] || yrange[1] < y)
108 if (y < yrange[0] || std::isnan(yrange[0])) yrange[0] = y;
109 if (y > yrange[1] || std::isnan(yrange[1])) yrange[1] = y;
114 bpdf.GetData(pdfs.back().fPDF);
117 if (yrange[0]==yrange[1])
126 fDX = xrange[1]-xrange[0];
128 fDY = yrange[1]-yrange[0];
129 fMean.resize(extents[fNX][fNY]);
130 fSigma.resize(extents[fNX][fNY]);
131 fCdf.resize(extents[fNX][fNY][nmuons]);
133 cout <<
"TabularTankResponse convolving";
135 #pragma omp parallel for
137 for (
size_t i = 0; i < pdfs.size(); ++i)
139 cout <<
"." << flush;
140 const vector<double>& pdf = pdfs[i].fPDF;
141 const double x = pdfs[i].fX;
142 const double y = pdfs[i].fY;
144 const size_t ix = round((x-xrange[0])/(xrange[1]-xrange[0])*(fNX-1));
145 const size_t iy = round((y-yrange[0])/(yrange[1]-yrange[0])*(fNY-1));
147 const size_t n = pdf.size();
153 const double* input = &pdf.front();
154 for (
size_t m = 0;
m < nmuons; ++
m)
156 fCdf[ix][iy][
m].resize(1+(
m+1)*n);
157 double*
data = &fCdf[ix][iy][
m].front();
173 for (
size_t i = 0; i < n; ++i)
175 data[1+i] = input[i];
177 vsum += input[i]*(i+0.5);
178 vvsum += input[i]*(i*i+i+1.0/3.0);
182 fMean[ix][iy] = vsum/sum;
183 fSigma[ix][iy] =
sqrt(vvsum/sum - fMean[ix][iy]*fMean[ix][iy]);
187 const double* zero = &fCdf[ix][iy][0].front();
188 const double* prev = &fCdf[ix][iy][
m-1].front();
189 for (
size_t i = 0; i < (
m+1)*n; ++i)
192 for (
size_t j = i >= n ? i-n+1 : 0; j <= min(i,
m*n-1); ++j)
193 data[1+i] += zero[1+i-j]*prev[1+j];
198 for (
size_t m = 0;
m < nmuons; ++
m)
201 double*
data = &fCdf[ix][iy][
m].front();
203 for (; i < (m+1)*n && data[i+1] > 0; ++i)
204 data[1+i] = data[i] + data[1+i];
207 const double mean = fMean[ix][iy]*(
m+1);
208 const double sigma = fSigma[ix][iy]*
sqrt(
m+1);
209 const double cTrans =
NormalCDF((i+0.5)*fDS, mean, sigma);
210 for (
size_t j = 0; j < i; ++j)
211 data[j] *= cTrans / data[i];
212 for (
size_t j = i; j < (
m+1)*n; ++j)
213 data[j] =
NormalCDF((j+0.5)*fDS, mean, sigma);
229 if (nmuons <= fCdf.shape()[2])
231 const double h = fSmooth*fDS;
232 double sm = signal - h;
if (sm < 0) sm = 0;
233 const double sp = signal + h;
235 const double cm = CDF(sm, theta, r, nmuons);
236 const double cp = CDF(sp, theta, r, nmuons);
237 result = (cp-
cm)/(sp-sm);
241 const double m =
Mean(theta, r, nmuons);
242 const double s = StDev(theta, r, nmuons);
258 return signalmax > 0;
260 if (nmuons <= fCdf.shape()[2])
264 Trafo(ix,zx,theta,fNX,fX,fDX);
265 Trafo(iy,zy,log10(r),fNY,fY,fDY);
267 const vector<double>& v00 = fCdf[ix ][iy ][nmuons-1];
268 const vector<double>& v01 = fCdf[ix ][min(iy+1, fNY-1)][nmuons-1];
269 const vector<double>& v10 = fCdf[min(ix+1, fNX-1)][iy ][nmuons-1];
270 const vector<double>& v11 = fCdf[min(ix+1, fNX-1)][min(iy+1, fNY-1)][nmuons-1];
273 const double z = (signalmax-
Mean(theta, r, nmuons))/StDev(theta, r, nmuons);
274 const double sqrtn =
sqrt(nmuons);
275 const double m00 = fMean[ix][iy]*nmuons;
276 const double m01 = fMean[ix][min(iy+1, fNY-1)]*nmuons;
277 const double m10 = fMean[min(ix+1, fNX-1)][iy]*nmuons;
278 const double m11 = fMean[min(ix+1, fNX-1)][min(iy+1, fNY-1)]*nmuons;
279 const double s00 = fSigma[ix][iy]*sqrtn;
280 const double s01 = fSigma[ix][min(iy+1, fNY-1)]*sqrtn;
281 const double s10 = fSigma[min(ix+1, fNX-1)][iy]*sqrtn;
282 const double s11 = fSigma[min(ix+1, fNX-1)][min(iy+1, fNY-1)]*sqrtn;
283 const double p00 = EvaluateCdf(v00,s00*z+m00, m00, s00);
284 const double p01 = EvaluateCdf(v01,s01*z+m01, m01, s01);
285 const double p10 = EvaluateCdf(v10,s10*z+m10, m10, s10);
286 const double p11 = EvaluateCdf(v11,s11*z+m11, m11, s11);
287 return (1.0-zx)*(1.0-zy)*p00
294 const double m =
Mean(theta, r, nmuons);
295 const double s = StDev(theta, r, nmuons);
309 Trafo(ix,zx,theta,fNX,fX,fDX);
310 Trafo(iy,zy,log10(r),fNY,fY,fDY);
312 return ((1.0-zx)*(1.0-zy)*fMean[ix ][iy ]
313 +(1.0-zx)* zy *fMean[ix ][min(iy+1, fNY-1)]
314 + zx *(1.0-zy)*fMean[min(ix+1, fNX-1)][iy ]
315 + zx * zy *fMean[min(ix+1, fNX-1)][min(iy+1, fNY-1)])*nmuons;
327 Trafo(ix,zx,theta,fNX,fX,fDX);
328 Trafo(iy,zy,log10(r),fNY,fY,fDY);
330 return ((1.0-zx)*(1.0-zy)*fSigma[ix ][iy ]
331 +(1.0-zx)* zy *fSigma[ix ][min(iy+1, fNY-1)]
332 + zx *(1.0-zy)*fSigma[min(ix+1, fNX-1)][iy ]
333 + zx * zy *fSigma[min(ix+1, fNX-1)][min(iy+1, fNY-1)])*
sqrt(nmuons);
virtual double StDev(const double theta, const double r, const ulong muons) const
Standard deviation of signal, given fixed number of muons.
virtual double PDF(const double signal, const double theta, const double r, const ulong muons) const
PDF of signal, given a fixed number of muons.
virtual double CDF(const double threshold, const double theta, const double r, const ulong muons) const
Probability of signal begin smaller than smax, given a fixed number of muons.
std::map< std::string, std::string > AttributeMap
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
double NormalPDF(const double x)
double NormalCDF(const double x)
Branch GetTopBranch() const
Get the top Branch (represents same entity as document node)
Branch GetNextSibling() const
Get next sibling of this branch.
Utility for parsing XML files.
Class representing a document branch.
void GetData(bool &b) const
Overloads of the GetData member template function.
static TankResponse & GetInstance(const utl::Branch branch)
virtual double Mean(const double theta, const double r, const ulong muons) const
Average signal, given fixed number of muons.
Branch GetFirstChild() const
Get first child of this Branch.
double Mean(const std::vector< double > &v)