Geant4  10.02.p01
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 // $Id: G4ParamExpTwoBodyAngDst.icc 71719 2013-06-21 00:01:54Z mkelsey $
27 // Author: Michael Kelsey (SLAC)
28 // Date: 20 February 2013
29 //
30 // Description: implementation base for exponential parametrization of
31 // two-body angular distributions in Bertini-style cascade
32 //
33 // 20130227 Renamed from "Barashenkov" to "ParamExp" to fix misattribution.
34 // 20130620 Fix Coverity #50296, recursive #include.
35 // 20130924 M. Kelsey -- Use G4Log, G4Exp for CPU speedup
36 
37 #ifndef G4ParamExpTwoBodyAngDst_icc
38 #define G4ParamExpTwoBodyAngDst_icc 1
39 
40 #include "G4Log.hh"
41 #include "G4Exp.hh"
42 #include "Randomize.hh"
43 #include <cfloat>
44 
45 
46 template <G4int NKEBINS> G4double
47 G4ParamExpTwoBodyAngDst<NKEBINS>::
48 GetCosTheta(const G4double& ekin, const G4double& pcm) const
49 {
50  if (verboseLevel>3) {
51  G4cout << theName << "::GetCosTheta: ekin " << ekin << " pcm " << pcm
52  << G4endl;
53  }
54 
55  // Get parameter values for interaction energy
56  G4double pA = interpolator.interpolate(ekin, smallScale);
57  G4double pC = interpolator.interpolate(ekin, largeScale);
58  G4double pCos = interpolator.interpolate(ekin, cosScale);
59  G4double pFrac = interpolator.interpolate(ekin, angleCut);
60 
61  // Bound parameters by their physical ranges
62  pCos = std::max(-1., std::min(pCos,1.));
63  pFrac = std::max(0., std::min(pFrac,1.));
64 
65  if (verboseLevel>3) {
66  G4cout << " pFrac " << pFrac << " pA " << pA << " pC " << pC
67  << " pCos " << pCos << G4endl;
68  }
69 
70  G4bool smallAngle = (G4UniformRand() < pFrac); // 0 < theta < theta0
71 
72  G4double term1 = 2.0 * pcm*pcm * (smallAngle ? pA : pC);
73 
74  if (std::abs(term1) < 1e-7) return 1.0; // No actual scattering here!
75  if (term1 > DBL_MAX_EXP) return 1.0;
76 
77  G4double term2 = G4Exp(-2.0*term1);
78  G4double randScale = (G4Exp(-term1*(1.0 - pCos)) - term2)/(1.0 - term2);
79 
80  G4double randVal;
81  if (smallAngle) randVal = (1.0 - randScale)*G4UniformRand() + randScale;
82  else randVal = randScale*G4UniformRand();
83 
84  G4double costh = 1.0 + G4Log(randVal*(1.0 - term2) + term2)/term1;
85 
86  if (verboseLevel>3) {
87  G4cout << " term1 " << term1 << " term2 " << term2 << " randVal "
88  << randVal << " => costheta " << costh << G4endl;
89  }
90 
91  return costh;
92 }
93 
94 #endif /* G4ParamExpTwoBodyAngDst_icc */