Geant4-11
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 currently *NOT* subclassed, since not meant to
52// act as a base class. Therefore, the destructor is NOT virtual.
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// 15.01.13 G.Cosmo, A.Dotti: Modified for thread-safety for MT
95// 12.11.04 G.Cosmo: Added GetMass() method for computing mass of the tree
96// 24.09.02 G.Cosmo: Added flags and accessors for region cuts handling
97// 17.05.02 G.Cosmo: Added IsToOptimise() method and related flag
98// 18.04.01 G.Cosmo: Migrated to STL vector
99// 12.02.99 S.Giani: Added user defined optimisation quality
100// 09.11.98 M.Verderi, J.Apostolakis: Added BiasWeight member and accessors
101// 10.20.97 P.M.DeFreitas, J.Apostolakis: Added pointer to a FastSimulation
102// 11.07.95 P.Kent: Initial version
103// ------------------------------------------------------------------------
104#ifndef G4LOGICALVOLUME_HH
105#define G4LOGICALVOLUME_HH 1
106
107#include <vector>
108
109#include "G4Types.hh"
110#include "G4Region.hh" // Required by inline methods
111#include "G4VPhysicalVolume.hh" // Need operator == for vector fdaughters
112#include "G4GeomSplitter.hh" // Needed for MT RW data splitting
113#include "G4Threading.hh"
114
115// Forward declarations
116//
117class G4FieldManager;
118class G4Material;
120class G4VSolid;
121class G4UserLimits;
123class G4VisAttributes;
126
128{
129 // Encapsulates the fields associated to the class
130 // G4LogicalVolume that may not be read-only.
131
132 public:
133
134 G4LVData();
136 {
137 fSolid = nullptr;
138 fSensitiveDetector = nullptr;
139 fFieldManager = nullptr;
140 fMaterial = nullptr;
141 fMass = 0.0;
142 fCutsCouple = nullptr;
143 }
144
145 public:
146
147 G4VSolid* fSolid = nullptr;
148 // Pointer to solid.
150 // Pointer to sensitive detector.
152 // Pointer (possibly nullptr) to (magnetic or other) field manager object.
154 // Pointer to material at this node.
156 // Mass of the logical volume tree.
158 // Pointer (possibly nullptr) to associated production cuts.
159};
160
161// The type G4LVManager is introduced to encapsulate the methods used by
162// both the master thread and worker threads to allocate memory space for
163// the fields encapsulated by the class G4LVData. When each thread
164// initializes the value for these fields, it refers to them using a macro
165// definition defined below. For every G4LogicalVolume instance, there is
166// a corresponding G4LVData instance. All G4LVData instances are organized
167// by the class G4LVManager as an array.
168// The field "int instanceID" is added to the class G4LogicalVolume.
169// The value of this field in each G4LogicalVolume instance is the subscript
170// of the corresponding G4LVData instance.
171// In order to use the class G4LVManager, we add a static member in the class
172// G4LogicalVolume as follows: "static G4LVManager subInstanceManager".
173// For the master thread, the array for G4LVData instances grows dynamically
174// along with G4LogicalVolume instances are created. For each worker thread,
175// it copies the array of G4LVData instances from the master thread.
176// In addition, it invokes a method similiar to the constructor explicitly
177// to achieve the partial effect for each instance in the array.
178//
180
182{
183 public:
184
186 G4Material* pMaterial,
187 const G4String& name,
188 G4FieldManager* pFieldMgr = nullptr,
189 G4VSensitiveDetector* pSDetector = nullptr,
190 G4UserLimits* pULimits = nullptr,
191 G4bool optimise = true);
192 // Constructor. The solid and material pointer must be non null.
193 // The parameters for field, detector and user limits are optional.
194 // The volume also enters itself into the logical volume Store.
195 // Optimisation of the geometry (voxelisation) for the volume
196 // hierarchy is applied by default. For parameterised volumes in
197 // the hierarchy, optimisation is -always- applied.
198
199 virtual ~G4LogicalVolume();
200 // Destructor. Removes the logical volume from the logical volume Store.
201 // This class is NOT meant to act as base class, except for exceptional
202 // circumstances of extended types used in the kernel.
203
206 // Copy-constructor and assignment operator not allowed.
207
208 inline const G4String& GetName() const;
209 void SetName(const G4String& pName);
210 // Returns and sets the name of the logical volume.
211
212 inline size_t GetNoDaughters() const;
213 // Returns the number of daughters (0 to n).
214 inline G4VPhysicalVolume* GetDaughter(const G4int i) const;
215 // Returns the ith daughter. Note numbering starts from 0,
216 // and no bounds checking is performed.
218 // Adds the volume p as a daughter of the current logical volume.
219 inline G4bool IsDaughter(const G4VPhysicalVolume* p) const;
220 // Returns true if the volume p is a daughter of the current
221 // logical volume.
222 G4bool IsAncestor(const G4VPhysicalVolume* p) const;
223 // Returns true if the volume p is part of the hierarchy of
224 // volumes established by the current logical volume. Scans
225 // recursively the volume tree.
226 void RemoveDaughter(const G4VPhysicalVolume* p);
227 // Removes the volume p from the List of daughter of the current
228 // logical volume.
229 void ClearDaughters();
230 // Clears the list of daughters. Used by the phys-volume store when
231 // the geometry tree is cleared, since modified at run-time.
233 // Returns the total number of physical volumes (replicated or placed)
234 // in the tree represented by the current logical volume.
236 // Characterise the daughters of this logical volume.
238 // Used by CharacteriseDaughters().
239
240 G4VSolid* GetSolid() const;
241 void SetSolid(G4VSolid* pSolid);
242 // Gets and sets the current solid.
243
244 G4Material* GetMaterial() const;
245 void SetMaterial(G4Material* pMaterial);
246 // Gets and sets the current material.
247 void UpdateMaterial(G4Material* pMaterial);
248 // Sets material and corresponding MaterialCutsCouple.
249 // This method is invoked by G4Navigator while it is navigating through
250 // material parameterization.
251 G4double GetMass(G4bool forced = false, G4bool propagate = true,
252 G4Material* parMaterial = nullptr);
253 // Returns the mass of the logical volume tree computed from the
254 // estimated geometrical volume of each solid and material associated
255 // to the logical volume and (by default) to its daughters.
256 // NOTE: the computation may require a considerable amount of time,
257 // depending from the complexity of the geometry tree.
258 // The returned value is cached and can be used for successive
259 // calls (default), unless recomputation is forced by providing
260 // 'true' for the boolean argument in input. Computation should
261 // be forced if the geometry setup has changed after the previous
262 // call. By setting the 'propagate' boolean flag to 'false' the
263 // method returns the mass of the present logical volume only
264 // (subtracted for the volume occupied by the daughter volumes).
265 // An optional argument to specify a material is also provided.
266 void ResetMass();
267 // Ensure that cached value of Mass is invalidated - due to change in
268 // state, e.g. change of size of Solid, change of type of solid,
269 // or the addition/deletion of a daughter volume.
270
272 // Gets current FieldManager.
273 void SetFieldManager(G4FieldManager* pFieldMgr, G4bool forceToAllDaughters);
274 // Sets FieldManager and propagates it:
275 // i) only to daughters with G4FieldManager = nullptr
276 // if forceToAllDaughters=false
277 // ii) to all daughters
278 // if forceToAllDaughters=true
279
281 // Gets current SensitiveDetector.
283 // Sets SensitiveDetector (can be nullptr).
284
286 inline void SetUserLimits(G4UserLimits *pULimits);
287 // Gets and sets current UserLimits.
288
290 inline void SetVoxelHeader(G4SmartVoxelHeader *pVoxel);
291 // Gets and sets current VoxelHeader.
292
293 inline G4double GetSmartless() const;
294 inline void SetSmartless(G4double s);
295 // Gets and sets user defined optimisation quality.
296
297 inline G4bool IsToOptimise() const;
298 // Replies if geometry optimisation (voxelisation) is to be
299 // applied for this volume hierarchy.
300 inline void SetOptimisation(G4bool optim);
301 // Specifies if to apply or not geometry optimisation to this
302 // volume hierarchy. Note that for parameterised volumes in the
303 // hierarchy, optimisation is always applied.
304
305 inline G4bool IsRootRegion() const;
306 // Replies if the logical volume represents a root region or not.
307 inline void SetRegionRootFlag(G4bool rreg);
308 // Sets/unsets the volume as a root region for cuts.
309 inline G4bool IsRegion() const;
310 // Replies if the logical volume is part of a cuts region or not.
311 inline void SetRegion(G4Region* reg);
312 // Sets/unsets the volume as cuts region.
313 inline G4Region* GetRegion() const;
314 // Return the region to which the volume belongs, if any.
315 inline void PropagateRegion();
316 // Propagates region pointer to daughters.
317
320 // Accessors for production cuts.
321
323 // Equality defined by address only.
324 // Returns true if objects are at same address, else false.
325
326 inline const G4VisAttributes* GetVisAttributes () const;
327 inline void SetVisAttributes (const G4VisAttributes* pVA);
328 void SetVisAttributes (const G4VisAttributes& VA);
329 // Gets and sets visualization attributes. A copy of 'VA' on the heap
330 // will be made in the case the call with a const reference is used.
331
333 // Gets current FastSimulationManager pointer if exists, otherwise null.
334
335 inline void SetBiasWeight (G4double w);
336 inline G4double GetBiasWeight() const;
337 // Sets and gets bias weight.
338
339 public:
340
341 G4LogicalVolume(__void__&);
342 // Fake default constructor for usage restricted to direct object
343 // persistency for clients requiring preallocation of memory for
344 // persistifiable objects.
345
346 virtual G4bool IsExtended() const;
347 // Return true if it is not a base-class object.
348
350 // Gets current FieldManager for the master thread.
352 // Gets current SensitiveDetector for the master thread.
353 inline G4VSolid* GetMasterSolid() const;
354 // Gets current Solid for the master thread.
355
356 inline G4int GetInstanceID() const;
357 // Returns the instance ID.
358
359 static const G4LVManager& GetSubInstanceManager();
360 // Returns the private data instance manager.
361
362 static void Clean();
363 // Clear memory allocated by sub-instance manager.
364
365 inline void Lock();
366 // Set lock identifier for final deletion of entity.
367
368 void InitialiseWorker(G4LogicalVolume* ptrMasterObject,
369 G4VSolid* pSolid, G4VSensitiveDetector* pSDetector);
370 // This method is similar to the constructor. It is used by each worker
371 // thread to achieve the partial effect as that of the master thread.
372
373 void TerminateWorker(G4LogicalVolume* ptrMasterObject);
374 // This method is similar to the destructor. It is used by each worker
375 // thread to achieve the partial effect as that of the master thread.
376
378 // Set the FieldManager - only at this level (do not push down hierarchy)
379
380 static G4VSolid* GetSolid(G4LVData& instLVdata) ; // const;
381 static void SetSolid(G4LVData& instLVdata, G4VSolid* pSolid);
382 // Optimised Methods - passing thread instance of worker data
383
385 // Change the type of the daughters volume to be of type atype.
386 // Meant for the user who wants to use the external navigator for
387 // the contents of a volume.
388 // Returns: success (true) or failure (false).
389
390 private:
391
392 using G4PhysicalVolumeList = std::vector<G4VPhysicalVolume *>;
393
395 // This new field helps to use the class G4LVManager introduced above.
396
398 // Vector of daughters. Given initial size of 0.
400 // Name of logical volume.
402 // Pointer (possibly nullptr) to user Step limit object for this node.
404 // Pointer (possibly nullptr) to optimisation info objects.
406 // Quality for optimisation, average number of voxels to be spent
407 // per content.
409 // Pointer (possibly nullptr) to visualization attributes.
410 G4Region* fRegion = nullptr;
411 // Pointer to the cuts region (if any)
413 // Weight used in the event biasing technique.
414
415 // Shadow of master pointers.
416 // Each worker thread can access this field from the master thread
417 // through these pointers.
418 //
419 G4VSolid* fSolid = nullptr;
422 G4LVData* lvdata = nullptr; // For use of object persistency
423
425 // This new field is used as instance ID.
427 // Are contents of volume placements, replica, parameterised or external?
429 // Flag to identify if optimisation should be applied or not.
431 // Flag to identify if the logical volume is a root region.
432 G4bool fLock = false;
433 // Flag to identify if entity is locked for final deletion.
434};
435
436#include "G4LogicalVolume.icc"
437
438#endif
static const G4double reg
static constexpr double s
Definition: G4SIunits.hh:154
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
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
G4FieldManager * fFieldManager
void SetName(const G4String &pName)
G4VSensitiveDetector * fSensitiveDetector
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)
virtual ~G4LogicalVolume()
void RemoveDaughter(const G4VPhysicalVolume *p)
void SetRegionRootFlag(G4bool rreg)
void SetRegion(G4Region *reg)
size_t GetNoDaughters() const
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
static G4GEOM_DLL G4LVManager subInstanceManager
G4double GetBiasWeight() const
static void Clean()
G4bool IsRegion() const
const G4VisAttributes * fVisAttributes
G4LogicalVolume(const G4LogicalVolume &)=delete
std::vector< G4VPhysicalVolume * > G4PhysicalVolumeList
G4double GetSmartless() const
G4bool IsDaughter(const G4VPhysicalVolume *p) const
G4Material * GetMaterial() const
void PropagateRegion()
G4VPhysicalVolume * GetDaughter(const G4int i) const
G4LogicalVolume & operator=(const G4LogicalVolume &)=delete
G4UserLimits * GetUserLimits() const
void InitialiseWorker(G4LogicalVolume *ptrMasterObject, G4VSolid *pSolid, G4VSensitiveDetector *pSDetector)
G4FieldManager * GetMasterFieldManager() const
EVolume fDaughtersVolumeType
G4FieldManager * GetFieldManager() const
void SetVisAttributes(const G4VisAttributes *pVA)
G4int TotalVolumeEntities() const
G4SmartVoxelHeader * fVoxel
void SetBiasWeight(G4double w)
G4int GetInstanceID() const
G4bool IsToOptimise() const
const G4String & GetName() const
G4UserLimits * fUserLimits
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)
G4PhysicalVolumeList fDaughters
void SetOptimisation(G4bool optim)
void SetMaterialCutsCouple(G4MaterialCutsCouple *cuts)
void UpdateMaterial(G4Material *pMaterial)
EVolume
Definition: geomdefs.hh:83
#define G4GEOM_DLL
Definition: geomwdefs.hh:44
const char * name(G4int ptype)