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

#include <G4Region.hh>

Public Member Functions

 G4Region (const G4String &name)
 
virtual ~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 *thePhys) 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

Definition at line 95 of file G4Region.hh.

Constructor & Destructor Documentation

◆ G4Region() [1/3]

G4Region::G4Region ( const G4String & name)

Definition at line 65 of file G4Region.cc.

66 : fName(pName)
67{
68
69 instanceID = subInstanceManager.CreateSubInstance();
70 G4MT_fsmanager = nullptr;
71 G4MT_rsaction = nullptr;
72
74 if (rStore->GetRegion(pName, false) != nullptr)
75 {
76 std::ostringstream message;
77 message << "The region has NOT been registered !" << G4endl
78 << " Region " << pName << " already existing in store !"
79 << G4endl;
80 G4Exception("G4Region::G4Region()", "GeomMgt1001",
81 JustWarning, message);
82 }
83 else
84 {
85 rStore->Register(this);
86 }
87}
@ 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
G4int CreateSubInstance()
static void Register(G4Region *pRegion)
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const

◆ ~G4Region()

G4Region::~G4Region ( )
virtual

Definition at line 111 of file G4Region.cc.

112{
114 delete fUserInfo;
115}
static void DeRegister(G4Region *pRegion)

◆ G4Region() [2/3]

G4Region::G4Region ( const G4Region & )
delete

◆ G4Region() [3/3]

G4Region::G4Region ( __void__ & )

Definition at line 94 of file G4Region.cc.

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

Member Function Documentation

◆ AddRootLogicalVolume()

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

Definition at line 293 of file G4Region.cc.

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

Referenced by G4RunManagerKernel::CheckRegions(), and G4RunManagerKernel::DefineWorldVolume().

◆ BelongsTo()

G4bool G4Region::BelongsTo ( G4VPhysicalVolume * thePhys) const

Definition at line 428 of file G4Region.cc.

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

Referenced by BelongsTo(), and SetWorld().

◆ Clean()

void G4Region::Clean ( )
static

Definition at line 370 of file G4Region.cc.

371{
372 subInstanceManager.FreeSlave();
373}

Referenced by G4RegionStore::~G4RegionStore().

◆ ClearFastSimulationManager()

void G4Region::ClearFastSimulationManager ( )

Definition at line 448 of file G4Region.cc.

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

Referenced by G4FastSimulationManager::~G4FastSimulationManager().

◆ ClearMap()

void G4Region::ClearMap ( )
inline

◆ ClearMaterialList()

void G4Region::ClearMaterialList ( )

Definition at line 380 of file G4Region.cc.

381{
382 fMaterials.clear();
383}

Referenced by UpdateMaterialList().

◆ FindCouple()

◆ GetFastSimulationManager()

◆ GetFieldManager()

G4FieldManager * G4Region::GetFieldManager ( ) const
inline

◆ GetInstanceID()

G4int G4Region::GetInstanceID ( ) const
inline

◆ GetMaterialIterator()

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

◆ GetName()

◆ GetNumberOfMaterials()

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

◆ GetNumberOfRootVolumes()

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

◆ GetParentRegion()

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

Definition at line 483 of file G4Region.cc.

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

Referenced by ClearFastSimulationManager().

◆ GetProductionCuts()

◆ GetRegionalSteppingAction()

G4UserSteppingAction * G4Region::GetRegionalSteppingAction ( ) const

Definition at line 158 of file G4Region.cc.

159{
160 return G4MT_rsaction;
161}

Referenced by G4RunManagerKernel::DumpRegion(), and G4SteppingManager::Stepping().

◆ GetRootLogicalVolumeIterator()

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

◆ GetSubInstanceManager()

const G4RegionManager & G4Region::GetSubInstanceManager ( )
static

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

◆ 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

◆ RegionModified()

void G4Region::RegionModified ( G4bool flag)
inline

◆ RegisterMaterialCouplePair()

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

◆ RemoveRootLogicalVolume()

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

Definition at line 342 of file G4Region.cc.

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

Referenced by G4RunManagerKernel::SetupDefaultRegion(), and G4LogicalVolume::~G4LogicalVolume().

◆ ScanVolumeTree()

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

Definition at line 172 of file G4Region.cc.

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

◆ SetFieldManager()

void G4Region::SetFieldManager ( G4FieldManager * fm)
inline

◆ SetName()

void G4Region::SetName ( const G4String & name)

Definition at line 121 of file G4Region.cc.

122{
123 fName = pName;
125}
void SetMapValid(G4bool val)

◆ SetProductionCuts()

◆ SetRegionalSteppingAction()

void G4Region::SetRegionalSteppingAction ( G4UserSteppingAction * rusa)

Definition at line 149 of file G4Region.cc.

150{
151 G4MT_rsaction = rusa;
152}

Referenced by G4WorkerThread::UpdateGeometryAndPhysicsVectorFromMaster().

◆ SetUserInformation()

void G4Region::SetUserInformation ( G4VUserRegionInformation * ui)
inline

◆ SetUserLimits()

void G4Region::SetUserLimits ( G4UserLimits * ul)
inline

◆ SetWorld()

void G4Region::SetWorld ( G4VPhysicalVolume * wp)

Definition at line 412 of file G4Region.cc.

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

◆ UpdateMaterialList()

void G4Region::UpdateMaterialList ( )

Definition at line 391 of file G4Region.cc.

392{
393 // Reset the materials list
394 //
396
397 // Loop over the root logical volumes and rebuild the list
398 // of materials from scratch
399 //
400 for (auto pLV=fRootVolumes.cbegin(); pLV!=fRootVolumes.cend(); ++pLV)
401 {
402 ScanVolumeTree(*pLV, true);
403 }
404}
void ClearMaterialList()
Definition G4Region.cc:380

Referenced by RemoveRootLogicalVolume().

◆ UsedInMassGeometry()

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

◆ UsedInParallelGeometry()

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

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