|
||||
File indexing completed on 2025-01-18 09:59:02
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 // G4Region 0027 // 0028 // Class description: 0029 // 0030 // Defines a region or a group of regions in the detector geometry 0031 // setup, sharing properties associated to materials or production 0032 // cuts which may affect or bias specific physics processes. 0033 0034 // 18.09.02, G.Cosmo - Initial version 0035 // -------------------------------------------------------------------- 0036 #ifndef G4REGION_HH 0037 #define G4REGION_HH 1 0038 0039 #include <vector> 0040 #include <map> 0041 #include <algorithm> 0042 0043 #include "G4Types.hh" 0044 #include "G4String.hh" 0045 #include "G4GeomSplitter.hh" 0046 0047 class G4ProductionCuts; 0048 class G4LogicalVolume; 0049 class G4Material; 0050 class G4VUserRegionInformation; 0051 class G4MaterialCutsCouple; 0052 class G4UserLimits; 0053 class G4FieldManager; 0054 class G4FastSimulationManager; 0055 class G4VPhysicalVolume; 0056 class G4UserSteppingAction; 0057 0058 class G4RegionData 0059 { 0060 // Encapsulates the fields associated to the class 0061 // G4Region that may not be read-only. 0062 0063 public: 0064 0065 void initialize() 0066 { 0067 fFastSimulationManager = nullptr; 0068 fRegionalSteppingAction = nullptr; 0069 } 0070 0071 G4FastSimulationManager* fFastSimulationManager; 0072 G4UserSteppingAction* fRegionalSteppingAction; 0073 }; 0074 0075 // The type G4RegionManager is introduced to encapsulate the methods used by 0076 // both the master thread and worker threads to allocate memory space for 0077 // the fields encapsulated by the class G4RegionData. When each thread 0078 // initializes the value for these fields, it refers to them using a macro 0079 // definition defined below. For every G4Region instance, there is a 0080 // corresponding G4RegionData instance. All G4RegionData instances are 0081 // organized by the class G4RegionManager as an array. 0082 // The field "int instanceID" is added to the class G4Region. 0083 // The value of this field in each G4Region instance is the subscript 0084 // of the corresponding G4RegionData instance. 0085 // In order to use the class G4RegionManager, we add a static member in 0086 // the class G4Region as follows: "static G4RegionManager subInstanceManager". 0087 // For the master thread, the array for G4RegionData instances grows 0088 // dynamically along with G4Region instances are created. For each worker 0089 // thread, it copies the array of G4RegionData instances from the master thread. 0090 // In addition, it invokes a method similiar to the constructor explicitly 0091 // to achieve the partial effect for each instance in the array. 0092 // 0093 using G4RegionManager = G4GeomSplitter<G4RegionData>; 0094 0095 class G4Region 0096 { 0097 public: 0098 0099 G4Region(const G4String& name); 0100 virtual ~G4Region(); 0101 0102 G4Region(const G4Region&) = delete; 0103 G4Region& operator=(const G4Region&) = delete; 0104 // Copy constructor and assignment operator not allowed. 0105 0106 inline G4bool operator==(const G4Region& rg) const; 0107 // Equality defined by address only. 0108 0109 void AddRootLogicalVolume(G4LogicalVolume* lv, G4bool search=true); 0110 void RemoveRootLogicalVolume(G4LogicalVolume* lv, G4bool scan=true); 0111 // Add/remove root logical volumes and set/reset their 0112 // daughters flags as regions. They also recompute the 0113 // materials list for the region. Flag for scanning the subtree 0114 // always enabled by default. Search in the tree can be turned off 0115 // when adding, assuming the user guarantees the logical volume is 0116 // NOT already inserted, in which case significant speedup can be 0117 // achieved in very complex flat geometry setups. 0118 0119 void SetName(const G4String& name); 0120 inline const G4String& GetName() const; 0121 // Set/get region's name. 0122 0123 inline void RegionModified(G4bool flag); 0124 inline G4bool IsModified() const; 0125 // Accessors to flag identifying if a region has been modified 0126 // (and still cuts needs to be computed) or not. 0127 0128 inline void SetProductionCuts(G4ProductionCuts* cut); 0129 inline G4ProductionCuts* GetProductionCuts() const; 0130 0131 inline std::vector<G4LogicalVolume*>::iterator 0132 GetRootLogicalVolumeIterator(); 0133 inline std::vector<G4Material*>::const_iterator 0134 GetMaterialIterator() const; 0135 // Return iterators to lists of root logical volumes and materials. 0136 0137 inline std::size_t GetNumberOfMaterials() const; 0138 inline std::size_t GetNumberOfRootVolumes() const; 0139 // Return the number of elements in the lists of materials and 0140 // root logical volumes. 0141 0142 void UpdateMaterialList(); 0143 // Clears material list and recomputes it looping through 0144 // each root logical volume in the region. 0145 0146 void ClearMaterialList(); 0147 // Clears the material list. 0148 0149 void ScanVolumeTree(G4LogicalVolume* lv, G4bool region); 0150 // Scans recursively the 'lv' logical volume tree, retrieves 0151 // and places all materials in the list if becoming a region. 0152 0153 inline void SetUserInformation(G4VUserRegionInformation* ui); 0154 inline G4VUserRegionInformation* GetUserInformation() const; 0155 // Set and Get methods for user information. 0156 0157 inline void SetUserLimits(G4UserLimits* ul); 0158 inline G4UserLimits* GetUserLimits() const; 0159 // Set and Get methods for userL-limits associated to a region. 0160 // Once user-limits are set, it will propagate to daughter volumes. 0161 0162 inline void ClearMap(); 0163 // Reset G4MaterialCoupleMap 0164 0165 inline void RegisterMaterialCouplePair(G4Material* mat, 0166 G4MaterialCutsCouple* couple); 0167 // Method invoked by G4ProductionCutsTable to register the pair. 0168 0169 inline G4MaterialCutsCouple* FindCouple(G4Material* mat); 0170 // Find a G4MaterialCutsCouple which corresponds to the material 0171 // in this region. 0172 0173 void SetFastSimulationManager(G4FastSimulationManager* fsm); 0174 G4FastSimulationManager* GetFastSimulationManager() const; 0175 // Set and Get methods for G4FastSimulationManager. 0176 // The root logical volume that has the region with G4FastSimulationManager 0177 // becomes an envelope of fast simulation. 0178 0179 void ClearFastSimulationManager(); 0180 // Set G4FastSimulationManager pointer to the one for the parent region 0181 // if it exists. Otherwise set to null. 0182 0183 inline void SetFieldManager(G4FieldManager* fm); 0184 inline G4FieldManager* GetFieldManager() const; 0185 // Set and Get methods for G4FieldManager. 0186 // The region with assigned field-manager sets the field to the 0187 // geometrical area associated with it; priority is anyhow given 0188 // to local fields eventually set to logical volumes. 0189 0190 inline G4VPhysicalVolume* GetWorldPhysical() const; 0191 // Get method for the world physical volume which this region 0192 // belongs to. A valid pointer will be assigned by G4RunManagerKernel 0193 // through G4RegionStore when the geometry is to be closed. Thus, this 0194 // pointer may be incorrect at PreInit and Idle state. If the pointer 0195 // is null at the proper state, this particular region does not belong 0196 // to any world (maybe not assigned to any volume, etc.). 0197 0198 void SetWorld(G4VPhysicalVolume* wp); 0199 // Set the world physical volume if this region belongs to this world. 0200 // If wp is null, reset the pointer. 0201 0202 G4bool BelongsTo(G4VPhysicalVolume* thePhys) const; 0203 // Returns whether this region belongs to the given physical volume 0204 // (recursively scanned to the bottom of the hierarchy). 0205 0206 G4Region* GetParentRegion(G4bool& unique) const; 0207 // Returns a region that contains this region. Otherwise null returned. 0208 // Flag 'unique' is true if there is only one parent region containing 0209 // the current region. 0210 0211 void SetRegionalSteppingAction(G4UserSteppingAction* rusa); 0212 G4UserSteppingAction* GetRegionalSteppingAction() const; 0213 // Set/Get method of the regional user stepping action 0214 0215 public: 0216 0217 G4Region(__void__&); 0218 // Fake default constructor for usage restricted to direct object 0219 // persistency for clients requiring preallocation of memory for 0220 // persistifiable objects. 0221 0222 inline G4int GetInstanceID() const; 0223 // Returns the instance ID. 0224 0225 static const G4RegionManager& GetSubInstanceManager(); 0226 // Returns the private data instance manager. 0227 0228 static void Clean(); 0229 // Clear memory allocated by sub-instance manager. 0230 0231 inline void UsedInMassGeometry(G4bool val = true); 0232 inline void UsedInParallelGeometry(G4bool val = true); 0233 inline G4bool IsInMassGeometry() const; 0234 inline G4bool IsInParallelGeometry() const; 0235 // Utility methods to identify if region is part of the main mass 0236 // geometry for tracking or a parallel geometry. 0237 0238 private: 0239 0240 inline void AddMaterial (G4Material* aMaterial); 0241 // Searchs the specified material in the material table and 0242 // if not present adds it. 0243 0244 private: 0245 0246 using G4RootLVList = std::vector<G4LogicalVolume*>; 0247 using G4MaterialList = std::vector<G4Material*>; 0248 using G4MaterialCouplePair = std::pair<G4Material*, G4MaterialCutsCouple*>; 0249 using G4MaterialCoupleMap = std::map<G4Material*, G4MaterialCutsCouple*>; 0250 0251 G4String fName; 0252 0253 G4RootLVList fRootVolumes; 0254 G4MaterialList fMaterials; 0255 G4MaterialCoupleMap fMaterialCoupleMap; 0256 0257 G4bool fRegionMod = true; 0258 G4ProductionCuts* fCut = nullptr; 0259 0260 G4VUserRegionInformation* fUserInfo = nullptr; 0261 G4UserLimits* fUserLimits = nullptr; 0262 G4FieldManager* fFieldManager = nullptr; 0263 0264 G4VPhysicalVolume* fWorldPhys = nullptr; 0265 0266 G4bool fInMassGeometry = false; 0267 G4bool fInParallelGeometry = false; 0268 0269 G4int instanceID; 0270 // This field is used as instance ID. 0271 G4GEOM_DLL static G4RegionManager subInstanceManager; 0272 // This field helps to use the class G4RegionManager introduced above. 0273 }; 0274 0275 #include "G4Region.icc" 0276 0277 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |