Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AssemblyVolume.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4AssemblyVolume
27//
28// Class description:
29//
30// G4AssemblyVolume is a helper class to make the build process of geometry
31// easier. It allows one to combine several volumes together in an arbitrary way
32// in 3D space and then work with the result as with a single logical volume
33// for placement.
34// The resulting objects are independent copies of each of the assembled
35// logical volumes. The placements are not, however, bound one to each other
36// when placement is done. They are seen as independent physical volumes in
37// space.
38
39// Authors: R.Chytracek, J.Apostolakis, G.Cosmo (CERN), November 2000
40// ----------------------------------------------------------------------
41#ifndef G4ASSEMBLYVOLUME_HH
42#define G4ASSEMBLYVOLUME_HH
43
44#include <vector>
45
46#include "G4Transform3D.hh"
47#include "G4AssemblyTriplet.hh"
48
50
51/**
52 * @brief G4AssemblyVolume is a helper class to make the build process of
53 * geometry easier. It allows one to combine several volumes together in an
54 * arbitrary way in 3D space and then work with the result as with a single
55 * logical volume for placement.
56 * The resulting objects are independent copies of each of the assembled
57 * logical volumes. The placements are not, however, bound one to each other
58 * when placement is done. They are seen as independent physical volumes in
59 * space.
60 */
61
63{
64 public:
65
66 /**
67 * Default Constructor.
68 */
70
71 /**
72 * Constructor.
73 * The rotation matrix passed as argument can be nullptr (identity) or an
74 * address even of an object on the upper stack frame. During assembly
75 * imprint, a new matrix is created anyway and it is kept track of it so
76 * it can be automatically deleted later at the end of the application.
77 * This policy is adopted since user has no control on the way the
78 * rotations are combined.
79 * @param[in] volume Pointer to the logical volume of the assembly.
80 * @param[in] translation Translation vector of the assembly.
81 * @param[in] rotation Pointer to the rotation matrix of the assembly.
82 */
84 G4ThreeVector& translation,
85 G4RotationMatrix* rotation);
86
87 /**
88 * Destructor.
89 * At destruction all the generated physical volumes and associated
90 * rotation matrices of the imprints will be destroyed.
91 */
93
94 /**
95 * Places the given volume 'pPlacedVolume' inside the assembly.
96 *
97 * The adopted approach:
98 *
99 * - Place it w.r.t. the assembly coordinate system.
100 * This step is applied to each of the participating volumes.
101 *
102 * The other possible approaches:
103 *
104 * - Place w.r.t. the firstly added volume.
105 * When placed the first, the virtual coordinate system becomes
106 * the coordinate system of the first one.
107 * Every next volume being added into the assembly will be placed
108 * w.r.t to the first one.
109 *
110 * - Place w.r.t the last placed volume.
111 * When placed the first, the virtual coordinate system becomes
112 * the coordinate system of the first one.
113 * Every next volume being added into the assembly will be placed
114 * w.r.t to the previous one.
115 *
116 * The rotation matrix passed as argument can be nullptr (identity) or an
117 * address even of an object on the upper stack frame. During assembly
118 * imprint, a new matrix is created anyway and it is kept track of it so
119 * it can be automatically deleted later at the end of the application.
120 * This policy is adopted since user has no control on the way the
121 * rotations are combined.
122 * @param[in] pPlacedVolume Pointer to the logical volume of the volume
123 * to be added to the assembly.
124 * @param[in] translation Translation vector of the volume.
125 * @param[in] rotation Pointer to the rotation matrix of the volume.
126 */
127 void AddPlacedVolume( G4LogicalVolume* pPlacedVolume,
128 G4ThreeVector& translation,
129 G4RotationMatrix* rotation);
130
131 /**
132 * The same as previous method, except that it takes the complete 3D
133 * transformation in space as its argument.
134 * @param[in] pPlacedVolume Pointer to the logical volume of the volume
135 * to be added to the assembly.
136 * @param[in] transformation The 3D transformation in space.
137 */
138 void AddPlacedVolume( G4LogicalVolume* pPlacedVolume,
139 G4Transform3D& transformation);
140
141 /**
142 * The same as previous method, but takes an assembly volume as argument.
143 * @param[in] pAssembly Pointer to the assembly volume to be added
144 * to the assembly.
145 * @param[in] transformation The 3D transformation in space.
146 */
147 void AddPlacedAssembly( G4AssemblyVolume* pAssembly,
148 G4Transform3D& transformation);
149
150 /**
151 * The same as previous method, but takes an assembly volume
152 * as its argument with translation and rotation.
153 * @param[in] pAssembly Pointer to the assembly volume to be added
154 * to the assembly.
155 * @param[in] translation Translation vector of the volume.
156 * @param[in] rotation Pointer to the rotation matrix of the volume.
157 */
158 void AddPlacedAssembly( G4AssemblyVolume* pAssembly,
159 G4ThreeVector& translation,
160 G4RotationMatrix* rotation);
161
162 /**
163 * Creates instance of an assembly volume inside the given mother volume.
164 * @param[in] pMotherLV Pointer to the logical volume of the assembly.
165 * @param[in] translationInMother Translation vector of the imprint.
166 * @param[in] pRotationInMother Pointer to the rotation of the imprint.
167 * @param[in] copyNumBase Optional index to assign to the imprint.
168 * @param[in] surfCheck Flag to enable overlaps checking while imprinting.
169 */
170 void MakeImprint( G4LogicalVolume* pMotherLV,
171 G4ThreeVector& translationInMother,
172 G4RotationMatrix* pRotationInMother,
173 G4int copyNumBase = 0,
174 G4bool surfCheck = false );
175
176 /**
177 * The same as previous Imprint() method, but takes a complete 3D
178 * transformation in space as its argument.
179 * @param[in] pMotherLV Pointer to the logical volume of the assembly.
180 * @param[in] transformation The 3D transformation in space of the imprint.
181 * @param[in] copyNumBase Optional index to assign to the imprint.
182 * @param[in] surfCheck Flag to enable overlaps checking while imprinting.
183 */
184 void MakeImprint( G4LogicalVolume* pMotherLV,
185 G4Transform3D& transformation,
186 G4int copyNumBase = 0,
187 G4bool surfCheck = false );
188
189 /**
190 * To access the physical volumes imprinted through an iterator.
191 */
192 inline std::vector<G4VPhysicalVolume*>::iterator GetVolumesIterator();
193
194 /**
195 * Returns the total number of imprinted volumes of the assembly.
196 */
197 inline std::size_t TotalImprintedVolumes() const;
198
199 /**
200 * To access the 3D transformation in space for each imprint, given the ID.
201 */
202 inline G4Transform3D& GetImprintTransformation(unsigned int imprintID);
203
204 /**
205 * To access the created triplets in the assembly through an iterator.
206 */
207 inline std::vector<G4AssemblyTriplet>::iterator GetTripletsIterator();
208
209 /**
210 * Returns the total number of triplets in the assembly.
211 */
212 inline std::size_t TotalTriplets() const;
213
214 /**
215 * Returns the number of currently made imprints.
216 */
217 inline unsigned int GetImprintsCount() const;
218
219 /**
220 * Returns the number of existing instances of G4AssemblyVolume class.
221 */
222 unsigned int GetInstanceCount() const;
223
224 /**
225 * Returns the instance number of the assembly.
226 */
227 inline unsigned int GetAssemblyID() const;
228
229 protected:
230
231 inline void SetInstanceCount( unsigned int value );
232 inline void SetAssemblyID( unsigned int value );
233
234 void InstanceCountPlus();
235 void InstanceCountMinus();
236
237 // Internal counting mechanism, used to compute unique the names of
238 // physical volumes created by MakeImprint() methods.
239 //
240 inline void SetImprintsCount( unsigned int value );
241 inline void ImprintsCountPlus();
242 inline void ImprintsCountMinus();
243
244 private:
245
246 /**
247 * Function for placement of the given assembly in the given mother
248 * (called recursively if the assembly contains an assembly).
249 */
250 void MakeImprint( G4AssemblyVolume* pAssembly,
251 G4LogicalVolume* pMotherLV,
252 G4Transform3D& transformation,
253 G4int copyNumBase = 0,
254 G4bool surfCheck = false );
255
256 private:
257
258 /** Participating volumes represented as a vector of
259 * <logical volume, translation, rotation>. */
260 std::vector<G4AssemblyTriplet> fTriplets;
261
262 /** We need to keep list of physical volumes created by MakeImprint()
263 * in order to be able to cleanup the objects when not needed anymore.
264 * This requires the user to keep assembly objects in memory during the
265 * whole job or during the life-time of G4Navigator, logical volume store
266 * and physical volume store keep pointers to physical volumes generated
267 * by the assembly volume.
268 * When an assembly object is about to die it will destroy all its
269 * generated physical volumes and rotation matrices as well ! */
270 std::vector<G4VPhysicalVolume*> fPVStore;
271
272 /** Number of imprints of the given assembly volume. */
273 unsigned int fImprintsCounter;
274
275 /** Class instance counter. */
276 static G4ThreadLocal unsigned int fsInstanceCounter;
277
278 /** Assembly object ID derived from instance counter at construction time. */
279 unsigned int fAssemblyID = 0;
280
281 /** Container of transformations for each imprint (used in GDML). */
282 std::map<unsigned int, G4Transform3D> fImprintsTransf;
283};
284
285#include "G4AssemblyVolume.icc"
286
287#endif
CLHEP::HepRotation G4RotationMatrix
CLHEP::Hep3Vector G4ThreeVector
HepGeom::Transform3D G4Transform3D
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
unsigned int GetImprintsCount() const
void MakeImprint(G4LogicalVolume *pMotherLV, G4ThreeVector &translationInMother, G4RotationMatrix *pRotationInMother, G4int copyNumBase=0, G4bool surfCheck=false)
G4Transform3D & GetImprintTransformation(unsigned int imprintID)
std::vector< G4VPhysicalVolume * >::iterator GetVolumesIterator()
void ImprintsCountMinus()
std::vector< G4AssemblyTriplet >::iterator GetTripletsIterator()
void SetAssemblyID(unsigned int value)
void AddPlacedAssembly(G4AssemblyVolume *pAssembly, G4Transform3D &transformation)
unsigned int GetAssemblyID() const
void SetInstanceCount(unsigned int value)
void AddPlacedVolume(G4LogicalVolume *pPlacedVolume, G4ThreeVector &translation, G4RotationMatrix *rotation)
void ImprintsCountPlus()
void SetImprintsCount(unsigned int value)
std::size_t TotalTriplets() const
unsigned int GetInstanceCount() const
std::size_t TotalImprintedVolumes() const
G4LogicalVolume represents a leaf node or unpositioned subtree in the geometry hierarchy....
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
#define G4ThreadLocal
Definition tls.hh:77