Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4InuclSpecialFunctions.cc
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: G4InuclSpecialFunctions.cc 68163 2013-03-15 20:11:44Z mkelsey $
27 //
28 // 20100114 M. Kelsey -- Remove G4CascadeMomentum, use G4LorentzVector directly
29 // 20100914 M. Kelsey -- Migrate to integer A and Z. Discard pointless
30 // verbosity.
31 // 20120608 M. Kelsey -- Fix variable-name "shadowing" compiler warnings.
32 // 20130308 M. Kelsey -- New function to compute INUCL-style random value
33 // 20130314 M. Kelsey -- Restore null initializer and if-block for _TLS_.
34 // 20130924 M. Kelsey -- Use G4Log, G4Exp, G4Pow for CPU speedup
35 
36 #include <cmath>
37 
39 #include "G4PhysicalConstants.hh"
40 #include "G4LorentzVector.hh"
41 #include "G4ThreeVector.hh"
42 #include "G4Log.hh"
43 #include "G4Exp.hh"
44 #include "G4Pow.hh"
45 #include "Randomize.hh"
46 
47 
48 // Compute power series in random value, with powers-of-Ekin coeffciences
49 
50 G4double
52  const G4double (&coeff)[4][4]) {
53  G4Pow* theG4Pow = G4Pow::GetInstance();
54 
55  G4double S = G4UniformRand(); // Random fraction for expansion
56 
57  G4double C, V;
58  G4double PQ=0., PR=0.;
59  for (G4int i=0; i<4; i++) {
60  V = 0.0;
61  for (G4int k=0; k<4; k++) {
62  C = coeff[i][k];
63  V += C * theG4Pow->powN(ekin, k);
64  }
65 
66  PQ += V;
67  PR += V * theG4Pow->powN(S, i);
68  }
69 
70  return std::sqrt(S) * (PR + (1-PQ)*(S*S*S*S));
71 }
72 
73 
74 
76  return 0.76 + 2.2 / G4cbrt(A);
77 }
78 
80  G4double snn;
81 
82  if (e < 40.0) {
83  snn = -1174.8 / (e * e) + 3088.5 / e + 5.3107;
84  } else {
85  snn = 93074.0 / (e * e) - 11.148 / e + 22.429;
86  }
87 
88  return snn;
89 }
90 
92  G4double spn;
93 
94  if (e < 40.0) {
95  spn = -5057.4 / (e * e) + 9069.2 / e + 6.9466;
96  } else {
97  spn = 239380.0 / (e * e) + 1802.0 / e + 27.147;
98  }
99 
100  return spn;
101 }
102 
103 // calculates the nuclei Fermi energy for 0 - neutron and 1 - proton
104 
106  const G4double C = 55.4;
107  G4double arg = (ntype==0) ? G4double(A-Z)/A : G4double(Z)/A;
108 
109  return C * G4cbrt(arg*arg); // 2/3 power
110 }
111 
113  return x==0 ? 0. : (x<0?-1.:1.)*G4Exp(G4Log(std::fabs(x))/3.);
114 }
115 
117  return G4UniformRand();
118 }
119 
121  const G4double eps = 1.0e-6;
122  G4double r1 = inuclRndm();
123  r1 = r1 > eps ? r1 : eps;
124  G4double r2 = inuclRndm();
125  r2 = r2 > eps ? r2 : eps;
126  r2 = r2 < 1.0 - eps ? r2 : 1.0 - eps;
127 
128  return sigma * std::sin(twopi * r1) * std::sqrt(-2.0 * G4Log(r2));
129 }
130 
132  return twopi * inuclRndm();
133 }
134 
135 std::pair<G4double, G4double> G4InuclSpecialFunctions::randomCOS_SIN() {
136  G4double CT = 1.0 - 2.0 * inuclRndm();
137 
138  return std::pair<G4double, G4double>(CT, std::sqrt(1.0 - CT*CT));
139 }
140 
143  G4double mass) {
144  G4double phi = randomPHI();
145  G4double pt = p * std::sqrt(std::fabs(1.0 - ct * ct));
146 
147  // Buffers to avoid memory thrashing
148  static G4ThreadLocal G4ThreeVector *pvec_G4MT_TLS_ = 0;
149  if (!pvec_G4MT_TLS_) pvec_G4MT_TLS_ = new G4ThreeVector;
150  G4ThreeVector &pvec = *pvec_G4MT_TLS_;
151 
152  static G4ThreadLocal G4LorentzVector *momr_G4MT_TLS_ = 0;
153  if (!momr_G4MT_TLS_) momr_G4MT_TLS_ = new G4LorentzVector;
154  G4LorentzVector &momr = *momr_G4MT_TLS_;
155 
156  pvec.set(pt*std::cos(phi), pt*std::sin(phi), p*ct);
157  momr.setVectM(pvec, mass);
158 
159  return momr;
160 }
161 
164  std::pair<G4double, G4double> COS_SIN = randomCOS_SIN();
165  G4double phi = randomPHI();
166  G4double pt = p * COS_SIN.second;
167 
168  // Buffers to avoid memory thrashing
169  static G4ThreadLocal G4ThreeVector *pvec_G4MT_TLS_ = 0;
170  if (!pvec_G4MT_TLS_) pvec_G4MT_TLS_ = new G4ThreeVector;
171  G4ThreeVector &pvec = *pvec_G4MT_TLS_;
172 
173  static G4ThreadLocal G4LorentzVector *momr_G4MT_TLS_ = 0;
174  if (!momr_G4MT_TLS_) momr_G4MT_TLS_ = new G4LorentzVector;
175  G4LorentzVector &momr = *momr_G4MT_TLS_;
176 
177  pvec.set(pt*std::cos(phi), pt*std::sin(phi), p*COS_SIN.first);
178  momr.setVectM(pvec, mass);
179 
180  return momr;
181 }
void set(double x, double y, double z)
G4double randomGauss(G4double sigma)
static G4Pow * GetInstance()
Definition: G4Pow.cc:53
G4double powN(G4double x, G4int n) const
Definition: G4Pow.cc:125
CLHEP::Hep3Vector G4ThreeVector
Definition: G4Pow.hh:56
const char * p
Definition: xmltok.h:285
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
void setVectM(const Hep3Vector &spatial, double mass)
#define G4UniformRand()
Definition: Randomize.hh:87
G4double randomInuclPowers(G4double ekin, const G4double(&coeff)[4][4])
G4LorentzVector generateWithRandomAngles(G4double p, G4double mass=0.)
G4double G4Log(G4double x)
Definition: G4Log.hh:227
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:180
G4LorentzVector generateWithFixedTheta(G4double ct, G4double p, G4double mass=0.)
std::pair< G4double, G4double > randomCOS_SIN()
double G4double
Definition: G4Types.hh:76
G4double FermiEnergy(G4int A, G4int Z, G4int ntype)
CLHEP::HepLorentzVector G4LorentzVector