BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSGeometryComponent.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef BDSGEOMETRYCOMPONENT_H
19#define BDSGEOMETRYCOMPONENT_H
20
21#include "BDSExtent.hh"
22#include "BDSSDType.hh"
23
24#include "globals.hh" // geant4 globals / types
25#include "G4LogicalVolume.hh"
26#include "G4Transform3D.hh"
27
28#include <map>
29#include <set>
30#include <utility> //for std::pair
31
32class G4AssemblyVolume;
33class G4UserLimits;
34class G4VisAttributes;
35class G4VPhysicalVolume;
36class G4VSensitiveDetector;
37class G4VSolid;
38namespace CLHEP {
39 class HepRotation;
40}
41typedef CLHEP::HepRotation G4RotationMatrix;
42
69{
70public:
71 BDSGeometryComponent(G4VSolid* containerSolidIn,
72 G4LogicalVolume* containerLVIn,
73 const BDSExtent& extentIn = BDSExtent(),
74 const BDSExtent& innerExtentIn = BDSExtent(),
75 const G4ThreeVector& placementOffsetIn = G4ThreeVector(0,0,0),
76 G4RotationMatrix* placementRotationIn = nullptr);
77
78 BDSGeometryComponent(G4AssemblyVolume* containerAssemblyIn,
79 const BDSExtent& extentIn = BDSExtent(),
80 const BDSExtent& innerExtentIn = BDSExtent(),
81 const G4ThreeVector& placementOffsetIn = G4ThreeVector(0,0,0),
82 G4RotationMatrix* placementRotationIn = nullptr);
83
88 virtual ~BDSGeometryComponent();
91
93 virtual inline G4String GetName() const {return containerLogicalVolume->GetName();}
94 inline G4VSolid* GetContainerSolid() const {return containerSolid;}
95 inline G4LogicalVolume* GetContainerLogicalVolume() const {return containerLogicalVolume;}
96 inline G4AssemblyVolume* GetContainerAssemblyVolume() const {return containerAssembly;}
97 inline G4Transform3D GetPlacementTransform() const;
98 inline G4ThreeVector GetPlacementOffset() const {return placementOffset;}
99 inline G4RotationMatrix* GetPlacementRotation() const {return placementRotation;}
100 inline BDSExtent GetExtent() const {return outerExtent;}
101 inline BDSExtent GetInnerExtent() const {return innerExtent;}
102 inline std::pair<G4double,G4double> GetExtentX() const {return outerExtent.ExtentX();}
103 inline std::pair<G4double,G4double> GetExtentY() const {return outerExtent.ExtentY();}
104 inline std::pair<G4double,G4double> GetExtentZ() const {return outerExtent.ExtentZ();}
105 inline std::pair<G4double,G4double> GetInnerExtentX() const {return innerExtent.ExtentX();}
106 inline std::pair<G4double,G4double> GetInnerExtentY() const {return innerExtent.ExtentY();}
107 inline std::pair<G4double,G4double> GetInnerExtentZ() const {return innerExtent.ExtentZ();}
108 virtual std::set<G4VPhysicalVolume*> GetAllPhysicalVolumes() const {return allPhysicalVolumes;}
109 virtual std::set<G4RotationMatrix*> GetAllRotationMatrices() const {return allRotationMatrices;}
110 virtual std::set<G4VisAttributes*> GetAllVisAttributes() const {return allVisAttributes;}
111 virtual std::set<G4UserLimits*> GetAllUserLimits() const {return allUserLimits;}
112 virtual std::set<BDSGeometryComponent*> GetAllDaughters() const {return allDaughters;}
113 virtual std::set<G4VSolid*> GetAllSolids() const {return allSolids;}
115
117 inline void SetPlacementOffset(const G4ThreeVector& offsetIn) {placementOffset = G4ThreeVector(offsetIn);}
118
120 inline void SetExtent(const BDSExtent& extIn) {outerExtent = extIn;}
121 inline void SetInnerExtent(const BDSExtent& extIn) {innerExtent = extIn;}
123
125 G4ThreeVector GetExtentPositive() const {return outerExtent.ExtentPositive();}
126
128 G4ThreeVector GetExtentNegative() const {return outerExtent.ExtentNegative();}
129
131 void InheritExtents(BDSGeometryComponent const * const anotherComponent);
132
135 void InheritExtents(BDSGeometryComponent const * const anotherComponent,
136 const G4ThreeVector& offset);
137
140 void RegisterDaughter(BDSGeometryComponent* anotherComponent) {allDaughters.insert(anotherComponent);}
141
144 inline void RegisterSolid(G4VSolid* solid) {allSolids.insert(solid);}
145
147 void RegisterSolid(const std::set<G4VSolid*>& solids);
148
152 inline void RegisterLogicalVolume(G4LogicalVolume* logicalVolume) {allLogicalVolumes.insert(logicalVolume);}
153
155 void RegisterLogicalVolume(const std::set<G4LogicalVolume*>& localVolumes);
156
160 void RegisterSensitiveVolume(G4LogicalVolume* sensitiveVolume,
161 BDSSDType sensitivityType);
162
165 void RegisterSensitiveVolume(const std::set<G4LogicalVolume*>& sensitiveVolumes,
166 BDSSDType sensitivityType);
167
169 void RegisterSensitiveVolume(const std::map<G4LogicalVolume*, BDSSDType>& sensitiveVolumes);
170
173 inline void RegisterPhysicalVolume(G4VPhysicalVolume* physicalVolume) {allPhysicalVolumes.insert(physicalVolume);}
174
176 void RegisterPhysicalVolume(const std::set<G4VPhysicalVolume*>& physicalVolumes);
177
180 inline void RegisterRotationMatrix(G4RotationMatrix* rotationMatrix) {allRotationMatrices.insert(rotationMatrix);}
181
183 void RegisterRotationMatrix(const std::set<G4RotationMatrix*>& rotationMatrices);
184
187 inline void RegisterVisAttributes(G4VisAttributes* visAttribute) {allVisAttributes.insert(visAttribute);}
188
190 void RegisterVisAttributes(const std::set<G4VisAttributes*>& visAttributes);
191
194 inline void RegisterUserLimits(G4UserLimits* userLimit) {allUserLimits.insert(userLimit);}
195
197 void RegisterUserLimits(const std::set<G4UserLimits*>& userLimits);
198
202 void InheritObjects(BDSGeometryComponent* component);
203
205 virtual std::set<G4LogicalVolume*> GetAllLogicalVolumes() const;
206
208 virtual std::set<G4LogicalVolume*> GetAllBiasingVolumes() const;
209
211 virtual std::map<G4LogicalVolume*, BDSSDType> GetAllSensitiveVolumes() const;
212
215 inline void MakeAllVolumesSensitive(BDSSDType stype = BDSSDType::energydep) {RegisterSensitiveVolume(GetAllLogicalVolumes(), stype);}
216
218 virtual void AttachSensitiveDetectors();
219
222 virtual void ExcludeLogicalVolumeFromBiasing(G4LogicalVolume* lv);
223
226
228 static void AttachUserLimitsToAssembly(G4AssemblyVolume* av,
229 G4UserLimits* ul);
230
231protected:
233 G4VSolid* containerSolid;
234 G4LogicalVolume* containerLogicalVolume;
235 G4AssemblyVolume* containerAssembly;
236 BDSExtent outerExtent;
237 BDSExtent innerExtent;
238
240 std::set<BDSGeometryComponent*> allDaughters;
241
243 std::set<G4VSolid*> allSolids;
244
245 std::set<G4LogicalVolume*> allLogicalVolumes;
246 // we have to keep a registry of all logical volumes to be able to associate
247 // information with them at construction time - for example S position - that
248 // can't be stored in the Logical Volume class itself without modifying geant
249
252 std::map<G4LogicalVolume*, BDSSDType> sensitivity;
253
257
259 std::set<G4VPhysicalVolume*> allPhysicalVolumes;
260
262 std::set<G4RotationMatrix*> allRotationMatrices;
263
265 std::set<G4VisAttributes*> allVisAttributes;
266
268 std::set<G4UserLimits*> allUserLimits;
269
272 G4ThreeVector placementOffset;
273
278 G4RotationMatrix* placementRotation;
279
281 std::set<G4LogicalVolume*>* lvsExcludedFromBiasing;
282};
283
285{
287 {return G4Transform3D(G4RotationMatrix(), placementOffset);}
288 else
289 {return G4Transform3D(*placementRotation, placementOffset);}
290}
291
292#endif
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:38
std::pair< G4double, G4double > ExtentX() const
Accessor.
Definition BDSExtent.hh:60
G4ThreeVector ExtentNegative() const
Accessor.
Definition BDSExtent.hh:74
G4ThreeVector ExtentPositive() const
Accessor.
Definition BDSExtent.hh:71
std::pair< G4double, G4double > ExtentZ() const
Accessor.
Definition BDSExtent.hh:62
std::pair< G4double, G4double > ExtentY() const
Accessor.
Definition BDSExtent.hh:61
A generic geometry component for a bdsim model.
virtual std::set< BDSGeometryComponent * > GetAllDaughters() const
Accessor - see member for more info.
std::set< G4VSolid * > allSolids
registry of all solids belonging to this component
G4LogicalVolume * GetContainerLogicalVolume() const
Accessor - see member for more info.
G4bool ContainerIsAssembly() const
Whether the container is an assembly. If not, it's a logical volume.
std::set< G4VPhysicalVolume * > allPhysicalVolumes
registry of all physical volumes belonging to this component
void InheritExtents(BDSGeometryComponent const *const anotherComponent)
Update the extents of this object with those of another object.
void SetInnerExtent(const BDSExtent &extIn)
Set extent.
G4RotationMatrix * GetPlacementRotation() const
Accessor - see member for more info.
BDSExtent GetExtent() const
Accessor - see member for more info.
G4Transform3D GetPlacementTransform() const
Accessor - see member for more info.
void SetPlacementOffset(const G4ThreeVector &offsetIn)
Set the offset from 0,0,0 that the object should ideally be placed in its parent.
virtual G4String GetName() const
Accessor - see member for more info.
std::pair< G4double, G4double > GetExtentZ() const
Accessor - see member for more info.
G4ThreeVector GetExtentPositive() const
Get the extent of the object in the positive direction in all dimensions.
void RegisterRotationMatrix(G4RotationMatrix *rotationMatrix)
std::set< G4UserLimits * > allUserLimits
registry of all user limits belonging to this component
G4AssemblyVolume * GetContainerAssemblyVolume() const
Accessor - see member for more info.
std::set< G4LogicalVolume * > * lvsExcludedFromBiasing
Volumes that should not be included when return GetAllBiasingVolumes().
void MakeAllVolumesSensitive(BDSSDType stype=BDSSDType::energydep)
virtual std::set< G4RotationMatrix * > GetAllRotationMatrices() const
Accessor - see member for more info.
void RegisterDaughter(BDSGeometryComponent *anotherComponent)
virtual void AttachSensitiveDetectors()
Attach a sensitive detector class to all registered sensitive volumes in this component.
std::pair< G4double, G4double > GetInnerExtentX() const
Accessor - see member for more info.
std::pair< G4double, G4double > GetInnerExtentY() const
Accessor - see member for more info.
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)
G4ThreeVector GetExtentNegative() const
Get the extent of the object in the negative direction in all dimensions.
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.
std::pair< G4double, G4double > GetInnerExtentZ() const
Accessor - see member for more info.
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.
BDSGeometryComponent & operator=(const BDSGeometryComponent &)=delete
Assignment operator not used.
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.
G4VSolid * GetContainerSolid() const
Accessor - see member for more info.
std::set< BDSGeometryComponent * > allDaughters
registry of all daughter geometry components
std::pair< G4double, G4double > GetExtentY() const
Accessor - see member for more info.
G4ThreeVector GetPlacementOffset() const
Accessor - see member for more info.
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
BDSExtent GetInnerExtent() const
Accessor - see member for more info.
virtual std::set< G4VPhysicalVolume * > GetAllPhysicalVolumes() const
Accessor - see member for more info.
void SetExtent(const BDSExtent &extIn)
Set extent.
void RegisterVisAttributes(G4VisAttributes *visAttribute)
std::pair< G4double, G4double > GetExtentX() const
Accessor - see member for more info.
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)
Improve type-safety of native enum data type in C++.