BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchSlowExt.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
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 "BDSBunchSlowExt.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22#include "BDSParticleCoordsFull.hh"
23#include "BDSUtilities.hh"
24#include "BDSWarning.hh"
25
26#include "parser/beam.h"
27
28#include "Randomize.hh"
29#include "CLHEP/Units/PhysicalConstants.h"
30
31#include <cmath>
32
33BDSBunchSlowExt::BDSBunchSlowExt():
34 BDSBunch("slowext"),
35 dTStart(0),
36 dTStop(0),
37 dPStart(0),
38 dPStop(0),
39 applyGradient(false),
40 dT(0),
41 dEStart(0),
42 dE(0)
43{;}
44
45BDSBunchSlowExt::~BDSBunchSlowExt()
46{;}
47
49 const GMAD::Beam& beam,
50 const BDSBunchType& distrType,
51 G4Transform3D beamlineTransformIn,
52 const G4double beamlineSIn)
53{
54 BDSBunch::SetOptions(beamParticle, beam, distrType, beamlineTransformIn, beamlineSIn);
55 dTStart = beam.dTStart * CLHEP::s;
56 dTStop = beam.dTStop * CLHEP::s;
57 dPStart = beam.dPStart * CLHEP::GeV;
58 dPStop = beam.dPStop * CLHEP::GeV;
59
60 dT = dTStop - dTStart;
61
62 // bunch definition needs total energy, so we go from dP to dE
63 G4double pA = P0 + dPStart;
64 G4double pB = P0 + dPStop;
66 pdCopy.SetEnergies(0, 0, pA);
67 G4double EStart = pdCopy.TotalEnergy();
68 pdCopy.SetEnergies(0, 0, pB);
69 G4double EStop = pdCopy.TotalEnergy();
70 dEStart = EStart - E0;
71 dE = EStop - EStart;
72
73 // if not difference in both time or momentum then no need to do anything
74 applyGradient = BDS::IsFinite(std::abs(dTStop - dTStart)) && BDS::IsFinite(std::abs(dPStop - dPStart));
75
76 if (!applyGradient)
77 {BDS::Warning(__METHOD_NAME__, "no difference in time and momentum - no action for this distribution");}
78}
79
81{
83 if (dTStop < dTStart)
84 {throw BDSException(__METHOD_NAME__, "dTStop must be greater or equal to dTStart");}
85}
86
88{
89 if (!applyGradient)
91
92 G4double dtLocal, dELocal;
93 GetDeltas(dtLocal, dELocal);
94 G4double t = T0 + dtLocal;
95 G4double E = E0 + dELocal;
96
97 return BDSParticleCoordsFull(X0,Y0,Z0,Xp0,Yp0,Zp0,t,S0,E,/*weight=*/1.0);
98}
99
100void BDSBunchSlowExt::GetDeltas(G4double& dtLocal, G4double& dELocal) const
101{
102 G4double fraction = G4RandFlat::shoot();
103 dtLocal = dTStart + dT*fraction;
104 dELocal = dEStart + dE*fraction;
105}
virtual void CheckParameters()
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
virtual BDSParticleCoordsFull GetNextParticleLocal()
void GetDeltas(G4double &dt, G4double &dE) const
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 P0
central momentum
Definition BDSBunch.hh:180
G4double Z0
Centre of distributions.
Definition BDSBunch.hh:173
virtual BDSParticleCoordsFull GetNextParticleLocal()
Definition BDSBunch.cc:272
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
BDSParticleDefinition * particleDefinition
Particle definition for bunch - this class owns it.
Definition BDSBunch.hh:199
virtual void CheckParameters()
Definition BDSBunch.cc:223
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++.
double dPStop
for slow-extraction beam
Definition beamBase.h:170
double dTStart
for slow-extraction beam
Definition beamBase.h:167
double dPStart
for slow-extraction beam
Definition beamBase.h:169
double dTStop
for slow-extraction beam
Definition beamBase.h:168
Beam class.
Definition beam.h:44
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())