Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4LogicalVolume.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// G4LogicalVolume
27//
28// Class description:
29//
30// Represents a leaf node or unpositioned subtree in the geometry hierarchy.
31// Logical volumes are named, and may have daughters ascribed to them.
32// They are responsible for retrieval of the physical and tracking attributes
33// of the physical volume that it represents: solid, material, magnetic field,
34// and optionally, user limits, sensitive detectors, regions, biasing weights.
35//
36// Get and Set functionality is provided for all attributes, but note that
37// most set functions should not be used when the geometry is `closed'.
38// As a further development, `Guard' checks can be added to ensure
39// only legal operations at tracking time.
40//
41// On construction, solid, material and name must be specified.
42//
43// Daughters are ascribed and managed by means of a simple
44// GetNoDaughters,Get/SetDaughter(n),AddDaughter interface.
45//
46// Smart voxels as used for tracking optimisation. They're also an attribute.
47//
48// Logical volumes self register to the logical volume Store on construction,
49// and deregister on destruction.
50//
51// NOTE: This class is NOT meant to act as base class, except for exceptional
52// circumstances of extended types used in the kernel.
53//
54// Data members:
55//
56// std::vector<G4VPhysicalVolume*> fDaughters
57// - Vector of daughters. Given initial size of 0.
58// G4FieldManager* fFieldManager
59// - Pointer (possibly 0) to (magnetic or other) field manager object.
60// G4Material* fMaterial
61// - Pointer to material at this node.
62// G4String fName
63// - Name of logical volume.
64// G4VSensitiveDetector *fSensitiveDetector
65// - Pointer (possibly 0) to `Hit' object.
66// G4VSolid* fSolid
67// - Pointer to solid.
68// G4UserLimits* fUserLimits
69// - Pointer (possibly 0) to user Step limit object for this node.
70// G4SmartVoxelHeader* fVoxel
71// - Pointer (possibly 0) to optimisation info objects.
72// G4bool fOptimise
73// - Flag to identify if optimisation should be applied or not.
74// G4bool fRootRegion
75// - Flag to identify if the logical volume is a root region.
76// G4double fSmartless
77// - Quality for optimisation, average number of voxels to be spent
78// per content.
79// const G4VisAttributes* fVisAttributes
80// - Pointer (possibly 0) to visualization attributes.
81// G4Region* fRegion
82// - Pointer to the cuts region (if any)
83// G4MaterialCutsCouple* fCutsCouple
84// - Pointer (possibly 0) to associated production cuts.
85// G4double fBiasWeight
86// - Weight used in the event biasing technique.
87//
88// Following data members has been moved to G4Region - M.Asai (Aug/18/2005)
89// G4FastSimulationManager* fFastSimulationManager
90// - Pointer (possibly 0) to G4FastSimulationManager object.
91// G4bool fIsEnvelope
92// - Flags if the Logical Volume is an envelope for a FastSimulationManager.
93
94// Author: Paul Kent (CERN), 11.07.1995 - Initial version
95// ------------------------------------------------------------------------
96#ifndef G4LOGICALVOLUME_HH
97#define G4LOGICALVOLUME_HH
98
99#include <vector>
100#include <memory>
101
102#include "G4Types.hh"
103#include "G4Region.hh" // Required by inline methods
104#include "G4VPhysicalVolume.hh" // Need operator == for vector fdaughters
105#include "G4GeomSplitter.hh" // Needed for MT RW data splitting
106#include "G4Threading.hh"
107
108// Forward declarations
109//
110class G4FieldManager;
111class G4Material;
113class G4VSolid;
114class G4UserLimits;
118class G4VisAttributes;
119
120/**
121 * @brief G4LVData encapsulates the fields associated to the class
122 * G4LogicalVolume that may not be read-only.
123 */
124
126{
127 public:
128
129 G4LVData();
131 {
132 fSolid = nullptr;
133 fSensitiveDetector = nullptr;
134 fFieldManager = nullptr;
135 fMaterial = nullptr;
136 fMass = 0.0;
137 fCutsCouple = nullptr;
138 }
139
140 public:
141
142 G4VSolid* fSolid = nullptr;
143 // Pointer to solid.
145 // Pointer to sensitive detector.
147 // Pointer (possibly nullptr) to (magnetic or other) field manager object.
149 // Pointer to material at this node.
151 // Mass of the logical volume tree.
153 // Pointer (possibly nullptr) to associated production cuts.
154};
155
156/** G4LVManager encapsulates the methods used by both the master thread and
157 worker threads to allocate memory space for the fields encapsulated by the
158 class G4LVData. */
160
161/**
162 * @brief G4LogicalVolume represents a leaf node or unpositioned subtree in the
163 * geometry hierarchy. Logical volumes are named, and may have daughters
164 * ascribed to them. They are responsible for retrieval of the physical and
165 * tracking attributes of the physical volume that it represents: solid,
166 * material, magnetic field, and optionally, user limits, sensitive detectors,
167 * regions, biasing weights.
168 */
169
171{
172 public:
173
174 /**
175 * Constructor for G4LogicalVolume. The solid and material pointer must be
176 * non null. The parameters for field, detector and user limits are optional.
177 * The volume also enters itself into the logical volume Store.
178 * Optimisation of the geometry (voxelisation) for the volume hierarchy is
179 * applied by default. For parameterised volumes in the hierarchy,
180 * optimisation is -always- applied.
181 * @param[in] pSolid Pointer to the associated solid primitive.
182 * @param[in] pMaterial Pointer to the associated material.
183 * @param[in] name The volume name.
184 * @param[in] pFieldMgr Pointer to optional magnetic field manager.
185 * @param[in] pSDetector Pointer to optional associated sensitive detector.
186 * @param[in] pULimits Pointer to optional user limits.
187 * @param[in] optimise Flag to enable/disable optimisation structure.
188 */
190 G4Material* pMaterial,
191 const G4String& name,
192 G4FieldManager* pFieldMgr = nullptr,
193 G4VSensitiveDetector* pSDetector = nullptr,
194 G4UserLimits* pULimits = nullptr,
195 G4bool optimise = true);
196
197 /**
198 * Destructor. Removes the logical volume from the logical volume Store.
199 * This class is NOT meant to act as base class, except for exceptional
200 * circumstances of extended types used in the kernel.
201 */
202 virtual ~G4LogicalVolume();
203
204 /**
205 * Copy-constructor and assignment operator not allowed.
206 */
209
210 /**
211 * Returns and sets the name of the logical volume.
212 */
213 inline const G4String& GetName() const;
214 void SetName(const G4String& pName);
215
216 /**
217 * Returns the number of daughters (0 to n).
218 */
219 inline std::size_t GetNoDaughters() const;
220
221 /**
222 * Returns the ith daughter. Note numbering starts from 0,
223 * and no bounds checking is performed.
224 */
225 inline G4VPhysicalVolume* GetDaughter(const std::size_t i) const;
226
227 /**
228 * Adds the volume 'p' as a daughter of the current logical volume.
229 */
231
232 /**
233 * Returns true if the volume 'p' is a daughter of the current
234 * logical volume.
235 */
236 inline G4bool IsDaughter(const G4VPhysicalVolume* p) const;
237
238 /**
239 * Returns true if the volume 'p' is part of the hierarchy of volumes
240 * established by the current logical volume. Scans recursively the volume
241 * tree.
242 */
243 G4bool IsAncestor(const G4VPhysicalVolume* p) const;
244
245 /**
246 * Removes the volume 'p' from the list of daughters of the current
247 * logical volume.
248 */
249 void RemoveDaughter(const G4VPhysicalVolume* p);
250
251 /**
252 * Clears the list of daughters. Used by the physical volume store when
253 * the geometry tree is cleared, since modified at run-time.
254 */
255 void ClearDaughters();
256
257 /**
258 * Returns the total number of physical volumes (replicated or placed)
259 * in the tree represented by the current logical volume.
260 */
262
263 /**
264 * Characterises the daughters of this logical volume.
265 */
267
268 /**
269 * Utility method used by CharacteriseDaughters().
270 */
272
273 /**
274 * Gets and sets the current solid.
275 */
276 G4VSolid* GetSolid() const;
277 void SetSolid(G4VSolid* pSolid);
278
279 /**
280 * Gets and sets the current material.
281 */
282 G4Material* GetMaterial() const;
283 void SetMaterial(G4Material* pMaterial);
284
285 /**
286 * Sets the material and corresponding Material-Cuts-Couple.
287 * This method is invoked by G4Navigator while it is navigating through
288 * material parameterisation.
289 */
290 void UpdateMaterial(G4Material* pMaterial);
291
292 /**
293 * Returns the mass of the logical volume tree computed from the
294 * estimated geometrical volume of each solid and material associated
295 * to the logical volume and (by default) to its daughters.
296 * @note The computation may require a considerable amount of time,
297 * depending from the complexity of the geometry tree.
298 * The returned value is cached and can be used for successive
299 * calls (default), unless recomputation is forced by providing
300 * 'true' for the Boolean argument in input. Computation should
301 * be forced if the geometry setup has changed after the previous
302 * call. By setting the 'propagate' Boolean flag to 'false' the
303 * method returns the mass of the present logical volume only
304 * (subtracted for the volume occupied by the daughter volumes).
305 * An optional argument to specify a material is also provided.
306 * @param[in] forced Flag to force recomputation or use cached value.
307 * @param[in] propagate Flag to limit or not computation to daughters.
308 * @param[in] parMaterial Optional pointer to a custom material, usually
309 * used in parameterisations.
310 */
311 G4double GetMass(G4bool forced = false, G4bool propagate = true,
312 G4Material* parMaterial = nullptr);
313
314 /**
315 * Resets the cached value of mass. Ensures that cached value of mass is
316 * invalidated due to change in state, e.g. change of the size of the
317 * solid, change of the type of solid, or the addition/deletion of a
318 * daughter volume.
319 */
320 void ResetMass();
321
322 /**
323 * Gets current Field Manager pointer.
324 */
326
327 /**
328 * Sets the Field Manager and propagates it.
329 * @param[in] pFieldMgr Pointer to the field manager.
330 * @param[in] forceToAllDaughters Flag to force propagation to all
331 * daughters (true), or only to daughters having null pointer
332 * to the field manager (false).
333 */
334 void SetFieldManager(G4FieldManager* pFieldMgr, G4bool forceToAllDaughters);
335
336 /**
337 * Gets and sets the current sensitive detector (can be a null pointer).
338 */
341
342 /**
343 * Gets and sets the current User Limits.
344 */
346 inline void SetUserLimits(G4UserLimits *pULimits);
347
348 /**
349 * Gets and sets the current Voxel Header.
350 */
352 inline void SetVoxelHeader(G4SmartVoxelHeader *pVoxel);
353
354 /**
355 * Gets and sets the user defined optimisation quality associated to
356 * the volume.
357 */
358 inline G4double GetSmartless() const;
359 inline void SetSmartless(G4double s);
360
361 /**
362 * Replies if the geometry optimisation (voxelisation) is to be applied
363 * for this volume hierarchy.
364 */
365 inline G4bool IsToOptimise() const;
366
367 /**
368 * Specifies if to apply or not geometry optimisation to the volume
369 * hierarchy. For parameterised volumes in the hierarchy, optimisation is
370 * always applied.
371 */
372 inline void SetOptimisation(G4bool optim);
373
374 /**
375 * Replies if the logical volume represents a root region or not.
376 */
377 inline G4bool IsRootRegion() const;
378
379 /**
380 * Sets/unsets the volume as a root region for cuts.
381 */
382 inline void SetRegionRootFlag(G4bool rreg);
383
384 /**
385 * Replies if the logical volume is part of a cuts region or not.
386 */
387 inline G4bool IsRegion() const;
388
389 /**
390 * Sets/unsets the volume as cuts region.
391 */
392 inline void SetRegion(G4Region* reg);
393
394 /**
395 * Returns the region to which the volume belongs, if any.
396 */
397 inline G4Region* GetRegion() const;
398
399 /**
400 * Propagates region pointer to daughters.
401 */
402 inline void PropagateRegion();
403
404 /**
405 * Accessor and modifier for production cuts.
406 */
409
410 /**
411 * Equality defined by address only.
412 * Returns true if objects are at same address, else false.
413 */
415
416 /**
417 * Accessor and modifiers for visualization attributes.
418 * Arguments are converted to shared_ptr.
419 */
421 void SetVisAttributes (const G4VisAttributes* pVA);
422 void SetVisAttributes (const G4VisAttributes& VA);
423
424 /**
425 * Gets the current FastSimulationManager pointer if existing,
426 * otherwise null.
427 */
429
430 /**
431 * Sets and gets the bias weight.
432 */
433 inline void SetBiasWeight (G4double w);
434 inline G4double GetBiasWeight() const;
435
436 /**
437 * Returns true if it is not a base-class object.
438 */
439 virtual G4bool IsExtended() const;
440
441 /**
442 * Returns current Field Manager for the master thread.
443 */
445
446 /**
447 * Returns current Sensitive Detector for the master thread.
448 */
450
451 /**
452 * Returns current Solid for the master thread.
453 */
454 inline G4VSolid* GetMasterSolid() const;
455
456 /**
457 * Returns the instance ID.
458 */
459 inline G4int GetInstanceID() const;
460
461 /**
462 * Returns the private data instance manager.
463 */
464 static const G4LVManager& GetSubInstanceManager();
465
466 /**
467 * Clears memory allocated by sub-instance manager.
468 */
469 static void Clean();
470
471 /**
472 * Sets lock identifier for final deletion of entity.
473 */
474 inline void Lock();
475
476 /**
477 * This method is similar to the constructor. It is used by each worker
478 * thread to achieve the partial effect as that of the master thread.
479 */
480 void InitialiseWorker(G4LogicalVolume* ptrMasterObject,
481 G4VSolid* pSolid, G4VSensitiveDetector* pSDetector);
482
483 /**
484 * This method is similar to the destructor. It is used by each worker
485 * thread to achieve the partial effect as that of the master thread.
486 */
487 void TerminateWorker(G4LogicalVolume* ptrMasterObject);
488
489 /**
490 * Sets the Field Manager only at this level (does not push down hierarchy)
491 */
493
494 /**
495 * Optimised methods, passing thread instance of worker data.
496 */
497 static G4VSolid* GetSolid(G4LVData& instLVdata);
498 static void SetSolid(G4LVData& instLVdata, G4VSolid* pSolid);
499
500 /**
501 * Changes the type of the daughters volume to be of type 'atype'.
502 * Meant for the user adopting an external navigator for the contents
503 * of a volume.
504 * @returns Success (true) or failure (false).
505 */
507
508 /**
509 * Fake default constructor for usage restricted to direct object
510 * persistency for clients requiring preallocation of memory for
511 * persistifiable objects.
512 */
513 G4LogicalVolume(__void__&);
514
515 private:
516
517 using G4PhysicalVolumeList = std::vector<G4VPhysicalVolume *>;
518
519 /** This field helps in the use of the class G4LVManager. */
520 G4GEOM_DLL static G4LVManager subInstanceManager;
521
522 /** Vector of daughters. Given initial size of 0. */
523 G4PhysicalVolumeList fDaughters;
524
525 /** Name of logical volume. */
526 G4String fName;
527
528 /** Pointer (possibly nullptr) to user step limit object for this node. */
529 G4UserLimits* fUserLimits = nullptr;
530
531 /** Pointer (possibly nullptr) to optimisation info objects. */
532 G4SmartVoxelHeader* fVoxel = nullptr;
533
534 /** Optimisation quality, average number of voxels to be spent per content. */
535 G4double fSmartless = 2.0;
536
537 /** Pointer to the cuts region (if any). */
538 G4Region* fRegion = nullptr;
539
540 /** Weight used in the event biasing technique. */
541 G4double fBiasWeight = 1.0;
542
543 /** Pointer to visualization attributes. */
544 std::shared_ptr<const G4VisAttributes> fVisAttributes;
545
546 // Shadow of master pointers.
547 // Each worker thread can access this field from the master thread
548 // through these pointers.
549 //
550 G4VSolid* fSolid = nullptr;
551 G4VSensitiveDetector* fSensitiveDetector = nullptr;
552 G4FieldManager* fFieldManager = nullptr;
553 G4LVData* lvdata = nullptr; // For use of object persistency
554
555 /** This new field is used as instance ID. */
556 G4int instanceID;
557
558 /** Are contents of volume placements, replica, parameterised or external? */
559 EVolume fDaughtersVolumeType;
560
561 /** Flag to identify if optimisation should be applied or not. */
562 G4bool fOptimise = true;
563
564 /** Flag to identify if the logical volume is a root region. */
565 G4bool fRootRegion = false;
566
567 /** Flag to identify if entity is locked for final deletion. */
568 G4bool fLock = false;
569};
570
571#include "G4LogicalVolume.icc"
572
573// NOTE:
574//
575// The type G4LVManager is introduced to encapsulate the methods used by
576// both the master thread and worker threads to allocate memory space for
577// the fields encapsulated by the class G4LVData. When each thread
578// initializes the value for these fields, it refers to them using a macro
579// definition defined below. For every G4LogicalVolume instance, there is
580// a corresponding G4LVData instance. All G4LVData instances are organized
581// by the class G4LVManager as an array.
582// The field "int instanceID" is added to the class G4LogicalVolume.
583// The value of this field in each G4LogicalVolume instance is the subscript
584// of the corresponding G4LVData instance.
585// In order to use the class G4LVManager, we add a static member in the class
586// G4LogicalVolume as follows: "static G4LVManager subInstanceManager".
587// For the master thread, the array for G4LVData instances grows dynamically
588// along with G4LogicalVolume instances are created. For each worker thread,
589// it copies the array of G4LVData instances from the master thread.
590// In addition, it invokes a method similiar to the constructor explicitly
591// to achieve the partial effect for each instance in the array.
592
593#endif
G4GeomSplitter< G4LVData > G4LVManager
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4FieldManager is a manager (store) for a pointer to the Field subclass that describes the field of a...
G4GeomSplitter is an utility class for splitting of R/W data for thread-safety from geometry classes....
G4LVData encapsulates the fields associated to the class G4LogicalVolume that may not be read-only.
void initialize()
G4double fMass
G4VSensitiveDetector * fSensitiveDetector
G4MaterialCutsCouple * fCutsCouple
G4FieldManager * fFieldManager
G4Material * fMaterial
G4VSolid * fSolid
G4bool operator==(const G4LogicalVolume &lv) const
void SetSmartless(G4double s)
G4VSolid * GetSolid() const
G4double GetMass(G4bool forced=false, G4bool propagate=true, G4Material *parMaterial=nullptr)
EVolume CharacteriseDaughters() const
const G4VisAttributes * GetVisAttributes() const
void SetName(const G4String &pName)
G4bool IsAncestor(const G4VPhysicalVolume *p) const
void SetFieldManager(G4FieldManager *pFieldMgr, G4bool forceToAllDaughters)
void AddDaughter(G4VPhysicalVolume *p)
G4VSensitiveDetector * GetMasterSensitiveDetector() const
void SetUserLimits(G4UserLimits *pULimits)
void SetVoxelHeader(G4SmartVoxelHeader *pVoxel)
G4VSensitiveDetector * GetSensitiveDetector() const
void TerminateWorker(G4LogicalVolume *ptrMasterObject)
std::size_t GetNoDaughters() const
virtual ~G4LogicalVolume()
void RemoveDaughter(const G4VPhysicalVolume *p)
void SetRegionRootFlag(G4bool rreg)
void SetRegion(G4Region *reg)
EVolume DeduceDaughtersType() const
virtual G4bool IsExtended() const
G4FastSimulationManager * GetFastSimulationManager() const
G4bool ChangeDaughtersType(EVolume atype)
static const G4LVManager & GetSubInstanceManager()
G4LogicalVolume(G4VSolid *pSolid, G4Material *pMaterial, const G4String &name, G4FieldManager *pFieldMgr=nullptr, G4VSensitiveDetector *pSDetector=nullptr, G4UserLimits *pULimits=nullptr, G4bool optimise=true)
G4bool IsRootRegion() const
G4Region * GetRegion() const
G4double GetBiasWeight() const
static void Clean()
G4bool IsRegion() const
G4LogicalVolume(const G4LogicalVolume &)=delete
G4double GetSmartless() const
G4bool IsDaughter(const G4VPhysicalVolume *p) const
G4Material * GetMaterial() const
G4VPhysicalVolume * GetDaughter(const std::size_t i) const
void PropagateRegion()
G4LogicalVolume & operator=(const G4LogicalVolume &)=delete
G4UserLimits * GetUserLimits() const
void InitialiseWorker(G4LogicalVolume *ptrMasterObject, G4VSolid *pSolid, G4VSensitiveDetector *pSDetector)
G4FieldManager * GetMasterFieldManager() const
G4FieldManager * GetFieldManager() const
void SetVisAttributes(const G4VisAttributes *pVA)
G4int TotalVolumeEntities() const
void SetBiasWeight(G4double w)
G4int GetInstanceID() const
G4bool IsToOptimise() const
const G4String & GetName() const
const G4MaterialCutsCouple * GetMaterialCutsCouple() const
G4VSolid * GetMasterSolid() const
void AssignFieldManager(G4FieldManager *fldMgr)
void SetMaterial(G4Material *pMaterial)
void SetSolid(G4VSolid *pSolid)
G4SmartVoxelHeader * GetVoxelHeader() const
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)
void SetOptimisation(G4bool optim)
void SetMaterialCutsCouple(G4MaterialCutsCouple *cuts)
void UpdateMaterial(G4Material *pMaterial)
G4Region defines a region or a group of regions in the detector geometry setup, sharing properties as...
Definition G4Region.hh:90
G4SmartVoxelHeader represents a set of voxels, created by a single axis of virtual division....
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4VSolid is an abstract base class for solids, physical shapes that can be tracked through....
Definition G4VSolid.hh:80
EVolume
Definition geomdefs.hh:83
#define G4GEOM_DLL
Definition geomwdefs.hh:45