Geant4-11
G4ParamExpTwoBodyAngDst.icc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// Author: Michael Kelsey (SLAC)
27// Date: 20 February 2013
28//
29// Description: implementation base for exponential parametrization of
30// two-body angular distributions in Bertini-style cascade
31//
32// 20130227 Renamed from "Barashenkov" to "ParamExp" to fix misattribution.
33// 20130620 Fix Coverity #50296, recursive #include.
34// 20130924 M. Kelsey -- Use G4Log, G4Exp for CPU speedup
35
36#ifndef G4ParamExpTwoBodyAngDst_icc
37#define G4ParamExpTwoBodyAngDst_icc 1
38
39#include "G4Log.hh"
40#include "G4Exp.hh"
41#include "Randomize.hh"
42#include <cfloat>
43
44
45template <G4int NKEBINS> G4double
46G4ParamExpTwoBodyAngDst<NKEBINS>::
47GetCosTheta(const G4double& ekin, const G4double& pcm) const
48{
49 if (verboseLevel>3) {
50 G4cout << theName << "::GetCosTheta: ekin " << ekin << " pcm " << pcm
51 << G4endl;
52 }
53
54 // Get parameter values for interaction energy
55 G4double pA = interpolator.interpolate(ekin, smallScale);
56 G4double pC = interpolator.interpolate(ekin, largeScale);
57 G4double pCos = interpolator.interpolate(ekin, cosScale);
58 G4double pFrac = interpolator.interpolate(ekin, angleCut);
59
60 // Bound parameters by their physical ranges
61 pCos = std::max(-1., std::min(pCos,1.));
62 pFrac = std::max(0., std::min(pFrac,1.));
63
64 if (verboseLevel>3) {
65 G4cout << " pFrac " << pFrac << " pA " << pA << " pC " << pC
66 << " pCos " << pCos << G4endl;
67 }
68
69 G4bool smallAngle = (G4UniformRand() < pFrac); // 0 < theta < theta0
70
71 G4double term1 = 2.0 * pcm*pcm * (smallAngle ? pA : pC);
72
73 if (std::abs(term1) < 1e-7) return 1.0; // No actual scattering here!
74 if (term1 > DBL_MAX_EXP) return 1.0;
75
76 G4double term2 = G4Exp(-2.0*term1);
77 G4double randScale = (G4Exp(-term1*(1.0 - pCos)) - term2)/(1.0 - term2);
78
79 G4double randVal;
80 if (smallAngle) randVal = (1.0 - randScale)*G4UniformRand() + randScale;
81 else randVal = randScale*G4UniformRand();
82
83 G4double costh = 1.0 + G4Log(randVal*(1.0 - term2) + term2)/term1;
84
85 if (verboseLevel>3) {
86 G4cout << " term1 " << term1 << " term2 " << term2 << " randVal "
87 << randVal << " => costheta " << costh << G4endl;
88 }
89
90 return costh;
91}
92
93#endif /* G4ParamExpTwoBodyAngDst_icc */