BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchRing.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 "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{;}
38
39BDSBunchRing::~BDSBunchRing()
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 rMin = beam.Rmin * CLHEP::m;
50 rMax = beam.Rmax * CLHEP::m;
51}
52
54{
56 if (rMin < 0)
57 {throw BDSException(__METHOD_NAME__, "rMin: " + std::to_string(rMin) + " < 0");}
58 if (rMax < 0)
59 {throw BDSException(__METHOD_NAME__, "rMax: " + std::to_string(rMin) + " < 0");}
60 if (rMax <= rMin)
61 {throw BDSException(__METHOD_NAME__, "rMax: " + std::to_string(rMax) + " < rMin: " + std::to_string(rMin));}
62}
63
65{
66 G4double r = std::sqrt(G4RandFlat::shoot(std::pow(rMin,2), std::pow(rMax,2)));
67 G4double phi = 2 * CLHEP::pi * G4RandFlat::shoot();
68 G4double x = X0 + r * std::sin(phi);
69 G4double y = Y0 + r * std::cos(phi);
70
71 return BDSParticleCoordsFull(x,y,Z0,Xp0,Yp0,Zp0,T0,S0,E0,/*weight=*/1.0);
72}
virtual BDSParticleCoordsFull GetNextParticleLocal()
Definition: BDSBunchRing.cc:64
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
Definition: BDSBunchRing.cc:42
virtual void CheckParameters()
Definition: BDSBunchRing.cc:53
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
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 Rmax
for the ring beam distribution
Definition: beamBase.h:120
double Rmin
for the ring beam distribution
Definition: beamBase.h:120
Beam class.
Definition: beam.h:44