BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSGeometryComponent.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef BDSGEOMETRYCOMPONENT_H
20#define BDSGEOMETRYCOMPONENT_H
21
22#include "BDSExtent.hh"
23#include "BDSSDType.hh"
24
25#include "globals.hh" // geant4 globals / types
26#include "G4LogicalVolume.hh"
27#include "G4Transform3D.hh"
28
29#include <map>
30#include <set>
31#include <utility> //for std::pair
32
33class G4AssemblyVolume;
34class G4UserLimits;
35class G4VisAttributes;
36class G4VPhysicalVolume;
37class G4VSensitiveDetector;
38class G4VSolid;
39namespace CLHEP {
40 class HepRotation;
41}
42typedef CLHEP::HepRotation G4RotationMatrix;
43
70{
71public:
72 BDSGeometryComponent(G4VSolid* containerSolidIn,
73 G4LogicalVolume* containerLVIn,
74 const BDSExtent& extentIn = BDSExtent(),
75 const BDSExtent& innerExtentIn = BDSExtent(),
76 const G4ThreeVector& placementOffsetIn = G4ThreeVector(0,0,0),
77 G4RotationMatrix* placementRotationIn = nullptr);
78
79 BDSGeometryComponent(G4AssemblyVolume* containerAssemblyIn,
80 const BDSExtent& extentIn = BDSExtent(),
81 const BDSExtent& innerExtentIn = BDSExtent(),
82 const G4ThreeVector& placementOffsetIn = G4ThreeVector(0,0,0),
83 G4RotationMatrix* placementRotationIn = nullptr);
84
89 virtual ~BDSGeometryComponent();
92
94 virtual inline G4String GetName() const {return containerLogicalVolume->GetName();}
95 inline G4VSolid* GetContainerSolid() const {return containerSolid;}
96 inline G4LogicalVolume* GetContainerLogicalVolume() const {return containerLogicalVolume;}
97 inline G4AssemblyVolume* GetContainerAssemblyVolume() const {return containerAssembly;}
98 inline G4Transform3D GetPlacementTransform() const;
99 inline G4ThreeVector GetPlacementOffset() const {return placementOffset;}
100 inline G4RotationMatrix* GetPlacementRotation() const {return placementRotation;}
101 inline BDSExtent GetExtent() const {return outerExtent;}
102 inline BDSExtent GetInnerExtent() const {return innerExtent;}
103 inline std::pair<G4double,G4double> GetExtentX() const {return outerExtent.ExtentX();}
104 inline std::pair<G4double,G4double> GetExtentY() const {return outerExtent.ExtentY();}
105 inline std::pair<G4double,G4double> GetExtentZ() const {return outerExtent.ExtentZ();}
106 inline std::pair<G4double,G4double> GetInnerExtentX() const {return innerExtent.ExtentX();}
107 inline std::pair<G4double,G4double> GetInnerExtentY() const {return innerExtent.ExtentY();}
108 inline std::pair<G4double,G4double> GetInnerExtentZ() const {return innerExtent.ExtentZ();}
109 virtual std::set<G4VPhysicalVolume*> GetAllPhysicalVolumes() const {return allPhysicalVolumes;}
110 virtual std::set<G4RotationMatrix*> GetAllRotationMatrices() const {return allRotationMatrices;}
111 virtual std::set<G4VisAttributes*> GetAllVisAttributes() const {return allVisAttributes;}
112 virtual std::set<G4UserLimits*> GetAllUserLimits() const {return allUserLimits;}
113 virtual std::set<BDSGeometryComponent*> GetAllDaughters() const {return allDaughters;}
114 virtual std::set<G4VSolid*> GetAllSolids() const {return allSolids;}
116
118 inline void SetPlacementOffset(const G4ThreeVector& offsetIn) {placementOffset = G4ThreeVector(offsetIn);}
119
121 inline void SetExtent(const BDSExtent& extIn) {outerExtent = extIn;}
122 inline void SetInnerExtent(const BDSExtent& extIn) {innerExtent = extIn;}
124
126 G4ThreeVector GetExtentPositive() const {return outerExtent.ExtentPositive();}
127
129 G4ThreeVector GetExtentNegative() const {return outerExtent.ExtentNegative();}
130
132 void InheritExtents(BDSGeometryComponent const * const anotherComponent);
133
136 void InheritExtents(BDSGeometryComponent const * const anotherComponent,
137 const G4ThreeVector& offset);
138
141 void RegisterDaughter(BDSGeometryComponent* anotherComponent) {allDaughters.insert(anotherComponent);}
142
145 inline void RegisterSolid(G4VSolid* solid) {allSolids.insert(solid);}
146
148 void RegisterSolid(const std::set<G4VSolid*>& solids);
149
153 inline void RegisterLogicalVolume(G4LogicalVolume* logicalVolume) {allLogicalVolumes.insert(logicalVolume);}
154
156 void RegisterLogicalVolume(const std::set<G4LogicalVolume*>& localVolumes);
157
161 void RegisterSensitiveVolume(G4LogicalVolume* sensitiveVolume,
162 BDSSDType sensitivityType);
163
166 void RegisterSensitiveVolume(const std::set<G4LogicalVolume*>& sensitiveVolumes,
167 BDSSDType sensitivityType);
168
170 void RegisterSensitiveVolume(const std::map<G4LogicalVolume*, BDSSDType>& sensitiveVolumes);
171
174 inline void RegisterPhysicalVolume(G4VPhysicalVolume* physicalVolume) {allPhysicalVolumes.insert(physicalVolume);}
175
177 void RegisterPhysicalVolume(const std::set<G4VPhysicalVolume*>& physicalVolumes);
178
181 inline void RegisterRotationMatrix(G4RotationMatrix* rotationMatrix) {allRotationMatrices.insert(rotationMatrix);}
182
184 void RegisterRotationMatrix(const std::set<G4RotationMatrix*>& rotationMatrices);
185
188 inline void RegisterVisAttributes(G4VisAttributes* visAttribute) {allVisAttributes.insert(visAttribute);}
189
191 void RegisterVisAttributes(const std::set<G4VisAttributes*>& visAttributes);
192
195 inline void RegisterUserLimits(G4UserLimits* userLimit) {allUserLimits.insert(userLimit);}
196
198 void RegisterUserLimits(const std::set<G4UserLimits*>& userLimits);
199
203 void InheritObjects(BDSGeometryComponent* component);
204
206 virtual std::set<G4LogicalVolume*> GetAllLogicalVolumes() const;
207
209 virtual std::set<G4LogicalVolume*> GetAllBiasingVolumes() const;
210
212 virtual std::map<G4LogicalVolume*, BDSSDType> GetAllSensitiveVolumes() const;
213
216 inline void MakeAllVolumesSensitive(BDSSDType stype = BDSSDType::energydep) {RegisterSensitiveVolume(GetAllLogicalVolumes(), stype);}
217
219 virtual void AttachSensitiveDetectors();
220
223 virtual void ExcludeLogicalVolumeFromBiasing(G4LogicalVolume* lv);
224
227
229 static void AttachUserLimitsToAssembly(G4AssemblyVolume* av,
230 G4UserLimits* ul);
231
232protected:
234 G4VSolid* containerSolid;
235 G4LogicalVolume* containerLogicalVolume;
236 G4AssemblyVolume* containerAssembly;
237 BDSExtent outerExtent;
238 BDSExtent innerExtent;
239
241 std::set<BDSGeometryComponent*> allDaughters;
242
244 std::set<G4VSolid*> allSolids;
245
246 std::set<G4LogicalVolume*> allLogicalVolumes;
247 // we have to keep a registry of all logical volumes to be able to associate
248 // information with them at construction time - for example S position - that
249 // can't be stored in the Logical Volume class itself without modifying geant
250
253 std::map<G4LogicalVolume*, BDSSDType> sensitivity;
254
258
260 std::set<G4VPhysicalVolume*> allPhysicalVolumes;
261
263 std::set<G4RotationMatrix*> allRotationMatrices;
264
266 std::set<G4VisAttributes*> allVisAttributes;
267
269 std::set<G4UserLimits*> allUserLimits;
270
273 G4ThreeVector placementOffset;
274
279 G4RotationMatrix* placementRotation;
280
282 std::set<G4LogicalVolume*>* lvsExcludedFromBiasing;
283};
284
286{
288 {return G4Transform3D(G4RotationMatrix(), placementOffset);}
289 else
290 {return G4Transform3D(*placementRotation, placementOffset);}
291}
292
293#endif
Holder for +- extents in 3 dimensions.
Definition: BDSExtent.hh:39
std::pair< G4double, G4double > ExtentX() const
Accessor.
Definition: BDSExtent.hh:61
G4ThreeVector ExtentNegative() const
Accessor.
Definition: BDSExtent.hh:75
G4ThreeVector ExtentPositive() const
Accessor.
Definition: BDSExtent.hh:72
std::pair< G4double, G4double > ExtentZ() const
Accessor.
Definition: BDSExtent.hh:63
std::pair< G4double, G4double > ExtentY() const
Accessor.
Definition: BDSExtent.hh:62
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++.