BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchComposite.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 "BDSBunch.hh"
19#include "BDSBunchComposite.hh"
20#include "BDSBunchFactory.hh"
21#include "BDSDebug.hh"
22#include "BDSException.hh"
23#include "BDSParticleCoordsFull.hh"
24
25#include "parser/beam.h"
26
27BDSBunchComposite::BDSBunchComposite():
28BDSBunch("composite"),
29 xBunch(nullptr),
30 yBunch(nullptr),
31 zBunch(nullptr)
32{;}
33
34BDSBunchComposite::~BDSBunchComposite()
35{
36 delete xBunch;
37 delete yBunch;
38 delete zBunch;
39}
40
42 const GMAD::Beam& beam,
43 const BDSBunchType& distrType,
44 G4Transform3D beamlineTransformIn,
45 G4double beamlineSIn)
46{
47 BDSBunch::SetOptions(beamParticle, beam, distrType, beamlineTransformIn,beamlineSIn);
48
49 delete xBunch;
50 delete yBunch;
51 delete zBunch;
52 BDSBunchType xType;
53 BDSBunchType yType;
54 BDSBunchType zType;
55 try
56 {xType = BDS::DetermineBunchType(beam.xDistrType);}
57 catch (BDSException& e)
58 {e.AppendToMessage("Error with x dimension composite beam distribution"); throw e;}
59 try
60 {yType = BDS::DetermineBunchType(beam.yDistrType);}
61 catch (BDSException& e)
62 {e.AppendToMessage("Error with y dimension composite beam distribution"); throw e;}
63 try
64 {zType = BDS::DetermineBunchType(beam.zDistrType);}
65 catch (BDSException& e)
66 {e.AppendToMessage("Error with z dimension composite beam distribution"); throw e;}
67
68 if (xType == BDSBunchType::composite ||
69 yType == BDSBunchType::composite ||
70 zType == BDSBunchType::composite)
71 {throw BDSException(__METHOD_NAME__, "x,y,z distributions cannot be 'composite'");}
72
73 // here we don't have generatePrimariesOnly bool but this will be overridden with the
74 // separate call to SetGeneratePrimariesOnly in BDSBunchFactory
75 xBunch = BDSBunchFactory::CreateBunch(beamParticle, xType, beam, beamlineTransformIn);
76 yBunch = BDSBunchFactory::CreateBunch(beamParticle, yType, beam, beamlineTransformIn);
77 zBunch = BDSBunchFactory::CreateBunch(beamParticle, zType, beam, beamlineTransformIn);
78
79 name = "composite: x: " + xBunch->Name() + ", y: " + yBunch->Name() + ", z: " + zBunch->Name();
80}
81
82void BDSBunchComposite::SetGeneratePrimariesOnly(G4bool generatePrimariesOnlyIn)
83{
84 BDSBunch::SetGeneratePrimariesOnly(generatePrimariesOnlyIn);
85 xBunch->SetGeneratePrimariesOnly(generatePrimariesOnlyIn);
86 yBunch->SetGeneratePrimariesOnly(generatePrimariesOnlyIn);
87 zBunch->SetGeneratePrimariesOnly(generatePrimariesOnlyIn);
88}
89
91{
92 xBunch->CheckParameters();
93 yBunch->CheckParameters();
94 zBunch->CheckParameters();
95}
96
98{
99 auto x = xBunch->GetNextParticleLocal();
100 auto y = yBunch->GetNextParticleLocal();
101 auto z = zBunch->GetNextParticleLocal();
102
106
107 BDSParticleCoordsFull result(x.x, y.y, z.z,
108 x.xp, y.yp, z.zp,
109 z.T, z.s,
110 z.totalEnergy,
111 x.weight * y.weight * z.weight);
112 return result;
113}
virtual BDSParticleCoordsFull GetNextParticleLocal()
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
virtual void SetGeneratePrimariesOnly(G4bool generatePrimariesOnlyIn)
virtual void CheckParameters()
static BDSBunch * CreateBunch(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const G4Transform3D &beamlineTransform=G4Transform3D::Identity, G4double beamlineS=0, G4bool generatePrimariesOnlyIn=false)
factory method
The base class for bunch distribution generators.
Definition BDSBunch.hh:46
G4bool ParticleDefinitionHasBeenUpdated() const
Definition BDSBunch.hh:128
G4bool particleDefinitionHasBeenUpdated
Definition BDSBunch.hh:202
virtual void SetGeneratePrimariesOnly(G4bool generatePrimariesOnlyIn)
Definition BDSBunch.cc:288
virtual BDSParticleCoordsFull GetNextParticleLocal()
Definition BDSBunch.cc:271
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
G4String name
Name of distribution.
Definition BDSBunch.hh:167
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++.
std::string zDistrType
beam parameters
Definition beamBase.h:47
std::string yDistrType
beam parameters
Definition beamBase.h:46
std::string xDistrType
beam parameters
Definition beamBase.h:45
Beam class.
Definition beam.h:43
BDSBunchType DetermineBunchType(G4String distrType)
Function that gives corresponding enum value for string (case-insensitive).