19#include "BDSException.hh"
20#include "BDSExtent.hh"
21#include "BDSGeometryComponent.hh"
22#include "BDSSDManager.hh"
23#include "BDSSDType.hh"
26#include "G4AssemblyVolume.hh"
27#include "G4LogicalVolume.hh"
28#include "G4RotationMatrix.hh"
29#include "G4UserLimits.hh"
30#include "G4VisAttributes.hh"
31#include "G4VPhysicalVolume.hh"
38class G4VSensitiveDetector;
40BDSGeometryComponent::BDSGeometryComponent(G4VSolid* containerSolidIn,
41 G4LogicalVolume* containerLVIn,
44 const G4ThreeVector& placementOffsetIn,
45 G4RotationMatrix* placementRotationIn):
46 containerIsAssembly(false),
47 containerSolid(containerSolidIn),
48 containerLogicalVolume(containerLVIn),
49 containerAssembly(nullptr),
50 outerExtent(extentIn),
51 innerExtent(innerExtentIn),
52 overrideSensitivity(false),
53 placementOffset(placementOffsetIn),
54 placementRotation(placementRotationIn),
55 lvsExcludedFromBiasing(nullptr)
58BDSGeometryComponent::BDSGeometryComponent(G4AssemblyVolume* containerAssemblyIn,
61 const G4ThreeVector& placementOffsetIn,
62 G4RotationMatrix* placementRotationIn):
63 containerIsAssembly(true),
64 containerSolid(nullptr),
65 containerLogicalVolume(nullptr),
66 containerAssembly(containerAssemblyIn),
67 outerExtent(extentIn),
68 innerExtent(innerExtentIn),
69 overrideSensitivity(false),
70 placementOffset(placementOffsetIn),
71 placementRotation(placementRotationIn),
72 lvsExcludedFromBiasing(nullptr)
76 containerIsAssembly(component.containerIsAssembly),
77 containerSolid(component.containerSolid),
78 containerLogicalVolume(component.containerLogicalVolume),
79 containerAssembly(component.containerAssembly),
80 outerExtent(component.outerExtent),
81 innerExtent(component.innerExtent),
82 allLogicalVolumes(component.allLogicalVolumes),
83 sensitivity(component.sensitivity),
84 overrideSensitivity(component.overrideSensitivity),
85 allPhysicalVolumes(component.allPhysicalVolumes),
86 placementOffset(component.placementOffset),
87 placementRotation(component.placementRotation),
88 lvsExcludedFromBiasing(nullptr)
91BDSGeometryComponent::~BDSGeometryComponent()
112 outerExtent = anotherComponent->
GetExtent();
117 const G4ThreeVector &offset)
125 for (
auto solid : solids)
131 for (
auto lv : logicalVolumes)
137 for (
auto pv : physicalVolumes)
143 for (
auto rm : rotationMatrices)
150 if (!sensitiveVolume)
153 G4cout << __METHOD_NAME__ << sensitiveVolume->GetName() <<
" : " << sensitivityType << G4endl;
166 for (
auto sv : sensitiveVolumes)
172 sensitivity.insert(sensitiveVolumes.begin(), sensitiveVolumes.end());
177 for (
auto va : visAttributes)
183 for (
auto ul : userLimits)
200 std::set<G4LogicalVolume*> result(allLogicalVolumes);
203 auto dLVs = it->GetAllLogicalVolumes();
204 result.insert(dLVs.begin(), dLVs.end());
211 std::set<G4LogicalVolume*> result(allLogicalVolumes);
215 auto dLVs = it->GetAllBiasingVolumes();
216 result.insert(dLVs.begin(), dLVs.end());
230 std::map<G4LogicalVolume*, BDSSDType> result(
sensitivity);
233 auto dSVs = it->GetAllSensitiveVolumes();
234 result.insert(dSVs.begin(), dSVs.end());
245 {daughter->AttachSensitiveDetectors();}
250 if (allLogicalVolumes.find(lv) == allLogicalVolumes.end())
252 throw BDSException(__METHOD_NAME__,
"excluding volume \"" + lv->GetName()
253 +
"\" from component \"" +
GetName()
254 +
"\" but it's not a member of this piece of geometry or its daughters.");
266 containerAssembly =
new G4AssemblyVolume();
267 for (G4int i = 0; i < (G4int)containerLogicalVolume->GetNoDaughters(); i++)
269 auto daughterPV = containerLogicalVolume->GetDaughter(i);
270 auto daughterLV = daughterPV->GetLogicalVolume();
271 auto translation = daughterPV->GetObjectTranslation();
272 auto rotation = daughterPV->GetObjectRotation();
273 G4RotationMatrix* rm = rotation ?
new G4RotationMatrix(*(rotation)) :
nullptr;
274 containerAssembly->AddPlacedVolume(daughterLV, translation, rm);
282 std::set<G4LogicalVolume*> lvSet;
283 auto it = av->GetVolumesIterator();
284 for (G4int i = 0; i < (G4int)av->TotalImprintedVolumes(); i++, it++)
285 {lvSet.insert((*it)->GetLogicalVolume());}
286 for (
auto& lv : lvSet)
287 {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++.