Geant4  10.02.p02
G4DeltaAngle.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: G4DeltaAngle.cc 68380 2013-03-22 18:39:29Z vnivanch $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 Class file
31 //
32 //
33 // File name: G4DeltaAngle
34 //
35 // Author: Vladimir Ivantcheko
36 //
37 // Creation date: 23 August 2013
38 //
39 // Modifications:
40 //
41 // Class Description:
42 //
43 // Delta-electron Angular Distribution Generation
44 //
45 // Class Description: End
46 //
47 // -------------------------------------------------------------------
48 //
49 
50 #include "G4DeltaAngle.hh"
51 #include "G4PhysicalConstants.hh"
52 #include "Randomize.hh"
53 #include "G4ParticleDefinition.hh"
54 #include "G4Electron.hh"
55 #include "G4AtomicShells.hh"
56 #include "G4SystemOfUnits.hh"
57 #include "G4Log.hh"
58 
59 using namespace std;
60 
62  : G4VEmAngularDistribution("deltaVI")
63 {
65  nprob = 26;
66  prob.resize(nprob,0.0);
67  fShellIdx = -1;
68 }
69 
71 {}
72 
75  G4double kinEnergyFinal, G4int Z, G4int idx,
76  const G4Material* mat)
77 {
78  fShellIdx = idx;
79  return SampleDirection(dp, kinEnergyFinal,Z, mat);
80 }
81 
84  G4double kinEnergyFinal, G4int Z,
85  const G4Material*)
86 {
88  G4int idx = fShellIdx;
89 
90  // if idx is not properly defined sample shell index
91  if(idx < 0 || idx >= nShells) {
92  if(nShells> nprob) {
93  nprob = nShells;
94  prob.resize(nprob,0.0);
95  }
96  G4double sum = 0.0;
97  for(idx=0; idx<nShells; ++idx) {
100  prob[idx] = sum;
101  }
102  sum *= G4UniformRand();
103  for(idx=0; idx<nShells; ++idx) {
104  if(sum <= prob[idx]) { break; }
105  }
106  }
108  G4double cost;
109  /*
110  G4cout << "E(keV)= " << kinEnergyFinal/keV
111  << " Ebind(keV)= " << bindingEnergy
112  << " idx= " << idx << " nShells= " << nShells << G4endl;
113  */
114  G4int n = 0;
115  G4bool isOK = false;
116  static const G4int nmax = 100;
117  do {
118  ++n;
119  // the atomic electron
121  G4double eKinEnergy = bindingEnergy*x;
122  G4double ePotEnergy = bindingEnergy*(1.0 + x);
123  G4double e = kinEnergyFinal + ePotEnergy + electron_mass_c2;
124  G4double p = sqrt((e + electron_mass_c2)*(e - electron_mass_c2));
125 
126  G4double totEnergy = dp->GetTotalEnergy();
127  G4double totMomentum = dp->GetTotalMomentum();
128  if(dp->GetParticleDefinition() == fElectron) {
129  totEnergy += ePotEnergy;
130  totMomentum = sqrt((totEnergy + electron_mass_c2)
131  *(totEnergy - electron_mass_c2));
132  }
133 
134  G4double eTotEnergy = eKinEnergy + electron_mass_c2;
135  G4double eTotMomentum = sqrt(eKinEnergy*(eTotEnergy + electron_mass_c2));
136  G4double costet = 2*G4UniformRand() - 1;
137  G4double sintet = sqrt((1 - costet)*(1 + costet));
138 
139  cost = 1.0;
140  if(n >= nmax) {
141  /*
142  G4ExceptionDescription ed;
143  ed << "### G4DeltaAngle Warning: " << n
144  << " iterations - stop the loop with cost= 1.0 "
145  << " for " << dp->GetDefinition()->GetParticleName() << "\n"
146  << " Ekin(MeV)= " << dp->GetKineticEnergy()/MeV
147  << " Efinal(MeV)= " << kinEnergyFinal/MeV
148  << " Ebinding(MeV)= " << bindingEnergy/MeV;
149  G4Exception("G4DeltaAngle::SampleDirection","em0044",
150  JustWarning, ed,"");
151  */
152  if(0.0 == bindingEnergy) { isOK = true; }
153  bindingEnergy = 0.0;
154  }
155 
156  G4double x0 = p*(totMomentum + eTotMomentum*costet);
157  /*
158  G4cout << " x0= " << x0 << " p= " << p
159  << " ptot= " << totMomentum << " pe= " << eTotMomentum
160  << " e= " << e << " totMom= " << totMomentum
161  << G4endl;
162  */
163  if(x0 > 0.0) {
164  G4double x1 = p*eTotMomentum*sintet;
165  G4double x2 = totEnergy*(eTotEnergy - e) - e*eTotEnergy
166  - totMomentum*eTotMomentum*costet + electron_mass_c2*electron_mass_c2;
167  G4double y = -x2/x0;
168  if(std::fabs(y) <= 1.0) {
169  cost = -(x2 + x1*sqrt(1. - y*y))/x0;
170  if(std::fabs(cost) <= 1.0) { isOK = true; }
171  else { cost = 1.0; }
172  }
173 
174  /*
175  G4cout << " Ekin(MeV)= " << dp->GetKineticEnergy()
176  << " e1(keV)= " << eKinEnergy/keV
177  << " e2(keV)= " << (e - electron_mass_c2)/keV
178  << " 1-cost= " << 1-cost
179  << " x0= " << x0 << " x1= " << x1 << " x2= " << x2
180  << G4endl;
181  */
182  }
183 
184  // Loop checking, 03-Aug-2015, Vladimir Ivanchenko
185  } while(!isOK);
186 
187  G4double sint = sqrt((1 - cost)*(1 + cost));
188  G4double phi = twopi*G4UniformRand();
189 
190  fLocalDirection.set(sint*cos(phi), sint*sin(phi), cost);
191  fLocalDirection.rotateUz(dp->GetMomentumDirection());
192 
193  return fLocalDirection;
194 }
195 
197 {}
G4DeltaAngle(const G4String &name="")
Definition: G4DeltaAngle.cc:61
CLHEP::Hep3Vector G4ThreeVector
G4double GetTotalEnergy() const
const G4ParticleDefinition * fElectron
Definition: G4DeltaAngle.hh:85
int G4int
Definition: G4Types.hh:78
G4double GetTotalMomentum() const
#define G4UniformRand()
Definition: Randomize.hh:97
virtual ~G4DeltaAngle()
Definition: G4DeltaAngle.cc:70
bool G4bool
Definition: G4Types.hh:79
static G4double GetBindingEnergy(G4int Z, G4int SubshellNb)
const G4ThreeVector & GetMomentumDirection() const
static const double twopi
Definition: G4SIunits.hh:75
const G4int nmax
const G4ParticleDefinition * GetParticleDefinition() const
const G4int n
void PrintGeneratorInformation() const
G4double G4Log(G4double x)
Definition: G4Log.hh:230
const G4double x[NPOINTSGL]
std::vector< G4double > prob
Definition: G4DeltaAngle.hh:86
static G4int GetNumberOfElectrons(G4int Z, G4int SubshellNb)
static G4Electron * Electron()
Definition: G4Electron.cc:94
virtual G4ThreeVector & SampleDirection(const G4DynamicParticle *dp, G4double kinEnergyFinal, G4int Z, const G4Material *mat=0)
Definition: G4DeltaAngle.cc:83
double G4double
Definition: G4Types.hh:76
G4double bindingEnergy(G4int A, G4int Z)
virtual G4ThreeVector & SampleDirectionForShell(const G4DynamicParticle *dp, G4double kinEnergyFinal, G4int Z, G4int shellIdx, const G4Material *mat=0)
Definition: G4DeltaAngle.cc:74
static G4int GetNumberOfShells(G4int Z)