BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchEShell.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 "BDSBunchEShell.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22#include "BDSParticleCoordsFull.hh"
23
24#include "parser/beam.h"
25
26#include "Randomize.hh"
27#include "CLHEP/Units/PhysicalConstants.h"
28#include "CLHEP/Units/SystemOfUnits.h"
29
30#include <cmath>
31
32BDSBunchEShell::BDSBunchEShell():
33 BDSBunch("eshell"),
34 shellX(0.0),
35 shellXp(0.0),
36 shellY(0.0),
37 shellYp(0.0),
38 shellXWidth(0.0),
39 shellXpWidth(0.0),
40 shellYWidth(0.0),
41 shellYpWidth(0.0)
42{;}
43
44BDSBunchEShell::~BDSBunchEShell()
45{;}
46
48 const GMAD::Beam& beam,
49 const BDSBunchType& distrType,
50 G4Transform3D beamlineTransformIn,
51 const G4double beamlineSIn)
52{
53 BDSBunch::SetOptions(beamParticle, beam, distrType, beamlineTransformIn, beamlineSIn);
54 shellX = beam.shellX * CLHEP::m;
55 shellY = beam.shellY * CLHEP::m;
56 shellXp = beam.shellXp * CLHEP::rad;
57 shellYp = beam.shellYp * CLHEP::rad;
58 shellXWidth = beam.shellXWidth * CLHEP::m;
59 shellXpWidth = beam.shellXpWidth * CLHEP::rad;
60 shellYWidth = beam.shellYWidth * CLHEP::m;
61 shellYpWidth = beam.shellYpWidth * CLHEP::rad;
62}
63
65{
67 if (shellX <= 0)
68 {throw BDSException(__METHOD_NAME__, "shellX <= 0");}
69 if (shellY <= 0)
70 {throw BDSException(__METHOD_NAME__, "shellY <= 0");}
71 if (shellXp <= 0)
72 {throw BDSException(__METHOD_NAME__, "shellXp <= 0");}
73 if (shellYp <= 0)
74 {throw BDSException(__METHOD_NAME__, "shellYp <= 0");}
75
76 // widths can be zero but can't be negative
77 if (shellXWidth < 0)
78 {throw BDSException(__METHOD_NAME__, "shellXWidth < 0");}
79 if (shellYWidth < 0)
80 {throw BDSException(__METHOD_NAME__, "shellYWidth < 0");}
81 if (shellXpWidth < 0)
82 {throw BDSException(__METHOD_NAME__, "shellXpWidth < 0");}
83 if (shellYpWidth < 0)
84 {throw BDSException(__METHOD_NAME__, "shellYpWidth < 0");}
85}
86
88{
89 G4double phi = 2 * CLHEP::pi * G4RandFlat::shoot();
90 G4double xamp = 0.5 - G4RandFlat::shoot();
91 G4double yamp = 0.5 - G4RandFlat::shoot();
92 G4double xpamp = 0.5 - G4RandFlat::shoot();
93 G4double ypamp = 0.5 - G4RandFlat::shoot();
94
95 G4double x = X0 + (std::sin(phi) * shellX) + xamp * shellXWidth;
96 G4double xp = Xp0 + (std::cos(phi) * shellXp) + xpamp * shellXpWidth;
97 phi = 2 * CLHEP::pi * G4RandFlat::shoot();
98 G4double y = Y0 + (std::sin(phi) * shellY) + yamp * shellYWidth;
99 G4double yp = Yp0 + (std::cos(phi) * shellYp) + ypamp * shellYpWidth;
100 G4double zp = CalculateZp(xp,yp,Zp0);
101 G4double E = E0 * (1 + sigmaE/2. * (1. -2. * G4RandFlat::shoot()));
102
103 return BDSParticleCoordsFull(x,y,Z0,xp,yp,zp,T0,S0,E,/*weight=*/1.0);
104}
virtual BDSParticleCoordsFull GetNextParticleLocal()
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
virtual void CheckParameters()
The base class for bunch distribution generators.
Definition: BDSBunch.hh:47
G4double sigmaE
Centre of distributions.
Definition: BDSBunch.hh:184
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 shellXp
for the elliptic shell distribution
Definition: beamBase.h:115
double shellXpWidth
for the elliptic shell distribution
Definition: beamBase.h:116
double shellYp
for the elliptic shell distribution
Definition: beamBase.h:115
double shellX
for the elliptic shell distribution
Definition: beamBase.h:115
double shellY
for the elliptic shell distribution
Definition: beamBase.h:115
double shellYpWidth
for the elliptic shell distribution
Definition: beamBase.h:116
double shellXWidth
for the elliptic shell distribution
Definition: beamBase.h:116
double shellYWidth
for the elliptic shell distribution
Definition: beamBase.h:116
Beam class.
Definition: beam.h:44