BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSBunchBox.cc
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#include "BDSBunchBox.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22#include "BDSParticleCoordsFull.hh"
23
24#include "parser/beam.h"
25
26#include "Randomize.hh"
27#include "CLHEP/Units/PhysicalConstants.h"
28
29BDSBunchBox::BDSBunchBox():
30 BDSBunch("box"),
31 envelopeX(0.0),
32 envelopeY(0.0),
33 envelopeZ(0.0),
34 envelopeXp(0.0),
35 envelopeYp(0.0),
36 envelopeZp(0.0),
37 envelopeT(0.0),
38 envelopeE(0.0)
39{
40 flatGen = new CLHEP::RandFlat(*CLHEP::HepRandom::getTheEngine());
41}
42
43BDSBunchBox::~BDSBunchBox()
44{
45 delete flatGen;
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 envelopeX = beam.envelopeX * CLHEP::m;
56 envelopeY = beam.envelopeY * CLHEP::m;
57 envelopeZ = beam.envelopeY * CLHEP::m;
58 envelopeXp = beam.envelopeXp * CLHEP::rad;
59 envelopeYp = beam.envelopeYp * CLHEP::rad;
60 envelopeZp = beam.envelopeYp * CLHEP::rad;
61 envelopeT = beam.envelopeT * CLHEP::s;
62 envelopeE = beam.envelopeE * CLHEP::GeV;
63}
64
66{
68 if (envelopeX < 0)
69 {throw BDSException(__METHOD_NAME__, "envelopeX < 0");}
70 if (envelopeXp < 0)
71 {throw BDSException(__METHOD_NAME__, "envelopeXp < 0");}
72 if (envelopeY < 0)
73 {throw BDSException(__METHOD_NAME__, "envelopeY < 0");}
74 if (envelopeYp < 0)
75 {throw BDSException(__METHOD_NAME__, "envelopeYp < 0");}
76 if (envelopeZ < 0)
77 {throw BDSException(__METHOD_NAME__, "envelopeZ < 0");}
78 if (envelopeZp < 0)
79 {throw BDSException(__METHOD_NAME__, "envelopeZp < 0");}
80 if (envelopeT < 0)
81 {throw BDSException(__METHOD_NAME__, "envelopeT < 0");}
82 if (envelopeE < 0)
83 {throw BDSException(__METHOD_NAME__, "envelopeE < 0");}
84}
85
87{
88 G4double x = X0 + envelopeX * (1-2*flatGen->shoot());
89 G4double y = Y0 + envelopeY * (1-2*flatGen->shoot());
90 G4double z = Z0 + envelopeZ * (1-2*flatGen->shoot());
91 G4double xp = envelopeXp * (1-2*flatGen->shoot());
92 G4double yp = envelopeYp * (1-2*flatGen->shoot());
93 G4double zp = envelopeZp * (1-2*flatGen->shoot());
94 G4ThreeVector dir(xp,yp,zp);
95 dir = dir.unit();
96 xp = dir.x();
97 yp = dir.y();
98 zp = dir.z();
99
100 G4double t = T0 + envelopeT * (1.- 2.*flatGen->shoot());
101 G4double E = E0 + envelopeE * (1 - 2.*flatGen->shoot());
102
103 return BDSParticleCoordsFull(x,y,z,xp,yp,zp,t,S0+z,E,/*weight=*/1.0);
104}
virtual void CheckParameters()
Definition: BDSBunchBox.cc:65
virtual BDSParticleCoordsFull GetNextParticleLocal()
Definition: BDSBunchBox.cc:86
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
Definition: BDSBunchBox.cc:48
The base class for bunch distribution generators.
Definition: BDSBunch.hh:47
G4double T0
Centre of distributions.
Definition: BDSBunch.hh:164
G4double S0
Centre of distributions.
Definition: BDSBunch.hh:163
G4double Z0
Centre of distributions.
Definition: BDSBunch.hh:162
G4double X0
Centre of distributions.
Definition: BDSBunch.hh:160
G4double E0
Centre of distributions.
Definition: BDSBunch.hh:168
G4double Y0
Centre of distributions.
Definition: BDSBunch.hh:161
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 CheckParameters()
Definition: BDSBunch.cc:195
General exception with possible name of object and message.
Definition: BDSException.hh:35
A set of particle coordinates including energy and weight.
Wrapper for particle definition.
Improve type-safety of native enum data type in C++.
double envelopeE
for the circle/square/box beam distribution
Definition: beamBase.h:92
double envelopeYp
for the circle/square/box beam distribution
Definition: beamBase.h:91
double envelopeX
for the circle/square/box beam distribution
Definition: beamBase.h:91
double envelopeXp
for the circle/square/box beam distribution
Definition: beamBase.h:91
double envelopeY
for the circle/square/box beam distribution
Definition: beamBase.h:91
double envelopeT
for the circle/square/box beam distribution
Definition: beamBase.h:92
Beam class.
Definition: beam.h:44