19#include "BDSAcceleratorModel.hh"
20#include "BDSBeamline.hh"
21#include "BDSBeamlineElement.hh"
22#include "BDSBeamlinePlacementBuilder.hh"
23#include "BDSComponentFactory.hh"
25#include "BDSDetectorConstruction.hh"
26#include "BDSException.hh"
27#include "BDSExtent.hh"
28#include "BDSFieldFactory.hh"
29#include "BDSFieldInfo.hh"
30#include "BDSGeometryExternal.hh"
31#include "BDSGeometryFactory.hh"
32#include "BDSGlobalConstants.hh"
33#include "BDSMaterials.hh"
34#include "BDSParser.hh"
35#include "BDSPlacementToMake.hh"
36#include "BDSSimpleComponent.hh"
37#include "BDSUtilities.hh"
39#include "parser/element.h"
40#include "parser/placement.h"
42#include "G4LogicalVolume.hh"
43#include "G4RotationMatrix.hh"
44#include "G4ThreeVector.hh"
45#include "G4Transform3D.hh"
56 if (placements.empty())
60 std::vector<BDSPlacementToMake> fieldPlacements;
62 for (
const auto& placement : placements)
66 if (!placement.sequence.empty())
70 G4bool hasAField =
false;
71 G4String fieldPlacementName;
74 if (placement.name.empty())
76 G4cerr <<
"Problem with unnamed placement, its contents are:" << G4endl;
78 throw BDSException(__METHOD_NAME__,
"a placement must be defined with a name");
81 G4bool elementSpecified = !placement.bdsimElement.empty();
82 G4bool geometrySpecified = !placement.geometryFile.empty();
83 if (elementSpecified && geometrySpecified)
85 G4String msg =
"only one of \"geometryFile\" or \"bdsimElemenet\" can be specified in placement \"" + placement.name +
"\"";
88 else if (!elementSpecified && !geometrySpecified)
90 G4String msg =
"at least one of \"geometryFile\" or \"bdsimElemenet\" must be specified in placement \"" + placement.name +
"\"";
94 if (geometrySpecified)
96 hasAField = !placement.fieldAll.empty();
101 fieldRecipe->SetUsePlacementWorldTransform(
true);
105 placement.geometryFile,
107 placement.autoColour,
112 BDSSDType::energydep,
113 BDSSDType::energydepvacuum,
114 placement.stripOuterVolume,
116 placement.dontReloadGeometry);
119 comp =
new BDSSimpleComponent(placement.name +
"_" + geom->GetName(), geom, chordLength);
131 {
throw BDSException(__METHOD_NAME__,
"no such element definition by name \"" + placement.bdsimElement +
"\" found for placement.");}
136 fieldPlacementName = comp->
GetName() +
"_field";
146 G4ThreeVector halfLengthBeg = G4ThreeVector(0,0,-chordLength*0.5);
147 G4ThreeVector halfLengthEnd = G4ThreeVector(0,0, chordLength*0.5);
148 G4ThreeVector midPos = transform.getTranslation();
149 G4ThreeVector startPos = midPos + transform * (HepGeom::Point3D<G4double>)halfLengthBeg;
150 G4ThreeVector endPos = midPos + transform * (HepGeom::Point3D<G4double>)halfLengthEnd;
151 G4RotationMatrix* rm =
new G4RotationMatrix(transform.getRotation());
158 new G4RotationMatrix(*rm),
159 new G4RotationMatrix(*rm),
163 new G4RotationMatrix(*rm),
164 new G4RotationMatrix(*rm),
165 new G4RotationMatrix(*rm),
173 G4LogicalVolume* lv =
new G4LogicalVolume(containerSolidClone,
nullptr, fieldPlacementName+
"_lv");
174 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 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, G4double currentArcLengthIn=0)
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)
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)