Geant4 11.4.0
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// Author: Gabriele Cosmo (CERN), 18.09.2002
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
58/**
59 * @brief G4RegionData encapsulates the fields associated to the class
60 * G4Region that may not be read-only..
61 */
62
76
77// Encapsulate the methods used by both the master thread and worker threads
78// to allocate memory space for the fields encapsulated by the class
79// G4RegionData.
80//
82
83/**
84 * @brief G4Region defines a region or a group of regions in the detector
85 * geometry setup, sharing properties associated to materials or production
86 * cuts which may affect or bias specific physics processes.
87 */
88
90{
91 public:
92
93 /**
94 * Constructor for G4Region.
95 * @param[in] name The name of the region.
96 */
97 G4Region(const G4String& name);
98
99 /**
100 * Destructor.
101 */
102 ~G4Region();
103
104 /**
105 * Copy constructor and assignment operator not allowed.
106 */
107 G4Region(const G4Region&) = delete;
108 G4Region& operator=(const G4Region&) = delete;
109
110 /**
111 * Equality operator, defined by address only.
112 */
113 inline G4bool operator==(const G4Region& rg) const;
114
115 /**
116 * Adds a root logical volume and sets its daughters flags as regions.
117 * It also recompute the materials list for the region.
118 * Search in the tree can be turned off, assuming the user guarantees
119 * the logical volume is NOT already inserted, in which case significant
120 * speedup can be achieved in complex flat geometry setups.
121 * @param[in] lv Pointer to the logical volume to act as root region.
122 * @param[in] search To enable/disable search in the tree (default true).
123 */
124 void AddRootLogicalVolume(G4LogicalVolume* lv, G4bool search=true);
125
126 /**
127 * Removes a root logical volume and resets its daughters flags as regions.
128 * It also recompute the materials list for the region.
129 * The flag for scanning the subtree is always enabled by default.
130 * @param[in] lv Pointer to the logical volume to remove as root region.
131 * @param[in] scan To enable/disable scanning the tree (default true).
132 */
134
135 /**
136 * Setter/getter for the region's name.
137 */
138 void SetName(const G4String& name);
139 inline const G4String& GetName() const;
140
141 /**
142 * Accessors to flag identifying if a region has been modified (and still
143 * cuts needs to be computed) or not.
144 */
145 inline void RegionModified(G4bool flag);
146 inline G4bool IsModified() const;
147
148 /**
149 * Setter/getter for the production cuts values.
150 */
153
154 /**
155 * Methods to return iterators to the lists of root logical volumes
156 * and materials.
157 */
158 inline std::vector<G4LogicalVolume*>::iterator
160 inline std::vector<G4Material*>::const_iterator
162
163 /**
164 * Methods to return the number of elements in the lists of materials and
165 * root logical volumes.
166 */
167 inline std::size_t GetNumberOfMaterials() const;
168 inline std::size_t GetNumberOfRootVolumes() const;
169
170 /**
171 * Clears the material list and recomputes it, looping through each root
172 * logical volume in the region.
173 */
174 void UpdateMaterialList();
175
176 /**
177 * Clears the material list.
178 */
179 void ClearMaterialList();
180
181 /**
182 * Scans recursively the 'lv' logical volume tree, retrieves and places
183 * all materials in the list if becoming a region.
184 */
185 void ScanVolumeTree(G4LogicalVolume* lv, G4bool region);
186
187 /**
188 * Setter/getter for the user information data.
189 */
192
193 /**
194 * Setter/getter for the user-limits associated to a region.
195 * Once user-limits are set, it will propagate to the daughter volumes.
196 */
197 inline void SetUserLimits(G4UserLimits* ul);
199
200 /**
201 * Resets the material-cuts-couples map.
202 */
203 inline void ClearMap();
204
205 /**
206 * Method invoked by G4ProductionCutsTable to register the material-cuts
207 * couple pair.
208 */
210 G4MaterialCutsCouple* couple);
211
212 /**
213 * Finds a G4MaterialCutsCouple which corresponds to the material 'mat'
214 * in the region.
215 */
217
218 /**
219 * Setter/getter for the fast-simulation manager. The root logical volume
220 * that has the region with G4FastSimulationManager becomes an envelope of
221 * fast simulation.
222 */
225
226 /**
227 * Sets the G4FastSimulationManager pointer to the one for the parent
228 * region if it exists, otherwise it sets it to null.
229 */
231
232 /**
233 * Setter/getter for the field manager. The region with assigned
234 * field-manager sets the field to the geometrical area associated with
235 * it; priority is anyhow given to local fields eventually set to logical
236 * volumes.
237 */
240
241 /**
242 * Get method for the world physical volume which the region belongs to.
243 * A valid pointer will be assigned by G4RunManagerKernel through the
244 * G4RegionStore when the geometry is to be closed. Thus, this pointer
245 * may be incorrect at the PreInit and Idle state. If the pointer is null
246 * at the proper state, this particular region does not belong to any
247 * world (maybe not assigned to any volume, etc.).
248 */
250
251 /**
252 * Sets the world physical volume if the region belongs to this world.
253 * If 'wp' pointer is null, resets the pointer.
254 */
255 void SetWorld(G4VPhysicalVolume* wp);
256
257 /**
258 * Returns whether the region belongs to the given physical volume 'pv'
259 * (recursively scanned to the bottom of the hierarchy).
260 */
262
263 /**
264 * Returns a region that contains this region. Otherwise null returned.
265 * @param[out] unique Returns true if there is only one parent region
266 * containing the current region.
267 * @returns A pointer to the mother region.
268 */
270
271 /**
272 * Setter/getter methods for the regional user stepping action.
273 */
276
277 /**
278 * Fake default constructor for usage restricted to direct object
279 * persistency for clients requiring preallocation of memory for
280 * persistifiable objects.
281 */
282 G4Region(__void__&);
283
284 /**
285 * Returns the instance ID for multi-threading.
286 */
287 inline G4int GetInstanceID() const;
288
289 /**
290 * Returns the private data instance manager for multi-threading.
291 */
293
294 /**
295 * Clears the memory allocated by the MT sub-instance manager.
296 */
297 static void Clean();
298
299 /**
300 * Utility methods to identify if the region is part of the main mass
301 * geometry for tracking or part of a parallel geometry.
302 */
303 inline void UsedInMassGeometry(G4bool val = true);
304 inline void UsedInParallelGeometry(G4bool val = true);
305 inline G4bool IsInMassGeometry() const;
307
308 private:
309
310 /**
311 * Searchs the specified material 'aMaterial' in the material table and
312 * if not present adds it.
313 */
314 inline void AddMaterial (G4Material* aMaterial);
315
316 private:
317
318 using G4RootLVList = std::vector<G4LogicalVolume*>;
319 using G4MaterialList = std::vector<G4Material*>;
320 using G4MaterialCouplePair = std::pair<G4Material*, G4MaterialCutsCouple*>;
321 using G4MaterialCoupleMap = std::map<G4Material*, G4MaterialCutsCouple*>;
322
323 G4String fName;
324
325 G4RootLVList fRootVolumes;
326 G4MaterialList fMaterials;
327 G4MaterialCoupleMap fMaterialCoupleMap;
328
329 G4bool fRegionMod = true;
330 G4ProductionCuts* fCut = nullptr;
331
332 G4VUserRegionInformation* fUserInfo = nullptr;
333 G4UserLimits* fUserLimits = nullptr;
334 G4FieldManager* fFieldManager = nullptr;
335
336 G4VPhysicalVolume* fWorldPhys = nullptr;
337
338 G4bool fInMassGeometry = false;
339 G4bool fInParallelGeometry = false;
340
341 /** This field is used as instance ID. */
342 G4int instanceID;
343
344 /** This field helps to use the class G4RegionManager introduced above. */
345 G4GEOM_DLL static G4RegionManager subInstanceManager;
346};
347
348#include "G4Region.icc"
349
350// NOTE:
351//
352// The type G4RegionManager is introduced to encapsulate the methods used by
353// both the master thread and worker threads to allocate memory space for
354// the fields encapsulated by the class G4RegionData. When each thread
355// initializes the value for these fields, it refers to them using a macro
356// definition defined below. For every G4Region instance, there is a
357// corresponding G4RegionData instance. All G4RegionData instances are
358// organized by the class G4RegionManager as an array.
359// The field "int instanceID" is added to the class G4Region.
360// The value of this field in each G4Region instance is the subscript
361// of the corresponding G4RegionData instance.
362// In order to use the class G4RegionManager, we add a static member in
363// the class G4Region as follows: "static G4RegionManager subInstanceManager".
364// For the master thread, the array for G4RegionData instances grows
365// dynamically along with G4Region instances are created. For each worker
366// thread, it copies the array of G4RegionData instances from the master thread.
367// In addition, it invokes a method similiar to the constructor explicitly
368// to achieve the partial effect for each instance in the array.
369
370#endif
G4GeomSplitter< G4RegionData > G4RegionManager
Definition G4Region.hh:81
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4FieldManager is a manager (store) for a pointer to the Field subclass that describes the field of a...
G4GeomSplitter is an utility class for splitting of R/W data for thread-safety from geometry classes....
G4LogicalVolume represents a leaf node or unpositioned subtree in the geometry hierarchy....
G4RegionData encapsulates the fields associated to the class G4Region that may not be read-only....
Definition G4Region.hh:64
G4UserSteppingAction * fRegionalSteppingAction
Definition G4Region.hh:74
G4FastSimulationManager * fFastSimulationManager
Definition G4Region.hh:73
void initialize()
Definition G4Region.hh:67
G4int GetInstanceID() const
std::size_t GetNumberOfRootVolumes() const
G4bool IsModified() const
void ScanVolumeTree(G4LogicalVolume *lv, G4bool region)
Definition G4Region.cc:171
void ClearMaterialList()
Definition G4Region.cc:379
G4Region * GetParentRegion(G4bool &unique) const
Definition G4Region.cc:486
std::size_t GetNumberOfMaterials() const
G4FastSimulationManager * GetFastSimulationManager() const
Definition G4Region.cc:139
G4VUserRegionInformation * GetUserInformation() const
void SetWorld(G4VPhysicalVolume *wp)
Definition G4Region.cc:411
G4bool IsInParallelGeometry() const
G4FieldManager * GetFieldManager() const
G4ProductionCuts * GetProductionCuts() const
void RemoveRootLogicalVolume(G4LogicalVolume *lv, G4bool scan=true)
Definition G4Region.cc:341
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
G4bool BelongsTo(G4VPhysicalVolume *pv) const
Definition G4Region.cc:431
void UpdateMaterialList()
Definition G4Region.cc:390
G4Region(const G4String &name)
Definition G4Region.cc:65
void SetFastSimulationManager(G4FastSimulationManager *fsm)
Definition G4Region.cc:130
void ClearMap()
void SetUserInformation(G4VUserRegionInformation *ui)
void SetRegionalSteppingAction(G4UserSteppingAction *rusa)
Definition G4Region.cc:148
G4Region(const G4Region &)=delete
void SetName(const G4String &name)
Definition G4Region.cc:120
G4Region & operator=(const G4Region &)=delete
G4bool IsInMassGeometry() const
static const G4RegionManager & GetSubInstanceManager()
Definition G4Region.cc:55
G4UserSteppingAction * GetRegionalSteppingAction() const
Definition G4Region.cc:157
static void Clean()
Definition G4Region.cc:369
void ClearFastSimulationManager()
Definition G4Region.cc:451
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:292
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator()
void UsedInMassGeometry(G4bool val=true)
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4VUserRegionInformation is an abstract class, the user can subclass for storing information associat...
#define G4GEOM_DLL
Definition geomwdefs.hh:45
PUGI__FN I unique(I begin, I end)
Definition pugixml.cc:7592