Dear Geant4 experts,
I am working with a rather complex geometry which is parsed from a GDML file. Some volumes need to have a magnetic field attached to them which is done with a custom G4MagneticField class called
“T2KLineCurrentMagField” (called this way since it is a straight up modified version of the G4LineCurrent class). The magnetic field needs to be using the coordinate system of the volume where the field is located.
In order to obtain the transformation, the G4Navigator class is used as shown in the documentation and some examples.
The transformation to local coordinates is obtained in the constructor of the Magnetic field class:
T2KLineCurrentMagField::T2KLineCurrentMagField(G4double pFieldConstant,G4ThreeVector hc)
{
fFieldConstant = pFieldConstant ;
hornCenter = hc;
G4Navigator* theNavigator =
G4TransportationManager::GetTransportationManager()->
GetNavigatorForTracking();
if ( theNavigator->GetWorldVolume() )
fNavigator->SetWorldVolume(theNavigator->GetWorldVolume());
// To make sure the Geometry is closed
G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
if (!geomManager->IsGeometryClosed()) {
geomManager->OpenGeometry();
geomManager->CloseGeometry(true);
}
fNavigator->LocateGlobalPointAndSetup(hc); // This is the problematic line: causes segmentation fault
fTouchable = fNavigator->CreateTouchableHistoryHandle(); // We can use fTouchable->GetHistory()->GetTopTransform() to go from global to local coords.
}
In the written code above a segmentation fault error occurs upon calling the “LocateGlobalPointAndSetup” method as Geant4 starts up. From my understanding, this method is important to obtain the volume whose local frame we are interested in.
A similar problem is described here: https://micewww.pp.rl.ac.uk/issues/1790.
The constructor is called in the detector construction to attach the magnetic field to relevant volumes.
Here is the output from valgrind:
"
==1301078== Invalid read of size 8
==1301078== at 0xC50F334: G4Navigator::LocateGlobalPointAndSetup(CLHEP::Hep3Vector const&, CLHEP::Hep3Vector const*, bool, bool) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4geometry.so)
==1301078== by 0x412470: T2KLineCurrentMagField::T2KLineCurrentMagField(double, CLHEP::Hep3Vector) (T2KLineCurrentMagField.cc:78)
==1301078== by 0x40CA5B: DetectorConstruction::Construct() (DetectorConstruction.cc:370)
==1301078== by 0x8E48F75: G4RunManager::InitializeGeometry() (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4run.so)
==1301078== by 0x8E48D4F: G4RunManager::Initialize() (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4run.so)
==1301078== by 0x8E547D8: G4MTRunManager::Initialize() (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4run.so)
==1301078== by 0x8E63FF5: G4RunMessenger::SetNewValue(G4UIcommand*, G4String) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4run.so)
==1301078== by 0xD01DFB6: G4UIcommand::DoIt(G4String) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4intercoms.so)
==1301078== by 0xD0355EF: G4UImanager::ApplyCommand(char const*) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4intercoms.so)
==1301078== by 0xD00E3F6: G4UIbatch::ExecCommand(G4String const&) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4intercoms.so)
==1301078== by 0xD00F6E7: G4UIbatch::SessionStart() (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4intercoms.so)
==1301078== by 0xD0365EB: G4UImanager::ExecuteMacroFile(char const*) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4intercoms.so)
==1301078== Address 0x10 is not stack’d, malloc’d or (recently) free’d
==1301078==
==1301078==
==1301078== Process terminating with default action of signal 11 (SIGSEGV)
==1301078== Access not within mapped region at address 0x10
==1301078== at 0xC50F334: G4Navigator::LocateGlobalPointAndSetup(CLHEP::Hep3Vector const&, CLHEP::Hep3Vector const*, bool, bool) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4geometry.so)
==1301078== by 0x412470: T2KLineCurrentMagField::T2KLineCurrentMagField(double, CLHEP::Hep3Vector) (T2KLineCurrentMagField.cc:78)
==1301078== by 0x40CA5B: DetectorConstruction::Construct() (DetectorConstruction.cc:370)
==1301078== by 0x8E48F75: G4RunManager::InitializeGeometry() (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4run.so)
==1301078== by 0x8E48D4F: G4RunManager::Initialize() (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4run.so)
==1301078== by 0x8E547D8: G4MTRunManager::Initialize() (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4run.so)
==1301078== by 0x8E63FF5: G4RunMessenger::SetNewValue(G4UIcommand*, G4String) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4run.so)
==1301078== by 0xD01DFB6: G4UIcommand::DoIt(G4String) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4intercoms.so)
==1301078== by 0xD0355EF: G4UImanager::ApplyCommand(char const*) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4intercoms.so)
==1301078== by 0xD00E3F6: G4UIbatch::ExecCommand(G4String const&) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4intercoms.so)
==1301078== by 0xD00F6E7: G4UIbatch::SessionStart() (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4intercoms.so)
==1301078== by 0xD0365EB: G4UImanager::ExecuteMacroFile(char const*) (in /home/ppe/t/tmaurin/geant4_fs/geant4.10.07-install2/lib64/libG4intercoms.so)
==1301078== If you believe this happened as a result of a stack
==1301078== overflow in your program’s main thread (unlikely but
==1301078== possible), you can try to increase the size of the
==1301078== main thread stack using the --main-stacksize= flag.
==1301078== The main thread stack size used in this run was 8388608.
==1301078==
==1301078== HEAP SUMMARY:
==1301078== in use at exit: 5,523,386 bytes in 80,438 blocks
==1301078== total heap usage: 810,961 allocs, 730,523 frees, 291,770,843 bytes allocated
==1301078==
==1301078== LEAK SUMMARY:
==1301078== definitely lost: 0 bytes in 0 blocks
==1301078== indirectly lost: 0 bytes in 0 blocks
==1301078== possibly lost: 308,764 bytes in 2,833 blocks
==1301078== still reachable: 5,214,622 bytes in 77,605 blocks
==1301078== of which reachable via heuristic:
==1301078== stdstring : 674,344 bytes in 17,033 blocks
==1301078== newarray : 400 bytes in 2 blocks
==1301078== suppressed: 0 bytes in 0 blocks
==1301078== Rerun with --leak-check=full to see details of leaked memory
==1301078==
==1301078== For lists of detected and suppressed errors, rerun with: -s
==1301078== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
"
I have made sure that the “hc” G4ThreeVector describes the coordinates of an actual volume present in the World Volume.
Is there a big mistake or something that I’m missing that could solve this segmentation fault to occur? (I have just started using Geant4 this September so I know very little about its intricaties).
Thank you for your time and for any help available.
Théo Maurin