BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSBunchHaloFlatSigma.hh
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#ifndef BDSBUNCHHALOFLATSIGMA_H
20#define BDSBUNCHHALOFLATSIGMA_H
21#include "BDSBunch.hh"
22#include "BDSBunchType.hh"
23#include "BDSException.hh"
24
25#include "G4Transform3D.hh"
26#include "G4Types.hh"
27
28#include <algorithm>
29#include <cmath>
30#include <iterator>
31#include <memory>
32#include <numeric>
33#include <vector>
34
35namespace CLHEP
36{
37 class RandFlat;
38}
39
40namespace GMAD
41{
42 class Beam;
43}
44
45namespace BDS
46{
55{
56 G4double action;
57 G4double angle;
58};
59
68{
69 G4double position;
70 G4double momentum;
71};
72
81{
82 G4double alpha;
83 G4double beta;
84};
85
86PhaseSpaceCoord PhaseSpaceCoordFromActionAngle(ActionAngleCoord aa, const TwissPair& tp);
87
88template <typename T>
89std::vector<G4double> CumulativeDistances(T pairs)
90{
91 if (pairs.size() < 2)
92 {throw BDSException("At least two points needed to calculated adjacent distances.");}
93 std::vector<G4double> distances;
94
95 auto it = std::begin(pairs);
96 auto next = std::next(it);
97 for (; next != std::end(pairs); ++it, ++next)
98 {
99 G4double x0 = it->position;
100 G4double xp0 = it->momentum;
101
102 G4double x1 = next->position;
103 G4double xp1 = next->momentum;
104
105 G4double xd = std::pow((x0 - x1), 2);
106 G4double xpd = std::pow((xp0 - xp1), 2);
107
108 G4double distance = std::sqrt(xd + xpd);
109
110 distances.push_back(distance);
111 }
112 std::vector<G4double> result;
113 std::partial_sum(std::begin(distances), std::end(distances), std::back_inserter(result));
114 return result;
115}
116
125{
126public:
127 EllipsePointGenerator(G4double actionIn,
128 const TwissPair& tp,
129 CLHEP::RandFlat* flatRandomGeneratorIn);
130 ~EllipsePointGenerator() = default;
131
132 PhaseSpaceCoord GetRandomPointOnEllipse() const;
133 inline double EllipsePerimeter() const {return pathLengths.back();};
134
135private:
136 G4double PathLengthToAngle(G4double pathLength) const;
137
138 G4double action;
139 TwissPair twisspair;
140 CLHEP::RandFlat* flatRandomGenerator;
141 std::vector<G4double> angles;
142 std::vector<G4double> pathLengths;
143};
144
145} // namespace BDS
146
154{
155public:
157 virtual ~BDSBunchHaloFlatSigma(){};
158 virtual void SetOptions(const BDSParticleDefinition* beamParticle,
159 const GMAD::Beam& beam,
160 const BDSBunchType& distrType,
161 G4Transform3D beamlineTransformIn = G4Transform3D::Identity,
162 const G4double beamlineS = 0);
163 virtual void CheckParameters();
165
166private:
168 G4double alphaX;
169 G4double alphaY;
170 G4double betaX;
171 G4double betaY;
172 G4double emitX;
173 G4double emitY;
174 G4double sigmaX;
175 G4double sigmaY;
177
178 G4double haloNSigmaXInner;
179 G4double haloNSigmaXOuter;
180 G4double haloNSigmaYInner;
181 G4double haloNSigmaYOuter;
182
183 CLHEP::RandFlat* flatGen;
184};
185
186#endif
Bunch halo distribution where the PDF is uniformly distribution in sigma.
G4double alphaX
Twiss parameter.
G4double sigmaY
Twiss parameter.
G4double betaY
Twiss parameter.
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
G4double sigmaX
Twiss parameter.
G4double emitX
Twiss parameter.
G4double betaX
Twiss parameter.
G4double emitY
Twiss parameter.
virtual BDSParticleCoordsFull GetNextParticleLocal()
G4double alphaY
Twiss parameter.
The base class for bunch distribution generators.
Definition: BDSBunch.hh:47
G4double beamlineS
Beamline initial S position.
Definition: BDSBunch.hh:201
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++.
Class for generating points uniformly on ellipse perimeters via interpolation. Part of implementation...
Beam loader.
Definition: Beam.hh:37
Beam class.
Definition: beam.h:44
Return either G4Tubs or G4CutTubs depending on flat face.
Parser namespace for GMAD language. Combination of Geant4 and MAD.
Simple struct for storing action/angle pairs to aid readability. Implementation detail.
Simple struct for storing position/momentum pairs to aid readability. Implementation detail.
Simple struct for storing Twiss alpha/beta pairs to aid readability. Implementation detail.