BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchCircle.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
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 "BDSBunchCircle.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22
23#include "parser/beam.h"
24
25#include "Randomize.hh"
26#include "CLHEP/Units/PhysicalConstants.h"
27#include "CLHEP/Units/SystemOfUnits.h"
28
29#include <cmath>
30
31BDSBunchCircle::BDSBunchCircle():
32 BDSBunch("circle"),
33 envelopeR(0.0),
34 envelopeRp(0.0),
35 envelopeT(0.0),
36 envelopeE(0.0)
37{;}
38
39BDSBunchCircle::~BDSBunchCircle()
40{;}
41
43 const GMAD::Beam& beam,
44 const BDSBunchType& distrType,
45 G4Transform3D beamlineTransformIn,
46 const G4double beamlineSIn)
47{
48 BDSBunch::SetOptions(beamParticle, beam, distrType, beamlineTransformIn, beamlineSIn);
49 envelopeR = beam.envelopeR * CLHEP::m;
50 envelopeRp = beam.envelopeRp * CLHEP::rad;
51 envelopeT = beam.envelopeT * CLHEP::s;
52 envelopeE = beam.envelopeE * CLHEP::GeV;
53}
54
56{
58 if (envelopeR <= 0)
59 {throw BDSException(__METHOD_NAME__, "envelopeR <= 0");}
60 if (envelopeRp < 0)
61 {throw BDSException(__METHOD_NAME__, "envelopeRp <= 0");}
62 if (envelopeT < 0)
63 {throw BDSException(__METHOD_NAME__, "envelopeT < 0");}
64 if (envelopeE < 0)
65 {throw BDSException(__METHOD_NAME__, "envelopeE < 0");}
66}
67
69{
70 G4double dt = envelopeT * (1.-2.*G4RandFlat::shoot());
71 G4double dz = dt * CLHEP::c_light;
72
73 G4double t = T0 + dt;
74 G4double z = Z0 + dz;
75 G4double phiR = G4RandFlat::shoot() * CLHEP::twopi;
76 G4double phiRp = G4RandFlat::shoot() * CLHEP::twopi;
77 G4double r = std::sqrt(G4RandFlat::shoot()) * envelopeR;
78 G4double rp = std::sqrt(G4RandFlat::shoot()) * envelopeRp;
79
80 G4double x = X0 + std::cos(phiR) * r;
81 G4double y = Y0 + std::sin(phiR) * r;
82 G4double xp = Xp0 + std::cos(phiRp) * rp;
83 G4double yp = Yp0 + std::sin(phiRp) * rp;
84 G4double zp = CalculateZp(xp,yp,Zp0);
85 G4double E = E0 + envelopeE * (1-2*G4RandFlat::shoot());
86
87 return BDSParticleCoordsFull(x,y,z,xp,yp,zp,t,S0-dz,E,/*weight=*/1.0);
88}
virtual void CheckParameters()
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, G4double beamlineS=0)
virtual BDSParticleCoordsFull GetNextParticleLocal()
The base class for bunch distribution generators.
Definition: BDSBunch.hh:47
G4double Yp0
Centre of distributions.
Definition: BDSBunch.hh:177
G4double T0
Centre of distributions.
Definition: BDSBunch.hh:175
G4double S0
Centre of distributions.
Definition: BDSBunch.hh:174
G4double Z0
Centre of distributions.
Definition: BDSBunch.hh:173
G4double X0
Centre of distributions.
Definition: BDSBunch.hh:171
G4double Zp0
Centre of distributions.
Definition: BDSBunch.hh:178
G4double Xp0
Centre of distributions.
Definition: BDSBunch.hh:176
G4double E0
Centre of distributions.
Definition: BDSBunch.hh:179
G4double Y0
Centre of distributions.
Definition: BDSBunch.hh:172
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
Definition: BDSBunch.cc:82
static G4double CalculateZp(G4double xp, G4double yp, G4double Zp0)
Calculate zp safely based on other components.
Definition: BDSBunch.cc:367
virtual void CheckParameters()
Definition: BDSBunch.cc:223
General exception with possible name of object and message.
Definition: BDSException.hh:35
A set of particle coordinates including energy and weight.
Wrapper for particle definition.
Improve type-safety of native enum data type in C++.
double envelopeRp
for the circle/square/box beam distribution
Definition: beamBase.h:101
double envelopeE
for the circle/square/box beam distribution
Definition: beamBase.h:100
double envelopeR
for the circle/square/box beam distribution
Definition: beamBase.h:101
double envelopeT
for the circle/square/box beam distribution
Definition: beamBase.h:100
Beam class.
Definition: beam.h:44