20#include "BDSException.hh"
21#include "BDSExtent.hh"
22#include "BDSGeometryComponent.hh"
23#include "BDSSDManager.hh"
24#include "BDSSDType.hh"
27#include "G4AssemblyVolume.hh"
28#include "G4LogicalVolume.hh"
29#include "G4RotationMatrix.hh"
30#include "G4UserLimits.hh"
31#include "G4VisAttributes.hh"
32#include "G4VPhysicalVolume.hh"
39class G4VSensitiveDetector;
41BDSGeometryComponent::BDSGeometryComponent(G4VSolid* containerSolidIn,
42 G4LogicalVolume* containerLVIn,
45 const G4ThreeVector& placementOffsetIn,
46 G4RotationMatrix* placementRotationIn):
47 containerIsAssembly(false),
48 containerSolid(containerSolidIn),
49 containerLogicalVolume(containerLVIn),
50 containerAssembly(nullptr),
51 outerExtent(extentIn),
52 innerExtent(innerExtentIn),
53 overrideSensitivity(false),
54 placementOffset(placementOffsetIn),
55 placementRotation(placementRotationIn),
56 lvsExcludedFromBiasing(nullptr)
59BDSGeometryComponent::BDSGeometryComponent(G4AssemblyVolume* containerAssemblyIn,
62 const G4ThreeVector& placementOffsetIn,
63 G4RotationMatrix* placementRotationIn):
64 containerIsAssembly(true),
65 containerSolid(nullptr),
66 containerLogicalVolume(nullptr),
67 containerAssembly(containerAssemblyIn),
68 outerExtent(extentIn),
69 innerExtent(innerExtentIn),
70 overrideSensitivity(false),
71 placementOffset(placementOffsetIn),
72 placementRotation(placementRotationIn),
73 lvsExcludedFromBiasing(nullptr)
77 containerIsAssembly(component.containerIsAssembly),
78 containerSolid(component.containerSolid),
79 containerLogicalVolume(component.containerLogicalVolume),
80 containerAssembly(component.containerAssembly),
81 outerExtent(component.outerExtent),
82 innerExtent(component.innerExtent),
83 allLogicalVolumes(component.allLogicalVolumes),
84 sensitivity(component.sensitivity),
85 overrideSensitivity(component.overrideSensitivity),
86 allPhysicalVolumes(component.allPhysicalVolumes),
87 placementOffset(component.placementOffset),
88 placementRotation(component.placementRotation),
89 lvsExcludedFromBiasing(nullptr)
92BDSGeometryComponent::~BDSGeometryComponent()
113 outerExtent = anotherComponent->
GetExtent();
118 const G4ThreeVector &offset)
126 for (
auto solid : solids)
132 for (
auto lv : logicalVolumes)
138 for (
auto pv : physicalVolumes)
144 for (
auto rm : rotationMatrices)
151 if (!sensitiveVolume)
154 G4cout << __METHOD_NAME__ << sensitiveVolume->GetName() <<
" : " << sensitivityType << G4endl;
167 for (
auto sv : sensitiveVolumes)
173 sensitivity.insert(sensitiveVolumes.begin(), sensitiveVolumes.end());
178 for (
auto va : visAttributes)
184 for (
auto ul : userLimits)
201 std::set<G4LogicalVolume*> result(allLogicalVolumes);
204 auto dLVs = it->GetAllLogicalVolumes();
205 result.insert(dLVs.begin(), dLVs.end());
212 std::set<G4LogicalVolume*> result(allLogicalVolumes);
216 auto dLVs = it->GetAllBiasingVolumes();
217 result.insert(dLVs.begin(), dLVs.end());
231 std::map<G4LogicalVolume*, BDSSDType> result(
sensitivity);
234 auto dSVs = it->GetAllSensitiveVolumes();
235 result.insert(dSVs.begin(), dSVs.end());
246 {daughter->AttachSensitiveDetectors();}
251 if (allLogicalVolumes.find(lv) == allLogicalVolumes.end())
253 throw BDSException(__METHOD_NAME__,
"excluding volume \"" + lv->GetName()
254 +
"\" from component \"" +
GetName()
255 +
"\" but it's not a member of this piece of geometry or its daughters.");
267 containerAssembly =
new G4AssemblyVolume();
268 for (G4int i = 0; i < (G4int)containerLogicalVolume->GetNoDaughters(); i++)
270 auto daughterPV = containerLogicalVolume->GetDaughter(i);
271 auto daughterLV = daughterPV->GetLogicalVolume();
272 auto translation = daughterPV->GetObjectTranslation();
273 auto rotation = daughterPV->GetObjectRotation();
274 G4RotationMatrix* rm = rotation ?
new G4RotationMatrix(*(rotation)) :
nullptr;
275 containerAssembly->AddPlacedVolume(daughterLV, translation, rm);
283 std::set<G4LogicalVolume*> lvSet;
284 auto it = av->GetVolumesIterator();
285 for (G4int i = 0; i < (G4int)av->TotalImprintedVolumes(); i++, it++)
286 {lvSet.insert((*it)->GetLogicalVolume());}
287 for (
auto& lv : lvSet)
288 {lv->SetUserLimits(ul);}
General exception with possible name of object and message.
Holder for +- extents in 3 dimensions.
BDSExtent Translate(const G4ThreeVector &offset) const
Provide a new copy of this extent with an offset applied.
A generic geometry component for a bdsim model.
void InheritExtents(BDSGeometryComponent const *const anotherComponent)
Update the extents of this object with those of another object.
BDSExtent GetExtent() const
Accessor - see member for more info.
virtual G4String GetName() const
Accessor - see member for more info.
void RegisterRotationMatrix(G4RotationMatrix *rotationMatrix)
std::set< G4UserLimits * > allUserLimits
registry of all user limits belonging to this component
std::set< G4LogicalVolume * > * lvsExcludedFromBiasing
Volumes that should not be included when return GetAllBiasingVolumes().
virtual std::set< G4RotationMatrix * > GetAllRotationMatrices() const
Accessor - see member for more info.
virtual void AttachSensitiveDetectors()
Attach a sensitive detector class to all registered sensitive volumes in this component.
virtual std::set< G4LogicalVolume * > GetAllBiasingVolumes() const
Return all logical volumes that should be used for biasing minus any that are in the excluded set.
void RegisterLogicalVolume(G4LogicalVolume *logicalVolume)
virtual std::set< G4UserLimits * > GetAllUserLimits() const
Accessor - see member for more info.
std::map< G4LogicalVolume *, BDSSDType > sensitivity
virtual std::map< G4LogicalVolume *, BDSSDType > GetAllSensitiveVolumes() const
Access all sensitive volumes belonging to this component.
virtual std::set< G4LogicalVolume * > GetAllLogicalVolumes() const
Access all logical volumes belonging to this component.
void InheritObjects(BDSGeometryComponent *component)
static void AttachUserLimitsToAssembly(G4AssemblyVolume *av, G4UserLimits *ul)
Utility function to apply user limits to an assembly volume as there's not interface.
virtual std::set< G4VisAttributes * > GetAllVisAttributes() const
Accessor - see member for more info.
void RegisterPhysicalVolume(G4VPhysicalVolume *physicalVolume)
virtual std::set< G4VSolid * > GetAllSolids() const
Accessor - see member for more info.
std::set< BDSGeometryComponent * > allDaughters
registry of all daughter geometry components
void RegisterUserLimits(G4UserLimits *userLimit)
virtual void ExcludeLogicalVolumeFromBiasing(G4LogicalVolume *lv)
void StripOuterAndMakeAssemblyVolume()
Change from a container logical volume to an assembly volume.
std::set< G4VisAttributes * > allVisAttributes
registry of all visualisation attributes belonging to this component
std::set< G4RotationMatrix * > allRotationMatrices
registry of all rotation matrices belonging to this component
G4bool overrideSensitivity
BDSExtent GetInnerExtent() const
Accessor - see member for more info.
virtual std::set< G4VPhysicalVolume * > GetAllPhysicalVolumes() const
Accessor - see member for more info.
void RegisterVisAttributes(G4VisAttributes *visAttribute)
void RegisterSolid(G4VSolid *solid)
G4RotationMatrix * placementRotation
G4bool containerIsAssembly
True if the 'container' is really an assembly; false if an LV.
void RegisterSensitiveVolume(G4LogicalVolume *sensitiveVolume, BDSSDType sensitivityType)
A singleton class that holds all required sensitive detector class instances.
G4VSensitiveDetector * SensitiveDetector(const BDSSDType sdType, G4bool applyOptions=false) const
Improve type-safety of native enum data type in C++.