Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 //
27 // $Id: G4LogicalVolume.hh 100397 2016-10-20 07:34:38Z gcosmo $
28 //
29 //
30 // class G4LogicalVolume
31 //
32 // Class description:
33 //
34 // Represents a leaf node or unpositioned subtree in the geometry hierarchy.
35 // Logical volumes are named, and may have daughters ascribed to them.
36 // They are responsible for retrieval of the physical and tracking attributes
37 // of the physical volume that it represents: solid, material, magnetic field,
38 // and optionally, user limits, sensitive detectors, regions, biasing weights.
39 //
40 // Get and Set functionality is provided for all attributes, but note that
41 // most set functions should not be used when the geometry is `closed'.
42 // As a further development, `Guard' checks can be added to ensure
43 // only legal operations at tracking time.
44 //
45 // On construction, solid, material and name must be specified.
46 //
47 // Daughters are ascribed and managed by means of a simple
48 // GetNoDaughters,Get/SetDaughter(n),AddDaughter interface.
49 //
50 // Smart voxels as used for tracking optimisation. They're also an attribute.
51 //
52 // Logical volumes self register to the logical volume Store on construction,
53 // and deregister on destruction.
54 //
55 // NOTE: This class is currently *NOT* subclassed, since not meant to
56 // act as a base class. Therefore, the destructor is NOT virtual.
57 //
58 // Data members:
59 //
60 // std::vector<G4VPhysicalVolume*> fDaughters
61 // - Vector of daughters. Given initial size of 0.
62 // G4FieldManager* fFieldManager
63 // - Pointer (possibly 0) to (magnetic or other) field manager object.
64 // G4Material* fMaterial
65 // - Pointer to material at this node.
66 // G4String fName
67 // - Name of logical volume.
68 // G4VSensitiveDetector *fSensitiveDetector
69 // - Pointer (possibly 0) to `Hit' object.
70 // G4VSolid* fSolid
71 // - Pointer to solid.
72 // G4UserLimits* fUserLimits
73 // - Pointer (possibly 0) to user Step limit object for this node.
74 // G4SmartVoxelHeader* fVoxel
75 // - Pointer (possibly 0) to optimisation info objects.
76 // G4bool fOptimise
77 // - Flag to identify if optimisation should be applied or not.
78 // G4bool fRootRegion
79 // - Flag to identify if the logical volume is a root region.
80 // G4double fSmartless
81 // - Quality for optimisation, average number of voxels to be spent
82 // per content.
83 // const G4VisAttributes* fVisAttributes
84 // - Pointer (possibly 0) to visualization attributes.
85 // G4Region* fRegion
86 // - Pointer to the cuts region (if any)
87 // G4MaterialCutsCouple* fCutsCouple
88 // - Pointer (possibly 0) to associated production cuts.
89 // G4double fBiasWeight
90 // - Weight used in the event biasing technique.
91 //
92 // Following data members has been moved to G4Region - M.Asai (Aug/18/2005)
93 // G4FastSimulationManager* fFastSimulationManager
94 // - Pointer (possibly 0) to G4FastSimulationManager object.
95 // G4bool fIsEnvelope
96 // - Flags if the Logical Volume is an envelope for a FastSimulationManager.
97 
98 // History:
99 // 19.10.16 M.Asai: Added virtual keyword to the destructor
100 // 15.01.13 G.Cosmo, A.Dotti: Modified for thread-safety for MT
101 // 12.11.04 G.Cosmo: Added GetMass() method for computing mass of the tree
102 // 24.09.02 G.Cosmo: Added flags and accessors for region cuts handling
103 // 17.05.02 G.Cosmo: Added IsToOptimise() method and related flag
104 // 18.04.01 G.Cosmo: Migrated to STL vector
105 // 12.02.99 S.Giani: Added user defined optimisation quality
106 // 09.11.98 J.Apostolakis: Changed G4MagneticField to G4FieldManager
107 // 09.11.98 M.Verderi, J.Apostolakis: Added BiasWeight member and accessors
108 // 10.20.97 P.M.DeFreitas: Added pointer to a FastSimulation
109 // J.Apostolakis: & flag to indicate if it is an Envelope for it
110 // 19.11.96 J.Allison: Replaced G4Visible with explicit const G4VisAttributes*
111 // 19.08.96 P.Kent: Split -> hh/icc/cc files; G4VSensitiveDetector change
112 // 11.07.95 P.Kent: Initial version.
113 // ------------------------------------------------------------------------
114 #ifndef G4LOGICALVOLUME_HH
115 #define G4LOGICALVOLUME_HH
116 
117 #include <vector>
118 
119 #include "G4Types.hh"
120 #include "G4Region.hh" // Required by inline methods
121 #include "G4VPhysicalVolume.hh" // Need operator == for vector fdaughters
122 #include "G4GeomSplitter.hh" // Needed for MT RW data splitting
123 #include "G4Threading.hh"
124 
125 // Forward declarations
126 //
127 class G4FieldManager;
128 class G4Material;
130 class G4VSolid;
131 class G4UserLimits;
132 class G4SmartVoxelHeader;
133 class G4VisAttributes;
136 
137 class G4LVData
138 {
139  // Encapsulates the fields associated to the class
140  // G4LogicalVolume that may not be read-only.
141 
142  public:
143  G4LVData();
144  void initialize()
145  {
146  fSolid = 0;
147  fSensitiveDetector = 0;
148  fFieldManager = 0;
149  fMaterial = 0;
150  fMass = 0.0;
151  fCutsCouple = 0;
152  }
153 
154  public:
155 
157  // Pointer to solid.
159  // Pointer to sensitive detector.
161  // Pointer (possibly 0) to (magnetic or other) field manager object.
163  // Pointer to material at this node.
165  // Mass of the logical volume tree.
167  // Pointer (possibly 0) to associated production cuts.
168 };
169 
170 // The type G4LVManager is introduced to encapsulate the methods used by
171 // both the master thread and worker threads to allocate memory space for
172 // the fields encapsulated by the class G4LVData. When each thread
173 // initializes the value for these fields, it refers to them using a macro
174 // definition defined below. For every G4LogicalVolume instance, there is
175 // a corresponding G4LVData instance. All G4LVData instances are organized
176 // by the class G4LVManager as an array.
177 // The field "int instanceID" is added to the class G4LogicalVolume.
178 // The value of this field in each G4LogicalVolume instance is the subscript
179 // of the corresponding G4LVData instance.
180 // In order to use the class G4LVManager, we add a static member in the class
181 // G4LogicalVolume as follows: "static G4LVManager subInstanceManager".
182 // For the master thread, the array for G4LVData instances grows dynamically
183 // along with G4LogicalVolume instances are created. For each worker thread,
184 // it copies the array of G4LVData instances from the master thread.
185 // In addition, it invokes a method similiar to the constructor explicitly
186 // to achieve the partial effect for each instance in the array.
187 //
189 
191 {
192  typedef std::vector<G4VPhysicalVolume*> G4PhysicalVolumeList;
193 
194  public: // with description
195 
196  G4LogicalVolume(G4VSolid* pSolid,
197  G4Material* pMaterial,
198  const G4String& name,
199  G4FieldManager* pFieldMgr=0,
200  G4VSensitiveDetector* pSDetector=0,
201  G4UserLimits* pULimits=0,
202  G4bool optimise=true);
203  // Constructor. The solid and material pointer must be non null.
204  // The parameters for field, detector and user limits are optional.
205  // The volume also enters itself into the logical volume Store.
206  // Optimisation of the geometry (voxelisation) for the volume
207  // hierarchy is applied by default. For parameterised volumes in
208  // the hierarchy, optimisation is -always- applied.
209 
210  virtual ~G4LogicalVolume();
211  // Destructor. Removes the logical volume from the logical volume Store.
212  // This class is NOT meant to act as base class, except for exceptional
213  // circumstances of extended types used in the kernel.
214 
215  inline const G4String& GetName() const;
216  inline void SetName(const G4String& pName);
217  // Returns and sets the name of the logical volume.
218 
219  inline G4int GetNoDaughters() const;
220  // Returns the number of daughters (0 to n).
221  inline G4VPhysicalVolume* GetDaughter(const G4int i) const;
222  // Returns the ith daughter. Note numbering starts from 0,
223  // and no bounds checking is performed.
225  // Adds the volume p as a daughter of the current logical volume.
226  inline G4bool IsDaughter(const G4VPhysicalVolume* p) const;
227  // Returns true if the volume p is a daughter of the current
228  // logical volume.
229  G4bool IsAncestor(const G4VPhysicalVolume* p) const;
230  // Returns true if the volume p is part of the hierarchy of
231  // volumes established by the current logical volume. Scans
232  // recursively the volume tree.
233  void RemoveDaughter(const G4VPhysicalVolume* p);
234  // Removes the volume p from the List of daughter of the current
235  // logical volume.
236  void ClearDaughters();
237  // Clears the list of daughters. Used by the phys-volume store when
238  // the geometry tree is cleared, since modified at run-time.
239  G4int TotalVolumeEntities() const;
240  // Returns the total number of physical volumes (replicated or placed)
241  // in the tree represented by the current logical volume.
242  inline EVolume CharacteriseDaughters() const;
243  // Characterise the daughters of this logical volume.
244 
245  G4VSolid* GetSolid() const;
246  void SetSolid(G4VSolid *pSolid);
247  // Gets and sets the current solid.
248 
249  G4Material* GetMaterial() const;
250  void SetMaterial(G4Material *pMaterial);
251  // Gets and sets the current material.
252  void UpdateMaterial(G4Material *pMaterial);
253  // Sets material and corresponding MaterialCutsCouple.
254  // This method is invoked by G4Navigator while it is navigating through
255  // material parameterization.
256  G4double GetMass(G4bool forced=false, G4bool propagate=true,
257  G4Material* parMaterial=0);
258  // Returns the mass of the logical volume tree computed from the
259  // estimated geometrical volume of each solid and material associated
260  // to the logical volume and (by default) to its daughters.
261  // NOTE: the computation may require a considerable amount of time,
262  // depending from the complexity of the geometry tree.
263  // The returned value is cached and can be used for successive
264  // calls (default), unless recomputation is forced by providing
265  // 'true' for the boolean argument in input. Computation should
266  // be forced if the geometry setup has changed after the previous
267  // call. By setting the 'propagate' boolean flag to 'false' the
268  // method returns the mass of the present logical volume only
269  // (subtracted for the volume occupied by the daughter volumes).
270  // An optional argument to specify a material is also provided.
271  void ResetMass();
272  // Ensure that cached value of Mass is invalidated - due to change in
273  // state, e.g. change of size of Solid, change of type of solid,
274  // or the addition/deletion of a daughter volume.
275 
277  // Gets current FieldManager.
278  void SetFieldManager(G4FieldManager *pFieldMgr, G4bool forceToAllDaughters);
279  // Sets FieldManager and propagates it:
280  // i) only to daughters with G4FieldManager = 0
281  // if forceToAllDaughters=false
282  // ii) to all daughters
283  // if forceToAllDaughters=true
284 
286  // Gets current SensitiveDetector.
287  void SetSensitiveDetector(G4VSensitiveDetector *pSDetector);
288  // Sets SensitiveDetector (can be 0).
289 
290  inline G4UserLimits* GetUserLimits() const;
291  inline void SetUserLimits(G4UserLimits *pULimits);
292  // Gets and sets current UserLimits.
293 
294  inline G4SmartVoxelHeader* GetVoxelHeader() const;
295  inline void SetVoxelHeader(G4SmartVoxelHeader *pVoxel);
296  // Gets and sets current VoxelHeader.
297 
298  inline G4double GetSmartless() const;
299  inline void SetSmartless(G4double s);
300  // Gets and sets user defined optimisation quality.
301 
302  inline G4bool IsToOptimise() const;
303  // Replies if geometry optimisation (voxelisation) is to be
304  // applied for this volume hierarchy.
305  inline void SetOptimisation(G4bool optim);
306  // Specifies if to apply or not geometry optimisation to this
307  // volume hierarchy. Note that for parameterised volumes in the
308  // hierarchy, optimisation is always applied.
309 
310  inline G4bool IsRootRegion() const;
311  // Replies if the logical volume represents a root region or not.
312  inline void SetRegionRootFlag(G4bool rreg);
313  // Sets/unsets the volume as a root region for cuts.
314  inline G4bool IsRegion() const;
315  // Replies if the logical volume is part of a cuts region or not.
316  inline void SetRegion(G4Region* reg);
317  // Sets/unsets the volume as cuts region.
318  inline G4Region* GetRegion() const;
319  // Return the region to which the volume belongs, if any.
320  inline void PropagateRegion();
321  // Propagates region pointer to daughters.
322 
325  // Accessors for production cuts.
326 
327  G4bool operator == (const G4LogicalVolume& lv) const;
328  // Equality defined by address only.
329  // Returns true if objects are at same address, else false.
330 
331  inline const G4VisAttributes* GetVisAttributes () const;
332  inline void SetVisAttributes (const G4VisAttributes* pVA);
333  void SetVisAttributes (const G4VisAttributes& VA);
334  // Gets and sets visualization attributes. A copy of 'VA' on the heap
335  // will be made in the case the call with a const reference is used.
336 
338  // Gets current FastSimulationManager pointer if exists, otherwise null.
339 
340  inline void SetBiasWeight (G4double w);
341  inline G4double GetBiasWeight() const;
342  // Sets and gets bias weight.
343 
344  public: // without description
345 
346  G4LogicalVolume(__void__&);
347  // Fake default constructor for usage restricted to direct object
348  // persistency for clients requiring preallocation of memory for
349  // persistifiable objects.
350 
351  virtual G4bool IsExtended() const;
352  // Return true if it is not a base-class object.
353 
354  inline G4FieldManager* GetMasterFieldManager() const;
355  // Gets current FieldManager for the master thread.
357  // Gets current SensitiveDetector for the master thread.
358  inline G4VSolid* GetMasterSolid() const;
359  // Gets current Solid for the master thread.
360 
361  inline G4int GetInstanceID() const;
362  // Returns the instance ID.
363  static const G4LVManager& GetSubInstanceManager();
364 
365  // Sets the private data instance manager - in order to use a particular Workspace
366 
367  // static const G4LVManager* GetSubInstanceManagerPtr();
368  // static const G4LVManager SetSubInstanceManager(G4LVManager* subInstanceManager);
369  // Revised Implementation - to enable Workspaces which can used by different
370  // threads at different times (only one thread or task can use a workspace at a time. )
371 
372  inline void Lock();
373  // Set lock identifier for final deletion of entity.
374 
375  void InitialiseWorker(G4LogicalVolume *ptrMasterObject,
376  G4VSolid* pSolid, G4VSensitiveDetector* pSDetector);
377  // This method is similar to the constructor. It is used by each worker
378  // thread to achieve the partial effect as that of the master thread.
379 
380  void TerminateWorker(G4LogicalVolume *ptrMasterObject);
381  // This method is similar to the destructor. It is used by each worker
382  // thread to achieve the partial effect as that of the master thread.
383 
384  void AssignFieldManager( G4FieldManager *fldMgr);
385  // Set the FieldManager - only at this level (do not push down hierarchy)
386 
387  static G4VSolid* GetSolid(G4LVData &instLVdata) ; // const;
388  static void SetSolid(G4LVData &instLVdata, G4VSolid *pSolid);
389  // Optimised Methods - passing thread instance of worker data
390 
391  private:
392 
394  G4LogicalVolume& operator=(const G4LogicalVolume&);
395  // Private copy-constructor and assignment operator.
396 
397  private:
398 
399  // Data members:
400 
401  G4PhysicalVolumeList fDaughters;
402  // Vector of daughters. Given initial size of 0.
403  G4String fName;
404  // Name of logical volume.
405  // Pointer (possibly 0) to `Hit' object.
406 
407  G4UserLimits* fUserLimits;
408  // Pointer (possibly 0) to user Step limit object for this node.
409  G4SmartVoxelHeader* fVoxel;
410  // Pointer (possibly 0) to optimisation info objects.
411  G4bool fOptimise;
412  // Flag to identify if optimisation should be applied or not.
413  G4bool fRootRegion;
414  // Flag to identify if the logical volume is a root region.
415  G4bool fLock;
416  // Flag to identify if entity is locked for final deletion.
417  G4double fSmartless;
418  // Quality for optimisation, average number of voxels to be spent
419  // per content.
420  const G4VisAttributes* fVisAttributes;
421  // Pointer (possibly 0) to visualization attributes.
422  G4Region* fRegion;
423  // Pointer to the cuts region (if any)
424  G4double fBiasWeight;
425  // Weight used in the event biasing technique.
426 
427  G4int instanceID;
428  // This new field is used as instance ID.
429  G4GEOM_DLL static G4LVManager subInstanceManager;
430  // This new field helps to use the class G4LVManager introduced above.
431 
432  // Shadow of master pointers.
433  // Each worker thread can access this field from the master thread
434  // through these pointers.
435  //
436  G4VSolid* fSolid;
437  G4VSensitiveDetector* fSensitiveDetector;
438  G4FieldManager* fFieldManager;
439  G4LVData* lvdata; // For use of object persistency
440 };
441 
442 #include "G4LogicalVolume.icc"
443 
444 #endif
const XML_Char * name
Definition: expat.h:151
G4SmartVoxelHeader * GetVoxelHeader() const
G4double GetSmartless() const
G4Material * GetMaterial() const
void UpdateMaterial(G4Material *pMaterial)
void SetRegionRootFlag(G4bool rreg)
G4VSolid * GetMasterSolid() const
G4bool IsAncestor(const G4VPhysicalVolume *p) const
G4bool operator==(const G4LogicalVolume &lv) const
G4GeomSplitter< G4LVData > G4LVManager
const char * p
Definition: xmltok.h:285
static const G4LVManager & GetSubInstanceManager()
void SetUserLimits(G4UserLimits *pULimits)
G4double fMass
G4VSolid * GetSolid() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
G4MaterialCutsCouple * fCutsCouple
void SetSolid(G4VSolid *pSolid)
G4FieldManager * GetMasterFieldManager() const
G4Region * GetRegion() const
G4VSensitiveDetector * fSensitiveDetector
int G4int
Definition: G4Types.hh:78
void InitialiseWorker(G4LogicalVolume *ptrMasterObject, G4VSolid *pSolid, G4VSensitiveDetector *pSDetector)
void SetFieldManager(G4FieldManager *pFieldMgr, G4bool forceToAllDaughters)
static const G4double reg
void SetVoxelHeader(G4SmartVoxelHeader *pVoxel)
const XML_Char * s
Definition: expat.h:262
void SetRegion(G4Region *reg)
G4double GetBiasWeight() const
void AssignFieldManager(G4FieldManager *fldMgr)
G4FieldManager * fFieldManager
G4VSensitiveDetector * GetMasterSensitiveDetector() const
bool G4bool
Definition: G4Types.hh:79
void SetOptimisation(G4bool optim)
G4FastSimulationManager * GetFastSimulationManager() const
G4bool IsRootRegion() const
G4bool IsRegion() const
const G4VisAttributes * GetVisAttributes() const
EVolume CharacteriseDaughters() const
virtual ~G4LogicalVolume()
void SetMaterialCutsCouple(G4MaterialCutsCouple *cuts)
void PropagateRegion()
G4int TotalVolumeEntities() const
G4LogicalVolume(G4VSolid *pSolid, G4Material *pMaterial, const G4String &name, G4FieldManager *pFieldMgr=0, G4VSensitiveDetector *pSDetector=0, G4UserLimits *pULimits=0, G4bool optimise=true)
G4int GetNoDaughters() const
G4UserLimits * GetUserLimits() const
G4Material * fMaterial
void TerminateWorker(G4LogicalVolume *ptrMasterObject)
void SetSmartless(G4double s)
G4bool IsDaughter(const G4VPhysicalVolume *p) const
void initialize()
void SetName(const G4String &pName)
G4int GetInstanceID() const
const G4MaterialCutsCouple * GetMaterialCutsCouple() const
G4FieldManager * GetFieldManager() const
G4double GetMass(G4bool forced=false, G4bool propagate=true, G4Material *parMaterial=0)
EVolume
Definition: geomdefs.hh:69
const G4String & GetName() const
G4bool IsToOptimise() const
double G4double
Definition: G4Types.hh:76
void SetBiasWeight(G4double w)
void AddDaughter(G4VPhysicalVolume *p)
void SetMaterial(G4Material *pMaterial)
virtual G4bool IsExtended() const
G4VSensitiveDetector * GetSensitiveDetector() const
#define G4GEOM_DLL
Definition: geomwdefs.hh:48
void SetVisAttributes(const G4VisAttributes *pVA)
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)
G4VSolid * fSolid
void RemoveDaughter(const G4VPhysicalVolume *p)