BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSLaserComptonScattering.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 "BDSAuxiliaryNavigator.hh"
20#include "BDSComptonEngine.hh"
21#include "BDSComptonScatteringEngine.hh"
22#include "BDSGlobalConstants.hh"
23#include "BDSLaserComptonScattering.hh"
24#include "BDSLogicalVolumeLaser.hh"
25#include "BDSLaser.hh"
26#include "BDSStep.hh"
27
28#include "globals.hh"
29#include "G4AffineTransform.hh"
30#include "G4Gamma.hh"
31#include "G4LogicalVolume.hh"
32#include "G4ParticleTable.hh"
33#include "G4ProcessType.hh"
34#include "G4Step.hh"
35#include "G4StepPoint.hh"
36#include "G4ThreeVector.hh"
37#include "G4Track.hh"
38#include "G4VPhysicalVolume.hh"
39#include "G4VTouchable.hh"
40#include "Randomize.hh"
41#include "G4RunManager.hh"
42
43#include "CLHEP/Units/PhysicalConstants.h"
44#include "CLHEP/Units/SystemOfUnits.h"
45
46#include <cmath>
47#include <limits>
48
49BDSLaserComptonScattering::BDSLaserComptonScattering(const G4String& processName):
50 G4VDiscreteProcess(processName, G4ProcessType::fElectromagnetic),
51 auxNavigator(new BDSAuxiliaryNavigator()),
52 comptonEngine(new BDSComptonScatteringEngine())
53{;}
54
55BDSLaserComptonScattering::~BDSLaserComptonScattering()
56{
57 delete auxNavigator;
58}
59
60G4double BDSLaserComptonScattering::GetMeanFreePath(const G4Track& track,
61 G4double /*previousStepSize*/,
62 G4ForceCondition* forceCondition)
63{
64
65 G4LogicalVolume* lv = track.GetVolume()->GetLogicalVolume();
66 if (!lv->IsExtended()) // not extended so can't be a laser logical volume
67 {return std::numeric_limits<double>::max();}
68
69 BDSLogicalVolumeLaser* lvv = dynamic_cast<BDSLogicalVolumeLaser*>(lv);
70 if (!lvv) // it's an extended volume but not ours (could be a crystal)
71 {return std::numeric_limits<double>::max();}
72
73 // else proceed
74 const BDSLaser* laser = lvv->Laser();
75
76 *forceCondition = Forced;
77 return laser->Sigma0()/10;
78}
79
80G4VParticleChange* BDSLaserComptonScattering::PostStepDoIt(const G4Track& track,
81 const G4Step& step)
82{
83 //G4RandomDirection.hh
84 // get coordinates for photon desity calculations
85 aParticleChange.Initialize(track);
86
87 G4LogicalVolume* lv = track.GetVolume()->GetLogicalVolume();
88 if (!lv->IsExtended()) // not extended so can't be a laser logical volume
89 {return pParticleChange;}
90
91 BDSLogicalVolumeLaser* lvv = dynamic_cast<BDSLogicalVolumeLaser*>(lv);
92 if (!lvv)// it's an extended volume but not ours (could be a crystal)
93 {return pParticleChange;}
94 // else proceed
95
96 const BDSLaser* laser = lvv->Laser();
97
98
99 // ######### Get particle information #########
100 const G4DynamicParticle* particle = track.GetDynamicParticle();
101 G4ThreeVector particlePositionPostStepGlobal = track.GetPosition();
102 G4ThreeVector particleMomentumDirectionGlobal = track.GetMomentumDirection();
103 G4int partID = particle->GetParticleDefinition()->GetPDGEncoding();
104
105 G4double particleEnergy = particle->GetTotalEnergy();
106 G4ThreeVector particleMomentum = particle->GetMomentum();
107 G4ThreeVector particleBeta = particleMomentum/particleEnergy;
108 G4double particleGamma = particleEnergy/CLHEP::electron_mass_c2;
109 G4LorentzVector particle4VectorMomentum = particle->Get4Momentum();
110 // ######### get rotation and transform information. #########
111 const G4RotationMatrix* rot = track.GetTouchable()->GetRotation();
112 const G4AffineTransform transform = track.GetTouchable()->GetHistory()->GetTopTransform();
113 G4ThreeVector particlePositionLocal = transform.TransformPoint(particlePositionPostStepGlobal);
114 G4ThreeVector particleDirectionMomentumLocal = transform.TransformPoint(particleMomentumDirectionGlobal).unit();
115
116 // ########## create photon #############
117 G4ThreeVector photonUnit(0,0,1);
118 photonUnit.transform(*rot);
119 G4double photonE = (CLHEP::h_Planck*CLHEP::c_light)/laser->Wavelength();
120 G4ThreeVector photonVector = photonUnit*photonE;
121 G4LorentzVector photonLorentz = G4LorentzVector(photonVector,photonE);
122
123 // ########## boost to rest frame #############
124 photonLorentz.boost(particleBeta);
125 particle4VectorMomentum.boost(-particleBeta);
126
127 G4double photonEnergy = photonLorentz.e();
128
129 G4double crossSection = comptonEngine->CrossSection(photonEnergy,partID);
130
131 G4double particleTimePostStepGlobal = track.GetGlobalTime();
132 G4double particleTimePreStepGlobal = step.GetPreStepPoint()->GetGlobalTime();
133 G4double photonFlux = ((laser->Intensity(particlePositionLocal)/photonEnergy) //photon density
134 * laser->TemporalProfileGaussian(particleTimePostStepGlobal,particlePositionLocal.z())); // temporal intensity
135
136
137 G4double particleStepTime = (particleTimePostStepGlobal - particleTimePreStepGlobal)*particleGamma;
138
139 G4double scatteringProb = 1.0-std::exp((-crossSection*photonFlux*particleStepTime));
141 G4double scaleFactor = g->ScaleFactorLaser();
142 G4double randomNumber = G4UniformRand();
143
144
145 if((scaleFactor*scatteringProb)>randomNumber)
146 {
147 G4double initialWeight=aParticleChange.GetParentWeight();
148 aParticleChange.ProposeParentWeight(initialWeight*1.0/scaleFactor);
149 aParticleChange.SetNumberOfSecondaries(1);
150 comptonEngine->setIncomingElectron(particle4VectorMomentum);
151 comptonEngine->setIncomingGamma(photonLorentz);
152 comptonEngine->PerformCompton(particleBeta,partID);
153 G4LorentzVector scatteredGamma = comptonEngine->GetScatteredGamma();
154
155 G4DynamicParticle* gamma = new G4DynamicParticle(G4Gamma::Gamma(),
156 scatteredGamma.vect().unit(),// direction
157 scatteredGamma.e());
158 G4LorentzVector scatteredElectron = comptonEngine->GetScatteredElectron();
159 G4LorentzVector electronLorentz = G4LorentzVector(scatteredElectron.vect().unit(),scatteredElectron.e());
160 aParticleChange.AddSecondary(gamma);
161 aParticleChange.ProposeEnergy(electronLorentz.e());
162 aParticleChange.ProposeMomentumDirection(electronLorentz.getX(),electronLorentz.getY(),electronLorentz.getZ());
163 aParticleChange.ProposeParentWeight(initialWeight);
164 return G4VDiscreteProcess::PostStepDoIt(track, step);
165 }
166 else
167 {return G4VDiscreteProcess::PostStepDoIt(track, step);}
168}
169
Extra G4Navigator to get coordinate transforms.
A class that holds global options and constants.
static BDSGlobalConstants * Instance()
Access method.
Class to provide laser intensity at any point.
Definition BDSLaser.hh:36
G4double Wavelength() const
Accessor.
Definition BDSLaser.hh:64
G4double Sigma0() const
Accessor.
Definition BDSLaser.hh:68
Extended logical volume with laser definition.
const BDSLaser * Laser() const
Access the laser.