19#include "BDSAcceleratorComponent.hh"
20#include "BDSBeamline.hh"
21#include "BDSBeamlineElement.hh"
23#include "BDSException.hh"
24#include "BDSFieldBuilder.hh"
25#include "BDSFieldInfo.hh"
26#include "BDSGlobalConstants.hh"
27#include "BDSSamplerPlane.hh"
28#include "BDSTeleporter.hh"
29#include "BDSUtilities.hh"
33#include "G4LogicalVolume.hh"
34#include "G4ThreeVector.hh"
35#include "G4Transform3D.hh"
36#include "G4UserLimits.hh"
43 const G4double horizontalWidthIn,
46 horizontalWidth(horizontalWidthIn),
47 vacuumFieldInfo(vacuumFieldInfoIn)
56 if(containerLogicalVolume)
61 G4UserLimits* ul =
new G4UserLimits(*defaultUL);
65 containerLogicalVolume->SetUserLimits(ul);
69 containerLogicalVolume,
75 containerSolid =
new G4Box(
name+
"_container_solid",
79 containerLogicalVolume =
new G4LogicalVolume(containerSolid,
81 name +
"_container_lv");
88 G4double& teleporterLength)
90 if (beamline->
empty())
93 return G4Transform3D();
99 auto firstElement = beamline->
front();
100 auto lastElement = beamline->
back();
102 G4ThreeVector firstItemPosition = firstElement->GetReferencePositionStart();
103 G4ThreeVector positionDelta = firstItemPosition - lastItemPosition;
111 G4ThreeVector lastItemUnitDir = G4ThreeVector(0,0,1).transform(*(lastElement->GetReferenceRotationEnd()));
114 G4double rawLength = positionDelta.dot(lastItemUnitDir);
120 G4double minimumRequiredSpace = 2*sL + 3*pL;
122 if (rawLength > 1*CLHEP::m)
124 std::string msg =
"\nError - the calculated teleporter delta is above 1m!\nThe teleporter was only intended for small shifts";
127 else if (rawLength < minimumRequiredSpace)
129 std::string msg =
"\nInsufficient space between the first and last elements\n";
130 msg +=
"in the beam line to fit the terminator and teleporter - these will not be built.\n";
131 msg +=
"Minimum space for circular mechanics is ";
132 msg += std::to_string( minimumRequiredSpace/CLHEP::um) +
" um";
137 teleporterLength = rawLength - (sL + 3*pL);
138 positionDelta -= lastItemUnitDir * (sL + 3*pL);
140 auto firstItemRotation = firstElement->GetReferenceRotationStart();
141 auto lastItemRotation = lastElement->GetReferenceRotationEnd();
142 auto rotation = (*firstItemRotation) * (*lastItemRotation);
144 G4Transform3D result = G4Transform3D(rotation, positionDelta);
146 G4cout <<
"Calculating Teleporter delta" << G4endl;
147 G4cout <<
"Last item end position: " << lastItemPosition <<
" mm" << G4endl;
148 G4cout <<
"First item start position: " << firstItemPosition <<
" mm" << G4endl;
149 G4cout <<
"Teleporter delta (pos): " << positionDelta <<
" mm" << G4endl;
150 G4cout <<
"Rotation: " << rotation << G4endl;
154BDSTeleporter::~BDSTeleporter()
Abstract class that represents a component of an accelerator.
const G4String name
Const protected member variable that may not be changed by derived classes.
static G4Material * emptyMaterial
Useful variable often used in construction.
G4double chordLength
Protected member variable that can be modified by derived classes.
G4ThreeVector GetReferencePositionEnd() const
Accessor.
A vector of BDSBeamlineElement instances - a beamline.
BDSBeamlineElement * front() const
Return a reference to the first element.
BDSBeamlineElement * back() const
Return a reference to the last element.
static G4double PaddingLength()
Access the padding length between each element added to the beamline.
G4bool empty() const
Iterator mechanics.
General exception with possible name of object and message.
Holder for +- extents in 3 dimensions.
void RegisterFieldForConstruction(const BDSFieldInfo *info, G4LogicalVolume *logicalVolume, const G4bool propagateToDaughters=false, const BDSMagnetStrength *magnetStrengthForScaling=nullptr, const G4String &scalingKey="none")
static BDSFieldBuilder * Instance()
Singleton pattern accessor.
All info required to build complete field of any type.
void RegisterUserLimits(G4UserLimits *userLimit)
void SetExtent(const BDSExtent &extIn)
Set extent.
static BDSGlobalConstants * Instance()
Access method.
static G4double ChordLength()
Access the sampler plane length in other classes.
BDSTeleporter()=delete
Private default constructor to force the use of the supplied one.
BDSFieldInfo * vacuumFieldInfo
Recipe for teleporter 'field'.
G4double horizontalWidth
The full horizontal width of the teleporter.
virtual void Build()
Overridden method from BDSAcceleratorComponent that dictates the construction.
virtual void BuildContainerLogicalVolume()
G4Transform3D CalculateTeleporterDelta(const BDSBeamline *beamline, G4double &teleporterLength)