ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Region.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Region.hh
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
38 
39 #include <vector>
40 #include <map>
41 #include <algorithm>
42 
43 #include "G4Types.hh"
44 #include "G4String.hh"
45 #include "G4GeomSplitter.hh"
46 
47 class G4ProductionCuts;
48 class G4LogicalVolume;
49 class G4Material;
52 class G4UserLimits;
53 class G4FieldManager;
55 class G4VPhysicalVolume;
57 
59 {
60  // Encapsulates the fields associated to the class
61  // G4Region that may not be read-only.
62 
63  public:
64 
65  void initialize()
66  {
67  fFastSimulationManager = nullptr;
68  fRegionalSteppingAction = 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 
95 class G4Region
96 {
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
103 
104  G4Region(const G4String& name);
105  virtual ~G4Region();
106 
107  G4Region(const G4Region&) = delete;
108  G4Region& operator=(const G4Region&) = delete;
109  // Copy constructor and assignment operator not allowed.
110 
111  inline G4bool operator==(const G4Region& rg) const;
112  // Equality defined by address only.
113 
114  void AddRootLogicalVolume(G4LogicalVolume* lv, G4bool search=true);
115  void RemoveRootLogicalVolume(G4LogicalVolume* lv, G4bool scan=true);
116  // Add/remove root logical volumes and set/reset their
117  // daughters flags as regions. They also recompute the
118  // materials list for the region. Flag for scanning the subtree
119  // always enabled by default. Search in the tree can be turned off
120  // when adding, assuming the user guarantees the logical volume is
121  // NOT already inserted, in which case significant speedup can be
122  // achieved in very complex flat geometry setups.
123 
124  inline void SetName(const G4String& name);
125  inline const G4String& GetName() const;
126  // Set/get region's name.
127 
128  inline void RegionModified(G4bool flag);
129  inline G4bool IsModified() const;
130  // Accessors to flag identifying if a region has been modified
131  // (and still cuts needs to be computed) or not.
132 
133  inline void SetProductionCuts(G4ProductionCuts* cut);
134  inline G4ProductionCuts* GetProductionCuts() const;
135 
136  inline std::vector<G4LogicalVolume*>::iterator
138  inline std::vector<G4Material*>::const_iterator
139  GetMaterialIterator() const;
140  // Return iterators to lists of root logical volumes and materials.
141 
142  inline size_t GetNumberOfMaterials() const;
143  inline size_t GetNumberOfRootVolumes() const;
144  // Return the number of elements in the lists of materials and
145  // root logical volumes.
146 
147  void UpdateMaterialList();
148  // Clears material list and recomputes it looping through
149  // each root logical volume in the region.
150 
151  void ClearMaterialList();
152  // Clears the material list.
153 
154  void ScanVolumeTree(G4LogicalVolume* lv, G4bool region);
155  // Scans recursively the 'lv' logical volume tree, retrieves
156  // and places all materials in the list if becoming a region.
157 
160  // Set and Get methods for user information.
161 
162  inline void SetUserLimits(G4UserLimits* ul);
163  inline G4UserLimits* GetUserLimits() const;
164  // Set and Get methods for userL-limits associated to a region.
165  // Once user-limits are set, it will propagate to daughter volumes.
166 
167  inline void ClearMap();
168  // Reset G4MaterialCoupleMap
169 
171  G4MaterialCutsCouple* couple);
172  // Method invoked by G4ProductionCutsTable to register the pair.
173 
175  // Find a G4MaterialCutsCouple which corresponds to the material
176  // in this region.
177 
180  // Set and Get methods for G4FastSimulationManager.
181  // The root logical volume that has the region with G4FastSimulationManager
182  // becomes an envelope of fast simulation.
183 
185  // Set G4FastSimulationManager pointer to the one for the parent region
186  // if it exists. Otherwise set to null.
187 
188  inline void SetFieldManager(G4FieldManager* fm);
189  inline G4FieldManager* GetFieldManager() const;
190  // Set and Get methods for G4FieldManager.
191  // The region with assigned field-manager sets the field to the
192  // geometrical area associated with it; priority is anyhow given
193  // to local fields eventually set to logical volumes.
194 
195  inline G4VPhysicalVolume* GetWorldPhysical() const;
196  // Get method for the world physical volume which this region
197  // belongs to. A valid pointer will be assigned by G4RunManagerKernel
198  // through G4RegionStore when the geometry is to be closed. Thus, this
199  // pointer may be incorrect at PreInit and Idle state. If the pointer
200  // is null at the proper state, this particular region does not belong
201  // to any world (maybe not assigned to any volume, etc.).
202 
204  // Set the world physical volume if this region belongs to this world.
205  // If wp is null, reset the pointer.
206 
207  G4bool BelongsTo(G4VPhysicalVolume* thePhys) const;
208  // Returns whether this region belongs to the given physical volume
209  // (recursively scanned to the bottom of the hierarchy).
210 
211  G4Region* GetParentRegion(G4bool& unique) const;
212  // Returns a region that contains this region. Otherwise null returned.
213  // Flag 'unique' is true if there is only one parent region containing
214  // the current region.
215 
218  // Set/Get method of the regional user stepping action
219 
220  public: // without description
221 
222  G4Region(__void__&);
223  // Fake default constructor for usage restricted to direct object
224  // persistency for clients requiring preallocation of memory for
225  // persistifiable objects.
226 
227  inline G4int GetInstanceID() const;
228  // Returns the instance ID.
229 
230  static const G4RegionManager& GetSubInstanceManager();
231  // Returns the private data instance manager.
232 
233  static void Clean();
234  // Clear memory allocated by sub-instance manager.
235 
236  inline void UsedInMassGeometry(G4bool val = true);
237  inline void UsedInParallelGeometry(G4bool val = true);
238  inline G4bool IsInMassGeometry() const;
239  inline G4bool IsInParallelGeometry() const;
240  // Utility methods to identify if region is part of the main mass
241  // geometry for tracking or a parallel geometry.
242 
243  private:
244 
245  inline void AddMaterial (G4Material* aMaterial);
246  // Searchs the specified material in the material table and
247  // if not present adds it.
248 
249  private:
250 
252 
256 
258  G4ProductionCuts* fCut = nullptr;
259 
263 
265 
268 
270  // This field is used as instance ID.
272  // This field helps to use the class G4RegionManager introduced above.
273 };
274 
275 #include "G4Region.icc"
276 
277 #endif