BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunch.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 BDSBUNCH_H
19#define BDSBUNCH_H
20
21#include "BDSBunchType.hh"
22#include "BDSParticleCoords.hh"
23#include "BDSParticleCoordsFull.hh"
24#include "BDSParticleCoordsFullGlobal.hh"
25#include "BDSParticleDefinition.hh"
26
27#include "globals.hh"
28#include "G4Transform3D.hh"
29
30class BDSBeamline;
31
32namespace GMAD
33{
34 class Beam;
35}
36
46{
47public:
48 BDSBunch();
49 explicit BDSBunch(const G4String& nameIn);
50 virtual ~BDSBunch();
51
55
61 virtual void SetOptions(const BDSParticleDefinition* beamParticle,
62 const GMAD::Beam& beam,
63 const BDSBunchType& distrType,
64 G4Transform3D beamlineTransformIn = G4Transform3D::Identity,
65 const G4double beamlineS = 0);
66
69 virtual void CheckParameters();
70
72 virtual void Initialise();
73
77
79 virtual G4bool ExpectChangingParticleType() const {return false;}
80
86 virtual BDSParticleCoordsFullGlobal GetNextParticleValid(G4int maxTries = 100);
87
91 virtual void BeginOfRunAction(G4int numberOfEvents,
92 G4bool batchMode);
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
144 inline G4String Name() const {return name;}
145
147 inline G4int CurrentBunchIndex() const {return currentBunchIndex;}
148
150 void CalculateBunchIndex(G4int eventIndex);
151
152protected:
157
159 void ApplyTilt(BDSParticleCoordsFull& localIn) const;
160
163
166
167 G4String name;
168
170 G4double X0;
171 G4double Y0;
172 G4double Z0;
173 G4double S0;
174 G4double T0;
175 G4double Xp0;
176 G4double Yp0;
177 G4double Zp0;
178 G4double E0;
179 G4double P0;
180 G4double tilt;
181 G4double sigmaT;
182 G4double sigmaP;
183 G4double sigmaE;
184 G4double sigmaEk;
186
191 G4double bunchPeriod;
193
196
199
203
204 G4bool finiteTilt;
209
213
214private:
216 G4Transform3D beamlineTransform;
217
218 G4double beamlineS;
219 G4double mass2;
220
222 mutable const BDSBeamline* beamline;
223};
224
225#endif
A vector of BDSBeamlineElement instances - a beamline.
The base class for bunch distribution generators.
Definition BDSBunch.hh:46
BDSParticleCoordsFullGlobal ApplyCurvilinearTransform(const BDSParticleCoordsFull &localIn) const
Calculate the global coordinates from curvilinear coordinates of a beam line.
Definition BDSBunch.cc:328
G4double mass2
Cache of mass squared as required to convert from p to E.
Definition BDSBunch.hh:219
G4double sigmaE
Centre of distributions.
Definition BDSBunch.hh:183
G4bool finiteTilt
Definition BDSBunch.hh:204
virtual void BeginOfRunAction(G4int numberOfEvents, G4bool batchMode)
Definition BDSBunch.cc:284
const BDSBeamline * beamline
A reference to the fully constructed beamline that's lazily instantiated.
Definition BDSBunch.hh:222
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:79
bool useBunchTiming
Bunch offset in time parameters.
Definition BDSBunch.hh:188
G4double Yp0
Centre of distributions.
Definition BDSBunch.hh:176
G4double T0
Centre of distributions.
Definition BDSBunch.hh:174
G4bool finiteSigmaE
Flags to ignore random number generator in case of no finite E or T.
Definition BDSBunch.hh:206
G4double tilt
Centre of distributions.
Definition BDSBunch.hh:180
BDSParticleCoordsFullGlobal ApplyTransform(const BDSParticleCoordsFull &localIn) const
Definition BDSBunch.cc:291
virtual void RecreateAdvanceToEvent(G4int eventOffset)
Definition BDSBunch.cc:279
void ApplyTilt(BDSParticleCoordsFull &localIn) const
Apply a rotation about unitZ for the local coordinates according to member variable tilt.
Definition BDSBunch.cc:310
G4double S0
Centre of distributions.
Definition BDSBunch.hh:173
G4int currentBunchIndex
Bunch offset in time parameters.
Definition BDSBunch.hh:189
G4double P0
central momentum
Definition BDSBunch.hh:179
G4bool particleDefinitionHasBeenUpdated
Definition BDSBunch.hh:202
G4bool generatePrimariesOnly
Definition BDSBunch.hh:212
virtual void SetGeneratePrimariesOnly(G4bool generatePrimariesOnlyIn)
Definition BDSBunch.cc:288
G4double sigmaP
Centre of distributions.
Definition BDSBunch.hh:182
G4bool useCurvilinear
Whether to ignore z and use s and transform for curvilinear coordinates.
Definition BDSBunch.hh:195
G4Transform3D beamlineTransform
Transform that beam line starts with that will also be applied to coordinates.
Definition BDSBunch.hh:216
void ApplyBunchTiming(BDSParticleCoordsFullGlobal &localIn) const
Add on the offset in T for the current bunch number (i*bunchPeriod).
Definition BDSBunch.cc:322
G4double sigmaT
Centre of distributions.
Definition BDSBunch.hh:181
G4double Z0
Centre of distributions.
Definition BDSBunch.hh:172
virtual const BDSParticleDefinition * ParticleDefinition() const
Access the beam particle definition.
Definition BDSBunch.hh:95
void CalculateBunchIndex(G4int eventIndex)
Calculate which bunch index we should be at given an event index.
Definition BDSBunch.cc:214
virtual BDSParticleCoordsFull GetNextParticleLocal()
Definition BDSBunch.cc:271
G4double bunchPeriod
Bunch offset in time parameters.
Definition BDSBunch.hh:191
G4int CurrentBunchIndex() const
Get the current bunch index for writing to output.
Definition BDSBunch.hh:147
G4double X0
Centre of distributions.
Definition BDSBunch.hh:170
G4double Zp0
Centre of distributions.
Definition BDSBunch.hh:177
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:230
G4double Xp0
Centre of distributions.
Definition BDSBunch.hh:175
G4double E0
Centre of distributions.
Definition BDSBunch.hh:178
G4double sigmaEk
Centre of distributions.
Definition BDSBunch.hh:184
static void SetEmittances(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, G4double &emittGeometricX, G4double &emittGeometricY, G4double &emittNormalisedX, G4double &emittNormalisedY)
Definition BDSBunch.cc:174
G4double Y0
Centre of distributions.
Definition BDSBunch.hh:171
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
Definition BDSBunch.cc:81
G4String Name() const
Distribution name.
Definition BDSBunch.hh:144
virtual void UpdateIonDefinition()
Definition BDSBunch.cc:388
G4double beamlineS
Beamline initial S position.
Definition BDSBunch.hh:218
BDSParticleCoordsFullGlobal GetNextParticle()
Definition BDSBunch.cc:261
G4bool finiteSigmaT
Flags to ignore random number generator in case of no finite E or T.
Definition BDSBunch.hh:207
static G4double CalculateZp(G4double xp, G4double yp, G4double Zp0)
Calculate zp safely based on other components.
Definition BDSBunch.cc:373
BDSParticleDefinition * particleDefinition
Particle definition for bunch - this class owns it.
Definition BDSBunch.hh:198
virtual BDSParticleCoordsFullGlobal GetNextParticleValid(G4int maxTries=100)
Definition BDSBunch.cc:233
G4String name
Name of distribution.
Definition BDSBunch.hh:167
G4int eventsPerBunch
Bunch offset in time parameters.
Definition BDSBunch.hh:190
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:222
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 use any HepMC3 compatible file.
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:36
Beam class.
Definition beam.h:43
Parser namespace for GMAD language. Combination of Geant4 and MAD.