BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSLaser.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 "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSLaser.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh" // geant4 types / globals
25
26#include "CLHEP/Units/PhysicalConstants.h"
27#include "CLHEP/Units/SystemOfUnits.h"
28
29#include <algorithm>
30#include <cmath>
31#include <iterator>
32#include <vector>
33
34const std::vector<G4double> BDSLaser::wavelengths = {340.0*CLHEP::nanometer, //magenta
35 425.0*CLHEP::nanometer, //purple
36 445.0*CLHEP::nanometer, //blue
37 520.0*CLHEP::nanometer, //indigo
38 565.0*CLHEP::nanometer, //green
39 590.0*CLHEP::nanometer, //yellow
40 625.0*CLHEP::nanometer, //orange
41 740.0*CLHEP::nanometer}; //red
42
43const std::vector<G4String> BDSLaser::colours = {"magenta",
44"decapole",
45"blue",
46"muonspoiler",
47"green",
48"yellow",
49"solenoid",
50"red",
51"quadrupole"};
52
53BDSLaser::BDSLaser(G4double wavelengthIn,
54 G4double m2In,
55 G4double pulseDurationIn,
56 G4double pulseEnergyIn,
57 G4double sigma0In,
58 G4double laserArrivalTimeIn,
59 G4double T0In,
60 const G4ThreeVector& polarizationIn,
61 G4bool ignoreRayleighRangeIn):
62 wavelength(wavelengthIn),
63 m2(m2In),
64 pulseDuration(pulseDurationIn),
65 pulseEnergy(pulseEnergyIn),
66 sigma0(sigma0In),
67 laserArrivalTime(laserArrivalTimeIn),
68 T0(T0In),
69 polarization(polarizationIn),
70 ignoreRayleighRange(ignoreRayleighRangeIn)
71{
72 if(!BDS::IsFinite(sigma0In))
73 {throw BDSException(__METHOD_NAME__, "Laser waist sigma0 is zero.");}
74 peakPower = pulseEnergy / ((2.0*std::sqrt(2.0*std::log(2.0)))*pulseDuration);
75 rayleighRange = (CLHEP::pi * (2.0*sigma0)*(2.0*sigma0)) / (wavelength * m2);
76}
77
78BDSLaser::BDSLaser(G4double wavelengthIn): wavelength(wavelengthIn),
79 m2(0),
80 pulseDuration(0),
81 pulseEnergy(0),
82 sigma0(0),
83 laserArrivalTime(0),
84 T0(0),
85 polarization(0),
86 ignoreRayleighRange(0) {}
87
88BDSLaser::~BDSLaser()
89{;}
90
91G4double BDSLaser::W(G4double z) const
92{
93 if (ignoreRayleighRange)
94 {return W0();}
95 return W0()*std::sqrt(1.0+std::pow(z/rayleighRange,2.0));
96}
97
98G4double BDSLaser::Intensity(G4double x, G4double y, G4double z) const
99{
100 return Intensity(G4ThreeVector(x,y,z));
101}
102G4double BDSLaser::Intensity(const G4ThreeVector& xyz) const
103{
104 G4double r2 = xyz.perpPart().mag2(); // x^2 + y^2
105 G4double wofz = W(xyz.z());
106 G4double wofz2 = wofz*wofz;
107 return (2.0*peakPower)/(CLHEP::pi*wofz2) * std::exp(-(1.0*(2.0*r2))/wofz2);
108}
109
110G4double BDSLaser::Radius() const
111{
112 return std::sqrt((W0()*std::log(1.0/(CLHEP::e_squared)))/-2.0);
113}
114
115G4double BDSLaser::PhotonEnergy(G4double particleGamma,
116 G4double overlapAngle,
117 G4double particleBeta) const
118{
119 return particleGamma*((CLHEP::h_Planck*CLHEP::c_light)/wavelength)
120 *(1-particleBeta*std::cos(overlapAngle*CLHEP::radian));
121}
122
123G4double BDSLaser::HyperbolicAngle() const
124{
125 return (m2*wavelength)/(2.0*CLHEP::pi*W0());
126}
127
128G4double BDSLaser::TemporalProfileGaussian(G4double particleGlobalTime, G4double particleZCoord) const
129{
130 G4double mu = (particleGlobalTime-(T0+laserArrivalTime)); // can be negative - locates the peak of the pulse in time for a given particleGlobalTime
131 G4double sigmaT = pulseDuration/(2.0 * std::sqrt(2.0 * std::log(2.0))) ;
132 return std::exp(-((particleZCoord/CLHEP::c_light - mu)*(particleZCoord/CLHEP::c_light-mu)) / (2.0 * sigmaT * sigmaT));
133}
134
135G4String BDSLaser::GetLaserColour() const
136{
137 auto it = std::lower_bound(wavelengths.begin(),wavelengths.end(),wavelength);
138 G4int index = std::distance(wavelengths.begin(),it);
139 return colours[index];
140}
General exception with possible name of object and message.
G4double rayleighRange
Calculated parameters.
Definition BDSLaser.hh:95
G4double peakPower
Calculated parameters.
Definition BDSLaser.hh:94
G4double W0() const
Accessor.
Definition BDSLaser.hh:70
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())