BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchBox.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 "BDSBunchBox.hh"
19#include "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSParticleCoordsFull.hh"
22
23#include "parser/beam.h"
24
25#include "Randomize.hh"
26#include "CLHEP/Units/PhysicalConstants.h"
27
28BDSBunchBox::BDSBunchBox():
29 BDSBunch("box"),
30 envelopeX(0.0),
31 envelopeY(0.0),
32 envelopeZ(0.0),
33 envelopeXp(0.0),
34 envelopeYp(0.0),
35 envelopeZp(0.0),
36 envelopeT(0.0),
37 envelopeE(0.0)
38{;}
39
40BDSBunchBox::~BDSBunchBox()
41{;}
42
44 const GMAD::Beam& beam,
45 const BDSBunchType& distrType,
46 G4Transform3D beamlineTransformIn,
47 const G4double beamlineSIn)
48{
49 BDSBunch::SetOptions(beamParticle, beam, distrType, beamlineTransformIn, beamlineSIn);
50 envelopeX = beam.envelopeX * CLHEP::m;
51 envelopeY = beam.envelopeY * CLHEP::m;
52 envelopeZ = beam.envelopeY * CLHEP::m;
53 envelopeXp = beam.envelopeXp * CLHEP::rad;
54 envelopeYp = beam.envelopeYp * CLHEP::rad;
55 envelopeZp = beam.envelopeYp * CLHEP::rad;
56 envelopeT = beam.envelopeT * CLHEP::s;
57 envelopeE = beam.envelopeE * CLHEP::GeV;
58}
59
61{
63 if (envelopeX < 0)
64 {throw BDSException(__METHOD_NAME__, "envelopeX < 0");}
65 if (envelopeXp < 0)
66 {throw BDSException(__METHOD_NAME__, "envelopeXp < 0");}
67 if (envelopeY < 0)
68 {throw BDSException(__METHOD_NAME__, "envelopeY < 0");}
69 if (envelopeYp < 0)
70 {throw BDSException(__METHOD_NAME__, "envelopeYp < 0");}
71 if (envelopeZ < 0)
72 {throw BDSException(__METHOD_NAME__, "envelopeZ < 0");}
73 if (envelopeZp < 0)
74 {throw BDSException(__METHOD_NAME__, "envelopeZp < 0");}
75 if (envelopeT < 0)
76 {throw BDSException(__METHOD_NAME__, "envelopeT < 0");}
77 if (envelopeE < 0)
78 {throw BDSException(__METHOD_NAME__, "envelopeE < 0");}
79}
80
82{
83 G4double x = X0 + envelopeX * (1-2*G4RandFlat::shoot());
84 G4double y = Y0 + envelopeY * (1-2*G4RandFlat::shoot());
85 G4double z = Z0 + envelopeZ * (1-2*G4RandFlat::shoot());
86 G4double xp = envelopeXp * (1-2*G4RandFlat::shoot());
87 G4double yp = envelopeYp * (1-2*G4RandFlat::shoot());
88 G4double zp = envelopeZp * (1-2*G4RandFlat::shoot());
89 G4ThreeVector dir(xp,yp,zp);
90 dir = dir.unit();
91 xp = dir.x();
92 yp = dir.y();
93 zp = dir.z();
94
95 G4double t = T0 + envelopeT * (1.- 2.*G4RandFlat::shoot());
96 G4double E = E0 + envelopeE * (1 - 2.*G4RandFlat::shoot());
97
98 return BDSParticleCoordsFull(x,y,z,xp,yp,zp,t,S0+z,E,/*weight=*/1.0);
99}
virtual void CheckParameters()
virtual BDSParticleCoordsFull GetNextParticleLocal()
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
The base class for bunch distribution generators.
Definition BDSBunch.hh:46
G4double T0
Centre of distributions.
Definition BDSBunch.hh:174
G4double S0
Centre of distributions.
Definition BDSBunch.hh:173
G4double Z0
Centre of distributions.
Definition BDSBunch.hh:172
G4double X0
Centre of distributions.
Definition BDSBunch.hh:170
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
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 envelopeE
for the circle/square/box beam distribution
Definition beamBase.h:99
double envelopeYp
for the circle/square/box beam distribution
Definition beamBase.h:98
double envelopeX
for the circle/square/box beam distribution
Definition beamBase.h:98
double envelopeXp
for the circle/square/box beam distribution
Definition beamBase.h:98
double envelopeY
for the circle/square/box beam distribution
Definition beamBase.h:98
double envelopeT
for the circle/square/box beam distribution
Definition beamBase.h:99
Beam class.
Definition beam.h:43