3 #include <utl/RandomEngine.h>
4 #include <utl/TabulatedFunction.h>
5 #include <utl/RandomSamplerFromPDF.h>
6 #include <utl/PhysicalConstants.h>
7 #include <utl/PhysicalFunctions.h>
34 const bool flagAngularFactorDa_in) :
35 fRandomEngine(randomEngine),
37 fCosTheta(cos(theta)),
40 flagAngularFactorDa(flagAngularFactorDa_in),
41 flagDecayFactor(false),
42 fGRDGeometricalLogtDist(0),
43 fGRDKinematicalLogtDist(0),
44 fGeometricalLogtDist(0),
45 fKinematicalLogtDist(0),
58 const bool flagAngularFactorDa_in,
59 const bool flagDecayFactor_in) :
60 fRandomEngine(randomEngine),
62 fCosTheta(cos(theta)),
63 flagAngularFactorDa(flagAngularFactorDa_in),
64 flagDecayFactor(flagDecayFactor_in),
65 fGRDGeometricalLogtDist(0),
66 fGRDKinematicalLogtDist(0),
67 fGeometricalLogtDist(0),
68 fKinematicalLogtDist(0),
76 sumXW += (*fLogzDist)[iBin].Y() * (*fLogzDist)[iBin].X();
77 sumW += (*fLogzDist)[iBin].Y();
109 cout.setf(ios_base::fixed);
111 "*******************************\n"
112 "* MODEL CONSTANTS *\n"
113 "*******************************\n"
115 << setw(5) << setprecision(2)
116 <<
fgPk*1000 <<
" GeV/km *\n"
118 << setw(5) << setprecision(1)
121 << setw(5) << setprecision(1)
124 << setw(5) << setprecision(1)
127 << setw(5) << setprecision(2)
129 "*******************************\n"
131 "*******************************\n"
132 "* SHOWER CONSTANTS *\n"
133 "*******************************\n"
135 << setw(5) << setprecision(1)
137 "*******************************\n"
139 "*******************************\n"
140 "* dN/d log10(z/m) *\n"
141 "*******************************\n";
143 const double cosTheta = cos(
fTheta);
144 cout <<
"* logMean /m "
145 << setw(5) << setprecision(3)
149 << setw(5) << setprecision(3)
153 << setw(5) << setprecision(3)
157 cout <<
"* User Defined function *\n"
159 << setw(5) << setprecision(3) << log10(
fzMean) <<
" *\n";
161 cout <<
"*******************************\n";
163 cout <<
"* D(a)=1 *\n";
165 cout <<
"* D(a)=cos(a)+Delta/L *\n";
166 cout <<
"*******************************\n"
168 "*******************************\n"
170 "*******************************\n"
172 << setw(10) << setprecision(1)
175 << setw(5) << setprecision(1)
177 "*******************************" << endl;
202 const double L =
L_Z(Z);
203 const double cosa2 = 1 - (
fR*
fR) / (L*L);
229 if (logz < fLogzDist->XFront() ||
239 if (logLambda <= 0) {
240 const double e = (logz - logMean) / logSigma;
241 static double sqrt2pi = 2.50662827463100024;
242 return exp(-0.5*e*e) / (logSigma*sqrt2pi);
245 const double norm = 1;
246 const double s2 =
sqrt(2.);
248 const double f1 = (logz - logMean) / logLambda;
249 const double f2 = 0.5 * (logSigma*logSigma) / (logLambda*logLambda);
250 const double f3 = (logz - logMean) / (s2*logSigma);
251 const double f4 = logSigma / (s2*logLambda);
253 return norm * exp(f1 + f2) *
ErrFC(f3 + f4) / (2*logLambda);
262 return 1 / (z*log(10.)) *
dNdlogz(log10(z));
269 const double Z =
Z_t(t);
280 const double t =
pow(10, logt);
281 return t * log(10.) *
g_t(t);
300 return 0.5 * fgPk * x /
310 if (E <
fgPk*x || x <= 0 || fR >= x)
323 const double E =
pow(10, logE);
324 return E * log(10.) *
dNdE(E, x);
342 const double t =
pow(10, logt);
343 return t * log(10.) *
e_t(t);
411 double t_first = 1e25;
412 for (
int i = 0; i < n; ++i) {
429 double t_first = 1e25;
430 for (
int i = 0; i < n; ++i) {
449 for (
int i = 0; i < n; ++i) {
467 for (
int i = 0; i < n; ++i) {
488 for (
int i = 0; i <n; ++i) {
511 for (
int i = 0; i <
stats; ++i) {
517 mean_t1 = t1sum /
stats;
518 rms_t1 =
sqrt(t1sum2/stats - mean_t1*mean_t1);
534 const double tmin = 0;
540 const double h = (tmax - tmin) / n;
542 double t_i = tmin + 0.5*h;
544 for (
int i = 0; i < n; ++i) {
545 sum +=
g_t(t - t_i) *
e_t(t_i);
556 const double t =
pow(10, logt);
583 cerr <<
"x less than 0 in routine gser" << endl;
589 for (
int n = 1; n <=
kITMAX; ++n) {
593 if (fabs(del) < fabs(sum)*
kEPS) {
594 gamser = sum * exp(-x + a*log(x) - gln);
598 cerr <<
"a too large, ITMAX too small in routine gser" << endl;
618 double b = x + 1 -
a;
624 for (i = 1; i <=
kITMAX; ++i) {
625 const double an = i * (a - i);
634 const double del = d*
c;
636 if (fabs(del - 1) <
kEPS)
640 cerr <<
"a too large, ITMAX too small in gcf" << endl;
642 gammcf = exp(-x + a*log(x) - gln) * h;
657 cerr <<
"gammp: Invalid arguments in x,a="
658 << x <<
' ' << a << endl;
683 cerr <<
"Invalid arguments in routine gammq" << endl;
utl::TabulatedFunction * fLogzDist
unsigned int GetNPoints() const
static const double fgKappa
void GetFirstAndMeanTime(double &t_first, double &t_mean, const int n=1)
double dNdz(const double z)
double e_logt(const double logt)
static double ErrF(const double)
utl::VRandomSampler * fGRDKinematicalLogtDist
ArrayConstReference XBack() const
read-only reference to back of array of X
RandomEngineType & GetEngine()
double GetParametricLogLambda(const double cosTheta, const double, const int) const
static void gcf(double &, const double, const double, double &)
Class to hold collection (x,y) points and provide interpolation between them.
double GetParametricLogSigma(const double cosTheta, const double, const int) const
static const double fgLambda
double dEdt(double t, double x)
MuonTimeModel(utl::RandomEngine &randomEngine, const double theta=0, const double logE=19, const int primary=1, const bool flagAngularFactorDa_in=true)
double dNdE(double E, double x)
void PushBack(const double x, const double y)
double pow(const double x, const unsigned int i)
double shoot(HepEngine &engine) const
Method to shoot random values using a given engine by-passing the static generator.
utl::VRandomSampler * fGRDGeometricalLogtDist
utl::RandomEngine & fRandomEngine
double GetMeanTime(const int n=1)
double GetLastTime(const int n=1)
double LogGamma(const double x)
double dNdlogz(double logz)
static const double fgGamma
static double ErrFC(const double x)
double g_logt(const double logt)
double GetParametricLogMean(const double cosTheta, const double, const int) const
Wraps the random number engine used to generate distributions.
static double GammaQ(const double, const double)
double GetFirstTime(const int n=1)
utl::TabulatedFunction * fKinematicalLogtDist
utl::TabulatedFunction * fGeometricalLogtDist
double TotaldNdt(const double t)
double L_Z(const double z) const
constexpr double kSpeedOfLight
double TotaldNdlogt(const double logt)
double dNdlogE(double logE, double x)
double GetTimes(const int n, double *const at)
void GetMeanAndRMSOfFirstTime(double &mean_t1, double &rms_t1, const int n=1, const int stats=1000)
static void gser(double &, const double, const double, double &)
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
double E(double t, double x)
static double GammaP(const double, const double)
double DecayFactor_Z(double Z)
void SetCoordinates(const double r, const double zeta)