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) 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#include "BDSBunchSlowExt.hh"
19#include "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSParticleCoordsFull.hh"
22#include "BDSUtilities.hh"
23#include "BDSWarning.hh"
24
25#include "parser/beam.h"
26
27#include "Randomize.hh"
28#include "CLHEP/Units/PhysicalConstants.h"
29
30#include <cmath>
31
32BDSBunchSlowExt::BDSBunchSlowExt():
33 BDSBunch("slowext"),
34 dTStart(0),
35 dTStop(0),
36 dPStart(0),
37 dPStop(0),
38 applyGradient(false),
39 dT(0),
40 dEStart(0),
41 dE(0)
42{;}
43
44BDSBunchSlowExt::~BDSBunchSlowExt()
45{;}
46
48 const GMAD::Beam& beam,
49 const BDSBunchType& distrType,
50 G4Transform3D beamlineTransformIn,
51 const G4double beamlineSIn)
52{
53 BDSBunch::SetOptions(beamParticle, beam, distrType, beamlineTransformIn, beamlineSIn);
54 dTStart = beam.dTStart * CLHEP::s;
55 dTStop = beam.dTStop * CLHEP::s;
56 dPStart = beam.dPStart * CLHEP::GeV;
57 dPStop = beam.dPStop * CLHEP::GeV;
58
59 dT = dTStop - dTStart;
60
61 // bunch definition needs total energy, so we go from dP to dE
62 G4double pA = P0 + dPStart;
63 G4double pB = P0 + dPStop;
65 pdCopy.SetEnergies(0, 0, pA);
66 G4double EStart = pdCopy.TotalEnergy();
67 pdCopy.SetEnergies(0, 0, pB);
68 G4double EStop = pdCopy.TotalEnergy();
69 dEStart = EStart - E0;
70 dE = EStop - EStart;
71
72 // if not difference in both time or momentum then no need to do anything
73 applyGradient = BDS::IsFinite(std::abs(dTStop - dTStart)) && BDS::IsFinite(std::abs(dPStop - dPStart));
74
75 if (!applyGradient)
76 {BDS::Warning(__METHOD_NAME__, "no difference in time and momentum - no action for this distribution");}
77}
78
80{
82 if (dTStop < dTStart)
83 {throw BDSException(__METHOD_NAME__, "dTStop must be greater or equal to dTStart");}
84}
85
87{
88 if (!applyGradient)
90
91 G4double dtLocal, dELocal;
92 GetDeltas(dtLocal, dELocal);
93 G4double t = T0 + dtLocal;
94 G4double E = E0 + dELocal;
95
96 return BDSParticleCoordsFull(X0,Y0,Z0,Xp0,Yp0,Zp0,t,S0,E,/*weight=*/1.0);
97}
98
99void BDSBunchSlowExt::GetDeltas(G4double& dtLocal, G4double& dELocal) const
100{
101 G4double fraction = G4RandFlat::shoot();
102 dtLocal = dTStart + dT*fraction;
103 dELocal = dEStart + dE*fraction;
104}
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:46
G4double Yp0
Centre of distributions.
Definition BDSBunch.hh:176
G4double T0
Centre of distributions.
Definition BDSBunch.hh:174
G4double S0
Centre of distributions.
Definition BDSBunch.hh:173
G4double P0
central momentum
Definition BDSBunch.hh:179
G4double Z0
Centre of distributions.
Definition BDSBunch.hh:172
virtual BDSParticleCoordsFull GetNextParticleLocal()
Definition BDSBunch.cc:271
G4double X0
Centre of distributions.
Definition BDSBunch.hh:170
G4double Zp0
Centre of distributions.
Definition BDSBunch.hh:177
G4double Xp0
Centre of distributions.
Definition BDSBunch.hh:175
G4double E0
Centre of distributions.
Definition BDSBunch.hh:178
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
BDSParticleDefinition * particleDefinition
Particle definition for bunch - this class owns it.
Definition BDSBunch.hh:198
virtual void CheckParameters()
Definition BDSBunch.cc:222
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:43
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())