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