BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchCompositeSDE.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 "BDSBunchCompositeSDE.hh"
20#include "BDSBunchFactory.hh"
21#include "BDSDebug.hh"
22#include "BDSException.hh"
23#include "BDSParticleCoordsFull.hh"
24
25#include "parser/beam.h"
26
27BDSBunchCompositeSDE::BDSBunchCompositeSDE():
28BDSBunch("compositespacedirectionenergy"),
29 sBunch(nullptr),
30 dBunch(nullptr),
31 eBunch(nullptr)
32{;}
33
34BDSBunchCompositeSDE::~BDSBunchCompositeSDE()
35{
36 delete sBunch;
37 delete dBunch;
38 delete eBunch;
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 sBunch;
50 delete dBunch;
51 delete eBunch;
52 BDSBunchType sType;
53 BDSBunchType dType;
54 BDSBunchType eType;
55 try
57 catch (BDSException& e)
58 {e.AppendToMessage("Error with space dimension in composite beam distribution"); throw e;}
59 try
61 catch (BDSException& e)
62 {e.AppendToMessage("Error with direction dimension in composite beam distribution"); throw e;}
63 try
65 catch (BDSException& e)
66 {e.AppendToMessage("Error with energy dimension in composite beam distribution"); throw e;}
67
68 std::vector<BDSBunchType> dims = {sType, dType, eType};
69 for (auto d : dims)
70 {
71 if (d == BDSBunchType::composite || d == BDSBunchType::compositesde)
72 {throw BDSException(__METHOD_NAME__, "s,y,z distributions cannot be 'composite'");}
73 }
74
75 // here we don't have generatePrimariesOnly bool but this will be overridden with the
76 // separate call to SetGeneratePrimariesOnly in BDSBunchFactory
77 sBunch = BDSBunchFactory::CreateBunch(beamParticle, sType, beam, beamlineTransformIn);
78 dBunch = BDSBunchFactory::CreateBunch(beamParticle, dType, beam, beamlineTransformIn);
79 eBunch = BDSBunchFactory::CreateBunch(beamParticle, eType, beam, beamlineTransformIn);
80
81 name = "composite: space: " + sBunch->Name() + ", direction: " + dBunch->Name() + ", energy: " + eBunch->Name();
82}
83
84void BDSBunchCompositeSDE::SetGeneratePrimariesOnly(G4bool generatePrimariesOnlyIn)
85{
86 BDSBunch::SetGeneratePrimariesOnly(generatePrimariesOnlyIn);
87 sBunch->SetGeneratePrimariesOnly(generatePrimariesOnlyIn);
88 dBunch->SetGeneratePrimariesOnly(generatePrimariesOnlyIn);
89 eBunch->SetGeneratePrimariesOnly(generatePrimariesOnlyIn);
90}
91
93{
94 sBunch->CheckParameters();
95 dBunch->CheckParameters();
96 eBunch->CheckParameters();
97}
98
100{
101 auto s = sBunch->GetNextParticleLocal();
102 auto d = dBunch->GetNextParticleLocal();
103 auto e = eBunch->GetNextParticleLocal();
104
108
109 // TODO - the weight only comes from the e distribution here... should it be product of all?
110 BDSParticleCoordsFull result(s.x, s.y, s.z,
111 d.xp, d.yp, d.zp,
112 e.T, s.s,
113 e.totalEnergy,
114 s.weight * d.weight * e.weight);
115 return result;
116}
virtual void SetGeneratePrimariesOnly(G4bool generatePrimariesOnlyIn)
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
virtual BDSParticleCoordsFull GetNextParticleLocal()
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 directionDistrType
beam parameters
Definition beamBase.h:49
std::string spaceDistrType
beam parameters
Definition beamBase.h:48
std::string energyDistrType
beam parameters
Definition beamBase.h:50
Beam class.
Definition beam.h:43
BDSBunchType DetermineBunchType(G4String distrType)
Function that gives corresponding enum value for string (case-insensitive).