BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSComponentFactory.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 BDSCOMPONENTFACTORY_H
20#define BDSCOMPONENTFACTORY_H
21
22#include "BDSBeamlineIntegral.hh"
23#include "BDSFieldType.hh"
24#include "BDSMagnetGeometryType.hh"
25#include "BDSMagnetStrength.hh"
26#include "BDSMagnetType.hh"
27#include "BDSIntegratorType.hh"
28#include "BDSIntegratorSetType.hh"
29#include "BDSParticleDefinition.hh"
30
31#include "globals.hh"
32#include "G4ThreeVector.hh"
33#include "G4Transform3D.hh"
34
35#include "CLHEP/Units/PhysicalConstants.h"
36
37#include <map>
38
39class G4Colour;
40class G4Material;
41
42namespace GMAD
43{
44 struct Element;
45}
47class BDSBeamPipeInfo;
48class BDSCavityInfo;
50class BDSCrystalInfo;
51class BDSFieldInfo;
53class BDSLaser;
54class BDSMagnet;
57class BDSTiltOffset;
58
79{
80public:
81 explicit BDSComponentFactory(BDSComponentFactoryUser* userComponentFactoryIn = nullptr,
82 G4bool usualPrintOut = true);
84
91 GMAD::Element const* prevElementIn,
92 GMAD::Element const* nextElementIn,
93 BDSBeamlineIntegral& integral);
94
98
101 BDSAcceleratorComponent* CreateTeleporter(const G4double teleporterLength,
102 const G4double teleporterWidth,
103 const G4Transform3D& transformIn);
104
107
109 static G4Transform3D CreateFieldTransform(const BDSTiltOffset* tiltOffset);
110
113 static G4Transform3D CreateFieldTransform(GMAD::Element const* el);
114
118 const G4ThreeVector& inputFaceNormal = G4ThreeVector(0,0,-1),
119 const G4ThreeVector& outputFaceNormal = G4ThreeVector(0,0,1));
120
124 G4double angleIn,
125 G4double angleOut);
126
129 static G4bool YokeOnLeft(const GMAD::Element* el,
130 const BDSMagnetStrength* st);
131
133 static G4double PrepareHorizontalWidth(GMAD::Element const* el,
134 G4double defaultHorizontalWidth = -1);
135
137 static G4double ScalingFieldOuter(const GMAD::Element* ele);
138
141 const BDSFieldType& fieldType,
142 const BDSBeamPipeInfo* bpInfo,
143 const BDSMagnetOuterInfo* outerInfo,
144 const G4Transform3D& fieldTransform,
145 const BDSIntegratorSet* integratorSetIn,
146 G4double brhoIn,
147 G4double outerFieldScaling = 1.0,
148 BDSModulatorInfo* modulatorInfo = nullptr);
149
153 static BDSMagnetOuterInfo* PrepareMagnetOuterInfo(const G4String& elementNameIn,
154 const GMAD::Element* el,
155 const BDSMagnetStrength* st,
156 const BDSBeamPipeInfo* beamPipe,
157 G4double defaultHorizontalWidth = -1,
158 G4double defaultVHRatio = 1.0,
159 G4double defaultCoilWidthFraction = -1,
160 G4double defaultCoilHeightFraction = -1);
161
165
169 static BDSMagnetOuterInfo* PrepareMagnetOuterInfo(const G4String& elementNameIn,
170 const GMAD::Element* el,
171 const G4double angleIn,
172 const G4double angleOut,
173 const BDSBeamPipeInfo* beamPipe,
174 const G4bool yokeOnLeft = false,
175 G4double defaultHorizontalWidth = -1,
176 G4double defaultVHRatio = -1,
177 G4double defaultCoilWidthFraction = -1,
178 G4double defaultCoilHeightFraction = -1);
179
183 static G4Colour* PrepareColour(GMAD::Element const* element, const G4Material* material = nullptr);
184
186 static G4Material* PrepareMaterial(GMAD::Element const* element,
187 const G4String& defaultMaterialName);
188
190 static G4Material* PrepareMaterial(GMAD::Element const* element);
191
193 static G4Material* PrepareTipMaterial(GMAD::Element const* element,
194 const G4String& defaultMaterialName);
195
197 static G4Material* PrepareTipMaterial(GMAD::Element const* element);
198
201 static void CheckBendLengthAngleWidthCombo(G4double arcLength,
202 G4double angle,
203 G4double horizontalWidth,
204 const G4String& name = "not given");
205
207 static void PoleFaceRotationsNotTooLarge(const GMAD::Element* el,
208 G4double maxAngle = 0.5*CLHEP::halfpi);
209
214 static G4double EFieldFromElement(GMAD::Element const* el,
215 BDSFieldType fieldType,
216 G4double cavityLength,
217 const BDSParticleDefinition& incomingParticle);
218
223 static void CalculateAngleAndFieldRBend(const GMAD::Element* el,
224 G4double brhoIn,
225 G4double& arcLength,
226 G4double& chordLength,
227 G4double& field,
228 G4double& angle);
229
232 BDSCrystalInfo* PrepareCrystalInfo(const G4String& crystalName) const;
233
234private:
237
239 G4double lengthSafety;
242 G4bool yokeFields;
245 G4double synchronousTAtMiddleOfThisComponent;
246
248 inline void SetBeta0(BDSMagnetStrength* stIn) const {(*stIn)["beta0"] = integralUpToThisComponent->designParticle.Beta();}
250 inline G4double BRho() const {return integralUpToThisComponent->designParticle.BRho();}
251
253 GMAD::Element const* element = nullptr;
255 GMAD::Element const* prevElement = nullptr;
257 GMAD::Element const* nextElement = nullptr;
258
260 enum class KickerType {horizontal, vertical, general};
261
263 enum class RFFieldDirection {x, y, z};
264
265 BDSAcceleratorComponent* CreateDrift(G4double angleIn, G4double angleOut);
266 BDSAcceleratorComponent* CreateRF(RFFieldDirection direction);
267 BDSAcceleratorComponent* CreateSBend();
268 BDSAcceleratorComponent* CreateRBend();
269 BDSAcceleratorComponent* CreateKicker(KickerType type);
270 BDSAcceleratorComponent* CreateQuad();
271 BDSAcceleratorComponent* CreateSextupole();
272 BDSAcceleratorComponent* CreateOctupole();
273 BDSAcceleratorComponent* CreateDecapole();
274 BDSAcceleratorComponent* CreateMultipole();
275 BDSAcceleratorComponent* CreateThinMultipole(G4double angleIn);
276 BDSAcceleratorComponent* CreateElement();
277 BDSAcceleratorComponent* CreateSolenoid();
278 BDSAcceleratorComponent* CreateParallelTransporter();
279 BDSAcceleratorComponent* CreateRectangularCollimator();
280 BDSAcceleratorComponent* CreateBeamMaskCollimator();
281 BDSAcceleratorComponent* CreateGasCapillary();
282 BDSAcceleratorComponent* CreateGasJet();
283 BDSAcceleratorComponent* CreateTarget();
284 BDSAcceleratorComponent* CreateEllipticalCollimator();
285 BDSAcceleratorComponent* CreateJawCollimator();
286 BDSAcceleratorComponent* CreateTipJawCollimator();
287 BDSAcceleratorComponent* CreateMuonCooler();
288 BDSAcceleratorComponent* CreateMuonSpoiler();
289 BDSAcceleratorComponent* CreateShield();
290 BDSAcceleratorComponent* CreateDegrader();
291 BDSAcceleratorComponent* CreateGap();
292 BDSAcceleratorComponent* CreateCrystalCollimator();
293 BDSAcceleratorComponent* CreateLaser();
294 BDSAcceleratorComponent* CreateScreen();
295 BDSAcceleratorComponent* CreateTransform3D();
296 BDSAcceleratorComponent* CreateWireScanner();
297 BDSAcceleratorComponent* CreateRMatrix();
298 BDSAcceleratorComponent* CreateThinRMatrix(G4double angleIn,
299 const G4String& name);
300 BDSAcceleratorComponent* CreateThinRMatrix(G4double angleIn,
301 BDSMagnetStrength* stIn,
302 const G4String& name,
303 BDSIntegratorType intType = BDSIntegratorType::rmatrixthin,
304 BDSFieldType fieldType = BDSFieldType::rmatrix,
305 G4double beamPipeRadius = 0,
306 BDSModulatorInfo* fieldModulator = nullptr);
307 BDSAcceleratorComponent* CreateUndulator();
308 BDSAcceleratorComponent* CreateDump();
309 BDSAcceleratorComponent* CreateLaserwire(G4double currentArcLength);
310
311#ifdef USE_DICOM
312 BDSAcceleratorComponent* CreateCT();
313#endif
314 BDSAcceleratorComponent* CreateCavityFringe(G4double angleIn,
315 BDSMagnetStrength* stIn,
316 const G4String& name,
317 G4double irisRadius,
318 BDSModulatorInfo* fieldModulator = nullptr);
319 BDSAcceleratorComponent* CreateGaborLens();
320#ifdef USE_AWAKE
321 BDSAcceleratorComponent* CreateAwakeScreen();
322 BDSAcceleratorComponent* CreateAwakeSpectrometer();
323#endif
324
328 BDSFieldType fieldType,
329 BDSMagnetType magnetType,
330 G4double angle = 0.0,
331 const G4String& nameSuffix = "") const;
332
335 G4bool printWarning = true);
336
338 G4Material* PrepareVacuumMaterial(GMAD::Element const* el) const;
339
342 void PrepareCavityModels();
343
345 void PrepareColours();
346
348 void PrepareCrystals();
349
351 void PrepareLasers();
352
355 BDSLaser* PrepareLaser(GMAD::Element const* el) const;
356
363 G4double frequency) const;
364
368 G4double frequency) const;
369
373 BDSFieldType fieldType,
374 G4double cavityLength,
375 BDSMagnetStrength*& fringeIn,
376 BDSMagnetStrength*& fringeOut) const;
377
381 void SetFieldDefinitions(GMAD::Element const* el,
382 BDSAcceleratorComponent* component) const;
383
387 BDSFieldInfo* info) const;
388
391
394
396 std::map<G4String, BDSCavityInfo*> cavityInfos;
397
399 std::map<G4String, BDSCrystalInfo*> crystalInfos;
400
402 std::map<G4String, BDSLaser*> lasers;
403
406
409
412 G4double FieldFromAngle(const G4double angle,
413 const G4double arcLength) const;
414
417 G4double AngleFromField(const G4double field,
418 const G4double arcLength) const;
419
423 G4double& angle,
424 G4double& field) const;
425
427 G4double BendAngle(const GMAD::Element* el) const;
428
434 G4double OutgoingFaceAngle(const GMAD::Element* el) const;
435
441 G4double IncomingFaceAngle(const GMAD::Element* el) const;
442
445 BDSModulatorInfo* ModulatorDefinition(const GMAD::Element* el, G4bool inDevelopment=false) const; // TBC
446
448 void INDEVELOPMENTERROR() const;
449
452 void GetKickValue(G4double& hkick,
453 G4double& vkick,
454 const KickerType type) const;
455
458
464 std::map<G4String, G4int> modifiedElements;
465
467 G4String elementName;
468
471 static G4bool coloursInitialised;
472};
473#endif
Abstract class that represents a component of an accelerator.
Holder class for all information required to describe a beam pipe model.
A class that holds the current integrated quantities along a beam line.
Holder for all Geometrical information required to create an RF cavity.
Factory for user specified accelerator components.
Factory to produce all types of BDSAcceleratorComponents.
static G4bool YokeOnLeft(const GMAD::Element *el, const BDSMagnetStrength *st)
std::map< G4String, BDSCrystalInfo * > crystalInfos
Maps of crystal info instances by name.
G4double OutgoingFaceAngle(const GMAD::Element *el) const
G4double AngleFromField(const G4double field, const G4double arcLength) const
void INDEVELOPMENTERROR() const
TBC - remove when modulators are implemented fully.
BDSComponentFactoryUser * userComponentFactory
User component factory if any.
KickerType
Private enum for kicker types.
BDSAcceleratorComponent * CreateComponent(GMAD::Element const *elementIn, GMAD::Element const *prevElementIn, GMAD::Element const *nextElementIn, BDSBeamlineIntegral &integral)
G4double FieldFromAngle(const G4double angle, const G4double arcLength) const
static G4double PrepareHorizontalWidth(GMAD::Element const *el, G4double defaultHorizontalWidth=-1)
Prepare the element horizontal width in Geant4 units - if not set, use the global default.
void CalculateGaborLensStrength(BDSMagnetStrength *st) const
Calculate the electric field strength of the confined plasma in a Gabor lens.
BDSComponentFactory()=delete
No default constructor.
BDSAcceleratorComponent * CreateTeleporter(const G4double teleporterLength, const G4double teleporterWidth, const G4Transform3D &transformIn)
BDSModulatorInfo * defaultModulator
Default modulator for all components.
G4Material * PrepareVacuumMaterial(GMAD::Element const *el) const
Prepare the vacuum material from the element or resort to default in options.
static G4Transform3D CreateFieldTransform(const BDSTiltOffset *tiltOffset)
Create a transform from a tilt offset. If nullptr, returns identity transform.
BDSMagnet * CreateMagnet(const GMAD::Element *el, BDSMagnetStrength *st, BDSFieldType fieldType, BDSMagnetType magnetType, G4double angle=0.0, const G4String &nameSuffix="") const
Helper method for common magnet construction.
BDSMagnetStrength * PrepareMagnetStrengthForMultipoles(GMAD::Element const *el) const
Prepare magnet strength for multipoles.
GMAD::Element const * element
element for storing instead of passing around
static void PoleFaceRotationsNotTooLarge(const GMAD::Element *el, G4double maxAngle=0.5 *CLHEP::halfpi)
Check whether the pole face rotation angles are too big for practical construction.
G4double thinElementLength
Length of a thin element.
static void CalculateAngleAndFieldRBend(const GMAD::Element *el, G4double brhoIn, G4double &arcLength, G4double &chordLength, G4double &field, G4double &angle)
BDSCavityInfo * PrepareCavityModelInfoForElement(GMAD::Element const *el, G4double frequency) const
GMAD::Element const * nextElement
element access to previous element (can be nullptr)
BDSCavityInfo * PrepareCavityModelInfo(GMAD::Element const *el, G4double frequency) const
BDSLaser * PrepareLaser(GMAD::Element const *el) const
const BDSIntegratorSetType integratorSetType
Local copy of enum of the integrator set, i.e. which one it is specifically.
G4bool yokeFields
Cache of whether to include yoke magnetic fields.
static G4double EFieldFromElement(GMAD::Element const *el, BDSFieldType fieldType, G4double cavityLength, const BDSParticleDefinition &incomingParticle)
static BDSFieldInfo * PrepareMagnetOuterFieldInfo(const BDSMagnetStrength *vacuumSt, const BDSFieldType &fieldType, const BDSBeamPipeInfo *bpInfo, const BDSMagnetOuterInfo *outerInfo, const G4Transform3D &fieldTransform, const BDSIntegratorSet *integratorSetIn, G4double brhoIn, G4double outerFieldScaling=1.0, BDSModulatorInfo *modulatorInfo=nullptr)
Prepare the field definition for the yoke of a magnet.
void PrepareColours()
Prepare all colours defined in the parser.
static BDSMagnetOuterInfo * PrepareMagnetOuterInfo(const G4String &elementNameIn, const GMAD::Element *el, const BDSMagnetStrength *st, const BDSBeamPipeInfo *beamPipe, G4double defaultHorizontalWidth=-1, G4double defaultVHRatio=1.0, G4double defaultCoilWidthFraction=-1, G4double defaultCoilHeightFraction=-1)
BDSAcceleratorComponent * CreateTerminator(G4double witdth)
BDSMagnetStrength * PrepareMagnetStrengthForRMatrix(GMAD::Element const *el) const
Prepare magnet strength for rmatrix.
G4bool includeFringeFields
Cache of whether to include fringe fields.
void SetFieldDefinitions(GMAD::Element const *el, BDSAcceleratorComponent *component) const
static void CheckBendLengthAngleWidthCombo(G4double arcLength, G4double angle, G4double horizontalWidth, const G4String &name="not given")
void PrepareCrystals()
Prepare all crystals in defined the parser.
static G4Colour * PrepareColour(GMAD::Element const *element, const G4Material *material=nullptr)
G4double lengthSafety
Length safety from global constants.
BDSMagnetStrength * PrepareCavityStrength(GMAD::Element const *el, BDSFieldType fieldType, G4double cavityLength, BDSMagnetStrength *&fringeIn, BDSMagnetStrength *&fringeOut) const
G4String elementName
Variable used to pass around the possibly modified name of an element.
std::map< G4String, BDSLaser * > lasers
Map of laser instances by name. Owned by this class.
static G4Material * PrepareTipMaterial(GMAD::Element const *element, const G4String &defaultMaterialName)
Checks if a material is named in Element::tipMaterial, else uses the supplied default.
std::map< G4String, G4int > modifiedElements
void GetKickValue(G4double &hkick, G4double &vkick, const KickerType type) const
BDSBeamlineIntegral * integralUpToThisComponent
To save passing it through many functions arguments.
G4double BendAngle(const GMAD::Element *el) const
Calculate the angle of a bend whether it's an rbend or an sbend.
G4double IncomingFaceAngle(const GMAD::Element *el) const
void CalculateAngleAndFieldSBend(GMAD::Element const *el, G4double &angle, G4double &field) const
static G4Material * PrepareMaterial(GMAD::Element const *element, const G4String &defaultMaterialName)
Checks if a material is named in Element::material, else uses the supplied default.
static BDSTiltOffset * CreateTiltOffset(GMAD::Element const *el)
Create the tilt and offset information object by inspecting the parser element.
void SetModulatorDefinition(GMAD::Element const *el, BDSFieldInfo *info) const
void PrepareLasers()
Prepare all lasers defined in the parser.
const BDSIntegratorSet * integratorSet
Local copy of reference to integrator set to use.
BDSModulatorInfo * ModulatorDefinition(const GMAD::Element *el, G4bool inDevelopment=false) const
RFFieldDirection
Private enum for RF cavity principle accelerating direction.
void SetBeta0(BDSMagnetStrength *stIn) const
Simple setter used to add Beta0 to a strength instance.
BDSCrystalInfo * PrepareCrystalInfo(const G4String &crystalName) const
static BDSBeamPipeInfo * PrepareBeamPipeInfo(GMAD::Element const *el, const G4ThreeVector &inputFaceNormal=G4ThreeVector(0, 0,-1), const G4ThreeVector &outputFaceNormal=G4ThreeVector(0, 0, 1))
static BDSMagnetGeometryType MagnetGeometryType(const GMAD::Element *el)
G4double BRho() const
Simple accessor to simplify repetitive code.
std::map< G4String, BDSCavityInfo * > cavityInfos
Map of cavity model info instances by name.
G4bool HasSufficientMinimumLength(GMAD::Element const *el, G4bool printWarning=true)
Test the component length is sufficient for practical construction.
static G4double ScalingFieldOuter(const GMAD::Element *ele)
Get the scaling factor for a particular outer field depending on the global and individual setting.
GMAD::Element const * prevElement
element access to previous element (can be nullptr)
Holder for all information required to create a crystal.
All info required to build complete field of any type.
Which integrator to use for each type of magnet / field object.
Class to provide laser intensity at any point.
Definition BDSLaser.hh:36
Holder struct of all information required to create the outer geometry of a magnet.
Efficient storage of magnet strengths.
Abstract base class that implements features common to all magnets.
Definition BDSMagnet.hh:45
Holder class for all information required to describe a modulator.
Wrapper for particle definition.
G4double BRho() const
Accessor.
G4double Beta() const
Accessor.
A holder for any placement offsets and rotations for a BDSAcceleratorComponent.
Parser namespace for GMAD language. Combination of Geant4 and MAD.
Element class.
Definition element.h:45