Message: Re: Reloading Geometry with Region Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: Reloading Geometry with Region 

Forum: Geometry
Re: Question Reloading Geometry with Region (Adrien MATTA)
Re: More Re: Reloading Geometry with Region (Gabriele Cosmo)
Date: Feb 01, 08:27
From: Adrien MATTA <Adrien MATTA>

Thanks for your answer Gabriele.

After trying many things, I was able to have a working version.

With the initial approach I always end up with either a G4Exception or a seg fault.

What I found surprising, is that the cleaning the region store leave the store empty and cause a segfault later because the region does not exist. I would expect the region to be created at some point during the G4RunManager::Initialize() but, apparently not. The region created in the Run Manager Kernel constructor and then the same pointer is used and never updated if the user call G4RegionStore::Clean().

I tried calling G4RegionStore::SetWorldVolume() myself at different points, but this did not work. I also think this is called by G4RunManager::Initialize().

Instead of cleaning the region, I simply changed the associated root volumes, but then the G4TransportationManager is lost...

At this point far into the Geant4 framework I am a bit lost of which manager is doing what...

I ended up with a solution that I found convoluted but that works: deleting everything but the world, so the default region from the world remained untouched.

I feel like the G4RunManager should have a function to do all that the proper way, effectively reverting to a "preConstruct" states.

My solution for reference, if some are facing the same issue.

 void DetectorConstruction::ClearGeometry(){                                     

   unsigned int mySize = m_Detectors.size();                                     

   for (unsigned short i = 0 ; i < mySize ; i++) {                               
     delete m_Detectors[i];                                                      

   // Delete previous Sensitive Detector (Scorer)                                
   delete G4SDManager::GetSDMpointer();                                          


   // Cleaning stores by hand (everything but the world)                                                
   // Cleaning the PVP                                                           
   G4PhysicalVolumeStore* PVP = G4PhysicalVolumeStore::GetInstance();            
     delete PVP->at(PVP->size()-1);                                              
   // Cleaning the Logical Volume                                                
   G4LogicalVolumeStore* LV = G4LogicalVolumeStore::GetInstance();               
   while(LV->size()>1) {                                                         
     delete LV->at(LV->size()-1);                                                
   // Cleaning the Solid store                                                   
   G4SolidStore* SL = G4SolidStore::GetInstance();                               
   while(SL->size()>1) {                                                         
     delete SL->at(SL->size()-1);                                                

   // Remover user specific region                                                                           
   G4Region* reg =   G4RegionStore::GetInstance()->GetRegion("NPSimulationProcess",false);
   if(reg) {                                                                      
     delete reg;                                                                   

   m_Target   = 0;                                                               
   m_Chamber  = 0;                                                               

then to reload the geometry:
 void DetectorConstruction::RedefineGeometry(){                  
   ClearGeometry() ;                                                                                                                                                               
   G4RunManager::GetRunManager()->PhysicsHasBeenModified() ;                     

 Add Message Add Message
to: "Re: Reloading Geometry with Region"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]