18#include "BDSAcceleratorComponent.hh"
19#include "BDSBeamPipe.hh"
20#include "BDSBeamPipeFactory.hh"
21#include "BDSBeamPipeInfo.hh"
22#include "BDSColours.hh"
24#include "BDSException.hh"
25#include "BDSFieldBuilder.hh"
26#include "BDSFieldInfo.hh"
27#include "BDSGlobalConstants.hh"
28#include "BDSMaterials.hh"
29#include "BDSSDType.hh"
30#include "BDSUndulator.hh"
31#include "BDSUtilities.hh"
32#include "BDSWarning.hh"
36#include "G4PVPlacement.hh"
37#include "G4VisAttributes.hh"
41BDSUndulator::BDSUndulator(
const G4String& nameIn,
44 G4double undulatorMagnetHeightIn,
45 G4double horizontalWidthIn,
46 G4double undulatorGapIn,
50 G4Material* materialIn):
52 vacuumFieldInfo(vacuumFieldInfoIn),
53 outerFieldInfo(outerFieldInfoIn),
54 undulatorPeriod(periodIn),
55 horizontalWidth(horizontalWidthIn),
56 undulatorMagnetHeight(undulatorMagnetHeightIn),
57 undulatorGap(undulatorGapIn),
65BDSUndulator::~BDSUndulator()
73 {
throw BDSException(__METHOD_NAME__,
"undulator period is 0, period must be finite.");}
77 {
throw BDSException(__METHOD_NAME__,
"undulator length \"arcLength\" does not divide into an integer number of\n undulator periods (length \"undulatorPeriod\".");}
85 G4cout << __METHOD_NAME__ <<
"\"undulatorGap\" = 0 -> using 2x beam pipe height." << G4endl;
89 {
throw BDSException(__METHOD_NAME__,
"\"undulatorGap\" for element: \"" +
name +
"\" smaller than beam pipe aperture.");}
92 {
throw BDSException(__METHOD_NAME__,
"\"undulatorGap\" for element: \"" +
name +
"\" larger than horizontalWidth.");}
100 {
throw BDSException(__METHOD_NAME__,
"\"undulatorMagnetHeight\" larger than 0.5*horizontalWidth in component " +
name);}
103 throw BDSException(__METHOD_NAME__,
"Total undulator height (2*undulatorMagnetHeight + undulatorGap) is larger than horizontalWidth in component " +
name);
107 containerSolid =
new G4Box(
name +
"_container_solid",
112 containerLogicalVolume =
new G4LogicalVolume(containerSolid,
114 name +
"_container_lv");
131 G4Box* magnet =
new G4Box(
name +
"_single_magnet_solid",
134 0.5*singleMagnetLength);
137 G4LogicalVolume* lowerBoxLV =
new G4LogicalVolume(magnet,
139 name +
"_lower_box_lv");
141 G4LogicalVolume* upperBoxLV =
new G4LogicalVolume(magnet,
143 name +
"_upper_box_lv");
153 G4VisAttributes* lowerBoxcolour =
new G4VisAttributes(*
BDSColours::Instance()->GetColour(
"quadrupole"));
154 lowerBoxLV->SetVisAttributes(lowerBoxcolour);
157 G4VisAttributes* upperBoxcolour =
new G4VisAttributes(*
BDSColours::Instance()->GetColour(
"sectorbend"));
158 upperBoxLV->SetVisAttributes(upperBoxcolour);
166 G4LogicalVolume* uVol = sign ? upperBoxLV : lowerBoxLV;
167 G4LogicalVolume* lVol = !sign ? upperBoxLV : lowerBoxLV;
169 G4ThreeVector upperBoxPos(0, verticalOffset, (0.5*
chordLength - undulatorPeriod/4.0) - ((i-1) *undulatorPeriod/2.0));
170 G4ThreeVector lowerBoxPos(0, -verticalOffset, (0.5*
chordLength - undulatorPeriod/4.0) - ((i-1) *undulatorPeriod/2.0));
172 G4PVPlacement* upperBoxPV =
new G4PVPlacement(
nullptr,
175 name +
"_upper_pos_" + std::to_string(i) +
"_pv",
176 containerLogicalVolume,
181 G4PVPlacement* lowerBoxPV=
new G4PVPlacement(
nullptr,
184 name +
"_lower_pos_" + std::to_string(i) +
"_pv",
185 containerLogicalVolume,
197 G4PVPlacement* bpPV =
new G4PVPlacement(
nullptr,
201 containerLogicalVolume,
216 containerLogicalVolume,
Abstract class that represents a component of an accelerator.
void SetAcceleratorVacuumLogicalVolume(G4LogicalVolume *accVacLVIn)
const G4String name
Const protected member variable that may not be changed by derived classes.
static G4Material * emptyMaterial
Useful variable often used in construction.
static G4bool sensitiveOuter
Useful variable often used in construction.
virtual void SetOutputFaceNormal(const G4ThreeVector &output)
Allow updating of face normals. Virtual so derived class may apply it to daughters.
static G4bool checkOverlaps
Useful variable often used in construction.
static G4double lengthSafetyLarge
virtual void SetInputFaceNormal(const G4ThreeVector &input)
Allow updating of face normals. Virtual so derived class may apply it to daughters.
G4double chordLength
Protected member variable that can be modified by derived classes.
BDSBeamPipeInfo * beamPipeInfo
Optional beam pipe recipe that is written out to the survey if it exists.
The main interface for using the beam pipe factories.
static BDSBeamPipeFactory * Instance()
Singleton accessor.
Holder class for all information required to describe a beam pipe model.
G4double beamPipeThickness
Public member for direct access.
G4double IndicativeRadius() const
Return an indicative extent of the beam pipe - typically the maximum of x or y extent.
A holder class for a piece of beam pipe geometry.
G4LogicalVolume * GetVacuumLogicalVolume() const
Access the vacuum volume to set fields and limits.
G4ThreeVector InputFaceNormal() const
Accessor.
G4ThreeVector OutputFaceNormal() const
Accessor.
static BDSColours * Instance()
singleton pattern
General exception with possible name of object and message.
Holder for +- extents in 3 dimensions.
G4double DY() const
The difference in a dimension.
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.
BDSMagnetStrength * MagnetStrength() const
Accessor.
G4LogicalVolume * GetContainerLogicalVolume() const
Accessor - see member for more info.
void RegisterDaughter(BDSGeometryComponent *anotherComponent)
void RegisterLogicalVolume(G4LogicalVolume *logicalVolume)
void RegisterPhysicalVolume(G4VPhysicalVolume *physicalVolume)
void SetExtent(const BDSExtent &extIn)
Set extent.
void RegisterVisAttributes(G4VisAttributes *visAttribute)
void RegisterSolid(G4VSolid *solid)
void RegisterSensitiveVolume(G4LogicalVolume *sensitiveVolume, BDSSDType sensitivityType)
static BDSGlobalConstants * Instance()
Access method.
G4double undulatorGap
Full undulator gap.
const G4double horizontalWidth
Element width (and height)
G4double undulatorMagnetHeight
Full magnet box height.
G4int numMagnets
Total number of magnets (1 undulator period is 2 magnets)
G4Material * material
Undulator magnet material.
virtual void BuildContainerLogicalVolume()
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())