Warning, file /include/Geant4/G4ParamExpTwoBodyAngDst.icc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifndef G4ParamExpTwoBodyAngDst_icc
0037 #define G4ParamExpTwoBodyAngDst_icc 1
0038
0039 #include "G4Log.hh"
0040 #include "G4Exp.hh"
0041 #include "Randomize.hh"
0042 #include <cfloat>
0043
0044
0045 template <G4int NKEBINS> G4double
0046 G4ParamExpTwoBodyAngDst<NKEBINS>::
0047 GetCosTheta(const G4double& ekin, const G4double& pcm) const
0048 {
0049 if (verboseLevel>3) {
0050 G4cout << theName << "::GetCosTheta: ekin " << ekin << " pcm " << pcm
0051 << G4endl;
0052 }
0053
0054
0055 G4double pA = interpolator.interpolate(ekin, smallScale);
0056 G4double pC = interpolator.interpolate(ekin, largeScale);
0057 G4double pCos = interpolator.interpolate(ekin, cosScale);
0058 G4double pFrac = interpolator.interpolate(ekin, angleCut);
0059
0060
0061 pCos = std::max(-1., std::min(pCos,1.));
0062 pFrac = std::max(0., std::min(pFrac,1.));
0063
0064 if (verboseLevel>3) {
0065 G4cout << " pFrac " << pFrac << " pA " << pA << " pC " << pC
0066 << " pCos " << pCos << G4endl;
0067 }
0068
0069 G4bool smallAngle = (G4UniformRand() < pFrac);
0070
0071 G4double term1 = 2.0 * pcm*pcm * (smallAngle ? pA : pC);
0072
0073 if (std::abs(term1) < 1e-7) return 1.0;
0074 if (term1 > DBL_MAX_EXP) return 1.0;
0075
0076 G4double term2 = G4Exp(-2.0*term1);
0077 G4double randScale = (G4Exp(-term1*(1.0 - pCos)) - term2)/(1.0 - term2);
0078
0079 G4double randVal;
0080 if (smallAngle) randVal = (1.0 - randScale)*G4UniformRand() + randScale;
0081 else randVal = randScale*G4UniformRand();
0082
0083 G4double costh = 1.0 + G4Log(randVal*(1.0 - term2) + term2)/term1;
0084
0085 if (verboseLevel>3) {
0086 G4cout << " term1 " << term1 << " term2 " << term2 << " randVal "
0087 << randVal << " => costheta " << costh << G4endl;
0088 }
0089
0090 return costh;
0091 }
0092
0093 #endif