19#include "BDSAcceleratorComponent.hh"
20#include "BDSBeamPipe.hh"
21#include "BDSBeamPipeFactory.hh"
22#include "BDSBeamPipeInfo.hh"
23#include "BDSColours.hh"
25#include "BDSException.hh"
26#include "BDSFieldBuilder.hh"
27#include "BDSFieldInfo.hh"
28#include "BDSGlobalConstants.hh"
29#include "BDSMaterials.hh"
30#include "BDSSDType.hh"
31#include "BDSUndulator.hh"
32#include "BDSUtilities.hh"
33#include "BDSWarning.hh"
37#include "G4PVPlacement.hh"
38#include "G4VisAttributes.hh"
42BDSUndulator::BDSUndulator(
const G4String& nameIn,
45 G4double undulatorMagnetHeightIn,
46 G4double horizontalWidthIn,
47 G4double undulatorGapIn,
51 const G4String& materialIn):
53 vacuumFieldInfo(vacuumFieldInfoIn),
54 outerFieldInfo(outerFieldInfoIn),
55 undulatorPeriod(periodIn),
56 horizontalWidth(horizontalWidthIn),
57 undulatorMagnetHeight(undulatorMagnetHeightIn),
58 undulatorGap(undulatorGapIn),
61 if (materialIn.empty())
63 BDS::Warning(__METHOD_NAME__,
"element \"" + name +
"\" no material set for undulator magnet - using iron");
67 {material = materialIn;}
73BDSUndulator::~BDSUndulator()
81 {
throw BDSException(__METHOD_NAME__,
"undulator period is 0, period must be finite.");}
85 {
throw BDSException(__METHOD_NAME__,
"undulator length \"arcLength\" does not divide into an integer number of\n undulator periods (length \"undulatorPeriod\".");}
93 G4cout << __METHOD_NAME__ <<
"\"undulatorGap\" = 0 -> using 2x beam pipe height." << G4endl;
97 {
throw BDSException(__METHOD_NAME__,
"\"undulatorGap\" for element: \"" +
name +
"\" smaller than beam pipe aperture.");}
100 {
throw BDSException(__METHOD_NAME__,
"\"undulatorGap\" for element: \"" +
name +
"\" larger than horizontalWidth.");}
108 {
throw BDSException(__METHOD_NAME__,
"\"undulatorMagnetHeight\" larger than 0.5*horizontalWidth in component " +
name);}
111 throw BDSException(__METHOD_NAME__,
"Total undulator height (2*undulatorMagnetHeight + undulatorGap) is larger than horizontalWidth in component " +
name);
115 containerSolid =
new G4Box(
name +
"_container_solid",
120 containerLogicalVolume =
new G4LogicalVolume(containerSolid,
122 name +
"_container_lv");
139 G4Box* magnet =
new G4Box(
name +
"_single_magnet_solid",
142 0.5*singleMagnetLength);
147 G4LogicalVolume* lowerBoxLV =
new G4LogicalVolume(magnet,
149 name +
"_lower_box_lv");
151 G4LogicalVolume* upperBoxLV =
new G4LogicalVolume(magnet,
153 name +
"_upper_box_lv");
163 G4VisAttributes* lowerBoxcolour =
new G4VisAttributes(*
BDSColours::Instance()->GetColour(
"quadrupole"));
164 lowerBoxLV->SetVisAttributes(lowerBoxcolour);
167 G4VisAttributes* upperBoxcolour =
new G4VisAttributes(*
BDSColours::Instance()->GetColour(
"sectorbend"));
168 upperBoxLV->SetVisAttributes(upperBoxcolour);
176 G4LogicalVolume* uVol = sign ? upperBoxLV : lowerBoxLV;
177 G4LogicalVolume* lVol = !sign ? upperBoxLV : lowerBoxLV;
179 G4ThreeVector upperBoxPos(0, verticalOffset, (0.5*
chordLength - undulatorPeriod/4.0) - ((i-1) *undulatorPeriod/2.0));
180 G4ThreeVector lowerBoxPos(0, -verticalOffset, (0.5*
chordLength - undulatorPeriod/4.0) - ((i-1) *undulatorPeriod/2.0));
182 G4PVPlacement* upperBoxPV =
new G4PVPlacement(
nullptr,
185 name +
"_upper_pos_" + std::to_string(i) +
"_pv",
186 containerLogicalVolume,
191 G4PVPlacement* lowerBoxPV=
new G4PVPlacement(
nullptr,
194 name +
"_lower_pos_" + std::to_string(i) +
"_pv",
195 containerLogicalVolume,
207 G4PVPlacement* bpPV =
new G4PVPlacement(
nullptr,
211 containerLogicalVolume,
226 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.
static BDSMaterials * Instance()
Singleton pattern access.
G4Material * GetMaterial(G4String material) const
Get material by name.
G4double undulatorGap
Full undulator gap.
const G4double horizontalWidth
Element width (and height)
G4double undulatorMagnetHeight
Full magnet box height.
G4String material
Undulator magnet material.
G4int numMagnets
Total number of magnets (1 undulator period is 2 magnets)
virtual void BuildContainerLogicalVolume()
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())