Geant4  10.03.p02
 All Classes 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 // 20150619 M. Kelsey -- Define G4cbrt(int) to use G4Pow::Z13, rearrange
36 // FermiEnergy() to use G4Pow::Z23.
37 // 20150622 M. Kelsey -- Use G4AutoDelete for _TLS_ buffers.
38 
39 #include <cmath>
40 
42 #include "G4AutoDelete.hh"
43 #include "G4Exp.hh"
44 #include "G4Log.hh"
45 #include "G4LorentzVector.hh"
46 #include "G4PhysicalConstants.hh"
47 #include "G4Pow.hh"
48 #include "G4ThreeVector.hh"
49 #include "Randomize.hh"
50 
51 
52 // Compute power series in random value, with powers-of-Ekin coeffciences
53 
54 G4double
56  const G4double (&coeff)[4][4]) {
57  G4Pow* theG4Pow = G4Pow::GetInstance();
58 
59  G4double S = G4UniformRand(); // Random fraction for expansion
60 
61  G4double C, V;
62  G4double PQ=0., PR=0.;
63  for (G4int i=0; i<4; i++) {
64  V = 0.0;
65  for (G4int k=0; k<4; k++) {
66  C = coeff[i][k];
67  V += C * theG4Pow->powN(ekin, k);
68  }
69 
70  PQ += V;
71  PR += V * theG4Pow->powN(S, i);
72  }
73 
74  return std::sqrt(S) * (PR + (1-PQ)*(S*S*S*S));
75 }
76 
77 
78 
80  return 0.76 + 2.2 / G4cbrt(A);
81 }
82 
84  G4double snn;
85 
86  if (e < 40.0) {
87  snn = -1174.8 / (e * e) + 3088.5 / e + 5.3107;
88  } else {
89  snn = 93074.0 / (e * e) - 11.148 / e + 22.429;
90  }
91 
92  return snn;
93 }
94 
96  G4double spn;
97 
98  if (e < 40.0) {
99  spn = -5057.4 / (e * e) + 9069.2 / e + 6.9466;
100  } else {
101  spn = 239380.0 / (e * e) + 1802.0 / e + 27.147;
102  }
103 
104  return spn;
105 }
106 
107 // calculates the nuclei Fermi energy for 0 - neutron and 1 - proton
108 
110  G4Pow* g4pow = G4Pow::GetInstance();
111  const G4double C = 55.4 / g4pow->Z23(A);
112  G4double arg = (ntype==0) ? g4pow->Z23(A-Z) : g4pow->Z23(Z);
113 
114  return C * arg;
115 }
116 
118  return x==0 ? 0. : (x<0?-1.:1.)*G4Exp(G4Log(std::fabs(x))/3.);
119 }
120 
122  return n==0 ? 0. : (n<0?-1.:1.)*G4Pow::GetInstance()->Z13(std::abs(n));
123 }
124 
126  return G4UniformRand();
127 }
128 
130  const G4double eps = 1.0e-6;
131  G4double r1 = inuclRndm();
132  r1 = r1 > eps ? r1 : eps;
133  G4double r2 = inuclRndm();
134  r2 = r2 > eps ? r2 : eps;
135  r2 = r2 < 1.0 - eps ? r2 : 1.0 - eps;
136 
137  return sigma * std::sin(twopi * r1) * std::sqrt(-2.0 * G4Log(r2));
138 }
139 
141  return twopi * inuclRndm();
142 }
143 
144 std::pair<G4double, G4double> G4InuclSpecialFunctions::randomCOS_SIN() {
145  G4double CT = 1.0 - 2.0 * inuclRndm();
146 
147  return std::pair<G4double, G4double>(CT, std::sqrt(1.0 - CT*CT));
148 }
149 
152  G4double mass) {
153  G4double phi = randomPHI();
154  G4double pt = p * std::sqrt(std::fabs(1.0 - ct * ct));
155 
156  // Buffers to avoid memory thrashing
157  static G4ThreadLocal G4ThreeVector *pvec_G4MT_TLS_ = 0;
158  if (!pvec_G4MT_TLS_) {
159  pvec_G4MT_TLS_ = new G4ThreeVector;
160  G4AutoDelete::Register(pvec_G4MT_TLS_);
161  }
162  G4ThreeVector &pvec = *pvec_G4MT_TLS_;
163 
164  static G4ThreadLocal G4LorentzVector *momr_G4MT_TLS_ = 0;
165  if (!momr_G4MT_TLS_) {
166  momr_G4MT_TLS_ = new G4LorentzVector;
167  G4AutoDelete::Register(momr_G4MT_TLS_);
168  }
169  G4LorentzVector &momr = *momr_G4MT_TLS_;
170 
171  pvec.set(pt*std::cos(phi), pt*std::sin(phi), p*ct);
172  momr.setVectM(pvec, mass);
173 
174  return momr;
175 }
176 
179  std::pair<G4double, G4double> COS_SIN = randomCOS_SIN();
180  G4double phi = randomPHI();
181  G4double pt = p * COS_SIN.second;
182 
183  // Buffers to avoid memory thrashing
184  static G4ThreadLocal G4ThreeVector *pvec_G4MT_TLS_ = 0;
185  if (!pvec_G4MT_TLS_) {
186  pvec_G4MT_TLS_ = new G4ThreeVector;
187  G4AutoDelete::Register(pvec_G4MT_TLS_);
188  }
189  G4ThreeVector &pvec = *pvec_G4MT_TLS_;
190 
191  static G4ThreadLocal G4LorentzVector *momr_G4MT_TLS_ = 0;
192  if (!momr_G4MT_TLS_) {
193  momr_G4MT_TLS_ = new G4LorentzVector;
194  G4AutoDelete::Register(momr_G4MT_TLS_);
195  }
196  G4LorentzVector &momr = *momr_G4MT_TLS_;
197 
198  pvec.set(pt*std::cos(phi), pt*std::sin(phi), p*COS_SIN.first);
199  momr.setVectM(pvec, mass);
200 
201  return momr;
202 }
void set(double x, double y, double z)
G4double randomGauss(G4double sigma)
static G4Pow * GetInstance()
Definition: G4Pow.cc:55
G4double powN(G4double x, G4int n) const
Definition: G4Pow.cc:128
double S(double temp)
CLHEP::Hep3Vector G4ThreeVector
Definition: G4Pow.hh:56
const char * p
Definition: xmltok.h:285
static const G4double eps
tuple x
Definition: test.py:50
double C(double temp)
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
static constexpr double twopi
Definition: G4SIunits.hh:76
void setVectM(const Hep3Vector &spatial, double mass)
void Register(T *inst)
Definition: G4AutoDelete.hh:65
#define G4UniformRand()
Definition: Randomize.hh:97
G4double Z13(G4int Z) const
Definition: G4Pow.hh:127
double A(double temperature)
G4double randomInuclPowers(G4double ekin, const G4double(&coeff)[4][4])
G4LorentzVector generateWithRandomAngles(G4double p, G4double mass=0.)
const G4int n
G4double G4Log(G4double x)
Definition: G4Log.hh:230
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:183
G4LorentzVector generateWithFixedTheta(G4double ct, G4double p, G4double mass=0.)
G4double Z23(G4int Z) const
Definition: G4Pow.hh:154
std::pair< G4double, G4double > randomCOS_SIN()
double G4double
Definition: G4Types.hh:76
G4double FermiEnergy(G4int A, G4int Z, G4int ntype)
CLHEP::HepLorentzVector G4LorentzVector