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