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) Royal Holloway,
3University of London 2001 - 2024.
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#ifndef BDSBEAMLINE_H
20#define BDSBEAMLINE_H
21
22#include "globals.hh" // geant4 globals / types
23#include "G4ThreeVector.hh"
24#include "G4Transform3D.hh"
25
26#include "BDSSamplerType.hh"
27#include "BDSExtentGlobal.hh"
28
29#include <iterator>
30#include <ostream>
31#include <set>
32#include <vector>
33
37class BDSSamplerInfo;
39class BDSTiltOffset;
40class BDSTransform3D;
41namespace CLHEP {
42 class HepRotation;
43}
44typedef CLHEP::HepRotation G4RotationMatrix;
45
62{
63private:
65 typedef std::vector<BDSBeamlineElement*> BeamlineVector;
66
69
70public:
73 BDSBeamline(BDSBeamline&) = delete;
74
79 BDSBeamline(const G4ThreeVector& initialGlobalPosition = G4ThreeVector(0,0,0),
80 G4RotationMatrix* initialGlobalRotation = nullptr,
81 G4double initialSIn = 0.0);
82
84 explicit BDSBeamline(G4Transform3D initialTransform,
85 G4double initialSIn = 0.0);
86
88
94 BDSTiltOffset* tiltOffset = nullptr,
95 BDSSamplerInfo* samplerInfo = nullptr,
96 const BDSBeamlineIntegral* beamlineIntegral = nullptr);
97
103 void ApplyTransform3D(BDSTransform3D* component);
104
112
115 void PrintAllComponents(std::ostream& out) const;
116
119 void UpdateExtents(BDSBeamlineElement* element);
120
122 inline const BDSBeamlineElement* at(int iElement) const { return beamline.at(iElement);}
123
125 inline const BDSBeamlineElement* GetFirstItem() const {return front();}
126
128 inline const BDSBeamlineElement* GetLastItem() const {return back();}
129
131 const BDSBeamlineElement* GetElement(G4String acceleratorComponentName, G4int i = 0) const;
132
135 G4Transform3D GetTransformForElement(const G4String& acceleratorComponentName, G4int i = 0) const;
136
138 inline G4double GetTotalChordLength() const {return totalChordLength;}
139
141 inline G4double GetTotalArcLength() const {return totalArcLength;}
142
144 inline G4double GetTotalAngle() const {return totalAngle;}
145
147 G4bool ElementAnglesSumToCircle() const;
148
150 BeamlineVector::size_type size() const {return beamline.size();}
151
153 G4ThreeVector GetMaximumExtentPositive() const {return maximumExtentPositive;}
154
156 G4ThreeVector GetMaximumExtentNegative() const {return maximumExtentNegative;}
157
159 G4ThreeVector GetMaximumExtentAbsolute() const;
160
163
165 typedef BeamlineVector::iterator iterator;
166 typedef BeamlineVector::const_iterator const_iterator;
167 typedef BeamlineVector::reverse_iterator reverse_iterator;
168 typedef BeamlineVector::const_reverse_iterator const_reverse_iterator;
169 iterator begin() {return beamline.begin();}
170 iterator end() {return beamline.end();}
171 const_iterator begin() const {return beamline.begin();}
172 const_iterator end() const {return beamline.end();}
173 reverse_iterator rbegin() {return beamline.rbegin();}
174 reverse_iterator rend() {return beamline.rend();}
175 const_reverse_iterator rbegin() const {return beamline.rbegin();}
176 const_reverse_iterator rend() const {return beamline.rend();}
177 G4bool empty() const {return beamline.empty();}
179
183 G4Transform3D GetGlobalEuclideanTransform(G4double s,
184 G4double x = 0,
185 G4double y = 0,
186 G4int* indexOfFoundElement = nullptr) const;
187
190 G4int* indexOfFoundElement = nullptr) const;
191
193 const_iterator FindFromS(G4double S) const;
194
197 std::vector<G4double> GetEdgeSPositions() const;
198
199 G4double GetSMinimum() const {return sInitial;}
200 G4double GetSMaximum() const {return sMaximum;}
201
206 const BDSBeamlineElement* GetPrevious(const BDSBeamlineElement* element) const;
207 const BDSBeamlineElement* GetNext(const BDSBeamlineElement* element) const;
208
209 const BDSBeamlineElement* GetPrevious(G4int index) const;
210 const BDSBeamlineElement* GetNext(G4int index) const;
211
212 // Accessors in a similar style to std::vector
214 inline BDSBeamlineElement* front() const {return beamline.front();}
216 inline BDSBeamlineElement* back() const {return beamline.back();}
217
219 friend std::ostream& operator<< (std::ostream &out, BDSBeamline const &bl);
220
223 void PrintMemoryConsumption() const;
224
225 BDSBeamlineElement* ProvideEndPieceElementBefore(BDSSimpleComponent* endPiece,
226 G4int index) const;
231 G4int index,
232 G4bool flip = false) const;
233
235 G4bool IndexOK(G4int index) const;
236
238 static G4double PaddingLength() {return paddingLength;}
239
241 std::vector<G4int> GetIndicesOfElementsOfType(const G4String& type) const;
242
245 std::vector<G4int> GetIndicesOfElementsOfType(const std::set<G4String>& types) const;
246
248 std::vector<G4int> GetIndicesOfCollimators() const;
249
250private:
254 BDSTiltOffset* tiltOffset = nullptr,
255 BDSSamplerInfo* samplerInfo = nullptr,
256 const BDSBeamlineIntegral* beamlineIntegral = nullptr);
257
260 void RegisterElement(BDSBeamlineElement* element);
261
262 G4double sInitial;
263 G4double sMaximum;
264
270 G4double totalAngle;
271
272 G4ThreeVector maximumExtentPositive;
273 G4ThreeVector maximumExtentNegative;
274
277
280
283
287
289 static G4double paddingLength;
290
292 std::map<G4String, BDSBeamlineElement*> components;
293
298 std::vector<G4double> sEnd;
299};
300
301#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.