Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VPhysicalVolume.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// G4VPhysicalVolume
27//
28// Class description:
29//
30// This is an abstract base class for the representation of a positioned volume.
31// The volume is placed within a mother volume, relative to its coordinate
32// system. Either a single positioned volume or many positioned volumes can
33// be represented by a particular G4VPhysicalVolume.
34
35// Author: Paul Kent (CERN), 24.07.1995 - First non-stub version
36// --------------------------------------------------------------------
37#ifndef G4VPHYSICALVOLUME_HH
38#define G4VPHYSICALVOLUME_HH
39
40#include "G4Types.hh"
41#include "G4String.hh"
42
43#include "geomdefs.hh"
44
45#include "G4RotationMatrix.hh"
46#include "G4ThreeVector.hh"
47#include "G4GeomSplitter.hh"
48
49class G4LogicalVolume;
51
52/**
53 * @brief G4PVData encapsulates the fields associated to G4VPhysicalVolume
54 * that are not read-only - they will change during simulation and must have
55 * a per-thread state.
56 */
57
59{
60 public:
61
62 G4PVData() = default;
63
65 {
66 frot = nullptr;
67 tx = 0.; ty = 0.; tz = 0.;
68 }
69
71 G4double tx = 0., ty = 0., tz = 0.;
72};
73
74/** Type defined for use of G4PVData objects. */
76
77/**
78 * @brief G4VPhysicalVolume is an abstract base class for the representation
79 * of a positioned volume. The volume is placed within a mother volume,
80 * relative to its coordinate system. Either a single positioned volume or
81 * many positioned volumes can be represented by a particular G4VPhysicalVolume.
82 */
83
85{
86 public:
87
88 /**
89 * Constructor for G4VPhysicalVolume; it initialises a volume, positioned
90 * in a frame which is rotated by 'pRot', relative to the coordinate system
91 * of the mother volume 'pMother'. The center of the object is then placed
92 * at 'tlate' in the new coordinates. If 'pRot' is null, the volume is
93 * unrotated with respect to its mother. The physical volume is added to
94 * the mother's logical volume.
95 * The constructor must be called by all subclasses; 'pMother' must point
96 * to a valid parent volume, except in the case of the world/top volume,
97 * when it can be a null pointer. The constructor also registers the volume
98 * within the physical volumes store.
99 * @param[in] pRot The pointer to the rotation matrix.
100 * @param[in] tlate The translation vector coordinates.
101 * @param[in] pName The name of the volume.
102 * @param[in] pLogical The pointer to its logical volume.
103 * @param[in] pMother The pointer to the mother's physical volume.
104 */
106 const G4ThreeVector& tlate,
107 const G4String& pName,
108 G4LogicalVolume* pLogical,
109 G4VPhysicalVolume* pMother);
110
111 /**
112 * Destructor, will be subclassed. Removes volume from the volume store.
113 */
114 virtual ~G4VPhysicalVolume();
115
116 /**
117 * Copy constructor and assignement operator not allowed.
118 */
121
122 /**
123 * Equality defined by equal addresses only..
124 */
125 inline G4bool operator == (const G4VPhysicalVolume& p) const;
126
127 // Accessors. They make a distinction between whether the rotation or
128 // translation is being made for the frame or the object/volume that is
129 // being placed (they are the inverse of each other).
130
131 /**
132 * Accessors returning the rotation/translation of the *object* relative
133 * to the mother.
134 */
135 G4RotationMatrix* GetObjectRotation() const; // Obsolete
136 G4RotationMatrix GetObjectRotationValue() const; // Replacement
138
139 /**
140 * Accessors returning the rotation/translation of the *frame* used to
141 * position this volume in its mother volume (opposite of object rot/trans).
142 */
143 const G4RotationMatrix* GetFrameRotation() const;
145
146 /**
147 * Old access functions, that do not distinguish between frame/object!
148 * They simply return the translation/rotation of the volume.
149 */
150 const G4ThreeVector GetTranslation() const;
151 const G4RotationMatrix* GetRotation() const;
153
154 // Modifiers for translation and rotation
155
156 /**
157 * Sets the translation vector.
158 */
159 void SetTranslation(const G4ThreeVector& v);
160
161 /**
162 * Sets the rotation matrix. NOT INTENDED FOR GENERAL USE.
163 * Non constant version, used to change transformation for the
164 * replication/parameterisation mechanism.
165 */
167
168 /**
169 * Returns the associated logical volume pointer.
170 */
172
173 /**
174 * Sets the logical volume pointer. Must not be called when geometry
175 * is closed.
176 */
177 inline void SetLogicalVolume(G4LogicalVolume* pLogical);
178
180 // Return the current mother logical volume pointer.
181 inline void SetMotherLogical(G4LogicalVolume* pMother);
182 // Set the mother logical volume. Must not be called when geometry closed.
183
184 /**
185 * Getter/setter for the volume's name.
186 */
187 inline const G4String& GetName() const;
188 void SetName(const G4String& pName);
189
190 /**
191 * Returns the number of object entities (1 for normal placements,
192 * n for replicas or parameterised).
193 */
194 virtual G4int GetMultiplicity() const;
195
196 // Functions required of subclasses
197
198 /**
199 * Characterises the type of volume - normal/replicated/parameterised.
200 */
201 virtual EVolume VolumeType() const = 0;
202
203 /**
204 * NOT implemented. Should return true if the volume is MANY type.
205 */
206 virtual G4bool IsMany() const = 0;
207
208 /**
209 * Accessor/modifier for optional handling of the volume copy-number.
210 */
211 virtual G4int GetCopyNo() const = 0;
212 virtual void SetCopyNo(G4int CopyNo) = 0;
213
214 /**
215 * Returns true if the volume is replicated (single object instance
216 * represents many real volumes), else false.
217 */
218 virtual G4bool IsReplicated() const = 0;
219
220 /**
221 * Returns true if the volume is parameterised (single object instance
222 * represents many real parameterised volumes), else false.
223 */
224 virtual G4bool IsParameterised() const = 0;
225
226 /**
227 * Returns a pointer to the replicas parameterisation object/algorithm
228 * (able to compute dimensions and transformations of replicas), or a
229 * null pointer if not applicable.
230 */
232
233 /**
234 * Returns the replication information. No-op for non replicated volumes.
235 * @param[in,out] axis The axis of replication/parameterisation.
236 * @param[in,out] nReplicas The number of replicated/parameterised objects.
237 * @param[in,out] width The width of replicated object.
238 * @param[in,out] offset The optional offset distance from mother's border.
239 * @param[in,out] consuming Flag of replica characterisation (always true
240 * for pure replicas).
241 */
243 G4int& nReplicas,
244 G4double& width,
246 G4bool& consuming) const = 0;
247
248 /**
249 * Returns true if the underlying volume structure is regular.
250 */
251 virtual G4bool IsRegularStructure() const = 0;
252
253 /**
254 * Returns non-zero code in case the underlying volume structure is regular,
255 * voxel-like. The value is an identifier for the structure type.
256 * If non-zero the volume is a candidate for specialised navigation such
257 * as 'nearest neighbour' directly on volumes.
258 */
259 virtual G4int GetRegularStructureId() const = 0;
260
261 /**
262 * Verifies if the placed volume is overlapping with the existing
263 * daughters or with the mother volume. It provides a default resolution
264 * for the number of points to be generated and verified. A concrete
265 * implementation is done and required only for placed and parameterised
266 * volumes. Returns true if the volume is overlapping.
267 * @param[in] res The number of points to generate on volume's surface.
268 * @param[in] tol The precision tolerance for the overlap check, below
269 * which to ignore overlaps (default is maximim precision).
270 * @param[in] verbose Verbosity mode (default is true).
271 * @param[in] errMax Maximum of overlaps errors to report (default is 1).
272 * @returns True if an overlap occurs.
273 */
274 virtual G4bool CheckOverlaps(G4int res=1000, G4double tol=0.,
275 G4bool verbose=true, G4int errMax=1);
276
277 /**
278 * Fake default constructor for usage restricted to direct object
279 * persistency for clients requiring preallocation of memory for
280 * persistifiable objects.
281 */
282 G4VPhysicalVolume(__void__&);
283
284 /**
285 * Returns the instance ID for multi-threading.
286 */
287 inline G4int GetInstanceID() const;
288
289 /**
290 * Returns the private data instance manager for multi-threading.
291 */
292 static const G4PVManager& GetSubInstanceManager();
293
294 /**
295 * Clears the memory allocated by the MT sub-instance manager.
296 */
297 static void Clean();
298
299 /**
300 * Old VolumeType() method, replaced by virtual method, kept for checking.
301 */
302 inline EVolume DeduceVolumeType() const;
303
304 protected:
305
306 /**
307 * This method is similar to the constructor. It is used by each worker
308 * thread to achieve the partial effect as that of the master thread.
309 */
310 void InitialiseWorker(G4VPhysicalVolume* pMasterObject,
311 G4RotationMatrix* pRot, const G4ThreeVector& tlate);
312
313 /**
314 * This method is similar to the destructor. It is used by each worker
315 * thread to achieve the partial effect as that of the master thread.
316 */
317 void TerminateWorker(G4VPhysicalVolume* pMasterObject);
318
319 protected:
320
321 /** For use in implementing the per-thread data.
322 It is equivalent to a pointer to a G4PVData object. */
324
325 /** Needed to use G4PVManager for the G4PVData per-thread objects. */
327
328 private:
329
330 /** The logical volume representing the attributes of the volume. */
331 G4LogicalVolume* flogical = nullptr;
332
333 /** The name of the volume. */
334 G4String fname;
335
336 /** The current mother logical volume. */
337 G4LogicalVolume* flmother = nullptr;
338
339 /** Shadow pointer for use of object persistency. */
340 G4PVData* pvdata = nullptr;
341};
342
343// NOTE:
344// The type G4PVManager is introduced to encapsulate the methods used by
345// both the master thread and worker threads to allocate memory space for
346// the fields encapsulated by the class G4PVData. When each thread
347// initializes the value for these fields, it refers to them using a macro
348// definition defined below. For every G4VPhysicalVolume instance, there is
349// a corresponding G4PVData instance. All G4PVData instances are organized
350// by the class G4PVManager as an array.
351// The field "int instanceID" is added to the class G4VPhysicalVolume.
352// The value of this field in each G4VPhysicalVolume instance is the subscript
353// of the corresponding G4PVData instance.
354// In order to use the class G4PVManager, we add a static member in the class
355// G4VPhysicalVolume as follows: "static G4PVManager subInstanceManager;".
356// For the master thread, the array for G4PVData instances grows dynamically
357// along with G4VPhysicalVolume instances are created. For each worker thread,
358// it copies the array of G4PVData instances from the master thread.
359// In addition, it invokes a method similiar to the constructor explicitly
360// to achieve the partial effect for each instance in the array.
361
362#include "G4VPhysicalVolume.icc"
363
364#endif
G4ThreadLocal T * G4GeomSplitter< T >::offset
CLHEP::HepRotation G4RotationMatrix
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4GeomSplitter< G4PVData > G4PVManager
G4GeomSplitter is an utility class for splitting of R/W data for thread-safety from geometry classes....
G4LogicalVolume represents a leaf node or unpositioned subtree in the geometry hierarchy....
G4PVData encapsulates the fields associated to G4VPhysicalVolume that are not read-only - they will c...
G4RotationMatrix * frot
G4PVData()=default
G4VPVParameterisation ia an abstract base class for Parameterisation, able to compute the transformat...
static G4GEOM_DLL G4PVManager subInstanceManager
G4LogicalVolume * GetMotherLogical() const
virtual G4bool IsReplicated() const =0
void SetLogicalVolume(G4LogicalVolume *pLogical)
virtual G4bool IsRegularStructure() const =0
virtual EVolume VolumeType() const =0
const G4RotationMatrix * GetRotation() const
G4RotationMatrix * GetObjectRotation() const
G4VPhysicalVolume & operator=(const G4VPhysicalVolume &)=delete
virtual void SetCopyNo(G4int CopyNo)=0
const G4ThreeVector GetTranslation() const
G4VPhysicalVolume(G4RotationMatrix *pRot, const G4ThreeVector &tlate, const G4String &pName, G4LogicalVolume *pLogical, G4VPhysicalVolume *pMother)
G4ThreeVector GetFrameTranslation() const
virtual G4bool CheckOverlaps(G4int res=1000, G4double tol=0., G4bool verbose=true, G4int errMax=1)
G4LogicalVolume * GetLogicalVolume() const
G4RotationMatrix GetObjectRotationValue() const
virtual G4int GetMultiplicity() const
EVolume DeduceVolumeType() const
const G4RotationMatrix * GetFrameRotation() const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
virtual G4int GetCopyNo() const =0
void TerminateWorker(G4VPhysicalVolume *pMasterObject)
const G4String & GetName() const
virtual G4int GetRegularStructureId() const =0
G4int GetInstanceID() const
virtual G4VPVParameterisation * GetParameterisation() const =0
G4VPhysicalVolume(const G4VPhysicalVolume &)=delete
virtual G4bool IsMany() const =0
void SetTranslation(const G4ThreeVector &v)
void SetRotation(G4RotationMatrix *)
G4ThreeVector GetObjectTranslation() const
static const G4PVManager & GetSubInstanceManager()
G4bool operator==(const G4VPhysicalVolume &p) const
virtual G4bool IsParameterised() const =0
void SetMotherLogical(G4LogicalVolume *pMother)
void SetName(const G4String &pName)
void InitialiseWorker(G4VPhysicalVolume *pMasterObject, G4RotationMatrix *pRot, const G4ThreeVector &tlate)
EAxis
Definition geomdefs.hh:54
EVolume
Definition geomdefs.hh:83
#define G4GEOM_DLL
Definition geomwdefs.hh:45
const axis_t axis_to_type< N >::axis
Definition pugixml.cc:9668