Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Region.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// G4Region
27//
28// Class description:
29//
30// Defines a region or a group of regions in the detector geometry
31// setup, sharing properties associated to materials or production
32// cuts which may affect or bias specific physics processes.
33
34// 18.09.02, G.Cosmo - Initial version
35// --------------------------------------------------------------------
36#ifndef G4REGION_HH
37#define G4REGION_HH 1
38
39#include <vector>
40#include <map>
41#include <algorithm>
42
43#include "G4Types.hh"
44#include "G4String.hh"
45#include "G4GeomSplitter.hh"
46
48class G4LogicalVolume;
49class G4Material;
52class G4UserLimits;
53class G4FieldManager;
57
59{
60 // Encapsulates the fields associated to the class
61 // G4Region that may not be read-only.
62
63 public:
64
66 {
67 fFastSimulationManager = nullptr;
69 }
70
73};
74
75// The type G4RegionManager is introduced to encapsulate the methods used by
76// both the master thread and worker threads to allocate memory space for
77// the fields encapsulated by the class G4RegionData. When each thread
78// initializes the value for these fields, it refers to them using a macro
79// definition defined below. For every G4Region instance, there is a
80// corresponding G4RegionData instance. All G4RegionData instances are
81// organized by the class G4RegionManager as an array.
82// The field "int instanceID" is added to the class G4Region.
83// The value of this field in each G4Region instance is the subscript
84// of the corresponding G4RegionData instance.
85// In order to use the class G4RegionManager, we add a static member in
86// the class G4Region as follows: "static G4RegionManager subInstanceManager".
87// For the master thread, the array for G4RegionData instances grows
88// dynamically along with G4Region instances are created. For each worker
89// thread, it copies the array of G4RegionData instances from the master thread.
90// In addition, it invokes a method similiar to the constructor explicitly
91// to achieve the partial effect for each instance in the array.
92//
94
96{
97 public:
98
99 G4Region(const G4String& name);
100 virtual ~G4Region();
101
102 G4Region(const G4Region&) = delete;
103 G4Region& operator=(const G4Region&) = delete;
104 // Copy constructor and assignment operator not allowed.
105
106 inline G4bool operator==(const G4Region& rg) const;
107 // Equality defined by address only.
108
109 void AddRootLogicalVolume(G4LogicalVolume* lv, G4bool search=true);
111 // Add/remove root logical volumes and set/reset their
112 // daughters flags as regions. They also recompute the
113 // materials list for the region. Flag for scanning the subtree
114 // always enabled by default. Search in the tree can be turned off
115 // when adding, assuming the user guarantees the logical volume is
116 // NOT already inserted, in which case significant speedup can be
117 // achieved in very complex flat geometry setups.
118
119 void SetName(const G4String& name);
120 inline const G4String& GetName() const;
121 // Set/get region's name.
122
123 inline void RegionModified(G4bool flag);
124 inline G4bool IsModified() const;
125 // Accessors to flag identifying if a region has been modified
126 // (and still cuts needs to be computed) or not.
127
130
131 inline std::vector<G4LogicalVolume*>::iterator
133 inline std::vector<G4Material*>::const_iterator
135 // Return iterators to lists of root logical volumes and materials.
136
137 inline std::size_t GetNumberOfMaterials() const;
138 inline std::size_t GetNumberOfRootVolumes() const;
139 // Return the number of elements in the lists of materials and
140 // root logical volumes.
141
142 void UpdateMaterialList();
143 // Clears material list and recomputes it looping through
144 // each root logical volume in the region.
145
146 void ClearMaterialList();
147 // Clears the material list.
148
149 void ScanVolumeTree(G4LogicalVolume* lv, G4bool region);
150 // Scans recursively the 'lv' logical volume tree, retrieves
151 // and places all materials in the list if becoming a region.
152
155 // Set and Get methods for user information.
156
157 inline void SetUserLimits(G4UserLimits* ul);
159 // Set and Get methods for userL-limits associated to a region.
160 // Once user-limits are set, it will propagate to daughter volumes.
161
162 inline void ClearMap();
163 // Reset G4MaterialCoupleMap
164
166 G4MaterialCutsCouple* couple);
167 // Method invoked by G4ProductionCutsTable to register the pair.
168
170 // Find a G4MaterialCutsCouple which corresponds to the material
171 // in this region.
172
175 // Set and Get methods for G4FastSimulationManager.
176 // The root logical volume that has the region with G4FastSimulationManager
177 // becomes an envelope of fast simulation.
178
180 // Set G4FastSimulationManager pointer to the one for the parent region
181 // if it exists. Otherwise set to null.
182
185 // Set and Get methods for G4FieldManager.
186 // The region with assigned field-manager sets the field to the
187 // geometrical area associated with it; priority is anyhow given
188 // to local fields eventually set to logical volumes.
189
191 // Get method for the world physical volume which this region
192 // belongs to. A valid pointer will be assigned by G4RunManagerKernel
193 // through G4RegionStore when the geometry is to be closed. Thus, this
194 // pointer may be incorrect at PreInit and Idle state. If the pointer
195 // is null at the proper state, this particular region does not belong
196 // to any world (maybe not assigned to any volume, etc.).
197
198 void SetWorld(G4VPhysicalVolume* wp);
199 // Set the world physical volume if this region belongs to this world.
200 // If wp is null, reset the pointer.
201
202 G4bool BelongsTo(G4VPhysicalVolume* thePhys) const;
203 // Returns whether this region belongs to the given physical volume
204 // (recursively scanned to the bottom of the hierarchy).
205
206 G4Region* GetParentRegion(G4bool& unique) const;
207 // Returns a region that contains this region. Otherwise null returned.
208 // Flag 'unique' is true if there is only one parent region containing
209 // the current region.
210
213 // Set/Get method of the regional user stepping action
214
215 public:
216
217 G4Region(__void__&);
218 // Fake default constructor for usage restricted to direct object
219 // persistency for clients requiring preallocation of memory for
220 // persistifiable objects.
221
222 inline G4int GetInstanceID() const;
223 // Returns the instance ID.
224
226 // Returns the private data instance manager.
227
228 static void Clean();
229 // Clear memory allocated by sub-instance manager.
230
231 inline void UsedInMassGeometry(G4bool val = true);
232 inline void UsedInParallelGeometry(G4bool val = true);
233 inline G4bool IsInMassGeometry() const;
235 // Utility methods to identify if region is part of the main mass
236 // geometry for tracking or a parallel geometry.
237
238 private:
239
240 inline void AddMaterial (G4Material* aMaterial);
241 // Searchs the specified material in the material table and
242 // if not present adds it.
243
244 private:
245
246 using G4RootLVList = std::vector<G4LogicalVolume*>;
247 using G4MaterialList = std::vector<G4Material*>;
248 using G4MaterialCouplePair = std::pair<G4Material*, G4MaterialCutsCouple*>;
249 using G4MaterialCoupleMap = std::map<G4Material*, G4MaterialCutsCouple*>;
250
251 G4String fName;
252
253 G4RootLVList fRootVolumes;
254 G4MaterialList fMaterials;
255 G4MaterialCoupleMap fMaterialCoupleMap;
256
257 G4bool fRegionMod = true;
258 G4ProductionCuts* fCut = nullptr;
259
260 G4VUserRegionInformation* fUserInfo = nullptr;
261 G4UserLimits* fUserLimits = nullptr;
262 G4FieldManager* fFieldManager = nullptr;
263
264 G4VPhysicalVolume* fWorldPhys = nullptr;
265
266 G4bool fInMassGeometry = false;
267 G4bool fInParallelGeometry = false;
268
269 G4int instanceID;
270 // This field is used as instance ID.
271 G4GEOM_DLL static G4RegionManager subInstanceManager;
272 // This field helps to use the class G4RegionManager introduced above.
273};
274
275#include "G4Region.icc"
276
277#endif
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4UserSteppingAction * fRegionalSteppingAction
Definition: G4Region.hh:72
G4FastSimulationManager * fFastSimulationManager
Definition: G4Region.hh:71
void initialize()
Definition: G4Region.hh:65
G4int GetInstanceID() const
std::size_t GetNumberOfRootVolumes() const
G4bool IsModified() const
G4bool BelongsTo(G4VPhysicalVolume *thePhys) const
Definition: G4Region.cc:414
void ScanVolumeTree(G4LogicalVolume *lv, G4bool region)
Definition: G4Region.cc:172
void ClearMaterialList()
Definition: G4Region.cc:366
G4Region * GetParentRegion(G4bool &unique) const
Definition: G4Region.cc:469
std::size_t GetNumberOfMaterials() const
G4FastSimulationManager * GetFastSimulationManager() const
Definition: G4Region.cc:140
virtual ~G4Region()
Definition: G4Region.cc:111
G4VUserRegionInformation * GetUserInformation() const
void SetWorld(G4VPhysicalVolume *wp)
Definition: G4Region.cc:398
G4bool IsInParallelGeometry() const
G4FieldManager * GetFieldManager() const
G4ProductionCuts * GetProductionCuts() const
void RemoveRootLogicalVolume(G4LogicalVolume *lv, G4bool scan=true)
Definition: G4Region.cc:328
G4MaterialCutsCouple * FindCouple(G4Material *mat)
void SetFieldManager(G4FieldManager *fm)
G4bool operator==(const G4Region &rg) const
void RegionModified(G4bool flag)
G4VPhysicalVolume * GetWorldPhysical() const
void SetProductionCuts(G4ProductionCuts *cut)
G4UserLimits * GetUserLimits() const
const G4String & GetName() const
void UpdateMaterialList()
Definition: G4Region.cc:377
void SetFastSimulationManager(G4FastSimulationManager *fsm)
Definition: G4Region.cc:131
void ClearMap()
void SetUserInformation(G4VUserRegionInformation *ui)
void SetRegionalSteppingAction(G4UserSteppingAction *rusa)
Definition: G4Region.cc:149
G4Region(const G4Region &)=delete
void SetName(const G4String &name)
Definition: G4Region.cc:121
G4Region & operator=(const G4Region &)=delete
G4bool IsInMassGeometry() const
static const G4RegionManager & GetSubInstanceManager()
Definition: G4Region.cc:55
G4UserSteppingAction * GetRegionalSteppingAction() const
Definition: G4Region.cc:158
static void Clean()
Definition: G4Region.cc:356
void ClearFastSimulationManager()
Definition: G4Region.cc:434
void UsedInParallelGeometry(G4bool val=true)
void RegisterMaterialCouplePair(G4Material *mat, G4MaterialCutsCouple *couple)
std::vector< G4Material * >::const_iterator GetMaterialIterator() const
void SetUserLimits(G4UserLimits *ul)
void AddRootLogicalVolume(G4LogicalVolume *lv, G4bool search=true)
Definition: G4Region.cc:293
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator()
void UsedInMassGeometry(G4bool val=true)
#define G4GEOM_DLL
Definition: geomwdefs.hh:44