BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchHaloFlatSigma.hh
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#ifndef BDSBUNCHHALOFLATSIGMA_H
19#define BDSBUNCHHALOFLATSIGMA_H
20#include "BDSBunch.hh"
21#include "BDSBunchType.hh"
22#include "BDSException.hh"
23
24#include "G4Transform3D.hh"
25#include "G4Types.hh"
26
27#include <algorithm>
28#include <cmath>
29#include <iterator>
30#include <memory>
31#include <numeric>
32#include <vector>
33
34namespace GMAD
35{
36 class Beam;
37}
38
39namespace BDS
40{
49{
50 G4double action;
51 G4double angle;
52};
53
62{
63 G4double position;
64 G4double momentum;
65};
66
75{
76 G4double alpha;
77 G4double beta;
78};
79
80PhaseSpaceCoord PhaseSpaceCoordFromActionAngle(ActionAngleCoord aa, const TwissPair& tp);
81
82template <typename T>
83std::vector<G4double> CumulativeDistances(T pairs)
84{
85 if (pairs.size() < 2)
86 {throw BDSException("At least two points needed to calculated adjacent distances.");}
87 std::vector<G4double> distances;
88
89 auto it = std::begin(pairs);
90 auto next = std::next(it);
91 for (; next != std::end(pairs); ++it, ++next)
92 {
93 G4double x0 = it->position;
94 G4double xp0 = it->momentum;
95
96 G4double x1 = next->position;
97 G4double xp1 = next->momentum;
98
99 G4double xd = std::pow((x0 - x1), 2);
100 G4double xpd = std::pow((xp0 - xp1), 2);
101
102 G4double distance = std::sqrt(xd + xpd);
103
104 distances.push_back(distance);
105 }
106 std::vector<G4double> result;
107 std::partial_sum(std::begin(distances), std::end(distances), std::back_inserter(result));
108 return result;
109}
110
119{
120public:
121 EllipsePointGenerator(G4double actionIn,
122 const TwissPair& tp);
123 ~EllipsePointGenerator() = default;
124
125 PhaseSpaceCoord GetRandomPointOnEllipse() const;
126 inline double EllipsePerimeter() const {return pathLengths.back();};
127
128private:
129 G4double PathLengthToAngle(G4double pathLength) const;
130
131 G4double action;
132 TwissPair twisspair;
133 std::vector<G4double> angles;
134 std::vector<G4double> pathLengths;
135};
136
137} // namespace BDS
138
146{
147public:
149 virtual ~BDSBunchHaloFlatSigma(){};
150 virtual void SetOptions(const BDSParticleDefinition* beamParticle,
151 const GMAD::Beam& beam,
152 const BDSBunchType& distrType,
153 G4Transform3D beamlineTransformIn = G4Transform3D::Identity,
154 const G4double beamlineS = 0);
155 virtual void CheckParameters();
157
158private:
160 G4double alphaX;
161 G4double alphaY;
162 G4double betaX;
163 G4double betaY;
164 G4double emitX;
165 G4double emitY;
166 G4double sigmaX;
167 G4double sigmaY;
169
170 G4double haloNSigmaXInner;
171 G4double haloNSigmaXOuter;
172 G4double haloNSigmaYInner;
173 G4double haloNSigmaYOuter;
174};
175
176#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:46
G4double beamlineS
Beamline initial S position.
Definition BDSBunch.hh:218
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++.
Class for generating points uniformly on ellipse perimeters via interpolation. Part of implementation...
Beam loader.
Definition Beam.hh:36
Beam class.
Definition beam.h:43
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.