BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSBunchRing.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
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 "BDSBunchRing.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#include <string>
32
33BDSBunchRing::BDSBunchRing():
34 BDSBunch("ring"),
35 rMin(0),
36 rMax(0),
37 rDif(0)
38{
39 flatGen = new CLHEP::RandFlat(*CLHEP::HepRandom::getTheEngine());
40}
41
42BDSBunchRing::~BDSBunchRing()
43{
44 delete flatGen;
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 rMin = beam.Rmin * CLHEP::m;
55 rMax = beam.Rmax * CLHEP::m;
56 rDif = rMax - rMin;
57}
58
60{
62 if (rMin < 0)
63 {throw BDSException(__METHOD_NAME__, "rMin: " + std::to_string(rMin) + " < 0");}
64 if (rMax < 0)
65 {throw BDSException(__METHOD_NAME__, "rMax: " + std::to_string(rMin) + " < 0");}
66 if (rMax <= rMin)
67 {throw BDSException(__METHOD_NAME__, "rMax: " + std::to_string(rMax) + " < rMin: " + std::to_string(rMin));}
68}
69
71{
72 G4double r = std::sqrt(flatGen->shoot(std::pow(rMin,2), std::pow(rMax,2)));
73 G4double phi = 2 * CLHEP::pi * flatGen->shoot();
74 G4double x = X0 + r * std::sin(phi);
75 G4double y = Y0 + r * std::cos(phi);
76
77 return BDSParticleCoordsFull(x,y,Z0,Xp0,Yp0,Zp0,T0,S0,E0,/*weight=*/1.0);
78}
79
virtual BDSParticleCoordsFull GetNextParticleLocal()
Definition: BDSBunchRing.cc:70
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
Definition: BDSBunchRing.cc:47
virtual void CheckParameters()
Definition: BDSBunchRing.cc:59
The base class for bunch distribution generators.
Definition: BDSBunch.hh:47
G4double Yp0
Centre of distributions.
Definition: BDSBunch.hh:166
G4double T0
Centre of distributions.
Definition: BDSBunch.hh:164
G4double S0
Centre of distributions.
Definition: BDSBunch.hh:163
G4double Z0
Centre of distributions.
Definition: BDSBunch.hh:162
G4double X0
Centre of distributions.
Definition: BDSBunch.hh:160
G4double Zp0
Centre of distributions.
Definition: BDSBunch.hh:167
G4double Xp0
Centre of distributions.
Definition: BDSBunch.hh:165
G4double E0
Centre of distributions.
Definition: BDSBunch.hh:168
G4double Y0
Centre of distributions.
Definition: BDSBunch.hh:161
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
Definition: BDSBunch.cc:78
virtual void CheckParameters()
Definition: BDSBunch.cc:195
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 Rmax
for the ring beam distribution
Definition: beamBase.h:111
double Rmin
for the ring beam distribution
Definition: beamBase.h:111
Beam class.
Definition: beam.h:44