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