Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4Region 26 // G4Region 27 // 27 // 28 // Class description: 28 // Class description: 29 // 29 // 30 // Defines a region or a group of regions in t 30 // Defines a region or a group of regions in the detector geometry 31 // setup, sharing properties associated to mat 31 // setup, sharing properties associated to materials or production 32 // cuts which may affect or bias specific phys 32 // cuts which may affect or bias specific physics processes. 33 33 34 // 18.09.02, G.Cosmo - Initial version 34 // 18.09.02, G.Cosmo - Initial version 35 // ------------------------------------------- 35 // -------------------------------------------------------------------- 36 #ifndef G4REGION_HH 36 #ifndef G4REGION_HH 37 #define G4REGION_HH 1 << 37 #define G4REGION_HH 38 38 39 #include <vector> 39 #include <vector> 40 #include <map> 40 #include <map> 41 #include <algorithm> 41 #include <algorithm> 42 42 43 #include "G4Types.hh" 43 #include "G4Types.hh" 44 #include "G4String.hh" 44 #include "G4String.hh" 45 #include "G4GeomSplitter.hh" 45 #include "G4GeomSplitter.hh" 46 46 47 class G4ProductionCuts; 47 class G4ProductionCuts; 48 class G4LogicalVolume; 48 class G4LogicalVolume; 49 class G4Material; 49 class G4Material; 50 class G4VUserRegionInformation; 50 class G4VUserRegionInformation; 51 class G4MaterialCutsCouple; 51 class G4MaterialCutsCouple; 52 class G4UserLimits; 52 class G4UserLimits; 53 class G4FieldManager; 53 class G4FieldManager; 54 class G4FastSimulationManager; 54 class G4FastSimulationManager; 55 class G4VPhysicalVolume; 55 class G4VPhysicalVolume; 56 class G4UserSteppingAction; 56 class G4UserSteppingAction; 57 57 58 class G4RegionData 58 class G4RegionData 59 { 59 { 60 // Encapsulates the fields associated to the 60 // Encapsulates the fields associated to the class 61 // G4Region that may not be read-only. 61 // G4Region that may not be read-only. 62 62 63 public: 63 public: 64 64 65 void initialize() 65 void initialize() 66 { 66 { 67 fFastSimulationManager = nullptr; 67 fFastSimulationManager = nullptr; 68 fRegionalSteppingAction = nullptr; 68 fRegionalSteppingAction = nullptr; 69 } 69 } 70 70 71 G4FastSimulationManager* fFastSimulationMa 71 G4FastSimulationManager* fFastSimulationManager; 72 G4UserSteppingAction* fRegionalSteppingAct 72 G4UserSteppingAction* fRegionalSteppingAction; 73 }; 73 }; 74 74 75 // The type G4RegionManager is introduced to e 75 // The type G4RegionManager is introduced to encapsulate the methods used by 76 // both the master thread and worker threads t 76 // both the master thread and worker threads to allocate memory space for 77 // the fields encapsulated by the class G4Regi 77 // the fields encapsulated by the class G4RegionData. When each thread 78 // initializes the value for these fields, it 78 // initializes the value for these fields, it refers to them using a macro 79 // definition defined below. For every G4Regio 79 // definition defined below. For every G4Region instance, there is a 80 // corresponding G4RegionData instance. All G4 80 // corresponding G4RegionData instance. All G4RegionData instances are 81 // organized by the class G4RegionManager as a 81 // organized by the class G4RegionManager as an array. 82 // The field "int instanceID" is added to the 82 // The field "int instanceID" is added to the class G4Region. 83 // The value of this field in each G4Region in 83 // The value of this field in each G4Region instance is the subscript 84 // of the corresponding G4RegionData instance. 84 // of the corresponding G4RegionData instance. 85 // In order to use the class G4RegionManager, 85 // In order to use the class G4RegionManager, we add a static member in 86 // the class G4Region as follows: "static G4Re 86 // the class G4Region as follows: "static G4RegionManager subInstanceManager". 87 // For the master thread, the array for G4Regi 87 // For the master thread, the array for G4RegionData instances grows 88 // dynamically along with G4Region instances a 88 // dynamically along with G4Region instances are created. For each worker 89 // thread, it copies the array of G4RegionData 89 // thread, it copies the array of G4RegionData instances from the master thread. 90 // In addition, it invokes a method similiar t 90 // In addition, it invokes a method similiar to the constructor explicitly 91 // to achieve the partial effect for each inst 91 // to achieve the partial effect for each instance in the array. 92 // 92 // 93 using G4RegionManager = G4GeomSplitter<G4Regio << 93 typedef G4GeomSplitter<G4RegionData> G4RegionManager; 94 94 95 class G4Region 95 class G4Region 96 { 96 { 97 public: << 97 typedef std::vector<G4LogicalVolume*> G4RootLVList; >> 98 typedef std::vector<G4Material*> G4MaterialList; >> 99 typedef std::pair<G4Material*,G4MaterialCutsCouple*> G4MaterialCouplePair; >> 100 typedef std::map<G4Material*,G4MaterialCutsCouple*> G4MaterialCoupleMap; >> 101 >> 102 public: // with description 98 103 99 G4Region(const G4String& name); 104 G4Region(const G4String& name); 100 virtual ~G4Region(); 105 virtual ~G4Region(); 101 106 102 G4Region(const G4Region&) = delete; 107 G4Region(const G4Region&) = delete; 103 G4Region& operator=(const G4Region&) = del 108 G4Region& operator=(const G4Region&) = delete; 104 // Copy constructor and assignment opera 109 // Copy constructor and assignment operator not allowed. 105 110 106 inline G4bool operator==(const G4Region& r 111 inline G4bool operator==(const G4Region& rg) const; 107 // Equality defined by address only. 112 // Equality defined by address only. 108 113 109 void AddRootLogicalVolume(G4LogicalVolume* 114 void AddRootLogicalVolume(G4LogicalVolume* lv, G4bool search=true); 110 void RemoveRootLogicalVolume(G4LogicalVolu 115 void RemoveRootLogicalVolume(G4LogicalVolume* lv, G4bool scan=true); 111 // Add/remove root logical volumes and s 116 // Add/remove root logical volumes and set/reset their 112 // daughters flags as regions. They also 117 // daughters flags as regions. They also recompute the 113 // materials list for the region. Flag f 118 // materials list for the region. Flag for scanning the subtree 114 // always enabled by default. Search in 119 // always enabled by default. Search in the tree can be turned off 115 // when adding, assuming the user guaran 120 // when adding, assuming the user guarantees the logical volume is 116 // NOT already inserted, in which case s 121 // NOT already inserted, in which case significant speedup can be 117 // achieved in very complex flat geometr 122 // achieved in very complex flat geometry setups. 118 123 119 void SetName(const G4String& name); << 124 inline void SetName(const G4String& name); 120 inline const G4String& GetName() const; 125 inline const G4String& GetName() const; 121 // Set/get region's name. 126 // Set/get region's name. 122 127 123 inline void RegionModified(G4bool flag); 128 inline void RegionModified(G4bool flag); 124 inline G4bool IsModified() const; 129 inline G4bool IsModified() const; 125 // Accessors to flag identifying if a re 130 // Accessors to flag identifying if a region has been modified 126 // (and still cuts needs to be computed) 131 // (and still cuts needs to be computed) or not. 127 132 128 inline void SetProductionCuts(G4Production 133 inline void SetProductionCuts(G4ProductionCuts* cut); 129 inline G4ProductionCuts* GetProductionCuts 134 inline G4ProductionCuts* GetProductionCuts() const; 130 135 131 inline std::vector<G4LogicalVolume*>::iter 136 inline std::vector<G4LogicalVolume*>::iterator 132 GetRootLogicalVolumeIterator(); 137 GetRootLogicalVolumeIterator(); 133 inline std::vector<G4Material*>::const_ite 138 inline std::vector<G4Material*>::const_iterator 134 GetMaterialIterator() const; 139 GetMaterialIterator() const; 135 // Return iterators to lists of root log 140 // Return iterators to lists of root logical volumes and materials. 136 141 137 inline std::size_t GetNumberOfMaterials() << 142 inline size_t GetNumberOfMaterials() const; 138 inline std::size_t GetNumberOfRootVolumes( << 143 inline size_t GetNumberOfRootVolumes() const; 139 // Return the number of elements in the 144 // Return the number of elements in the lists of materials and 140 // root logical volumes. 145 // root logical volumes. 141 146 142 void UpdateMaterialList(); 147 void UpdateMaterialList(); 143 // Clears material list and recomputes i 148 // Clears material list and recomputes it looping through 144 // each root logical volume in the regio 149 // each root logical volume in the region. 145 150 146 void ClearMaterialList(); 151 void ClearMaterialList(); 147 // Clears the material list. 152 // Clears the material list. 148 153 149 void ScanVolumeTree(G4LogicalVolume* lv, G 154 void ScanVolumeTree(G4LogicalVolume* lv, G4bool region); 150 // Scans recursively the 'lv' logical vo 155 // Scans recursively the 'lv' logical volume tree, retrieves 151 // and places all materials in the list 156 // and places all materials in the list if becoming a region. 152 157 153 inline void SetUserInformation(G4VUserRegi 158 inline void SetUserInformation(G4VUserRegionInformation* ui); 154 inline G4VUserRegionInformation* GetUserIn 159 inline G4VUserRegionInformation* GetUserInformation() const; 155 // Set and Get methods for user informat 160 // Set and Get methods for user information. 156 161 157 inline void SetUserLimits(G4UserLimits* ul 162 inline void SetUserLimits(G4UserLimits* ul); 158 inline G4UserLimits* GetUserLimits() const 163 inline G4UserLimits* GetUserLimits() const; 159 // Set and Get methods for userL-limits 164 // Set and Get methods for userL-limits associated to a region. 160 // Once user-limits are set, it will pro 165 // Once user-limits are set, it will propagate to daughter volumes. 161 166 162 inline void ClearMap(); 167 inline void ClearMap(); 163 // Reset G4MaterialCoupleMap 168 // Reset G4MaterialCoupleMap 164 169 165 inline void RegisterMaterialCouplePair(G4M 170 inline void RegisterMaterialCouplePair(G4Material* mat, 166 G4M 171 G4MaterialCutsCouple* couple); 167 // Method invoked by G4ProductionCutsTab 172 // Method invoked by G4ProductionCutsTable to register the pair. 168 173 169 inline G4MaterialCutsCouple* FindCouple(G4 174 inline G4MaterialCutsCouple* FindCouple(G4Material* mat); 170 // Find a G4MaterialCutsCouple which cor 175 // Find a G4MaterialCutsCouple which corresponds to the material 171 // in this region. 176 // in this region. 172 177 173 void SetFastSimulationManager(G4FastSimula 178 void SetFastSimulationManager(G4FastSimulationManager* fsm); 174 G4FastSimulationManager* GetFastSimulation 179 G4FastSimulationManager* GetFastSimulationManager() const; 175 // Set and Get methods for G4FastSimulat 180 // Set and Get methods for G4FastSimulationManager. 176 // The root logical volume that has the 181 // The root logical volume that has the region with G4FastSimulationManager 177 // becomes an envelope of fast simulatio 182 // becomes an envelope of fast simulation. 178 183 179 void ClearFastSimulationManager(); 184 void ClearFastSimulationManager(); 180 // Set G4FastSimulationManager pointer t 185 // Set G4FastSimulationManager pointer to the one for the parent region 181 // if it exists. Otherwise set to null. 186 // if it exists. Otherwise set to null. 182 187 183 inline void SetFieldManager(G4FieldManager 188 inline void SetFieldManager(G4FieldManager* fm); 184 inline G4FieldManager* GetFieldManager() c 189 inline G4FieldManager* GetFieldManager() const; 185 // Set and Get methods for G4FieldManage 190 // Set and Get methods for G4FieldManager. 186 // The region with assigned field-manage 191 // The region with assigned field-manager sets the field to the 187 // geometrical area associated with it; 192 // geometrical area associated with it; priority is anyhow given 188 // to local fields eventually set to log 193 // to local fields eventually set to logical volumes. 189 194 190 inline G4VPhysicalVolume* GetWorldPhysical 195 inline G4VPhysicalVolume* GetWorldPhysical() const; 191 // Get method for the world physical vol 196 // Get method for the world physical volume which this region 192 // belongs to. A valid pointer will be a 197 // belongs to. A valid pointer will be assigned by G4RunManagerKernel 193 // through G4RegionStore when the geomet 198 // through G4RegionStore when the geometry is to be closed. Thus, this 194 // pointer may be incorrect at PreInit a 199 // pointer may be incorrect at PreInit and Idle state. If the pointer 195 // is null at the proper state, this par 200 // is null at the proper state, this particular region does not belong 196 // to any world (maybe not assigned to a 201 // to any world (maybe not assigned to any volume, etc.). 197 202 198 void SetWorld(G4VPhysicalVolume* wp); 203 void SetWorld(G4VPhysicalVolume* wp); 199 // Set the world physical volume if this 204 // Set the world physical volume if this region belongs to this world. 200 // If wp is null, reset the pointer. 205 // If wp is null, reset the pointer. 201 206 202 G4bool BelongsTo(G4VPhysicalVolume* thePhy 207 G4bool BelongsTo(G4VPhysicalVolume* thePhys) const; 203 // Returns whether this region belongs t 208 // Returns whether this region belongs to the given physical volume 204 // (recursively scanned to the bottom of 209 // (recursively scanned to the bottom of the hierarchy). 205 210 206 G4Region* GetParentRegion(G4bool& unique) 211 G4Region* GetParentRegion(G4bool& unique) const; 207 // Returns a region that contains this r 212 // Returns a region that contains this region. Otherwise null returned. 208 // Flag 'unique' is true if there is onl 213 // Flag 'unique' is true if there is only one parent region containing 209 // the current region. 214 // the current region. 210 215 211 void SetRegionalSteppingAction(G4UserStepp 216 void SetRegionalSteppingAction(G4UserSteppingAction* rusa); 212 G4UserSteppingAction* GetRegionalSteppingA 217 G4UserSteppingAction* GetRegionalSteppingAction() const; 213 // Set/Get method of the regional user s 218 // Set/Get method of the regional user stepping action 214 219 215 public: << 220 public: // without description 216 221 217 G4Region(__void__&); 222 G4Region(__void__&); 218 // Fake default constructor for usage re 223 // Fake default constructor for usage restricted to direct object 219 // persistency for clients requiring pre 224 // persistency for clients requiring preallocation of memory for 220 // persistifiable objects. 225 // persistifiable objects. 221 226 222 inline G4int GetInstanceID() const; 227 inline G4int GetInstanceID() const; 223 // Returns the instance ID. 228 // Returns the instance ID. 224 229 225 static const G4RegionManager& GetSubInstan 230 static const G4RegionManager& GetSubInstanceManager(); 226 // Returns the private data instance man 231 // Returns the private data instance manager. 227 232 228 static void Clean(); 233 static void Clean(); 229 // Clear memory allocated by sub-instanc 234 // Clear memory allocated by sub-instance manager. 230 235 231 inline void UsedInMassGeometry(G4bool val 236 inline void UsedInMassGeometry(G4bool val = true); 232 inline void UsedInParallelGeometry(G4bool 237 inline void UsedInParallelGeometry(G4bool val = true); 233 inline G4bool IsInMassGeometry() const; 238 inline G4bool IsInMassGeometry() const; 234 inline G4bool IsInParallelGeometry() const 239 inline G4bool IsInParallelGeometry() const; 235 // Utility methods to identify if region 240 // Utility methods to identify if region is part of the main mass 236 // geometry for tracking or a parallel g 241 // geometry for tracking or a parallel geometry. 237 242 238 private: 243 private: 239 244 240 inline void AddMaterial (G4Material* aMate 245 inline void AddMaterial (G4Material* aMaterial); 241 // Searchs the specified material in the 246 // Searchs the specified material in the material table and 242 // if not present adds it. 247 // if not present adds it. 243 248 244 private: 249 private: 245 << 246 using G4RootLVList = std::vector<G4Logical << 247 using G4MaterialList = std::vector<G4Mater << 248 using G4MaterialCouplePair = std::pair<G4M << 249 using G4MaterialCoupleMap = std::map<G4Mat << 250 250 251 G4String fName; 251 G4String fName; 252 252 253 G4RootLVList fRootVolumes; 253 G4RootLVList fRootVolumes; 254 G4MaterialList fMaterials; 254 G4MaterialList fMaterials; 255 G4MaterialCoupleMap fMaterialCoupleMap; 255 G4MaterialCoupleMap fMaterialCoupleMap; 256 256 257 G4bool fRegionMod = true; 257 G4bool fRegionMod = true; 258 G4ProductionCuts* fCut = nullptr; 258 G4ProductionCuts* fCut = nullptr; 259 259 260 G4VUserRegionInformation* fUserInfo = null 260 G4VUserRegionInformation* fUserInfo = nullptr; 261 G4UserLimits* fUserLimits = nullptr; 261 G4UserLimits* fUserLimits = nullptr; 262 G4FieldManager* fFieldManager = nullptr; 262 G4FieldManager* fFieldManager = nullptr; 263 263 264 G4VPhysicalVolume* fWorldPhys = nullptr; 264 G4VPhysicalVolume* fWorldPhys = nullptr; 265 265 266 G4bool fInMassGeometry = false; 266 G4bool fInMassGeometry = false; 267 G4bool fInParallelGeometry = false; 267 G4bool fInParallelGeometry = false; 268 268 269 G4int instanceID; 269 G4int instanceID; 270 // This field is used as instance ID. 270 // This field is used as instance ID. 271 G4GEOM_DLL static G4RegionManager subInsta 271 G4GEOM_DLL static G4RegionManager subInstanceManager; 272 // This field helps to use the class G4R 272 // This field helps to use the class G4RegionManager introduced above. 273 }; 273 }; 274 274 275 #include "G4Region.icc" 275 #include "G4Region.icc" 276 276 277 #endif 277 #endif 278 278