BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSIonPhotonEmission.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSElectronOccupancy.hh"
20#include "BDSIonPhotonEmission.hh"
21#include "BDSLogicalVolumeLaser.hh"
22#include "BDSLaser.hh"
23#include "BDSIonExcitationEngine.hh"
24#include "BDSStep.hh"
25#include "BDSGlobalConstants.hh"
26#include "BDSUserTrackInformation.hh"
27
28#include "globals.hh"
29#include "G4IonTable.hh"
30#include "G4Track.hh"
31
32#include "G4AffineTransform.hh"
33#include "G4Electron.hh"
34#include "G4DecayProducts.hh"
35#include "G4Gamma.hh"
36#include "G4Hydrogen.hh"
37#include "G4LogicalVolume.hh"
38#include "G4ParticleTable.hh"
39#include "G4ProcessType.hh"
40#include "G4Proton.hh"
41#include "G4Step.hh"
42#include "G4StepPoint.hh"
43#include "G4ThreeVector.hh"
44
45#include "G4VTouchable.hh"
46#include "Randomize.hh"
47#include "G4TransportationManager.hh"
48#include "G4VPhysicalVolume.hh"
49
50#include "CLHEP/Units/PhysicalConstants.h"
51#include "CLHEP/Units/SystemOfUnits.h"
52
53#include <cmath>
54
55BDSIonPhotonEmission::BDSIonPhotonEmission(const G4String& processName):
56 G4VDiscreteProcess(processName, G4ProcessType::fUserDefined)
57{;}
58
59BDSIonPhotonEmission::~BDSIonPhotonEmission()
60{;}
61
62G4double BDSIonPhotonEmission::GetMeanFreePath(const G4Track& track,
63 G4double /*previousStepSize*/,
64 G4ForceCondition* /*forceCondition*/)
65{
66 const G4DynamicParticle* particle = track.GetDynamicParticle();
67 //const G4ParticleDefinition* particleDef = particle->GetDefinition();
68
69 BDSUserTrackInformation* trackInfo = dynamic_cast<BDSUserTrackInformation*>(track.GetUserInformation());
70 G4bool excited = trackInfo->GetElectronOccupancy()->StatePopulated(2,1,0.5);
71
72 // can only apply to ions
73 if (!excited)
74 {return DBL_MAX;}
75
76 // else proceed with lifetime calculation
77 G4double aMass = particle->GetMass();
78 G4double currentProperTime = particle->GetProperTime();
79 G4double excitedTime = trackInfo->GetElectronOccupancy()->GetTimeOfExcitation(2,1,0.5);
80 G4double timeOfFlight = currentProperTime-excitedTime;
81 //G4double lifeTime = trackInfo->GetElectronOccupancy()->GetStateLifetime(2,1,(1/2));
82
83
84 // returns the mean free path in GEANT4 internal units
85 G4double pathlength = DBL_MIN;
86 G4double aCtau = CLHEP::c_light * timeOfFlight;
87
88 const G4double highestValue = 20; // copied from G4Decay
89 if (aCtau < DBL_MIN)
90 {pathlength = DBL_MIN;}
91 else
92 {
93 // calculate the mean free path
94 // by using normalized kinetic energy (= Ekin/mass)
95 G4double rKineticEnergy = particle->GetKineticEnergy()/aMass;
96 if (rKineticEnergy > highestValue)
97 {
98 // gamma >> 1
99 pathlength = (rKineticEnergy + 1.0) * aCtau;
100 }
101 else if (rKineticEnergy < DBL_MIN)
102 {
103 // too slow particle
104 pathlength = DBL_MIN;
105 }
106 else
107 {
108 // beta <1
109 pathlength = (particle->GetTotalMomentum())/aMass*aCtau ;
110 }
111 }
112
113 return pathlength;
114}
115
116G4VParticleChange* BDSIonPhotonEmission::PostStepDoIt(const G4Track& track,
117 const G4Step& step)
118{
119 aParticleChange.Initialize(track);
120 G4DynamicParticle* particle = const_cast<G4DynamicParticle*>(track.GetDynamicParticle());
121
122 //G4double parentEnergy = particle->GetTotalEnergy();
123 // G4ThreeVector parentDirection = track.GetMomentumDirection();
124 BDSUserTrackInformation* trackInfo = dynamic_cast<BDSUserTrackInformation*>(track.GetUserInformation());
125 trackInfo->GetElectronOccupancy()->RemoveElectrons(2,1,0.5,1);
126 trackInfo->GetElectronOccupancy()->AddElectrons(2,0,0.5,1);
127
128
129 G4ThreeVector ionBeta = particle->GetMomentum()/particle->GetTotalEnergy();
130 G4LorentzVector ion4Vector = particle->Get4Momentum();
131 ion4Vector.boost(-ionBeta);
132 BDSIonExcitationEngine* excitationEngine = new BDSIonExcitationEngine();
133 excitationEngine->setIncomingIon(ion4Vector);
134 excitationEngine->PhotonEmission(ionBeta);
135 G4LorentzVector gammaLorentz = excitationEngine->GetEmittedGamma();
136 G4LorentzVector ionLorentz = excitationEngine->GetScatteredIonEmission();
137
138 G4DynamicParticle* gamma = new G4DynamicParticle(G4Gamma::Gamma(),
139 gammaLorentz.vect().unit(),
140 gammaLorentz.e());
141 aParticleChange.AddSecondary(gamma);
142 aParticleChange.ProposeEnergy(ionLorentz.e());
143 aParticleChange.ProposeMomentumDirection(ionLorentz.vect().unit());
144 /*
145 G4double ek = generalElectron->GetKineticEnergy();
146 G4DecayProducts* newProducts = new G4DecayProducts();
147 G4DynamicParticle* daughterparticle = new G4DynamicParticle(G4Gamma::Definition(),
148 direction,
149 ek);
150
151 newProducts->PushProducts(daughterparticle);
152 newProducts->SetParentParticle(*(track.GetDynamicParticle()));
153 newProducts->Boost(parentEnergy, parentDirection);
154
155 G4double finalGlobalTime = track.GetGlobalTime();
156
157 const G4TouchableHandle thand = track.GetTouchableHandle();
158 G4ThreeVector currentPosition = track.GetPosition();
159 // create a new track object
160 G4Track* secondary = new G4Track(newProducts->PopProducts(),
161 finalGlobalTime,
162 currentPosition);
163 // switch on good for tracking flag
164 secondary->SetGoodForTrackingFlag();
165 secondary->SetTouchableHandle(thand);
166 // add the secondary track in the List
167 aParticleChange.AddSecondary(secondary);
168
169 aParticleChange.SetNumberOfSecondaries(1);
170*/
171 delete excitationEngine;
172 return G4VDiscreteProcess::PostStepDoIt(track, step);
173}
174
175/*
176G4double BDSIonPhotonEmission::Pmx(G4double e, G4double p1, G4double p2)
177{
178 // calcurate momentum of daughter particles in two-body decay
179 G4double ppp = (e+p1+p2)*(e+p1-p2)*(e-p1+p2)*(e-p1-p2)/(4.0*e*e);
180 if (ppp>0) return std::sqrt(ppp);
181 else return -1.;
182}
183
184G4double BDSIonPhotonEmission::PostStepGetPhysicalInteractionLength(const G4Track& track,
185 G4double previousStepSize,
186 G4ForceCondition* condition)
187{
188 G4double result = G4Decay::PostStepGetPhysicalInteractionLength(track, previousStepSize, condition);
189 return result;
190}
191
192
193G4double BDSIonPhotonEmission::GetMeanFreePath(const G4Track& aTrack,
194 G4double previousStepSize,
195 G4ForceCondition* condition)
196{
197 G4double result = G4Decay::GetMeanFreePath(aTrack, previousStepSize, condition);
198 return result;
199}
200*/