10 using namespace Physics;
 
   25                                     const double &cosTheta,
 
   36                                     const double &vVThermal,
 
   37                                     const bool nEmissionMode) {
 
   40     double prob[11] = {0};
 
   41     std::vector<Vector_t> se_P;
 
   42     setSeMaterial(matNumber);
 
   43     seyNum=calcProb(incEnergy, cosTheta, prob);
 
   44     calcEmiNum(incEnergy, cosTheta, prob, seNum);
 
   58     double f_max=vw/vt*
exp(-0.5);
 
   60     double test_asq=test_a*test_a;
 
   68             for(
int i = 0; i < seNum; i++) {
 
   72                 double temp = 1.0 / (1.0 + seAlpha_m);
 
   73                 emiTheta[i] = 
acos(
pow(tmp1, temp));
 
   95                     f_x=test_x/test_asq*
exp(-test_x*test_x/2/test_asq);
 
   97                 double v_emi=test_x*vw;
 
  106                 double temp = incEnergy / seEpsn_m[0];
 
  107                 double p0 = gammp(sePn_m[0], temp);
 
  109                 Eemit[0] = seEpsn_m[0] * invgammp(temp, sePn_m[0]) ;
 
  117     } 
else if(seNum == 1) {
 
  129                 f_x=test_x/test_asq*
exp(-test_x*test_x/2/test_asq);
 
  131             double v_emi=test_x*vw;
 
  139             double tmp = prob[1] + deltae_m + deltar_m;
 
  141             double ae = deltae_m / tmp;
 
  143             double ar = deltar_m / tmp;
 
  144             double a_re = ae + ar;
 
  151                     Eemit[0] = incEnergy - seDelta_m * 
fabs(gaussRand()) ;
 
  153                 } 
while(Eemit[0] < 0&&t_count<200);
 
  158             } 
else if(urand >= ae && urand < a_re) {
 
  161                 double powArg = 1.0 / (1.0 + seQ_m);
 
  162                 Eemit[0] = incEnergy * 
pow(u1, powArg);
 
  170                 double temp = incEnergy / seEpsn_m[0];
 
  171                 double p0 = gammp(sePn_m[0], temp);
 
  173                 Eemit[0] = seEpsn_m[0] * invgammp(temp, sePn_m[0]) ;
 
  184             if (!nEmissionMode) {
 
  198                     f_x=test_x/test_asq*
exp(-test_x*test_x/2/test_asq);
 
  200                 double v_emi=test_x*vw;
 
  205                 for(
int i = 0; i < seNum; i++) {
 
  214                         f_x=test_x/test_asq*
exp(-test_x*test_x/2/test_asq);
 
  216                     double v_emi=test_x*vw;
 
  226             double x0 = incEnergy / seEpsn_m[seNum-1];
 
  227             double parg = seNum * sePn_m[seNum-1];
 
  228             double p0 =  gammp(parg, x0);
 
  229             double sin2theta_n[seNum];
 
  230             double cos2theta_n[seNum];
 
  232             double invarg = rand_y * p0;
 
  233             double y2 = invgammp(invarg, parg);
 
  235             double multisin = 1.0;
 
  237             if (!nEmissionMode) {
 
  239                 double Eemisum = 0.0;
 
  240                 for(
int i = 0; i < seNum - 1; i++) {
 
  241                     double mu = sePn_m[seNum-1] * (seNum  - i);
 
  242                     double nu =  sePn_m[seNum-1];
 
  244                     sin2theta_n[i] = invbetai(rand_n, mu, nu);
 
  245                     cos2theta_n[i] = 1.0 - sin2theta_n[i];
 
  248                         multisin *=  sin2theta_n[i-1];
 
  250                     y2_n[i] = y2 *  multisin * cos2theta_n[i];
 
  251                     Eemit[i] = seEpsn_m[seNum-1] * y2_n[i];
 
  257                 Eemit[seNum-1] = Eemit[seNum-2] / cos2theta_n[seNum-2] * sin2theta_n[seNum-2];
 
  258                 Eemisum += Eemit[seNum-1];
 
  260                 Eemit[0] = Eemisum/seNum;
 
  263                 for(
int i = 0; i < seNum - 1; i++) {
 
  264                     double mu = sePn_m[seNum-1] * (seNum  - i);
 
  265                     double nu =  sePn_m[seNum-1];
 
  267                     sin2theta_n[i] = invbetai(rand_n, mu, nu);
 
  268                     cos2theta_n[i] = 1.0 - sin2theta_n[i];
 
  271                         multisin *=  sin2theta_n[i-1];
 
  273                     y2_n[i] = y2 *  multisin * cos2theta_n[i];
 
  274                     Eemit[i] = seEpsn_m[seNum-1] * y2_n[i];
 
  279                 Eemit[seNum-1] = Eemit[seNum-2] / cos2theta_n[seNum-2] * sin2theta_n[seNum-2];
 
  288     Vector_t x_unit = localX - interCoords_l;
 
  289     double tmp = 
sqrt(
dot(x_unit,x_unit));
 
  294     if (!nEmissionMode) {
 
  296         double gamma_const = Eemit[0] / 
Physics::m_e/1.0e9 + 1.0;
 
  297         double beta_const = 
sqrt(1.0 - 1.0 / 
pow(gamma_const, 2.0));
 
  298         double P_emitted = gamma_const * beta_const;
 
  305             P_global = P_emitted*TriNorm_l;
 
  309             P_local[2] = P_emitted * 
cos(emiTheta[0]);
 
  310             P_local[1] = P_emitted * 
sin(emiTheta[0]) * 
sin(emiPhi[0]);
 
  311             P_local[0] = P_emitted * 
sin(emiTheta[0]) * 
cos(emiPhi[0]);
 
  312             P_global = P_local[0]*x_unit + P_local[1]*y_unit +  P_local[2]*z_unit;
 
  318         itsBunch->
R[lowMark] = interCoords_l;
 
  320         itsBunch->
P[lowMark] = P_global;
 
  321         itsBunch->
Bin[lowMark] = 0;
 
  323         itsBunch->
TriID[lowMark] = 0;
 
  325         itsBunch->
Q[lowMark] = incQ_l*seyNum;
 
  328         itsBunch->
dt[lowMark] = itsBunch->
getdT();
 
  334         for(
size_t i = 0; i < (size_t) seNum; i++) {
 
  336             double gamma_const = Eemit[i] / 
Physics::m_e/1.0e9 + 1.0;
 
  337             double beta_const = 
sqrt(1.0 - 1.0 / 
pow(gamma_const, 2.0));
 
  338             double P_emitted = gamma_const * beta_const;
 
  345                 P_global = P_emitted*TriNorm_l;
 
  349                 P_local[2] = P_emitted * 
cos(emiTheta[i]);
 
  350                 P_local[1] = P_emitted * 
sin(emiTheta[i]) * 
sin(emiPhi[i]);
 
  351                 P_local[0] = P_emitted * 
sin(emiTheta[i]) * 
cos(emiPhi[i]);
 
  352                 P_global = P_local[0]*x_unit + P_local[1]*y_unit +  P_local[2]*z_unit;
 
  358             itsBunch->
R[lowMark+i] = interCoords_l;
 
  360             itsBunch->
P[lowMark+i] = P_global;
 
  361             itsBunch->
Bin[lowMark+i] = 0;
 
  363             itsBunch->
TriID[lowMark+i] = 0;
 
  364             itsBunch->
Q[lowMark+i] = incQ_l;
 
  367             itsBunch->
dt[lowMark+i] = itsBunch->
getdT();
 
  378                                     const double &cosTheta,
 
  379                                     int &seNum, 
int &seType,
 
  385                                     double &seyNum, 
const double &ppVw,
 
  386                                     const double &vSeyZero,
 
  387                                     const double &vEzero,
 
  388                                     const double &vSeyMax,
 
  390                                     const double &vKenergy,
 
  391                                     const double &vKtheta,
 
  392                                     const double &vVThermal,
 
  393                                     const bool nEmissionMode)
 
  399     std::vector<Vector_t> se_P;
 
  400     calcEmiNum(incEnergy, cosTheta, seNum, vSeyZero, vEzero, vSeyMax, vEmax, vKenergy, vKtheta, seyNum);
 
  402     double emiTheta[seNum];
 
  403     double emiPhi[seNum];
 
  404     Vector_t interCoords_l = inteCoords;
 
  412         f_max=vw/vt*
exp(-0.5);
 
  415         test_asq=test_a*test_a;
 
  418         test_asq=test_a*test_a;
 
  419         f_max= 1.0/test_a*
exp(-1.0);
 
  423     double incQ_l = incQ;
 
  428         if (!nEmissionMode) {
 
  432             double seAlpha = 1.0;
 
  433             double temp = 1.0 / (1.0 + seAlpha);
 
  434             emiTheta[0] = 
acos(
pow(tmp1, temp));
 
  440             for(
int i = 0; i < seNum; i++) {
 
  444                 double seAlpha = 1.0;
 
  445                 double temp = 1.0 / (1.0 + seAlpha);
 
  446                 emiTheta[i] = 
acos(
pow(tmp1, temp));
 
  455         if (!nEmissionMode) {
 
  465                     f_x=test_x/test_asq*
exp(-test_x*test_x/2/test_asq);
 
  467                 double v_emi=test_x*vw;
 
  478                     f_x=test_x/test_asq*
exp(-test_x/test_a);
 
  492         if (!nEmissionMode) {
 
  502                     f_x=test_x/test_asq*
exp(-test_x*test_x/2/test_asq);
 
  504                 double v_emi=test_x*vw;
 
  515                     f_x=test_x/test_asq*
exp(-test_x/test_a);
 
  527                 for(
int i = 0; i < seNum; i++) {
 
  536                         f_x=test_x/test_asq*
exp(-test_x*test_x/2/test_asq);
 
  538                     double v_emi=test_x*vw;
 
  545                 for(
int i = 0; i < seNum; i++) {
 
  554                         f_x=test_x/test_asq*
exp(-test_x/test_a);
 
  564     Vector_t x_unit = localX - interCoords_l;
 
  565     double tmp = 
sqrt(
dot(x_unit,x_unit));
 
  570     if (!nEmissionMode) {
 
  571         double gamma_const = Eemit[0] / 
Physics::m_e/1.0e9 + 1.0;
 
  572         double beta_const = 
sqrt(1.0 - 1.0 / 
pow(gamma_const, 2.0));
 
  573         double P_emitted = gamma_const * beta_const;
 
  580             P_global = P_emitted*TriNorm_l;
 
  584             P_local[2] = P_emitted * 
cos(emiTheta[0]);
 
  585             P_local[1] = P_emitted * 
sin(emiTheta[0]) * 
sin(emiPhi[0]);
 
  586             P_local[0] = P_emitted * 
sin(emiTheta[0]) * 
cos(emiPhi[0]);
 
  587             P_global = P_local[0]*x_unit + P_local[1]*y_unit +  P_local[2]*z_unit;
 
  592         itsBunch->
R[lowMark] = interCoords_l;
 
  593         itsBunch->
P[lowMark] = P_global;
 
  594         itsBunch->
Bin[lowMark] = 0;
 
  596         itsBunch->
TriID[lowMark] = 0;
 
  597         itsBunch->
Q[lowMark] = incQ_l*seyNum;
 
  600         itsBunch->
dt[lowMark] = itsBunch->
getdT();
 
  603         for(
size_t i = 0; i < (size_t) seNum; i++) {
 
  605             double gamma_const = Eemit[i] / 
Physics::m_e/1.0e9 + 1.0;
 
  606             double beta_const = 
sqrt(1.0 - 1.0 / 
pow(gamma_const, 2.0));
 
  607             double P_emitted = gamma_const * beta_const;
 
  614                 P_global = P_emitted*TriNorm_l;
 
  618                 P_local[2] = P_emitted * 
cos(emiTheta[i]);
 
  619                 P_local[1] = P_emitted * 
sin(emiTheta[i]) * 
sin(emiPhi[i]);
 
  620                 P_local[0] = P_emitted * 
sin(emiTheta[i]) * 
cos(emiPhi[i]);
 
  621                 P_global = P_local[0]*x_unit + P_local[1]*y_unit +  P_local[2]*z_unit;
 
  626             itsBunch->
R[lowMark+i] = interCoords_l;
 
  628             itsBunch->
P[lowMark+i] = P_global;
 
  629             itsBunch->
Bin[lowMark+i] = 0;
 
  631             itsBunch->
TriID[lowMark+i] = 0;
 
  632             itsBunch->
Q[lowMark+i] = incQ_l;
 
  635             itsBunch->
dt[lowMark+i] = itsBunch->
getdT();
 
  646                                           const double cosTheta,
 
  648                                           const double &vSeyZero,
 
  649                                           const double &vEzero,
 
  650                                           const double &vSeyMax,
 
  652                                           const double &vKenergy,
 
  653                                           const double &vKtheta,
 
  658     if (incEnergy<vEzero) {
 
  662         double theta = 
acos(cosTheta);
 
  666         double v = (incEnergy-vEzero)/(E_max-vEzero);
 
  671                 vSEY = delta_max*
pow(v*
exp(1.0-v),0.56);
 
  673                 vSEY = delta_max*
pow(v*
exp(1.0-v),0.25);
 
  677             vSEY = delta_max*1.125/
pow(v,0.35);
 
  681     double L = 
exp(-vSEY);
 
  697     double prob_max = 0.0;
 
  700     for(
int i = 0; i < 11; i++) {
 
  702         if(prob[i] > prob_max) {
 
  713         seNum = (int)(rand1 * 11.0);
 
  717         pY = prob_max * rand2;
 
  725     double seypeak = seYPeakTS_m * (1 + seTOneTS_m * (1.0 - 
pow(cosTheta, seTTwoTS_m))); 
 
  726     double seepeak = seEPeakTS_m * (1 + seTThreeTS_m * (1.0 - 
pow(cosTheta, seTFourTS_m))); 
 
  727     double tmpx = incEnergy / seepeak;
 
  728     double tmpD = seSTS_m * tmpx / (seSTS_m - 1 + 
pow(tmpx, seSTS_m)); 
 
  729     double ret = seypeak * tmpD; 
 
  736     double tmp = 
pow(incEnergy / seERed_m, seR_m);
 
  737     double ret = sePRed_m * (1.0 - 
exp(-1 * tmp)); 
 
  738     ret = ret * (1.0 + seROne_m * (1.0 - 
pow(cosTheta, seRTwo_m))); 
 
  746     double tmp = 
pow(
std::abs(incEnergy - seEScatPeak_m) / seW_m, seP_m) / seP_m;
 
  747     double ret = sePScat_m + (sePScatPeak_m - sePScat_m) * 
exp(-1 * tmp); 
 
  748     ret = ret * (1.0 + seEOne_m * (1.0 - 
pow(cosTheta, seETwo_m))); 
 
  756     deltae_m = calcDeltae(incEnergy, cosTheta);
 
  757     deltar_m = calcDeltar(incEnergy, cosTheta);
 
  758     deltats_m = calcDeltats(incEnergy, cosTheta);
 
  760     double tmp = 1.0 - deltae_m - deltar_m;
 
  761     double p = deltats_m / tmp / 10.0;
 
  775     for(
int i = 0; i < 11; i++) {
 
  776         prob[i] = tmp * b[i] * 
pow(p, i) * 
pow(q, (10 - i));
 
  778     prob[1] = prob[1] + deltae_m + deltar_m;
 
  782     return (deltae_m+deltar_m+deltats_m);
 
  789     if(material_num == 0) {
 
  792         sePScatPeak_m = 0.496;
 
  807         seYPeakTS_m = 1.8848;
 
  837     if(material_num == 1) {
 
  905         w = x1 * x1 + x2 * x2;
 
  916     static const int ASWITCH = 100; 
 
  917     if(x < 0.0 || a <= 0.0)
 
  918         throw(
"bad args in gammp");
 
  921     else if((
int)a >= ASWITCH)
 
  922         return gammpapprox(a, x, 1); 
 
  926         return 1.0 - gcf(a, x); 
 
  933     double gln = gammln(a);
 
  941             return sum * 
exp(-x + a * 
log(x) - gln);
 
  949     double an, b, 
c, d, del, h;
 
  950     double gln = gammln(a);
 
  968     return exp(-x + a * 
log(x) - gln) * h; 
 
  974     const double y[18] = {0.0021695375159141994,
 
  975                           0.011413521097787704, 0.027972308950302116, 0.051727015600492421,
 
  976                           0.082502225484340941, 0.12007019910960293, 0.16415283300752470,
 
  977                           0.21442376986779355, 0.27051082840644336, 0.33199876341447887,
 
  978                           0.39843234186401943, 0.46931971407375483, 0.54413605556657973,
 
  979                           0.62232745288031077, 0.70331500465597174, 0.78649910768313447,
 
  980                           0.87126389619061517, 0.95698180152629142
 
  982     const double w[18] = {0.0055657196642445571,
 
  983                           0.012915947284065419, 0.020181515297735382, 0.027298621498568734,
 
  984                           0.034213810770299537, 0.040875750923643261, 0.047235083490265582,
 
  985                           0.053244713977759692, 0.058860144245324798, 0.064039797355015485,
 
  986                           0.068745323835736408, 0.072941885005653087, 0.076598410645870640,
 
  987                           0.079687828912071670, 0.082187266704339706, 0.084078218979661945,
 
  988                           0.085346685739338721, 0.085983275670394821
 
  991     double xu, t, 
sum, ans;
 
  992     double a1 = a - 1.0, lna1 = 
log(a1), sqrta1 = 
sqrt(a1);
 
  994     double gln = gammln(a);
 
  995     if(x > a1) xu = max_Gamma(a1 + 11.5 * sqrta1, x + 6.0 * sqrta1);
 
  996     else xu = max_Gamma(0., min_Gamma(a1 - 7.5 * sqrta1, x - 5.0 * sqrta1));
 
  998     for(j = 0; j < ngau; j++) {
 
 1000         t = x + (xu - x) * y[j];
 
 1001         sum += w[j] * 
exp(-(t - a1) + a1 * (
log(t) - lna1));
 
 1003     ans = sum * (xu - x) * 
exp(a1 * (lna1 - 1.) - gln);
 
 1004     return (psig ? (ans > 0.0 ? 1.0 - ans : -ans) : (ans >= 0.0 ? ans : 1.0 + ans));
 
 1010     double x, tmp, y, ser;
 
 1011     static const double cof[14] = {57.1562356658629235, -59.5979603554754912,
 
 1012                                    14.1360979747417471, -0.491913816097620199, .339946499848118887e-4,
 
 1013                                    .465236289270485756e-4, -.983744753048795646e-4, .158088703224912494e-3,
 
 1014                                    -.210264441724104883e-3, .217439618115212643e-3, -.164318106536763890e-3,
 
 1015                                    .844182239838527433e-4, -.261908384015814087e-4, .368991826595316234e-5
 
 1017     if(xx <= 0) 
throw(
"bad arg in gammln");
 
 1019     tmp = x + 5.24218750000000000; 
 
 1020     tmp = (x + 0.5) * 
log(tmp) - tmp;
 
 1021     ser = 0.999999999999997092;
 
 1022     for(j = 0; j < 14; j++) ser += cof[j] / ++y;
 
 1023     return tmp + 
log(2.5066282746310005 * ser / x);
 
 1029     double x, err, t, u, pp, lna1 = 0.0, afac = 0.0, a1 = a - 1;
 
 1030     const double EPS = 1.e-8; 
 
 1031     double gln = gammln(a);
 
 1032     if(a <= 0.) 
throw(
"a must be pos in invgammap");
 
 1033     if(p >= 1.) 
return max_Gamma(100., a + 100.*
sqrt(a));
 
 1034     if(p <= 0.) 
return 0.0;
 
 1038         afac = 
exp(a1 * (lna1 - 1.) - gln);
 
 1039         pp = (p < 0.5) ? p : 1. - p;
 
 1041         x = (2.30753 + t * 0.27061) / (1. + t * (0.99229 + t * 0.04481)) - t;
 
 1043         x = max_Gamma(1.
e-3, a * 
pow(1. - 1. / (9.*a) - x / (3.*
sqrt(a)), 3));
 
 1046         t = 1.0 - a * (0.253 + a * 0.12);
 
 1048         if(p < t) x = 
pow(p / t, 1. / a);
 
 1049         else x = 1. - 
log(1. - (p - t) / (1. - t));
 
 1051     for(j = 0; j < 12; j++) {
 
 1052         if(x <= 0.0) 
return 0.0;
 
 1054         err = gammp(a, x) - p;
 
 1055         if(a > 1.) t = afac * 
exp(-(x - a1) + a1 * (
log(x) - lna1));
 
 1056         else t = 
exp(-x + a1 * 
log(x) - gln);
 
 1058         x -= (t = u / (1. - 0.5 * min_Gamma(1., u * ((a - 1.) / x - 1))));
 
 1060         if(x <= 0.) x = 0.5 * (x + t);
 
 1070     static const int SWITCH = 3000;
 
 1077     if(a <= 0.0 || b <= 0.0) {
 
 1079         throw(
"Bad a or b in routine betai");
 
 1082     if(x < 0.0 || x > 1.0) {
 
 1084         throw(
"Bad x in routine betai");
 
 1087     if(x == 0.0 || x == 1.0) {
 
 1091     if(a > SWITCH && b > SWITCH) {
 
 1093         return betaiapprox(a, b, x);
 
 1095     bt = 
exp(gammln(a + b) - gammln(a) - gammln(b) + a * 
log(x) + b * 
log(1.0 - x));
 
 1096     if(x < (a + 1.0) / (a + b + 2.0)) {
 
 1098         return bt * betacf(a, b, x) / a;
 
 1106         return 1.0 - bt * betacf(b, a, 1.0 - x) / b;
 
 1113     double aa, 
c, d, del, h, qab, qam, qap;
 
 1119     d = 1.0 - qab * x / qap;
 
 1129     for(m = 1; m < 10000; m++) {
 
 1131         aa = m * (b - m) * x / ((qam + m2) * (a + m2));
 
 1140         aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2));
 
 1158     const double y[18] = {0.0021695375159141994,
 
 1159                           0.011413521097787704, 0.027972308950302116, 0.051727015600492421,
 
 1160                           0.082502225484340941, 0.12007019910960293, 0.16415283300752470,
 
 1161                           0.21442376986779355, 0.27051082840644336, 0.33199876341447887,
 
 1162                           0.39843234186401943, 0.46931971407375483, 0.54413605556657973,
 
 1163                           0.62232745288031077, 0.70331500465597174, 0.78649910768313447,
 
 1164                           0.87126389619061517, 0.95698180152629142
 
 1166     const double w[18] = {0.0055657196642445571,
 
 1167                           0.012915947284065419, 0.020181515297735382, 0.027298621498568734,
 
 1168                           0.034213810770299537, 0.040875750923643261, 0.047235083490265582,
 
 1169                           0.053244713977759692, 0.058860144245324798, 0.064039797355015485,
 
 1170                           0.068745323835736408, 0.072941885005653087, 0.076598410645870640,
 
 1171                           0.079687828912071670, 0.082187266704339706, 0.084078218979661945,
 
 1172                           0.085346685739338721, 0.085983275670394821
 
 1175     double xu, t, 
sum, ans;
 
 1176     double a1 = a - 1.0, b1 = b - 1.0, mu = a / (a + b);
 
 1177     double lnmu = 
log(mu), lnmuc = 
log(1. - mu);
 
 1178     t = 
sqrt(a * b / (
sqrt(a + b) * (a + b + 1.0)));
 
 1179     if(x > a / (a + b)) { 
 
 1182         xu = min_Gamma(1., max_Gamma(mu + 10.*t, x + 5.0 * t));
 
 1187         xu = max_Gamma(0., min_Gamma(mu - 10.*t, x - 5.0 * t));
 
 1190     for(j = 0; j < 18; j++) { 
 
 1191         t = x + (xu - x) * y[j];
 
 1192         sum += w[j] * 
exp(a1 * (
log(t) - lnmu) + b1 * (
log(1 - t) - lnmuc));
 
 1194     ans = sum * (xu - x) * 
exp(a1 * lnmu - gammln(a) + b1 * lnmuc - gammln(b) + gammln(a + b));
 
 1195     return ans > 0.0 ? 1.0 - ans : -ans;
 
 1200     const double EPS = 1.e-8;
 
 1201     double pp, t, u, err, x, al, h, w, afac, a1 = a - 1., b1 = b - 1.;
 
 1208     else if(a >= 1. && b >= 1.) { 
 
 1209         pp = (p < 0.5) ? p : 1. - p;
 
 1211         x = (2.30753 + t * 0.27061) / (1. + t * (0.99229 + t * 0.04481)) - t;
 
 1222         al = (
sqrt(x) - 3.) / 6.;
 
 1223         h = 2. / (1. / (2.*a - 1.) + 1. / (2.*b - 1.));
 
 1224         w = (x * 
sqrt(al + h) / h) - (1. / (2.*b - 1) - 1. / (2.*a - 1.)) * (al + 5. / 6. - 2. / (3.*h));
 
 1225         x = a / (a + b * 
exp(2.*w));
 
 1228         double lna = 
log(a / (a + b)), lnb = 
log(b / (a + b));
 
 1229         t = 
exp(a * lna) / a;
 
 1230         u = 
exp(b * lnb) / b;
 
 1233             x = 
pow(a * w * p, 1. / a);
 
 1235             x = 1. - 
pow(b * w * (1. - p), 1. / b);
 
 1237     afac = -gammln(a) - gammln(b) + gammln(a + b);
 
 1238     for(j = 0; j < 10; j++) {
 
 1239         if(x == 0. || x == 1.) 
 
 1241         err = betai(x, a, b) - p;
 
 1247         t = 
exp(a1 * 
log(x) + b1 * 
log(1. - x) + afac);
 
 1249         x -= (t = u / (1. - 0.5 * min_Gamma(1., u * (a1 / x - b1 / (1. - x)))));
 
 1258             x = 0.5 * (x + t + 1.);
 
double invbetai(double p, double a, double b)
ParticleAttrib< Vector_t > P
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
double gammln(const double xx)
PETE_TUTree< FnArcCos, typename T::PETE_Expr_t > acos(const PETE_Expr< T > &l)
double calcProb(const double incEnergy, const double cosTheta, double *prob)
constexpr double e
The value of . 
ParticleAttrib< Vector_t > Ef
double gammpapprox(double a, double x, int psig)
PETE_TUTree< FnFabs, typename T::PETE_Expr_t > fabs(const PETE_Expr< T > &l)
Tps< T > sin(const Tps< T > &x)
Sine. 
SecondaryEmissionPhysics()
ParticleAttrib< double > Q
constexpr double two_pi
The value of . 
Tps< T > exp(const Tps< T > &x)
Exponential. 
RandomNumberGen IpplRandom
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
Tps< T > log(const Tps< T > &x)
Natural logarithm. 
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product. 
constexpr double m_e
The electron rest mass in GeV. 
ParticleAttrib< short > PType
double gammp(const double a, const double x)
double calcDeltae(const double incEnergy, const double cosTheta)
ParticleAttrib< int > TriID
constexpr double c
The velocity of light in m/s. 
Vector3D cross(const Vector3D &lhs, const Vector3D &rhs)
Vector cross product. 
static void startTimer(TimerRef t)
Tps< T > pow(const Tps< T > &x, int y)
Integer power. 
Vektor< double, 3 > Vector_t
double calcDeltar(const double incEnergy, const double cosTheta)
double betacf(const double a, const double b, const double x)
double gcf(const double a, const double x)
size_t getLocalNum() const 
void calcEmiNum(const double incEnergy, const double cosTheta, int &seNum, const double &vSeyZero, const double &vEzero, const double &vSeyMax, const double &vEmax, const double &vKenergy, const double &vKtheta, double &seyNum)
Tps< T > sqrt(const Tps< T > &x)
Square root. 
ParticleAttrib< double > dt
double betaiapprox(double a, double b, double x)
double betai(const double x, const double a, const double b)
double gser(const double a, const double x)
Tps< T > cos(const Tps< T > &x)
Cosine. 
void setSeMaterial(int material_num)
ParticleAttrib< int > Bin
ParticleAttrib< Vector_t > Bf
double calcDeltats(const double incEnergy, const double cosTheta)
double invgammp(double p, double a)
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
bool ppdebug
ppdebug flag. 
void nSec(const double &incEnergy, const double &cosTheta, const int &matNumber, int &seNum, int &seType, const double &incQ, const Vector_t &TriNorm, const Vector_t &inteCoords, const Vector_t &localX, PartBunchBase< double, 3 > *itsBunch, double &seyNum, const double &ppVw, const double &vVThermal, const bool nEmissionMode)
~SecondaryEmissionPhysics()