19#include "BDSAcceleratorComponent.hh"
20#include "BDSApertureInfo.hh"
21#include "BDSApertureType.hh"
22#include "BDSBeamline.hh"
23#include "BDSColours.hh"
25#include "BDSException.hh"
26#include "BDSExtent.hh"
27#include "BDSGlobalConstants.hh"
28#include "BDSLinkOpaqueBox.hh"
29#include "BDSMaterials.hh"
30#include "BDSSamplerCustom.hh"
31#include "BDSSamplerPlacementRecord.hh"
32#include "BDSSamplerPlane.hh"
33#include "BDSSamplerRegistry.hh"
34#include "BDSSDManager.hh"
35#include "BDSSDSamplerLink.hh"
36#include "BDSTiltOffset.hh"
37#include "BDSUtilities.hh"
40#include "G4LogicalVolume.hh"
41#include "G4RotationMatrix.hh"
42#include "G4PVPlacement.hh"
43#include "G4SubtractionSolid.hh"
44#include "G4ThreeVector.hh"
46#include "G4UserLimits.hh"
47#include "G4VisAttributes.hh"
48#include "G4TwoVector.hh"
50#include "CLHEP/Units/SystemOfUnits.h"
56 G4double outputSamplerRadiusIn):
58 component(acceleratorComponentIn),
59 outputSamplerRadius(outputSamplerRadiusIn),
63 {
throw BDSException(__METHOD_NAME__,
"finite tilt with angled component unsupported.");}
65 G4double tilt = tiltOffsetIn->
GetTilt();
68 BDSExtent extent = component->GetExtent();
70 const G4double gap = 10 * CLHEP::cm;
71 const G4double opaqueBoxThickness = 10 * CLHEP::mm;
72 G4String name = component->GetName();
74 G4double mx = extent.MaximumX();
75 G4double my = extent.MaximumY();
76 G4double mr = std::max({mx, my, outputSamplerRadius});
77 G4double mz = extent.MaximumZ();
78 G4Box* terminatorBoxOuter =
new G4Box(name +
"_terminator_box_outer_solid",
79 mr + gap + opaqueBoxThickness,
80 mr + gap + opaqueBoxThickness,
81 mz + gap + opaqueBoxThickness);
82 RegisterSolid(terminatorBoxOuter);
83 G4Box* terminatorBoxInner =
new G4Box(name +
"_terminator_box_inner_solid",
87 RegisterSolid(terminatorBoxInner);
88 G4SubtractionSolid* opaqueBox =
new G4SubtractionSolid(name +
"_opaque_box_solid",
91 RegisterSolid(opaqueBox);
92 G4LogicalVolume* opaqueBoxLV =
new G4LogicalVolume(opaqueBox,
94 name +
"_opaque_box_lv");
95 RegisterLogicalVolume(opaqueBoxLV);
97 G4UserLimits* termUL =
new G4UserLimits();
98 termUL->SetUserMinEkine(std::numeric_limits<double>::max());
99 RegisterUserLimits(termUL);
100 opaqueBoxLV->SetUserLimits(termUL);
103 obVis->SetVisibility(
true);
104 opaqueBoxLV->SetVisAttributes(obVis);
105 RegisterVisAttributes(obVis);
108 G4double margin = gap + opaqueBoxThickness + ls;
109 G4double xsize = mr + margin;
110 G4double ysize = mr + margin;
111 G4double zsize = mz + margin;
112 containerSolid =
new G4Box(name +
"_opaque_box_vacuum_solid",
117 containerLogicalVolume =
new G4LogicalVolume(containerSolid,
119 name +
"_container_lv");
123 new G4PVPlacement(
nullptr,
126 name +
"_opaque_box_pv",
127 containerLogicalVolume,
132 G4ThreeVector of = G4ThreeVector(ox,oy,0);
133 G4RotationMatrix* rm =
new G4RotationMatrix();
138 G4Transform3D* placementTransform =
new G4Transform3D(*rm, of);
141 new G4PVPlacement(*placementTransform,
142 component->GetContainerLogicalVolume(),
143 component->GetName() +
"_pv",
144 containerLogicalVolume,
149 outerExtent =
BDSExtent(xsize, ysize, zsize);
151 G4RotationMatrix* rm2 =
new G4RotationMatrix();
152 offsetToStart = G4ThreeVector(0.0, 0.0, -0.5*component->GetChordLength());
153 transformToStart = G4Transform3D(*rm2, offsetToStart);
157BDSLinkOpaqueBox::~BDSLinkOpaqueBox()
164 G4String samplerName = component->
GetName() +
"_out";
172 G4RotationMatrix* rm =
nullptr;
175 rm =
new G4RotationMatrix();
176 rm->rotateY(0.5 * component->
GetAngle());
180 position += gap.transform(*rm);
183 G4RotationMatrix* rml = rm ?
new G4RotationMatrix(*rm) :
new G4RotationMatrix();
188 new G4PVPlacement(rm,
192 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())