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,v 1.21 2010/09/14 17:51:36 mkelsey Exp $ |
---|
27 | // Geant4 tag: $Name: hadr-casc-V09-03-85 $ |
---|
28 | // |
---|
29 | // 20100114 M. Kelsey -- Remove G4CascadeMomentum, use G4LorentzVector directly |
---|
30 | // 20100914 M. Kelsey -- Migrate to integer A and Z. Discard pointless |
---|
31 | // verbosity. |
---|
32 | |
---|
33 | #include "G4InuclSpecialFunctions.hh" |
---|
34 | #include "G4LorentzVector.hh" |
---|
35 | #include "G4ThreeVector.hh" |
---|
36 | #include "Randomize.hh" |
---|
37 | #include <cmath> |
---|
38 | |
---|
39 | |
---|
40 | G4double G4InuclSpecialFunctions::getAL(G4int A) { |
---|
41 | return 0.76 + 2.2 / G4cbrt(A); |
---|
42 | } |
---|
43 | |
---|
44 | G4double G4InuclSpecialFunctions::csNN(G4double e) { |
---|
45 | G4double snn; |
---|
46 | |
---|
47 | if (e < 40.0) { |
---|
48 | snn = -1174.8 / (e * e) + 3088.5 / e + 5.3107; |
---|
49 | } else { |
---|
50 | snn = 93074.0 / (e * e) - 11.148 / e + 22.429; |
---|
51 | } |
---|
52 | |
---|
53 | return snn; |
---|
54 | } |
---|
55 | |
---|
56 | G4double G4InuclSpecialFunctions::csPN(G4double e) { |
---|
57 | G4double spn; |
---|
58 | |
---|
59 | if (e < 40.0) { |
---|
60 | spn = -5057.4 / (e * e) + 9069.2 / e + 6.9466; |
---|
61 | } else { |
---|
62 | spn = 239380.0 / (e * e) + 1802.0 / e + 27.147; |
---|
63 | } |
---|
64 | |
---|
65 | return spn; |
---|
66 | } |
---|
67 | |
---|
68 | // calculates the nuclei Fermi energy for 0 - neutron and 1 - proton |
---|
69 | |
---|
70 | G4double G4InuclSpecialFunctions::FermiEnergy(G4int A, G4int Z, G4int ntype) { |
---|
71 | const G4double C = 55.4; |
---|
72 | G4double arg = (ntype==0) ? G4double(A-Z)/A : G4double(Z)/A; |
---|
73 | |
---|
74 | return C * G4cbrt(arg*arg); // 2/3 power |
---|
75 | } |
---|
76 | |
---|
77 | G4double G4InuclSpecialFunctions::G4cbrt(G4double x) { |
---|
78 | return x==0 ? 0. : (x<0?-1.:1.)*std::exp(std::log(std::fabs(x))/3.); |
---|
79 | } |
---|
80 | |
---|
81 | G4double G4InuclSpecialFunctions::inuclRndm() { |
---|
82 | G4double rnd = G4UniformRand(); |
---|
83 | return rnd; |
---|
84 | } |
---|
85 | |
---|
86 | G4double G4InuclSpecialFunctions::randomGauss(G4double sigma) { |
---|
87 | const G4double eps = 1.0e-6; |
---|
88 | const G4double twopi = 6.2831854; |
---|
89 | G4double r1 = inuclRndm(); |
---|
90 | r1 = r1 > eps ? r1 : eps; |
---|
91 | G4double r2 = inuclRndm(); |
---|
92 | r2 = r2 > eps ? r2 : eps; |
---|
93 | r2 = r2 < 1.0 - eps ? r2 : 1.0 - eps; |
---|
94 | |
---|
95 | return sigma * std::sin(twopi * r1) * std::sqrt(-2.0 * std::log(r2)); |
---|
96 | } |
---|
97 | |
---|
98 | G4double G4InuclSpecialFunctions::randomPHI() { |
---|
99 | const G4double twopi = 6.2831853; |
---|
100 | return twopi * inuclRndm(); |
---|
101 | } |
---|
102 | |
---|
103 | std::pair<G4double, G4double> G4InuclSpecialFunctions::randomCOS_SIN() { |
---|
104 | G4double CT = 1.0 - 2.0 * inuclRndm(); |
---|
105 | |
---|
106 | return std::pair<G4double, G4double>(CT, std::sqrt(1.0 - CT*CT)); |
---|
107 | } |
---|
108 | |
---|
109 | G4LorentzVector |
---|
110 | G4InuclSpecialFunctions::generateWithFixedTheta(G4double ct, G4double p, |
---|
111 | G4double m) { |
---|
112 | G4double phi = randomPHI(); |
---|
113 | G4double pt = p * std::sqrt(std::fabs(1.0 - ct * ct)); |
---|
114 | |
---|
115 | static G4ThreeVector pvec; // Buffers to avoid memory thrashing |
---|
116 | static G4LorentzVector momr; |
---|
117 | |
---|
118 | pvec.set(pt*std::cos(phi), pt*std::sin(phi), p*ct); |
---|
119 | momr.setVectM(pvec, m); |
---|
120 | |
---|
121 | return momr; |
---|
122 | } |
---|
123 | |
---|
124 | G4LorentzVector |
---|
125 | G4InuclSpecialFunctions::generateWithRandomAngles(G4double p, G4double m) { |
---|
126 | std::pair<G4double, G4double> COS_SIN = randomCOS_SIN(); |
---|
127 | G4double phi = randomPHI(); |
---|
128 | G4double pt = p * COS_SIN.second; |
---|
129 | |
---|
130 | static G4ThreeVector pvec; // Buffers to avoid memory thrashing |
---|
131 | static G4LorentzVector momr; |
---|
132 | |
---|
133 | pvec.set(pt*std::cos(phi), pt*std::sin(phi), p*COS_SIN.first); |
---|
134 | momr.setVectM(pvec, m); |
---|
135 | |
---|
136 | return momr; |
---|
137 | } |
---|