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