BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchSquare.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 "BDSBunchSquare.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
29BDSBunchSquare::BDSBunchSquare():
30 BDSBunch("square"),
31 envelopeX(0.0),
32 envelopeY(0.0),
33 envelopeXp(0.0),
34 envelopeYp(0.0),
35 envelopeT(0.0),
36 envelopeE(0.0),
37 envelopeZ(0.0),
38 correlatedZWithT(false)
39{;}
40
41BDSBunchSquare::~BDSBunchSquare()
42{;}
43
45 const GMAD::Beam& beam,
46 const BDSBunchType& distrType,
47 G4Transform3D beamlineTransformIn,
48 const G4double beamlineSIn)
49{
50 BDSBunch::SetOptions(beamParticle, beam, distrType, beamlineTransformIn, beamlineSIn);
51 envelopeX = beam.envelopeX * CLHEP::m;
52 envelopeY = beam.envelopeY * CLHEP::m;
53 envelopeXp = beam.envelopeXp * CLHEP::rad;
54 envelopeYp = beam.envelopeYp * CLHEP::rad;
55 envelopeT = beam.envelopeT * CLHEP::s;
56 envelopeE = beam.envelopeE * CLHEP::GeV;
57 envelopeZ = beam.envelopeZ * CLHEP::m;
58 correlatedZWithT = beam.zFromT;
59}
60
62{
64 if (envelopeX < 0)
65 {throw BDSException(__METHOD_NAME__, "envelopeX < 0");}
66 if (envelopeXp < 0)
67 {throw BDSException(__METHOD_NAME__, "envelopeXp < 0");}
68 if (envelopeY < 0)
69 {throw BDSException(__METHOD_NAME__, "envelopeY < 0");}
70 if (envelopeYp < 0)
71 {throw BDSException(__METHOD_NAME__, "envelopeYp < 0");}
72 if (envelopeT < 0)
73 {throw BDSException(__METHOD_NAME__, "envelopeT < 0");}
74 if (envelopeE < 0)
75 {throw BDSException(__METHOD_NAME__, "envelopeE < 0");}
76 if (envelopeZ < 0)
77 {throw BDSException(__METHOD_NAME__, "envelopeZ < 0");}
78}
79
81{
82 G4double x = X0 + envelopeX * (1-2*G4RandFlat::shoot());
83 G4double y = Y0 + envelopeY * (1-2*G4RandFlat::shoot());
84 G4double xp = Xp0 + envelopeXp * (1-2*G4RandFlat::shoot());
85 G4double yp = Yp0 + envelopeYp * (1-2*G4RandFlat::shoot());
86 G4double zp = CalculateZp(xp,yp,Zp0);
87 G4double dt = envelopeT * (1.-2.*G4RandFlat::shoot());
88 G4double t = T0 + dt;
89 G4double dz;
90 if (correlatedZWithT)
91 {dz = dt * CLHEP::c_light;}
92 else
93 {dz = envelopeZ * (1.-2*G4RandFlat::shoot());}
94
95 G4double z = Z0 + dz;
96 G4double E = E0 + envelopeE * (1 - 2*G4RandFlat::shoot());
97
98 return BDSParticleCoordsFull(x,y,z,xp,yp,zp,t,S0+dz,E,/*weight=*/1.0);
99}
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 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 envelopeZ
for the circle/square/box beam distribution
Definition: beamBase.h:99
double envelopeE
for the circle/square/box beam distribution
Definition: beamBase.h:100
double envelopeYp
for the circle/square/box beam distribution
Definition: beamBase.h:99
bool zFromT
for the circle/square/box beam distribution
Definition: beamBase.h:102
double envelopeX
for the circle/square/box beam distribution
Definition: beamBase.h:99
double envelopeXp
for the circle/square/box beam distribution
Definition: beamBase.h:99
double envelopeY
for the circle/square/box beam distribution
Definition: beamBase.h:99
double envelopeT
for the circle/square/box beam distribution
Definition: beamBase.h:100
Beam class.
Definition: beam.h:44