Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Region Class Reference

G4Region defines a region or a group of regions in the detector geometry setup, sharing properties associated to materials or production cuts which may affect or bias specific physics processes. More...

#include <G4Region.hh>

Public Member Functions

 G4Region (const G4String &name)
 ~G4Region ()
 G4Region (const G4Region &)=delete
G4Regionoperator= (const G4Region &)=delete
G4bool operator== (const G4Region &rg) const
void AddRootLogicalVolume (G4LogicalVolume *lv, G4bool search=true)
void RemoveRootLogicalVolume (G4LogicalVolume *lv, G4bool scan=true)
void SetName (const G4String &name)
const G4StringGetName () const
void RegionModified (G4bool flag)
G4bool IsModified () const
void SetProductionCuts (G4ProductionCuts *cut)
G4ProductionCutsGetProductionCuts () const
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator ()
std::vector< G4Material * >::const_iterator GetMaterialIterator () const
std::size_t GetNumberOfMaterials () const
std::size_t GetNumberOfRootVolumes () const
void UpdateMaterialList ()
void ClearMaterialList ()
void ScanVolumeTree (G4LogicalVolume *lv, G4bool region)
void SetUserInformation (G4VUserRegionInformation *ui)
G4VUserRegionInformationGetUserInformation () const
void SetUserLimits (G4UserLimits *ul)
G4UserLimitsGetUserLimits () const
void ClearMap ()
void RegisterMaterialCouplePair (G4Material *mat, G4MaterialCutsCouple *couple)
G4MaterialCutsCoupleFindCouple (G4Material *mat)
void SetFastSimulationManager (G4FastSimulationManager *fsm)
G4FastSimulationManagerGetFastSimulationManager () const
void ClearFastSimulationManager ()
void SetFieldManager (G4FieldManager *fm)
G4FieldManagerGetFieldManager () const
G4VPhysicalVolumeGetWorldPhysical () const
void SetWorld (G4VPhysicalVolume *wp)
G4bool BelongsTo (G4VPhysicalVolume *pv) const
G4RegionGetParentRegion (G4bool &unique) const
void SetRegionalSteppingAction (G4UserSteppingAction *rusa)
G4UserSteppingActionGetRegionalSteppingAction () const
 G4Region (__void__ &)
G4int GetInstanceID () const
void UsedInMassGeometry (G4bool val=true)
void UsedInParallelGeometry (G4bool val=true)
G4bool IsInMassGeometry () const
G4bool IsInParallelGeometry () const

Static Public Member Functions

static const G4RegionManagerGetSubInstanceManager ()
static void Clean ()

Detailed Description

G4Region defines a region or a group of regions in the detector geometry setup, sharing properties associated to materials or production cuts which may affect or bias specific physics processes.

Definition at line 89 of file G4Region.hh.

Constructor & Destructor Documentation

◆ G4Region() [1/3]

G4Region::G4Region ( const G4String & name)

Constructor for G4Region.

Parameters
[in]nameThe name of the region.

Definition at line 65 of file G4Region.cc.

66 : fName(pName)
67{
68 instanceID = subInstanceManager.CreateSubInstance();
69 G4MT_fsmanager = nullptr;
70 G4MT_rsaction = nullptr;
71
72 G4RegionStore* rStore = G4RegionStore::GetInstance();
73 if (rStore->GetRegion(pName, false) != nullptr)
74 {
75 std::ostringstream message;
76 message << "The region has NOT been registered !" << G4endl
77 << " Region " << pName << " already existing in store !"
78 << G4endl;
79 G4Exception("G4Region::G4Region()", "GeomMgt1001",
80 JustWarning, message);
81 }
82 else
83 {
84 rStore->Register(this);
85 }
86}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define G4MT_rsaction
Definition G4Region.cc:44
#define G4MT_fsmanager
Definition G4Region.cc:43
#define G4endl
Definition G4ios.hh:67
static void Register(G4Region *pRegion)
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const

Referenced by ClearFastSimulationManager(), G4Region(), GetParentRegion(), GetWorldPhysical(), operator=(), operator==(), and ScanVolumeTree().

◆ ~G4Region()

G4Region::~G4Region ( )

Destructor.

Definition at line 110 of file G4Region.cc.

111{
113 delete fUserInfo;
114}
static void DeRegister(G4Region *pRegion)

◆ G4Region() [2/3]

G4Region::G4Region ( const G4Region & )
delete

Copy constructor and assignment operator not allowed.

◆ G4Region() [3/3]

G4Region::G4Region ( __void__ & )

Fake default constructor for usage restricted to direct object persistency for clients requiring preallocation of memory for persistifiable objects.

Definition at line 93 of file G4Region.cc.

94 : fName("")
95{
96 instanceID = subInstanceManager.CreateSubInstance();
97 G4MT_fsmanager = nullptr;
98 G4MT_rsaction = nullptr;
99
100 // Register to store
101 //
103}

Member Function Documentation

◆ AddRootLogicalVolume()

void G4Region::AddRootLogicalVolume ( G4LogicalVolume * lv,
G4bool search = true )

Adds a root logical volume and sets its daughters flags as regions. It also recompute the materials list for the region. Search in the tree can be turned off, assuming the user guarantees the logical volume is NOT already inserted, in which case significant speedup can be achieved in complex flat geometry setups.

Parameters
[in]lvPointer to the logical volume to act as root region.
[in]searchTo enable/disable search in the tree (default true).

Definition at line 292 of file G4Region.cc.

293{
294 // Check if logical volume is already belonging to another region
295 //
296 if ((lv->IsRootRegion()) && (lv->GetRegion() != this))
297 {
298 std::ostringstream message;
299 message << "Logical volume <" << lv->GetName() << "> is already set as" << G4endl
300 << "root for region <" << lv->GetRegion()->GetName() << ">." << G4endl
301 << "It cannot be root logical volume for another region <" << GetName()
302 << ">" << G4endl;
303 G4Exception("G4Region::AddRootLogicalVolume()", "GeomMgt0002", FatalException,
304 message, "A logical volume cannot belong to more than one region!");
305 return;
306 }
307
308 // Check the logical volume is not already in the list
309 //
310 if (search)
311 {
312 auto pos = std::find(fRootVolumes.cbegin(),fRootVolumes.cend(),lv);
313 if (pos == fRootVolumes.cend())
314 {
315 // Insert the root volume in the list and set it as root region
316 //
317 fRootVolumes.push_back(lv);
318 lv->SetRegionRootFlag(true);
319 }
320 }
321 else // WARNING: user *MUST* guarantee lv is not already inserted.
322 { // Providing speedup for very complex flat geometries
323 fRootVolumes.push_back(lv);
324 lv->SetRegionRootFlag(true);
325 }
326 // Scan recursively the tree of daugther volumes and set regions
327 //
328 ScanVolumeTree(lv, true);
329
330 // Set region as modified
331 //
332 fRegionMod = true;
333}
@ FatalException
void SetRegionRootFlag(G4bool rreg)
G4bool IsRootRegion() const
G4Region * GetRegion() const
const G4String & GetName() const
void ScanVolumeTree(G4LogicalVolume *lv, G4bool region)
Definition G4Region.cc:171
const G4String & GetName() const

◆ BelongsTo()

G4bool G4Region::BelongsTo ( G4VPhysicalVolume * pv) const

Returns whether the region belongs to the given physical volume 'pv' (recursively scanned to the bottom of the hierarchy).

Definition at line 431 of file G4Region.cc.

432{
433 G4LogicalVolume* currLog = thePhys->GetLogicalVolume();
434 if (currLog->GetRegion()==this) {return true;}
435
436 std::size_t nDaughters = currLog->GetNoDaughters();
437 while ((nDaughters--) != 0) // Loop checking, 06.08.2015, G.Cosmo
438 {
439 if (BelongsTo(currLog->GetDaughter(nDaughters))) {return true;}
440 }
441
442 return false;
443}
std::size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const std::size_t i) const
G4bool BelongsTo(G4VPhysicalVolume *pv) const
Definition G4Region.cc:431

Referenced by BelongsTo(), and SetWorld().

◆ Clean()

void G4Region::Clean ( )
static

Clears the memory allocated by the MT sub-instance manager.

Definition at line 369 of file G4Region.cc.

370{
371 subInstanceManager.FreeSlave();
372}

Referenced by G4RegionStore::~G4RegionStore().

◆ ClearFastSimulationManager()

void G4Region::ClearFastSimulationManager ( )

Sets the G4FastSimulationManager pointer to the one for the parent region if it exists, otherwise it sets it to null.

Definition at line 451 of file G4Region.cc.

452{
453 G4bool isUnique;
454 G4Region* parent = GetParentRegion(isUnique);
455 if(parent != nullptr)
456 {
457 if (isUnique)
458 {
460 }
461 else
462 {
463 std::ostringstream message;
464 message << "Region <" << fName << "> belongs to more than"
465 << " one parent region !" << G4endl
466 << "A region cannot belong to more than one direct parent region,"
467 << G4endl
468 << "to have fast-simulation assigned.";
469 G4Exception("G4Region::ClearFastSimulationManager()",
470 "GeomMgt1002", JustWarning, message);
471 G4MT_fsmanager = nullptr;
472 }
473 }
474 else
475 {
476 G4MT_fsmanager = nullptr;
477 }
478}
bool G4bool
Definition G4Types.hh:86
G4Region * GetParentRegion(G4bool &unique) const
Definition G4Region.cc:486
G4FastSimulationManager * GetFastSimulationManager() const
Definition G4Region.cc:139
G4Region(const G4String &name)
Definition G4Region.cc:65

◆ ClearMap()

void G4Region::ClearMap ( )
inline

Resets the material-cuts-couples map.

◆ ClearMaterialList()

void G4Region::ClearMaterialList ( )

Clears the material list.

Definition at line 379 of file G4Region.cc.

380{
381 fMaterials.clear();
382}

Referenced by UpdateMaterialList().

◆ FindCouple()

G4MaterialCutsCouple * G4Region::FindCouple ( G4Material * mat)
inline

Finds a G4MaterialCutsCouple which corresponds to the material 'mat' in the region.

Referenced by G4EmUtility::FillFluctFlags().

◆ GetFastSimulationManager()

◆ GetFieldManager()

G4FieldManager * G4Region::GetFieldManager ( ) const
inline

◆ GetInstanceID()

G4int G4Region::GetInstanceID ( ) const
inline

Returns the instance ID for multi-threading.

◆ GetMaterialIterator()

std::vector< G4Material * >::const_iterator G4Region::GetMaterialIterator ( ) const
inline

◆ GetName()

◆ GetNumberOfMaterials()

std::size_t G4Region::GetNumberOfMaterials ( ) const
inline

Methods to return the number of elements in the lists of materials and root logical volumes.

Referenced by G4RunManagerKernel::DumpRegion().

◆ GetNumberOfRootVolumes()

std::size_t G4Region::GetNumberOfRootVolumes ( ) const
inline

◆ GetParentRegion()

G4Region * G4Region::GetParentRegion ( G4bool & unique) const

Returns a region that contains this region. Otherwise null returned.

Parameters
[out]uniqueReturns true if there is only one parent region containing the current region.
Returns
A pointer to the mother region.

Definition at line 486 of file G4Region.cc.

487{
488 G4Region* parent = nullptr; unique = true;
489 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
490
491 // Loop over all logical volumes in the store
492 //
493 for(const auto & lvol : *lvStore)
494 {
495 std::size_t nD = lvol->GetNoDaughters();
496 G4Region* aR = lvol->GetRegion();
497
498 // Loop over all daughters of each logical volume
499 //
500 for(std::size_t iD=0; iD<nD; ++iD)
501 {
502 if(lvol->GetDaughter(iD)->GetLogicalVolume()->GetRegion()==this)
503 {
504 if(parent != nullptr)
505 {
506 if(parent!=aR) { unique = false; }
507 }
508 else // Cache LV parent region which includes a daughter volume
509 // with the same associated region as the current one
510 {
511 parent = aR;
512 }
513 }
514 }
515 }
516 return parent;
517}
static G4LogicalVolumeStore * GetInstance()
PUGI__FN I unique(I begin, I end)
Definition pugixml.cc:7592

Referenced by ClearFastSimulationManager().

◆ GetProductionCuts()

◆ GetRegionalSteppingAction()

G4UserSteppingAction * G4Region::GetRegionalSteppingAction ( ) const

Definition at line 157 of file G4Region.cc.

158{
159 return G4MT_rsaction;
160}

Referenced by G4RunManagerKernel::DumpRegion().

◆ GetRootLogicalVolumeIterator()

std::vector< G4LogicalVolume * >::iterator G4Region::GetRootLogicalVolumeIterator ( )
inline

Methods to return iterators to the lists of root logical volumes and materials.

Referenced by G4RunManagerKernel::DumpRegion().

◆ GetSubInstanceManager()

const G4RegionManager & G4Region::GetSubInstanceManager ( )
static

Returns the private data instance manager for multi-threading.

Definition at line 55 of file G4Region.cc.

56{
57 return subInstanceManager;
58}

Referenced by G4GeometryWorkspace::G4GeometryWorkspace().

◆ GetUserInformation()

G4VUserRegionInformation * G4Region::GetUserInformation ( ) const
inline

◆ GetUserLimits()

G4UserLimits * G4Region::GetUserLimits ( ) const
inline

◆ GetWorldPhysical()

G4VPhysicalVolume * G4Region::GetWorldPhysical ( ) const
inline

Get method for the world physical volume which the region belongs to. A valid pointer will be assigned by G4RunManagerKernel through the G4RegionStore when the geometry is to be closed. Thus, this pointer may be incorrect at the PreInit and Idle state. If the pointer is null at the proper state, this particular region does not belong to any world (maybe not assigned to any volume, etc.).

Referenced by G4RunManagerKernel::DumpRegion().

◆ IsInMassGeometry()

G4bool G4Region::IsInMassGeometry ( ) const
inline

◆ IsInParallelGeometry()

G4bool G4Region::IsInParallelGeometry ( ) const
inline

◆ IsModified()

G4bool G4Region::IsModified ( ) const
inline

◆ operator=()

G4Region & G4Region::operator= ( const G4Region & )
delete

◆ operator==()

G4bool G4Region::operator== ( const G4Region & rg) const
inline

Equality operator, defined by address only.

◆ RegionModified()

void G4Region::RegionModified ( G4bool flag)
inline

Accessors to flag identifying if a region has been modified (and still cuts needs to be computed) or not.

◆ RegisterMaterialCouplePair()

void G4Region::RegisterMaterialCouplePair ( G4Material * mat,
G4MaterialCutsCouple * couple )
inline

Method invoked by G4ProductionCutsTable to register the material-cuts couple pair.

◆ RemoveRootLogicalVolume()

void G4Region::RemoveRootLogicalVolume ( G4LogicalVolume * lv,
G4bool scan = true )

Removes a root logical volume and resets its daughters flags as regions. It also recompute the materials list for the region. The flag for scanning the subtree is always enabled by default.

Parameters
[in]lvPointer to the logical volume to remove as root region.
[in]scanTo enable/disable scanning the tree (default true).

Definition at line 341 of file G4Region.cc.

342{
343 // Find and remove logical volume from the list
344 //
345 auto pos = std::find(fRootVolumes.cbegin(),fRootVolumes.cend(),lv);
346 if (pos != fRootVolumes.cend())
347 {
348 if (fRootVolumes.size() != 1) // Avoid resetting flag for world since
349 { // volume may be already deleted !
350 lv->SetRegionRootFlag(false);
351 }
352 fRootVolumes.erase(pos);
353 }
354
355 if (scan) // Update the materials list
356 {
358 }
359
360 // Set region as modified
361 //
362 fRegionMod = true;
363}
void UpdateMaterialList()
Definition G4Region.cc:390

◆ ScanVolumeTree()

void G4Region::ScanVolumeTree ( G4LogicalVolume * lv,
G4bool region )

Scans recursively the 'lv' logical volume tree, retrieves and places all materials in the list if becoming a region.

Definition at line 171 of file G4Region.cc.

172{
173 // If logical volume is going to become a region, add
174 // its material to the list if not already present
175 //
176 G4Region* currentRegion = nullptr;
177 std::size_t noDaughters = lv->GetNoDaughters();
178 G4Material* volMat = lv->GetMaterial();
179 if((volMat == nullptr) && fInMassGeometry)
180 {
181 std::ostringstream message;
182 message << "Logical volume <" << lv->GetName() << ">" << G4endl
183 << "does not have a valid material pointer." << G4endl
184 << "A logical volume belonging to the (tracking) world volume "
185 << "must have a valid material.";
186 G4Exception("G4Region::ScanVolumeTree()", "GeomMgt0002",
187 FatalException, message, "Check your geometry construction.");
188 }
189 if (region)
190 {
191 currentRegion = this;
192 if (volMat != nullptr)
193 {
194 AddMaterial(volMat);
195 auto baseMat = const_cast<G4Material*>(volMat->GetBaseMaterial());
196 if (baseMat != nullptr) { AddMaterial(baseMat); }
197 }
198 }
199
200 // Set the LV region to be either the current region or NULL,
201 // according to the boolean selector
202 //
203 lv->SetRegion(currentRegion);
204
205 // Stop recursion here if no further daughters are involved
206 //
207 if(noDaughters==0) { return; }
208
209 G4VPhysicalVolume* daughterPVol = lv->GetDaughter(0);
210 if (daughterPVol->IsParameterised())
211 {
212 // Adopt special treatment in case of parameterised volumes,
213 // where parameterisation involves a new material scan
214 //
215 G4VPVParameterisation* pParam = daughterPVol->GetParameterisation();
216
217 if (pParam->GetMaterialScanner() != nullptr)
218 {
219 std::size_t matNo = pParam->GetMaterialScanner()->GetNumberOfMaterials();
220 for (std::size_t mat=0; mat<matNo; ++mat)
221 {
222 volMat = pParam->GetMaterialScanner()->GetMaterial((G4int)mat);
223 if((volMat == nullptr) && fInMassGeometry)
224 {
225 std::ostringstream message;
226 message << "The parameterisation for the physical volume <"
227 << daughterPVol->GetName() << ">" << G4endl
228 << "does not return a valid material pointer." << G4endl
229 << "A volume belonging to the (tracking) world volume must "
230 << "have a valid material.";
231 G4Exception("G4Region::ScanVolumeTree()", "GeomMgt0002",
232 FatalException, message, "Check your parameterisation.");
233 }
234 if (volMat != nullptr)
235 {
236 AddMaterial(volMat);
237 auto baseMat = const_cast<G4Material*>(volMat->GetBaseMaterial());
238 if (baseMat != nullptr) { AddMaterial(baseMat); }
239 }
240 }
241 }
242 else
243 {
244 std::size_t repNo = daughterPVol->GetMultiplicity();
245 for (std::size_t rep=0; rep<repNo; ++rep)
246 {
247 volMat = pParam->ComputeMaterial((G4int)rep, daughterPVol);
248 if((volMat == nullptr) && fInMassGeometry)
249 {
250 std::ostringstream message;
251 message << "The parameterisation for the physical volume <"
252 << daughterPVol->GetName() << ">" << G4endl
253 << "does not return a valid material pointer." << G4endl
254 << "A volume belonging to the (tracking) world volume must "
255 << "have a valid material.";
256 G4Exception("G4Region::ScanVolumeTree()", "GeomMgt0002",
257 FatalException, message, "Check your parameterisation.");
258 }
259 if(volMat != nullptr)
260 {
261 AddMaterial(volMat);
262 auto baseMat = const_cast<G4Material*>(volMat->GetBaseMaterial());
263 if (baseMat != nullptr) { AddMaterial(baseMat); }
264 }
265 }
266 }
267 G4LogicalVolume* daughterLVol = daughterPVol->GetLogicalVolume();
268 ScanVolumeTree(daughterLVol, region);
269 }
270 else
271 {
272 for (std::size_t i=0; i<noDaughters; ++i)
273 {
274 G4LogicalVolume* daughterLVol = lv->GetDaughter(i)->GetLogicalVolume();
275 if (!daughterLVol->IsRootRegion())
276 {
277 // Set daughter's LV to be a region and store materials in
278 // the materials list, if the LV is not already a root region
279 //
280 ScanVolumeTree(daughterLVol, region);
281 }
282 }
283 }
284}
int G4int
Definition G4Types.hh:85
void SetRegion(G4Region *reg)
G4Material * GetMaterial() const
const G4Material * GetBaseMaterial() const
virtual G4VVolumeMaterialScanner * GetMaterialScanner()
virtual G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=nullptr)
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetMultiplicity() const
const G4String & GetName() const
virtual G4VPVParameterisation * GetParameterisation() const =0
virtual G4bool IsParameterised() const =0
virtual G4Material * GetMaterial(G4int idx) const =0
virtual G4int GetNumberOfMaterials() const =0

Referenced by AddRootLogicalVolume(), ScanVolumeTree(), and UpdateMaterialList().

◆ SetFastSimulationManager()

void G4Region::SetFastSimulationManager ( G4FastSimulationManager * fsm)

Setter/getter for the fast-simulation manager. The root logical volume that has the region with G4FastSimulationManager becomes an envelope of fast simulation.

Definition at line 130 of file G4Region.cc.

131{
132 G4MT_fsmanager = fsm;
133}

Referenced by G4FastSimulationManager::G4FastSimulationManager().

◆ SetFieldManager()

void G4Region::SetFieldManager ( G4FieldManager * fm)
inline

Setter/getter for the field manager. The region with assigned field-manager sets the field to the geometrical area associated with it; priority is anyhow given to local fields eventually set to logical volumes.

◆ SetName()

void G4Region::SetName ( const G4String & name)

Setter/getter for the region's name.

Definition at line 120 of file G4Region.cc.

121{
122 fName = pName;
124}
void SetMapValid(G4bool val)

◆ SetProductionCuts()

void G4Region::SetProductionCuts ( G4ProductionCuts * cut)
inline

Setter/getter for the production cuts values.

Referenced by G4RunManagerKernel::DumpRegion(), and G4VUserPhysicsList::SetParticleCuts().

◆ SetRegionalSteppingAction()

void G4Region::SetRegionalSteppingAction ( G4UserSteppingAction * rusa)

Setter/getter methods for the regional user stepping action.

Definition at line 148 of file G4Region.cc.

149{
150 G4MT_rsaction = rusa;
151}

◆ SetUserInformation()

void G4Region::SetUserInformation ( G4VUserRegionInformation * ui)
inline

Setter/getter for the user information data.

◆ SetUserLimits()

void G4Region::SetUserLimits ( G4UserLimits * ul)
inline

Setter/getter for the user-limits associated to a region. Once user-limits are set, it will propagate to the daughter volumes.

◆ SetWorld()

void G4Region::SetWorld ( G4VPhysicalVolume * wp)

Sets the world physical volume if the region belongs to this world. If 'wp' pointer is null, resets the pointer.

Definition at line 411 of file G4Region.cc.

412{
413 if(wp == nullptr)
414 {
415 fWorldPhys = nullptr;
416 }
417 else
418 {
419 if(BelongsTo(wp)) { fWorldPhys = wp; }
420 }
421
422 return;
423}

◆ UpdateMaterialList()

void G4Region::UpdateMaterialList ( )

Clears the material list and recomputes it, looping through each root logical volume in the region.

Definition at line 390 of file G4Region.cc.

391{
392 // Reset the materials list
393 //
395
396 // Loop over the root logical volumes and rebuild the list
397 // of materials from scratch
398 //
399 for (const auto & rootVolume : fRootVolumes)
400 {
401 ScanVolumeTree(rootVolume, true);
402 }
403}
void ClearMaterialList()
Definition G4Region.cc:379

Referenced by RemoveRootLogicalVolume().

◆ UsedInMassGeometry()

void G4Region::UsedInMassGeometry ( G4bool val = true)
inline

Utility methods to identify if the region is part of the main mass geometry for tracking or part of a parallel geometry.

◆ UsedInParallelGeometry()

void G4Region::UsedInParallelGeometry ( G4bool val = true)
inline

The documentation for this class was generated from the following files: