|
||||
File indexing completed on 2025-01-18 09:58:38
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // G4LogicalVolume 0027 // 0028 // Class description: 0029 // 0030 // Represents a leaf node or unpositioned subtree in the geometry hierarchy. 0031 // Logical volumes are named, and may have daughters ascribed to them. 0032 // They are responsible for retrieval of the physical and tracking attributes 0033 // of the physical volume that it represents: solid, material, magnetic field, 0034 // and optionally, user limits, sensitive detectors, regions, biasing weights. 0035 // 0036 // Get and Set functionality is provided for all attributes, but note that 0037 // most set functions should not be used when the geometry is `closed'. 0038 // As a further development, `Guard' checks can be added to ensure 0039 // only legal operations at tracking time. 0040 // 0041 // On construction, solid, material and name must be specified. 0042 // 0043 // Daughters are ascribed and managed by means of a simple 0044 // GetNoDaughters,Get/SetDaughter(n),AddDaughter interface. 0045 // 0046 // Smart voxels as used for tracking optimisation. They're also an attribute. 0047 // 0048 // Logical volumes self register to the logical volume Store on construction, 0049 // and deregister on destruction. 0050 // 0051 // NOTE: This class is currently *NOT* subclassed, since not meant to 0052 // act as a base class. Therefore, the destructor is NOT virtual. 0053 // 0054 // Data members: 0055 // 0056 // std::vector<G4VPhysicalVolume*> fDaughters 0057 // - Vector of daughters. Given initial size of 0. 0058 // G4FieldManager* fFieldManager 0059 // - Pointer (possibly 0) to (magnetic or other) field manager object. 0060 // G4Material* fMaterial 0061 // - Pointer to material at this node. 0062 // G4String fName 0063 // - Name of logical volume. 0064 // G4VSensitiveDetector *fSensitiveDetector 0065 // - Pointer (possibly 0) to `Hit' object. 0066 // G4VSolid* fSolid 0067 // - Pointer to solid. 0068 // G4UserLimits* fUserLimits 0069 // - Pointer (possibly 0) to user Step limit object for this node. 0070 // G4SmartVoxelHeader* fVoxel 0071 // - Pointer (possibly 0) to optimisation info objects. 0072 // G4bool fOptimise 0073 // - Flag to identify if optimisation should be applied or not. 0074 // G4bool fRootRegion 0075 // - Flag to identify if the logical volume is a root region. 0076 // G4double fSmartless 0077 // - Quality for optimisation, average number of voxels to be spent 0078 // per content. 0079 // const G4VisAttributes* fVisAttributes 0080 // - Pointer (possibly 0) to visualization attributes. 0081 // G4Region* fRegion 0082 // - Pointer to the cuts region (if any) 0083 // G4MaterialCutsCouple* fCutsCouple 0084 // - Pointer (possibly 0) to associated production cuts. 0085 // G4double fBiasWeight 0086 // - Weight used in the event biasing technique. 0087 // 0088 // Following data members has been moved to G4Region - M.Asai (Aug/18/2005) 0089 // G4FastSimulationManager* fFastSimulationManager 0090 // - Pointer (possibly 0) to G4FastSimulationManager object. 0091 // G4bool fIsEnvelope 0092 // - Flags if the Logical Volume is an envelope for a FastSimulationManager. 0093 0094 // 15.01.13 G.Cosmo, A.Dotti: Modified for thread-safety for MT 0095 // 12.11.04 G.Cosmo: Added GetMass() method for computing mass of the tree 0096 // 24.09.02 G.Cosmo: Added flags and accessors for region cuts handling 0097 // 17.05.02 G.Cosmo: Added IsToOptimise() method and related flag 0098 // 18.04.01 G.Cosmo: Migrated to STL vector 0099 // 12.02.99 S.Giani: Added user defined optimisation quality 0100 // 09.11.98 M.Verderi, J.Apostolakis: Added BiasWeight member and accessors 0101 // 10.20.97 P.M.DeFreitas, J.Apostolakis: Added pointer to a FastSimulation 0102 // 11.07.95 P.Kent: Initial version 0103 // ------------------------------------------------------------------------ 0104 #ifndef G4LOGICALVOLUME_HH 0105 #define G4LOGICALVOLUME_HH 1 0106 0107 #include <vector> 0108 #include <memory> 0109 0110 #include "G4Types.hh" 0111 #include "G4Region.hh" // Required by inline methods 0112 #include "G4VPhysicalVolume.hh" // Need operator == for vector fdaughters 0113 #include "G4GeomSplitter.hh" // Needed for MT RW data splitting 0114 #include "G4Threading.hh" 0115 0116 // Forward declarations 0117 // 0118 class G4FieldManager; 0119 class G4Material; 0120 class G4VSensitiveDetector; 0121 class G4VSolid; 0122 class G4UserLimits; 0123 class G4SmartVoxelHeader; 0124 class G4FastSimulationManager; 0125 class G4MaterialCutsCouple; 0126 class G4VisAttributes; 0127 0128 class G4LVData 0129 { 0130 // Encapsulates the fields associated to the class 0131 // G4LogicalVolume that may not be read-only. 0132 0133 public: 0134 0135 G4LVData(); 0136 void initialize() 0137 { 0138 fSolid = nullptr; 0139 fSensitiveDetector = nullptr; 0140 fFieldManager = nullptr; 0141 fMaterial = nullptr; 0142 fMass = 0.0; 0143 fCutsCouple = nullptr; 0144 } 0145 0146 public: 0147 0148 G4VSolid* fSolid = nullptr; 0149 // Pointer to solid. 0150 G4VSensitiveDetector* fSensitiveDetector = nullptr; 0151 // Pointer to sensitive detector. 0152 G4FieldManager* fFieldManager = nullptr; 0153 // Pointer (possibly nullptr) to (magnetic or other) field manager object. 0154 G4Material* fMaterial = nullptr; 0155 // Pointer to material at this node. 0156 G4double fMass = 0.0; 0157 // Mass of the logical volume tree. 0158 G4MaterialCutsCouple* fCutsCouple = nullptr; 0159 // Pointer (possibly nullptr) to associated production cuts. 0160 }; 0161 0162 // The type G4LVManager is introduced to encapsulate the methods used by 0163 // both the master thread and worker threads to allocate memory space for 0164 // the fields encapsulated by the class G4LVData. When each thread 0165 // initializes the value for these fields, it refers to them using a macro 0166 // definition defined below. For every G4LogicalVolume instance, there is 0167 // a corresponding G4LVData instance. All G4LVData instances are organized 0168 // by the class G4LVManager as an array. 0169 // The field "int instanceID" is added to the class G4LogicalVolume. 0170 // The value of this field in each G4LogicalVolume instance is the subscript 0171 // of the corresponding G4LVData instance. 0172 // In order to use the class G4LVManager, we add a static member in the class 0173 // G4LogicalVolume as follows: "static G4LVManager subInstanceManager". 0174 // For the master thread, the array for G4LVData instances grows dynamically 0175 // along with G4LogicalVolume instances are created. For each worker thread, 0176 // it copies the array of G4LVData instances from the master thread. 0177 // In addition, it invokes a method similiar to the constructor explicitly 0178 // to achieve the partial effect for each instance in the array. 0179 // 0180 using G4LVManager = G4GeomSplitter<G4LVData>; 0181 0182 class G4LogicalVolume 0183 { 0184 public: 0185 0186 G4LogicalVolume(G4VSolid* pSolid, 0187 G4Material* pMaterial, 0188 const G4String& name, 0189 G4FieldManager* pFieldMgr = nullptr, 0190 G4VSensitiveDetector* pSDetector = nullptr, 0191 G4UserLimits* pULimits = nullptr, 0192 G4bool optimise = true); 0193 // Constructor. The solid and material pointer must be non null. 0194 // The parameters for field, detector and user limits are optional. 0195 // The volume also enters itself into the logical volume Store. 0196 // Optimisation of the geometry (voxelisation) for the volume 0197 // hierarchy is applied by default. For parameterised volumes in 0198 // the hierarchy, optimisation is -always- applied. 0199 0200 virtual ~G4LogicalVolume(); 0201 // Destructor. Removes the logical volume from the logical volume Store. 0202 // This class is NOT meant to act as base class, except for exceptional 0203 // circumstances of extended types used in the kernel. 0204 0205 G4LogicalVolume(const G4LogicalVolume&) = delete; 0206 G4LogicalVolume& operator=(const G4LogicalVolume&) = delete; 0207 // Copy-constructor and assignment operator not allowed. 0208 0209 inline const G4String& GetName() const; 0210 void SetName(const G4String& pName); 0211 // Returns and sets the name of the logical volume. 0212 0213 inline std::size_t GetNoDaughters() const; 0214 // Returns the number of daughters (0 to n). 0215 inline G4VPhysicalVolume* GetDaughter(const std::size_t i) const; 0216 // Returns the ith daughter. Note numbering starts from 0, 0217 // and no bounds checking is performed. 0218 void AddDaughter(G4VPhysicalVolume* p); 0219 // Adds the volume p as a daughter of the current logical volume. 0220 inline G4bool IsDaughter(const G4VPhysicalVolume* p) const; 0221 // Returns true if the volume p is a daughter of the current 0222 // logical volume. 0223 G4bool IsAncestor(const G4VPhysicalVolume* p) const; 0224 // Returns true if the volume p is part of the hierarchy of 0225 // volumes established by the current logical volume. Scans 0226 // recursively the volume tree. 0227 void RemoveDaughter(const G4VPhysicalVolume* p); 0228 // Removes the volume p from the List of daughter of the current 0229 // logical volume. 0230 void ClearDaughters(); 0231 // Clears the list of daughters. Used by the phys-volume store when 0232 // the geometry tree is cleared, since modified at run-time. 0233 G4int TotalVolumeEntities() const; 0234 // Returns the total number of physical volumes (replicated or placed) 0235 // in the tree represented by the current logical volume. 0236 inline EVolume CharacteriseDaughters() const; 0237 // Characterise the daughters of this logical volume. 0238 inline EVolume DeduceDaughtersType() const; 0239 // Used by CharacteriseDaughters(). 0240 0241 G4VSolid* GetSolid() const; 0242 void SetSolid(G4VSolid* pSolid); 0243 // Gets and sets the current solid. 0244 0245 G4Material* GetMaterial() const; 0246 void SetMaterial(G4Material* pMaterial); 0247 // Gets and sets the current material. 0248 void UpdateMaterial(G4Material* pMaterial); 0249 // Sets material and corresponding MaterialCutsCouple. 0250 // This method is invoked by G4Navigator while it is navigating through 0251 // material parameterization. 0252 G4double GetMass(G4bool forced = false, G4bool propagate = true, 0253 G4Material* parMaterial = nullptr); 0254 // Returns the mass of the logical volume tree computed from the 0255 // estimated geometrical volume of each solid and material associated 0256 // to the logical volume and (by default) to its daughters. 0257 // NOTE: the computation may require a considerable amount of time, 0258 // depending from the complexity of the geometry tree. 0259 // The returned value is cached and can be used for successive 0260 // calls (default), unless recomputation is forced by providing 0261 // 'true' for the boolean argument in input. Computation should 0262 // be forced if the geometry setup has changed after the previous 0263 // call. By setting the 'propagate' boolean flag to 'false' the 0264 // method returns the mass of the present logical volume only 0265 // (subtracted for the volume occupied by the daughter volumes). 0266 // An optional argument to specify a material is also provided. 0267 void ResetMass(); 0268 // Ensure that cached value of Mass is invalidated - due to change in 0269 // state, e.g. change of size of Solid, change of type of solid, 0270 // or the addition/deletion of a daughter volume. 0271 0272 G4FieldManager* GetFieldManager() const; 0273 // Gets current FieldManager. 0274 void SetFieldManager(G4FieldManager* pFieldMgr, G4bool forceToAllDaughters); 0275 // Sets FieldManager and propagates it: 0276 // i) only to daughters with G4FieldManager = nullptr 0277 // if forceToAllDaughters=false 0278 // ii) to all daughters 0279 // if forceToAllDaughters=true 0280 0281 G4VSensitiveDetector* GetSensitiveDetector() const; 0282 // Gets current SensitiveDetector. 0283 void SetSensitiveDetector(G4VSensitiveDetector* pSDetector); 0284 // Sets SensitiveDetector (can be nullptr). 0285 0286 inline G4UserLimits* GetUserLimits() const; 0287 inline void SetUserLimits(G4UserLimits *pULimits); 0288 // Gets and sets current UserLimits. 0289 0290 inline G4SmartVoxelHeader* GetVoxelHeader() const; 0291 inline void SetVoxelHeader(G4SmartVoxelHeader *pVoxel); 0292 // Gets and sets current VoxelHeader. 0293 0294 inline G4double GetSmartless() const; 0295 inline void SetSmartless(G4double s); 0296 // Gets and sets user defined optimisation quality. 0297 0298 inline G4bool IsToOptimise() const; 0299 // Replies if geometry optimisation (voxelisation) is to be 0300 // applied for this volume hierarchy. 0301 inline void SetOptimisation(G4bool optim); 0302 // Specifies if to apply or not geometry optimisation to this 0303 // volume hierarchy. Note that for parameterised volumes in the 0304 // hierarchy, optimisation is always applied. 0305 0306 inline G4bool IsRootRegion() const; 0307 // Replies if the logical volume represents a root region or not. 0308 inline void SetRegionRootFlag(G4bool rreg); 0309 // Sets/unsets the volume as a root region for cuts. 0310 inline G4bool IsRegion() const; 0311 // Replies if the logical volume is part of a cuts region or not. 0312 inline void SetRegion(G4Region* reg); 0313 // Sets/unsets the volume as cuts region. 0314 inline G4Region* GetRegion() const; 0315 // Return the region to which the volume belongs, if any. 0316 inline void PropagateRegion(); 0317 // Propagates region pointer to daughters. 0318 0319 const G4MaterialCutsCouple* GetMaterialCutsCouple() const; 0320 void SetMaterialCutsCouple(G4MaterialCutsCouple* cuts); 0321 // Accessors for production cuts. 0322 0323 G4bool operator == (const G4LogicalVolume& lv) const; 0324 // Equality defined by address only. 0325 // Returns true if objects are at same address, else false. 0326 0327 const G4VisAttributes* GetVisAttributes () const; 0328 void SetVisAttributes (const G4VisAttributes* pVA); 0329 void SetVisAttributes (const G4VisAttributes& VA); 0330 // Gets and sets visualization attributes. 0331 // Arguments are converted to shared_ptr. 0332 0333 inline G4FastSimulationManager* GetFastSimulationManager () const; 0334 // Gets current FastSimulationManager pointer if exists, otherwise null. 0335 0336 inline void SetBiasWeight (G4double w); 0337 inline G4double GetBiasWeight() const; 0338 // Sets and gets bias weight. 0339 0340 public: 0341 0342 G4LogicalVolume(__void__&); 0343 // Fake default constructor for usage restricted to direct object 0344 // persistency for clients requiring preallocation of memory for 0345 // persistifiable objects. 0346 0347 virtual G4bool IsExtended() const; 0348 // Return true if it is not a base-class object. 0349 0350 inline G4FieldManager* GetMasterFieldManager() const; 0351 // Gets current FieldManager for the master thread. 0352 inline G4VSensitiveDetector* GetMasterSensitiveDetector() const; 0353 // Gets current SensitiveDetector for the master thread. 0354 inline G4VSolid* GetMasterSolid() const; 0355 // Gets current Solid for the master thread. 0356 0357 inline G4int GetInstanceID() const; 0358 // Returns the instance ID. 0359 0360 static const G4LVManager& GetSubInstanceManager(); 0361 // Returns the private data instance manager. 0362 0363 static void Clean(); 0364 // Clear memory allocated by sub-instance manager. 0365 0366 inline void Lock(); 0367 // Set lock identifier for final deletion of entity. 0368 0369 void InitialiseWorker(G4LogicalVolume* ptrMasterObject, 0370 G4VSolid* pSolid, G4VSensitiveDetector* pSDetector); 0371 // This method is similar to the constructor. It is used by each worker 0372 // thread to achieve the partial effect as that of the master thread. 0373 0374 void TerminateWorker(G4LogicalVolume* ptrMasterObject); 0375 // This method is similar to the destructor. It is used by each worker 0376 // thread to achieve the partial effect as that of the master thread. 0377 0378 void AssignFieldManager(G4FieldManager* fldMgr); 0379 // Set the FieldManager - only at this level (do not push down hierarchy) 0380 0381 static G4VSolid* GetSolid(G4LVData& instLVdata) ; // const; 0382 static void SetSolid(G4LVData& instLVdata, G4VSolid* pSolid); 0383 // Optimised Methods - passing thread instance of worker data 0384 0385 G4bool ChangeDaughtersType(EVolume atype); 0386 // Change the type of the daughters volume to be of type atype. 0387 // Meant for the user who wants to use the external navigator for 0388 // the contents of a volume. 0389 // Returns: success (true) or failure (false). 0390 0391 private: 0392 0393 using G4PhysicalVolumeList = std::vector<G4VPhysicalVolume *>; 0394 0395 G4GEOM_DLL static G4LVManager subInstanceManager; 0396 // This new field helps to use the class G4LVManager introduced above. 0397 0398 G4PhysicalVolumeList fDaughters; 0399 // Vector of daughters. Given initial size of 0. 0400 G4String fName; 0401 // Name of logical volume. 0402 G4UserLimits* fUserLimits = nullptr; 0403 // Pointer (possibly nullptr) to user Step limit object for this node. 0404 G4SmartVoxelHeader* fVoxel = nullptr; 0405 // Pointer (possibly nullptr) to optimisation info objects. 0406 G4double fSmartless = 2.0; 0407 // Quality for optimisation, average number of voxels to be spent 0408 // per content. 0409 G4Region* fRegion = nullptr; 0410 // Pointer to the cuts region (if any). 0411 G4double fBiasWeight = 1.0; 0412 // Weight used in the event biasing technique. 0413 std::shared_ptr<const G4VisAttributes> fVisAttributes; 0414 // Pointer to visualization attributes. 0415 0416 // Shadow of master pointers. 0417 // Each worker thread can access this field from the master thread 0418 // through these pointers. 0419 // 0420 G4VSolid* fSolid = nullptr; 0421 G4VSensitiveDetector* fSensitiveDetector = nullptr; 0422 G4FieldManager* fFieldManager = nullptr; 0423 G4LVData* lvdata = nullptr; // For use of object persistency 0424 0425 G4int instanceID; 0426 // This new field is used as instance ID. 0427 EVolume fDaughtersVolumeType; 0428 // Are contents of volume placements, replica, parameterised or external? 0429 G4bool fOptimise = true; 0430 // Flag to identify if optimisation should be applied or not. 0431 G4bool fRootRegion = false; 0432 // Flag to identify if the logical volume is a root region. 0433 G4bool fLock = false; 0434 // Flag to identify if entity is locked for final deletion. 0435 }; 0436 0437 #include "G4LogicalVolume.icc" 0438 0439 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |