19#include "BDSAcceleratorModel.hh"
20#include "BDSBeamline.hh"
21#include "BDSBeamlineElement.hh"
22#include "BDSBeamlineIntegral.hh"
23#include "BDSBeamlinePlacementBuilder.hh"
24#include "BDSComponentFactory.hh"
26#include "BDSDetectorConstruction.hh"
27#include "BDSException.hh"
28#include "BDSExtent.hh"
29#include "BDSFieldFactory.hh"
30#include "BDSFieldInfo.hh"
31#include "BDSGeometryExternal.hh"
32#include "BDSGeometryFactory.hh"
33#include "BDSGlobalConstants.hh"
34#include "BDSMaterials.hh"
35#include "BDSParser.hh"
36#include "BDSPlacementToMake.hh"
37#include "BDSSimpleComponent.hh"
38#include "BDSUtilities.hh"
40#include "parser/element.h"
41#include "parser/placement.h"
43#include "G4LogicalVolume.hh"
44#include "G4RotationMatrix.hh"
45#include "G4ThreeVector.hh"
46#include "G4Transform3D.hh"
58 if (placements.empty())
62 std::vector<BDSPlacementToMake> fieldPlacements;
67 for (
const auto& placement : placements)
71 if (!placement.sequence.empty())
75 G4bool hasAField =
false;
76 G4String fieldPlacementName;
79 if (placement.name.empty())
81 G4cerr <<
"Problem with unnamed placement, its contents are:" << G4endl;
83 throw BDSException(__METHOD_NAME__,
"a placement must be defined with a name");
86 G4bool elementSpecified = !placement.bdsimElement.empty();
87 G4bool geometrySpecified = !placement.geometryFile.empty();
88 if (elementSpecified && geometrySpecified)
90 G4String msg =
"only one of \"geometryFile\" or \"bdsimElement\" can be specified in placement \"" + placement.name +
"\"";
93 else if (!elementSpecified && !geometrySpecified)
95 G4String msg =
"at least one of \"geometryFile\" or \"bdsimElement\" must be specified in placement \"" + placement.name +
"\"";
99 if (geometrySpecified)
101 hasAField = !placement.fieldAll.empty();
106 fieldRecipe->SetUsePlacementWorldTransform(
true);
110 placement.geometryFile,
112 placement.autoColour,
117 BDSSDType::energydep,
118 BDSSDType::energydepvacuum,
119 placement.stripOuterVolume,
121 placement.dontReloadGeometry);
124 comp =
new BDSSimpleComponent(placement.name +
"_" + geom->GetName(), geom, chordLength);
136 {
throw BDSException(__METHOD_NAME__,
"no such element definition by name \"" + placement.bdsimElement +
"\" found for placement.");}
137 comp = componentFactory->
CreateComponent(element,
nullptr,
nullptr, *integral);
141 fieldPlacementName = comp->
GetName() +
"_field";
151 G4ThreeVector halfLengthBeg = G4ThreeVector(0,0,-chordLength*0.5);
152 G4ThreeVector halfLengthEnd = G4ThreeVector(0,0, chordLength*0.5);
153 G4ThreeVector midPos = transform.getTranslation();
154 G4ThreeVector startPos = midPos + transform * (HepGeom::Point3D<G4double>)halfLengthBeg;
155 G4ThreeVector endPos = midPos + transform * (HepGeom::Point3D<G4double>)halfLengthEnd;
156 G4RotationMatrix* rm =
new G4RotationMatrix(transform.getRotation());
163 new G4RotationMatrix(*rm),
164 new G4RotationMatrix(*rm),
168 new G4RotationMatrix(*rm),
169 new G4RotationMatrix(*rm),
170 new G4RotationMatrix(*rm),
178 G4LogicalVolume* lv =
new G4LogicalVolume(containerSolidClone,
nullptr, fieldPlacementName+
"_lv");
179 fieldPlacements.emplace_back(
BDSPlacementToMake(transform, lv, fieldPlacementName+
"_pv"));
Abstract class that represents a component of an accelerator.
virtual void Initialise()
virtual G4String GetName() const
The name of the component without modification.
virtual G4bool HasAField() const
Whether this component has a field or not (ie is active). Implicit cast of pointer to bool.
virtual G4double GetChordLength() const
void SetField(BDSFieldInfo *fieldInfoIn)
Set the field definition for the whole component.
virtual void SetFieldUsePlacementWorldTransform()
void RegisterPlacementFieldPlacements(const std::vector< BDSPlacementToMake > &pIn)
Register complete placements to make for field volumes in parallel world.
A class that holds a fully constructed BDSAcceleratorComponent as well as any information relevant to...
A class that holds the current integrated quantities along a beam line.
A vector of BDSBeamlineElement instances - a beamline.
void AddBeamlineElement(BDSBeamlineElement *element)
Factory to produce all types of BDSAcceleratorComponents.
BDSAcceleratorComponent * CreateComponent(GMAD::Element const *elementIn, GMAD::Element const *prevElementIn, GMAD::Element const *nextElementIn, BDSBeamlineIntegral &integral)
static G4Transform3D CreatePlacementTransform(const GMAD::Placement &placement, const BDSBeamline *beamLine, G4double *S=nullptr, BDSExtent *placementExtent=nullptr, const G4String &objectTypeForErrorMsg="placement")
General exception with possible name of object and message.
G4double DZ() const
The difference in a dimension.
static BDSFieldFactory * Instance()
Public accessor method for singleton pattern.
All info required to build complete field of any type.
G4String NameOfParserDefinition() const
Accessor.
BDSExtent GetExtent() const
Accessor - see member for more info.
G4VSolid * GetContainerSolid() const
Accessor - see member for more info.
BDSGeometryExternal * BuildGeometry(G4String componentName, const G4String &formatAndFilePath, std::map< G4String, G4Colour * > *colourMapping=nullptr, G4bool autoColour=true, G4double suggestedLength=0, G4double suggestedHorizontalWidth=0, std::vector< G4String > *namedVacuumVolumes=nullptr, G4bool makeSensitive=true, BDSSDType sensitivityType=BDSSDType::energydep, BDSSDType vacuumSensitivityType=BDSSDType::energydepvacuum, G4bool stripOuterVolumeAndMakeAssembly=false, G4UserLimits *userLimitsToAttachToAllLVs=nullptr, G4bool dontReloadGeometry=false)
static BDSGeometryFactory * Instance()
Singleton accessor.
static BDSParser * Instance()
Access method.
const GMAD::Element * GetPlacementElement(const std::string &name)
Wrapper for particle definition.
A cache of a components to make a placement.
A BDSAcceleratorComponent wrapper for BDSGeometryComponent.
BDSBeamline * BuildPlacementGeometry(const std::vector< GMAD::Placement > &placements, const BDSBeamline *parentBeamLine, BDSComponentFactory *componentFactory, const BDSParticleDefinition *designParticle)