BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSBunch.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 BDSBUNCH_H
20#define BDSBUNCH_H
21
22#include "BDSBunchType.hh"
23#include "BDSParticleCoords.hh"
24#include "BDSParticleCoordsFull.hh"
25#include "BDSParticleCoordsFullGlobal.hh"
26#include "BDSParticleDefinition.hh"
27
28#include "globals.hh"
29#include "G4Transform3D.hh"
30
31class BDSBeamline;
32
33namespace GMAD
34{
35 class Beam;
36}
37
47{
48public:
49 BDSBunch();
50 explicit BDSBunch(const G4String& nameIn);
51 virtual ~BDSBunch();
52
54 friend class BDSHepMC3Reader;
55 friend class BDSROOTSamplerReader;
56
62 virtual void SetOptions(const BDSParticleDefinition* beamParticle,
63 const GMAD::Beam& beam,
64 const BDSBunchType& distrType,
65 G4Transform3D beamlineTransformIn = G4Transform3D::Identity,
66 const G4double beamlineS = 0);
67
70 virtual void CheckParameters();
71
73 virtual void Initialise();
74
78
80 virtual G4bool ExpectChangingParticleType() const {return false;}
81
87 virtual BDSParticleCoordsFullGlobal GetNextParticleValid(G4int maxTries = 100);
88
92 virtual void BeginOfRunAction(G4int numberOfEvents);
93
95 inline virtual const BDSParticleDefinition* ParticleDefinition() const {return particleDefinition;}
96
100 virtual void SetGeneratePrimariesOnly(G4bool generatePrimariesOnlyIn);
101
106
109
115 virtual void RecreateAdvanceToEvent(G4int /*eventOffset*/){;}
116
118 inline G4bool BeamParticleIsAnIon() const {return particleDefinition->IsAnIon();}
119
124 virtual void UpdateIonDefinition();
125
129
131 static G4double CalculateZp(G4double xp, G4double yp, G4double Zp0);
132
136 static void SetEmittances(const BDSParticleDefinition* beamParticle,
137 const GMAD::Beam& beam,
138 G4double& emittGeometricX,
139 G4double& emittGeometricY,
140 G4double& emittNormalisedX,
141 G4double& emittNormalisedY);
142
143 inline G4String Name() const {return name;}
144
145protected:
150
152 void ApplyTilt(BDSParticleCoordsFull& localIn) const;
153
156
157 G4String name;
158
160 G4double X0;
161 G4double Y0;
162 G4double Z0;
163 G4double S0;
164 G4double T0;
165 G4double Xp0;
166 G4double Yp0;
167 G4double Zp0;
168 G4double E0;
169 G4double P0;
170 G4double tilt;
171 G4double sigmaT;
172 G4double sigmaP;
173 G4double sigmaE;
174 G4double sigmaEk;
176
179
182
186
187 G4bool finiteTilt;
192
196
197private:
199 G4Transform3D beamlineTransform;
200
201 G4double beamlineS;
202 G4double mass2;
203
205 mutable const BDSBeamline* beamline;
206};
207
208#endif
A vector of BDSBeamlineElement instances - a beamline.
Definition: BDSBeamline.hh:61
The base class for bunch distribution generators.
Definition: BDSBunch.hh:47
BDSParticleCoordsFullGlobal ApplyCurvilinearTransform(const BDSParticleCoordsFull &localIn) const
Calculate the global coordinates from curvilinear coordinates of a beam line.
Definition: BDSBunch.cc:278
G4double mass2
Cache of mass squared as required to convert from p to E.
Definition: BDSBunch.hh:202
G4double sigmaE
Centre of distributions.
Definition: BDSBunch.hh:173
G4bool finiteTilt
Definition: BDSBunch.hh:187
const BDSBeamline * beamline
A reference to the fully constructed beamline that's lazily instantiated.
Definition: BDSBunch.hh:205
G4bool ParticleDefinitionHasBeenUpdated() const
Definition: BDSBunch.hh:128
virtual G4bool ExpectChangingParticleType() const
A hint of whether we expect to require and extended particle set (ie pions, kaons,...
Definition: BDSBunch.hh:80
G4double Yp0
Centre of distributions.
Definition: BDSBunch.hh:166
G4double T0
Centre of distributions.
Definition: BDSBunch.hh:164
G4bool finiteSigmaE
Flags to ignore random number generator in case of no finite E or T.
Definition: BDSBunch.hh:189
G4double tilt
Centre of distributions.
Definition: BDSBunch.hh:170
BDSParticleCoordsFullGlobal ApplyTransform(const BDSParticleCoordsFull &localIn) const
Definition: BDSBunch.cc:258
void ApplyTilt(BDSParticleCoordsFull &localIn) const
Apply a rotation about unitZ for the local coordinates according to member variable tilt.
Definition: BDSBunch.cc:266
G4double S0
Centre of distributions.
Definition: BDSBunch.hh:163
G4double P0
central momentum
Definition: BDSBunch.hh:169
G4bool particleDefinitionHasBeenUpdated
Definition: BDSBunch.hh:185
G4bool generatePrimariesOnly
Definition: BDSBunch.hh:195
virtual void SetGeneratePrimariesOnly(G4bool generatePrimariesOnlyIn)
Definition: BDSBunch.cc:255
G4double sigmaP
Centre of distributions.
Definition: BDSBunch.hh:172
G4bool useCurvilinear
Whether to ignore z and use s and transform for curvilinear coordinates.
Definition: BDSBunch.hh:178
virtual void RecreateAdvanceToEvent(G4int)
Definition: BDSBunch.hh:115
G4Transform3D beamlineTransform
Transform that beam line starts with that will also be applied to coordinates.
Definition: BDSBunch.hh:199
G4double sigmaT
Centre of distributions.
Definition: BDSBunch.hh:171
G4double Z0
Centre of distributions.
Definition: BDSBunch.hh:162
virtual const BDSParticleDefinition * ParticleDefinition() const
Access the beam particle definition.
Definition: BDSBunch.hh:95
virtual BDSParticleCoordsFull GetNextParticleLocal()
Definition: BDSBunch.cc:244
G4double X0
Centre of distributions.
Definition: BDSBunch.hh:160
G4double Zp0
Centre of distributions.
Definition: BDSBunch.hh:167
G4bool BeamParticleIsAnIon() const
Access whether the beam particle is an ion or not.
Definition: BDSBunch.hh:118
virtual void Initialise()
Any initialisation - to be used after SetOptions, then CheckParameters.
Definition: BDSBunch.cc:203
G4double Xp0
Centre of distributions.
Definition: BDSBunch.hh:165
G4double E0
Centre of distributions.
Definition: BDSBunch.hh:168
G4double sigmaEk
Centre of distributions.
Definition: BDSBunch.hh:174
static void SetEmittances(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, G4double &emittGeometricX, G4double &emittGeometricY, G4double &emittNormalisedX, G4double &emittNormalisedY)
Definition: BDSBunch.cc:155
G4double Y0
Centre of distributions.
Definition: BDSBunch.hh:161
virtual void BeginOfRunAction(G4int numberOfEvents)
Definition: BDSBunch.cc:252
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 UpdateIonDefinition()
Definition: BDSBunch.cc:332
G4double beamlineS
Beamline initial S position.
Definition: BDSBunch.hh:201
BDSParticleCoordsFullGlobal GetNextParticle()
Definition: BDSBunch.cc:234
G4bool finiteSigmaT
Flags to ignore random number generator in case of no finite E or T.
Definition: BDSBunch.hh:190
static G4double CalculateZp(G4double xp, G4double yp, G4double Zp0)
Calculate zp safely based on other components.
Definition: BDSBunch.cc:317
BDSParticleDefinition * particleDefinition
Particle definition for bunch - this class owns it.
Definition: BDSBunch.hh:181
virtual BDSParticleCoordsFullGlobal GetNextParticleValid(G4int maxTries=100)
Definition: BDSBunch.cc:206
G4String name
Name of distribution.
Definition: BDSBunch.hh:157
G4bool UseCurvilinearTransform() const
Access whether there's a finite S offset and therefore we're using a CL transform.
Definition: BDSBunch.hh:108
virtual void CheckParameters()
Definition: BDSBunch.cc:195
Loader to use any HepMC3 compatible file.
A set of particle coordinates in both local and global.
A set of particle coordinates including energy and weight.
Wrapper for particle definition.
G4bool IsAnIon() const
Accessor.
Loader to read a specific sampler from a BDSIM ROOT output file.
Improve type-safety of native enum data type in C++.
Beam loader.
Definition: Beam.hh:37
Beam class.
Definition: beam.h:44
Parser namespace for GMAD language. Combination of Geant4 and MAD.