BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBeamline.hh
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#ifndef BDSBEAMLINE_H
19#define BDSBEAMLINE_H
20
21#include "globals.hh" // geant4 globals / types
22#include "G4ThreeVector.hh"
23#include "G4Transform3D.hh"
24
25#include "BDSSamplerType.hh"
26#include "BDSExtentGlobal.hh"
27
28#include <iterator>
29#include <ostream>
30#include <set>
31#include <vector>
32
36class BDSSamplerInfo;
38class BDSTiltOffset;
39class BDSTransform3D;
40namespace CLHEP {
41 class HepRotation;
42}
43typedef CLHEP::HepRotation G4RotationMatrix;
44
61{
62private:
64 typedef std::vector<BDSBeamlineElement*> BeamlineVector;
65
68
69public:
72 BDSBeamline(BDSBeamline&) = delete;
73
78 BDSBeamline(const G4ThreeVector& initialGlobalPosition = G4ThreeVector(0,0,0),
79 G4RotationMatrix* initialGlobalRotation = nullptr,
80 G4double initialSIn = 0.0);
81
83 explicit BDSBeamline(G4Transform3D initialTransform,
84 G4double initialSIn = 0.0);
85
87
93 BDSTiltOffset* tiltOffset = nullptr,
94 BDSSamplerInfo* samplerInfo = nullptr,
95 const BDSBeamlineIntegral* beamlineIntegral = nullptr);
96
102 void ApplyTransform3D(BDSTransform3D* component);
103
111
114 void PrintAllComponents(std::ostream& out) const;
115
118 void UpdateExtents(BDSBeamlineElement* element);
119
121 inline const BDSBeamlineElement* at(int iElement) const { return beamline.at(iElement);}
122
124 inline const BDSBeamlineElement* GetFirstItem() const {return front();}
125
127 inline const BDSBeamlineElement* GetLastItem() const {return back();}
128
130 const BDSBeamlineElement* GetElement(G4String acceleratorComponentName, G4int i = 0) const;
131
134 G4Transform3D GetTransformForElement(const G4String& acceleratorComponentName, G4int i = 0) const;
135
137 inline G4double GetTotalChordLength() const {return totalChordLength;}
138
140 inline G4double GetTotalArcLength() const {return totalArcLength;}
141
143 inline G4double GetTotalAngle() const {return totalAngle;}
144
146 G4bool ElementAnglesSumToCircle() const;
147
149 BeamlineVector::size_type size() const {return beamline.size();}
150
152 G4ThreeVector GetMaximumExtentPositive() const {return maximumExtentPositive;}
153
155 G4ThreeVector GetMaximumExtentNegative() const {return maximumExtentNegative;}
156
158 G4ThreeVector GetMaximumExtentAbsolute() const;
159
162
164 typedef BeamlineVector::iterator iterator;
165 typedef BeamlineVector::const_iterator const_iterator;
166 typedef BeamlineVector::reverse_iterator reverse_iterator;
167 typedef BeamlineVector::const_reverse_iterator const_reverse_iterator;
168 iterator begin() {return beamline.begin();}
169 iterator end() {return beamline.end();}
170 const_iterator begin() const {return beamline.begin();}
171 const_iterator end() const {return beamline.end();}
172 reverse_iterator rbegin() {return beamline.rbegin();}
173 reverse_iterator rend() {return beamline.rend();}
174 const_reverse_iterator rbegin() const {return beamline.rbegin();}
175 const_reverse_iterator rend() const {return beamline.rend();}
176 G4bool empty() const {return beamline.empty();}
178
182 G4Transform3D GetGlobalEuclideanTransform(G4double s,
183 G4double x = 0,
184 G4double y = 0,
185 G4int* indexOfFoundElement = nullptr) const;
186
189 G4int* indexOfFoundElement = nullptr) const;
190
192 const_iterator FindFromS(G4double S) const;
193
196 std::vector<G4double> GetEdgeSPositions() const;
197
198 G4double GetSMinimum() const {return sInitial;}
199 G4double GetSMaximum() const {return sMaximum;}
200
205 const BDSBeamlineElement* GetPrevious(const BDSBeamlineElement* element) const;
206 const BDSBeamlineElement* GetNext(const BDSBeamlineElement* element) const;
207
208 const BDSBeamlineElement* GetPrevious(G4int index) const;
209 const BDSBeamlineElement* GetNext(G4int index) const;
210
211 // Accessors in a similar style to std::vector
213 inline BDSBeamlineElement* front() const {return beamline.front();}
215 inline BDSBeamlineElement* back() const {return beamline.back();}
216
218 friend std::ostream& operator<< (std::ostream &out, BDSBeamline const &bl);
219
222 void PrintMemoryConsumption() const;
223
224 BDSBeamlineElement* ProvideEndPieceElementBefore(BDSSimpleComponent* endPiece,
225 G4int index) const;
230 G4int index,
231 G4bool flip = false) const;
232
234 G4bool IndexOK(G4int index) const;
235
237 static G4double PaddingLength() {return paddingLength;}
238
240 std::vector<G4int> GetIndicesOfElementsOfType(const G4String& type) const;
241
244 std::vector<G4int> GetIndicesOfElementsOfType(const std::set<G4String>& types) const;
245
247 std::vector<G4int> GetIndicesOfCollimators() const;
248
249private:
253 BDSTiltOffset* tiltOffset = nullptr,
254 BDSSamplerInfo* samplerInfo = nullptr,
255 const BDSBeamlineIntegral* beamlineIntegral = nullptr);
256
259 void RegisterElement(BDSBeamlineElement* element);
260
261 G4double sInitial;
262 G4double sMaximum;
263
269 G4double totalAngle;
270
271 G4ThreeVector maximumExtentPositive;
272 G4ThreeVector maximumExtentNegative;
273
276
279
282
286
288 static G4double paddingLength;
289
291 std::map<G4String, BDSBeamlineElement*> components;
292
297 std::vector<G4double> sEnd;
298};
299
300#endif
Abstract class that represents a component of an accelerator.
A class that holds a fully constructed BDSAcceleratorComponent as well as any information relevant to...
A class that holds the current integrated quantities along a beam line.
A vector of BDSBeamlineElement instances - a beamline.
std::vector< BDSBeamlineElement * > BeamlineVector
Typedefs up first so we can declare public iterators.
G4double totalChordLength
Sum of all chord lengths.
std::vector< G4double > GetEdgeSPositions() const
G4ThreeVector previousReferencePositionEnd
Current reference position at the end of the previous element.
const BDSBeamlineElement * GetPrevious(const BDSBeamlineElement *element) const
void PrintAllComponents(std::ostream &out) const
const BDSBeamlineElement * GetElement(G4String acceleratorComponentName, G4int i=0) const
Get the ith placement of an element in the beam line. Returns null pointer if not found.
friend std::ostream & operator<<(std::ostream &out, BDSBeamline const &bl)
output stream
BDSBeamlineElement * front() const
Return a reference to the first element.
BDSBeamlineElement * back() const
Return a reference to the last element.
G4double GetTotalAngle() const
Get the total angle of the beamline.
G4ThreeVector maximumExtentPositive
maximum extent in the positive coordinates in each dimension
const BDSBeamlineElement * GetLastItem() const
Return a reference to the last element.
BDSBeamline & operator=(const BDSBeamline &)=delete
assignment and copy constructor not implemented nor used.
G4double GetTotalChordLength() const
Get the total length of the beamline - the sum of the chord length of each element.
G4double previousSPositionEnd
Current s coordinate at the end of the previous element.
G4bool ElementAnglesSumToCircle() const
Check if the sum of the angle of all elements is two pi.
G4double totalAngle
Sum of all angles.
BDSBeamlineElement * ProvideEndPieceElementAfter(BDSSimpleComponent *endPiece, G4int index, G4bool flip=false) const
G4RotationMatrix * previousReferenceRotationEnd
Current reference rotation at the end of the previous element.
G4bool transformHasJustBeenApplied
void RegisterElement(BDSBeamlineElement *element)
const_iterator begin() const
Iterator mechanics.
const_reverse_iterator rend() const
Iterator mechanics.
void UpdateExtents(BDSBeamlineElement *element)
G4ThreeVector GetMaximumExtentAbsolute() const
Get the maximum extent absolute in each dimension.
void PrintMemoryConsumption() const
void ApplyTransform3D(BDSTransform3D *component)
static G4double PaddingLength()
Access the padding length between each element added to the beamline.
static G4double paddingLength
The gap added for padding between each component.
G4ThreeVector GetMaximumExtentNegative() const
Get the maximum negative extent in all dimensions.
const_reverse_iterator rbegin() const
Iterator mechanics.
const BDSBeamlineElement * at(int iElement) const
Return a reference to the element at i.
reverse_iterator rend()
Iterator mechanics.
const BDSBeamlineElement * GetFirstItem() const
Return a reference to the first element.
G4bool IndexOK(G4int index) const
Whether the supplied index will lie within the beam line vector.
BeamlineVector::iterator iterator
Iterator mechanics.
BeamlineVector::size_type size() const
Get the number of elements.
void AddComponent(BDSAcceleratorComponent *component, BDSTiltOffset *tiltOffset=nullptr, BDSSamplerInfo *samplerInfo=nullptr, const BDSBeamlineIntegral *beamlineIntegral=nullptr)
void AddBeamlineElement(BDSBeamlineElement *element)
G4Transform3D GetTransformForElement(const G4String &acceleratorComponentName, G4int i=0) const
const_iterator FindFromS(G4double S) const
Returns an iterator to the beamline element at s.
G4double totalArcLength
Sum of all arc lengths.
BeamlineVector::const_reverse_iterator const_reverse_iterator
Iterator mechanics.
BeamlineVector beamline
Vector of beam line elements - the data.
const BDSBeamlineElement * GetElementFromGlobalS(G4double S, G4int *indexOfFoundElement=nullptr) const
Return the element in this beam line according to a given s coordinate.
G4bool empty() const
Iterator mechanics.
G4ThreeVector GetMaximumExtentPositive() const
Get the maximum positive extent in all dimensions
G4Transform3D GetGlobalEuclideanTransform(G4double s, G4double x=0, G4double y=0, G4int *indexOfFoundElement=nullptr) const
BDSExtentGlobal GetExtentGlobal() const
Get the global extents for this beamline.
reverse_iterator rbegin()
Iterator mechanics.
iterator begin()
Iterator mechanics.
void AddSingleComponent(BDSAcceleratorComponent *component, BDSTiltOffset *tiltOffset=nullptr, BDSSamplerInfo *samplerInfo=nullptr, const BDSBeamlineIntegral *beamlineIntegral=nullptr)
const_iterator end() const
Iterator mechanics.
std::map< G4String, BDSBeamlineElement * > components
Map of objects by placement name stored in this beam line.
iterator end()
Iterator mechanics.
std::vector< G4int > GetIndicesOfElementsOfType(const G4String &type) const
Return vector of indices for this beam line where element of type name 'type' is found.
G4double GetTotalArcLength() const
Get the total ARC length for the beamline - ie the maximum s position.
std::vector< G4double > sEnd
BeamlineVector::const_iterator const_iterator
Iterator mechanics.
G4double sInitial
Cache the initial S so we can tell if a requested S is too low.
std::vector< G4int > GetIndicesOfCollimators() const
Return indices in order of ecol, rcol, jcol and crystalcol elements.
BeamlineVector::reverse_iterator reverse_iterator
Iterator mechanics.
G4ThreeVector maximumExtentNegative
maximum extent in the negative coordinates in each dimension
Holder for +- extents in 3 dimensions with a rotation and translation.
All info required to build a sampler but not place it.
A BDSAcceleratorComponent wrapper for BDSGeometryComponent.
A holder for any placement offsets and rotations for a BDSAcceleratorComponent.
Transform in beam line that takes up no space.