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) 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 "BDSBunchCircle.hh"
19#include "BDSDebug.hh"
20#include "BDSException.hh"
21
22#include "parser/beam.h"
23
24#include "Randomize.hh"
25#include "CLHEP/Units/PhysicalConstants.h"
26#include "CLHEP/Units/SystemOfUnits.h"
27
28#include <cmath>
29
30BDSBunchCircle::BDSBunchCircle():
31 BDSBunch("circle"),
32 envelopeR(0.0),
33 envelopeRp(0.0),
34 envelopeT(0.0),
35 envelopeE(0.0)
36{;}
37
38BDSBunchCircle::~BDSBunchCircle()
39{;}
40
42 const GMAD::Beam& beam,
43 const BDSBunchType& distrType,
44 G4Transform3D beamlineTransformIn,
45 const G4double beamlineSIn)
46{
47 BDSBunch::SetOptions(beamParticle, beam, distrType, beamlineTransformIn, beamlineSIn);
48 envelopeR = beam.envelopeR * CLHEP::m;
49 envelopeRp = beam.envelopeRp * CLHEP::rad;
50 envelopeT = beam.envelopeT * CLHEP::s;
51 envelopeE = beam.envelopeE * CLHEP::GeV;
52}
53
55{
57 if (envelopeR <= 0)
58 {throw BDSException(__METHOD_NAME__, "envelopeR <= 0");}
59 if (envelopeRp < 0)
60 {throw BDSException(__METHOD_NAME__, "envelopeRp <= 0");}
61 if (envelopeT < 0)
62 {throw BDSException(__METHOD_NAME__, "envelopeT < 0");}
63 if (envelopeE < 0)
64 {throw BDSException(__METHOD_NAME__, "envelopeE < 0");}
65}
66
68{
69 G4double dt = envelopeT * (1.-2.*G4RandFlat::shoot());
70 G4double dz = dt * CLHEP::c_light;
71
72 G4double t = T0 + dt;
73 G4double z = Z0 + dz;
74 G4double phiR = G4RandFlat::shoot() * CLHEP::twopi;
75 G4double phiRp = G4RandFlat::shoot() * CLHEP::twopi;
76 G4double r = std::sqrt(G4RandFlat::shoot()) * envelopeR;
77 G4double rp = std::sqrt(G4RandFlat::shoot()) * envelopeRp;
78
79 G4double x = X0 + std::cos(phiR) * r;
80 G4double y = Y0 + std::sin(phiR) * r;
81 G4double xp = Xp0 + std::cos(phiRp) * rp;
82 G4double yp = Yp0 + std::sin(phiRp) * rp;
83 G4double zp = CalculateZp(xp,yp,Zp0);
84 G4double E = E0 + envelopeE * (1-2*G4RandFlat::shoot());
85
86 return BDSParticleCoordsFull(x,y,z,xp,yp,zp,t,S0-dz,E,/*weight=*/1.0);
87}
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:46
G4double Yp0
Centre of distributions.
Definition BDSBunch.hh:176
G4double T0
Centre of distributions.
Definition BDSBunch.hh:174
G4double S0
Centre of distributions.
Definition BDSBunch.hh:173
G4double Z0
Centre of distributions.
Definition BDSBunch.hh:172
G4double X0
Centre of distributions.
Definition BDSBunch.hh:170
G4double Zp0
Centre of distributions.
Definition BDSBunch.hh:177
G4double Xp0
Centre of distributions.
Definition BDSBunch.hh:175
G4double E0
Centre of distributions.
Definition BDSBunch.hh:178
G4double Y0
Centre of distributions.
Definition BDSBunch.hh:171
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
Definition BDSBunch.cc:81
static G4double CalculateZp(G4double xp, G4double yp, G4double Zp0)
Calculate zp safely based on other components.
Definition BDSBunch.cc:373
virtual void CheckParameters()
Definition BDSBunch.cc:222
General exception with possible name of object and message.
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:100
double envelopeE
for the circle/square/box beam distribution
Definition beamBase.h:99
double envelopeR
for the circle/square/box beam distribution
Definition beamBase.h:100
double envelopeT
for the circle/square/box beam distribution
Definition beamBase.h:99
Beam class.
Definition beam.h:43