18#include "BDSAcceleratorComponent.hh"
19#include "BDSApertureInfo.hh"
20#include "BDSApertureType.hh"
21#include "BDSBeamline.hh"
22#include "BDSColours.hh"
24#include "BDSException.hh"
25#include "BDSExtent.hh"
26#include "BDSGlobalConstants.hh"
27#include "BDSLinkOpaqueBox.hh"
28#include "BDSMaterials.hh"
29#include "BDSSamplerCustom.hh"
30#include "BDSSamplerPlacementRecord.hh"
31#include "BDSSamplerPlane.hh"
32#include "BDSSamplerRegistry.hh"
33#include "BDSSDManager.hh"
34#include "BDSSDSamplerLink.hh"
35#include "BDSTiltOffset.hh"
36#include "BDSUtilities.hh"
39#include "G4LogicalVolume.hh"
40#include "G4RotationMatrix.hh"
41#include "G4PVPlacement.hh"
42#include "G4SubtractionSolid.hh"
43#include "G4ThreeVector.hh"
45#include "G4UserLimits.hh"
46#include "G4VisAttributes.hh"
47#include "G4TwoVector.hh"
49#include "CLHEP/Units/SystemOfUnits.h"
55 G4double outputSamplerRadiusIn):
57 component(acceleratorComponentIn),
58 outputSamplerRadius(outputSamplerRadiusIn),
62 {
throw BDSException(__METHOD_NAME__,
"finite tilt with angled component unsupported.");}
64 G4double tilt = tiltOffsetIn->
GetTilt();
67 BDSExtent extent = component->GetExtent();
69 const G4double gap = 10 * CLHEP::cm;
70 const G4double opaqueBoxThickness = 10 * CLHEP::mm;
71 G4String name = component->GetName();
73 G4double mx = extent.MaximumX();
74 G4double my = extent.MaximumY();
75 G4double mr = std::max({mx, my, outputSamplerRadius});
76 G4double mz = extent.MaximumZ();
77 G4Box* terminatorBoxOuter =
new G4Box(name +
"_terminator_box_outer_solid",
78 mr + gap + opaqueBoxThickness,
79 mr + gap + opaqueBoxThickness,
80 mz + gap + opaqueBoxThickness);
81 RegisterSolid(terminatorBoxOuter);
82 G4Box* terminatorBoxInner =
new G4Box(name +
"_terminator_box_inner_solid",
86 RegisterSolid(terminatorBoxInner);
87 G4SubtractionSolid* opaqueBox =
new G4SubtractionSolid(name +
"_opaque_box_solid",
90 RegisterSolid(opaqueBox);
91 G4LogicalVolume* opaqueBoxLV =
new G4LogicalVolume(opaqueBox,
93 name +
"_opaque_box_lv");
94 RegisterLogicalVolume(opaqueBoxLV);
96 G4UserLimits* termUL =
new G4UserLimits();
97 termUL->SetUserMinEkine(std::numeric_limits<double>::max());
98 RegisterUserLimits(termUL);
99 opaqueBoxLV->SetUserLimits(termUL);
102 obVis->SetVisibility(
true);
103 opaqueBoxLV->SetVisAttributes(obVis);
104 RegisterVisAttributes(obVis);
107 G4double margin = gap + opaqueBoxThickness + ls;
108 G4double xsize = mr + margin;
109 G4double ysize = mr + margin;
110 G4double zsize = mz + margin;
111 containerSolid =
new G4Box(name +
"_opaque_box_vacuum_solid",
116 containerLogicalVolume =
new G4LogicalVolume(containerSolid,
118 name +
"_container_lv");
122 new G4PVPlacement(
nullptr,
125 name +
"_opaque_box_pv",
126 containerLogicalVolume,
131 G4ThreeVector of = G4ThreeVector(ox,oy,0);
132 G4RotationMatrix* rm =
new G4RotationMatrix();
137 G4Transform3D* placementTransform =
new G4Transform3D(*rm, of);
140 new G4PVPlacement(*placementTransform,
141 component->GetContainerLogicalVolume(),
142 component->GetName() +
"_pv",
143 containerLogicalVolume,
148 outerExtent =
BDSExtent(xsize, ysize, zsize);
150 G4RotationMatrix* rm2 =
new G4RotationMatrix();
151 offsetToStart = G4ThreeVector(0.0, 0.0, -0.5*component->GetChordLength());
152 transformToStart = G4Transform3D(*rm2, offsetToStart);
156BDSLinkOpaqueBox::~BDSLinkOpaqueBox()
163 G4String samplerName = component->
GetName() +
"_out";
171 G4RotationMatrix* rm =
nullptr;
174 rm =
new G4RotationMatrix();
175 rm->rotateY(0.5 * component->
GetAngle());
179 position += gap.transform(*rm);
182 G4RotationMatrix* rml = rm ?
new G4RotationMatrix(*rm) :
new G4RotationMatrix();
187 new G4PVPlacement(rm,
191 containerLogicalVolume,
Abstract class that represents a component of an accelerator.
G4double GetAngle() const
G4double Sagitta() const
Calculate the sagitta - ie the distance between the chord and the arc at the centre.
virtual G4String GetName() const
The name of the component without modification.
virtual G4double GetChordLength() const
Holder class for all information required to describe an aperture.
static BDSColours * Instance()
singleton pattern
General exception with possible name of object and message.
Holder for +- extents in 3 dimensions.
BDSExtent TiltOffset(const BDSTiltOffset *tiltOffset) const
Provide a new copy of this extent with both a tilt and an offset applied.
A generic geometry component for a bdsim model.
G4LogicalVolume * GetContainerLogicalVolume() const
Accessor - see member for more info.
BDSExtent GetExtent() const
Accessor - see member for more info.
void RegisterRotationMatrix(G4RotationMatrix *rotationMatrix)
static BDSGlobalConstants * Instance()
Access method.
BDSLinkOpaqueBox()=delete
Default constructor.
G4int PlaceOutputSampler()
Place the output sampler.
static BDSMaterials * Instance()
Singleton pattern access.
Custom shaped sampler with fixed thickness.
static G4double ChordLength()
Access the sampler plane length in other classes.
Information about a registered sampler.
static BDSSamplerRegistry * Instance()
Accessor for registry.
G4int RegisterSampler(const G4String &name, BDSSampler *sampler, const G4Transform3D &transform=G4Transform3D(), G4double S=-1000, const BDSBeamlineElement *element=nullptr, BDSSamplerType type=BDSSamplerType::plane, G4double radius=0)
void MakeMaterialValidForUseInMassWorld()
A holder for any placement offsets and rotations for a BDSAcceleratorComponent.
G4double GetYOffset() const
Accessor.
G4double GetXOffset() const
Accessor.
G4bool HasFiniteTilt() const
Inspector.
G4double GetTilt() const
Accessor.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())