Hello everyone,
I am running a reverse MC simulation on GRAS (Geant4 based software).
I am using the latest version of GRAS/G4, and I am running everything under Ubuntu (WSL).
When running a RMC simulation, you need to setup an Adjoint External Source, which surface needs to be calculated. Unfortunatly, I get a Segmentation Fault (core dump) coming from the ComputeGPSSourceSurface() function.
According to valgrind, the Seg Fault is of “Invalid read of size” type, as shown bellow.
You’ll find below the gdb + valgrind output from the execution of my macro file.
------------- GDB --------------
GRAS detector constructor geometry type: gdml
Program received signal SIGSEGV, Segmentation fault.
0x00007fffff59ae22 in GRASPrimaryGeneratorAction::ComputeGPSSourceSurface() const ()
from /home/osprey/software/gras/05.00/lib/libgras.so
(gdb) where
#0 0x00007fffff59ae22 in GRASPrimaryGeneratorAction::ComputeGPSSourceSurface() const ()
from /home/osprey/software/gras/05.00/lib/libgras.so
#1 0x00007fffff4dac41 in GRASAnalysisManager::ComputeSourceSurface() ()
from /home/osprey/software/gras/05.00/lib/libgras.so
#2 0x00007fffff4df9d5 in GRASAnalysisManager::BeginOfRun(G4Run const*) ()
from /home/osprey/software/gras/05.00/lib/libgras.so
#3 0x00007fffff59b6b0 in GRASRunActionStack::BeginOfRunAction(G4Run const*) ()
from /home/osprey/software/gras/05.00/lib/libgras.so
#4 0x00007ffffef7f29b in G4RunManager::RunInitialization() ()
from /home/osprey/Geant4/geant4-install/lib/libG4run.so
#5 0x00007fffff59ba93 in GRASRunManager::BeamOn(int, char const*, int) ()
from /home/osprey/software/gras/05.00/lib/libgras.so
#6 0x00007ffffef63035 in G4AdjointSimManager::RunAdjointSimulation(int) ()
from /home/osprey/Geant4/geant4-install/lib/libG4run.so
#7 0x00007ffffef63cab in G4AdjointSimMessenger::SetNewValue(G4UIcommand*, G4String) ()
from /home/osprey/Geant4/geant4-install/lib/libG4run.so
#8 0x00007ffffeef1b83 in G4UIcommand::DoIt(G4String) ()
from /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so
#9 0x00007ffffef109ef in G4UImanager::ApplyCommand(char const*) ()
from /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so
#10 0x00007ffffeee04b1 in G4UIbatch::ExecCommand(G4String const&) ()
from /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so
#11 0x00007ffffeee2466 in G4UIbatch::SessionStart() ()
from /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so
#12 0x00007ffffef12260 in G4UImanager::ExecuteMacroFile(char const*) ()
from /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so
#13 0x00007ffffeefe426 in G4UIcontrolMessenger::SetNewValue(G4UIcommand*, G4String) ()
from /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so
#14 0x00007ffffeef1b83 in G4UIcommand::DoIt(G4String) ()
from /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so
#15 0x00007ffffef109ef in G4UImanager::ApplyCommand(char const*) ()
from /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so
#16 0x0000000008003b01 in main ()
------------- VALGRIND --------------
GRAS detector constructor geometry type: gdml
==112== Invalid read of size 8
==112== at 0x4A03E22: GRASPrimaryGeneratorAction::ComputeGPSSourceSurface() const (in /home/osprey/software/gras/05.00/lib/libgras.so)
==112== by 0x4943C40: GRASAnalysisManager::ComputeSourceSurface() (in /home/osprey/software/gras/05.00/lib/libgras.so)
==112== by 0x49489D4: GRASAnalysisManager::BeginOfRun(G4Run const*) (in /home/osprey/software/gras/05.00/lib/libgras.so)
==112== by 0x4A046AF: GRASRunActionStack::BeginOfRunAction(G4Run const*) (in /home/osprey/software/gras/05.00/lib/libgras.so)
==112== by 0x507929A: G4RunManager::RunInitialization() (in /home/osprey/Geant4/geant4-install/lib/libG4run.so)
==112== by 0x4A04A92: GRASRunManager::BeamOn(int, char const*, int) (in /home/osprey/software/gras/05.00/lib/libgras.so)
==112== by 0x505D034: G4AdjointSimManager::RunAdjointSimulation(int) (in /home/osprey/Geant4/geant4-install/lib/libG4run.so)
==112== by 0x505DCAA: G4AdjointSimMessenger::SetNewValue(G4UIcommand*, G4String) (in /home/osprey/Geant4/geant4-install/lib/libG4run.so)
==112== by 0x50EDB82: G4UIcommand::DoIt(G4String) (in /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so)
==112== by 0x510C9EE: G4UImanager::ApplyCommand(char const*) (in /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so)
==112== by 0x50DC4B0: G4UIbatch::ExecCommand(G4String const&) (in /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so)
==112== by 0x50DE465: G4UIbatch::SessionStart() (in /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so)
==112== Address 0x8 is not stack’d, malloc’d or (recently) free’d
==112==
==112==
==112== Process terminating with default action of signal 11 (SIGSEGV)
==112== Access not within mapped region at address 0x8
==112== at 0x4A03E22: GRASPrimaryGeneratorAction::ComputeGPSSourceSurface() const (in /home/osprey/software/gras/05.00/lib/libgras.so)
==112== by 0x4943C40: GRASAnalysisManager::ComputeSourceSurface() (in /home/osprey/software/gras/05.00/lib/libgras.so)
==112== by 0x49489D4: GRASAnalysisManager::BeginOfRun(G4Run const*) (in /home/osprey/software/gras/05.00/lib/libgras.so)
==112== by 0x4A046AF: GRASRunActionStack::BeginOfRunAction(G4Run const*) (in /home/osprey/software/gras/05.00/lib/libgras.so)
==112== by 0x507929A: G4RunManager::RunInitialization() (in /home/osprey/Geant4/geant4-install/lib/libG4run.so)
==112== by 0x4A04A92: GRASRunManager::BeamOn(int, char const*, int) (in /home/osprey/software/gras/05.00/lib/libgras.so)
==112== by 0x505D034: G4AdjointSimManager::RunAdjointSimulation(int) (in /home/osprey/Geant4/geant4-install/lib/libG4run.so)
==112== by 0x505DCAA: G4AdjointSimMessenger::SetNewValue(G4UIcommand*, G4String) (in /home/osprey/Geant4/geant4-install/lib/libG4run.so)
==112== by 0x50EDB82: G4UIcommand::DoIt(G4String) (in /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so)
==112== by 0x510C9EE: G4UImanager::ApplyCommand(char const*) (in /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so)
==112== by 0x50DC4B0: G4UIbatch::ExecCommand(G4String const&) (in /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so)
==112== by 0x50DE465: G4UIbatch::SessionStart() (in /home/osprey/Geant4/geant4-install/lib/libG4intercoms.so)
Ok, now here’s a copy of the annoying function :
double GRASPrimaryGeneratorAction::ComputeGPSSourceSurface() const
{
G4SPSPosDistribution* thePosDis= m_particleGun->GetCurrentSource()->GetPosDist();
G4String disType = thePosDis->GetPosDisType();
G4String disShape = thePosDis->GetPosDisShape();
if (disType ==G4String(“Point”)) return 0.;
G4double dX,dY,dZ,r;
dX= 2.thePosDis->GetHalfX();
dY = 2.thePosDis->GetHalfY();
dZ = 2.thePosDis->GetHalfZ();
r= thePosDis->GetRadius();
if (disType == G4String(“Plane”)) {
if (disShape == G4String(“Square”)) return dXdX;
if (disShape == G4String(“Rectangle”)) return dXdY;
if (disShape == G4String(“Circle”)) return pirr;
if (disShape == G4String(“Ellipse”)) return 0.25pidXdY;
if (disShape == G4String(“Annulus”)) {//temporary solution to determine r0, to be update when GetR0 will be
//provided in GPS
G4double rmin =r;
G4int n=100000;
G4ThreeVector center= thePosDis->GetCentreCoords();
for (int i=0; i<n;i++){
G4ThreeVector pos=thePosDis->GenerateOne();
rmin=std::min(rmin,(pos-center).mag());
}
return pi*(rr-rminrmin);
}
}
if (disType == G4String(“Surface”)) {
if (disShape == G4String(“Para”)) return 2.(dXdY+dYdZ+dZdX);
if (disShape == G4String(“Sphere”)) return 4.pirr;
if (disShape == G4String(“Cylinder”)) return 2.pir(r+dZ);
if (disShape == G4String(“Ellipsoid”)) { //Knud Thomsen approximation with max 1.07% error taken from http://en.wikipedia.org/wiki/Ellipsoid
G4double p=1.6075;
G4double ap=std::pow(0.5dX,p);
G4double bp=std::pow(0.5dY,p);
G4double cp=std::pow(0.5dZ,p);
return 4.pistd::pow((apbp+bpcp+cpap)/3.,1./p);
}
}
return -1.;
}
I suspect the first three lines to be the problem… What do you think?
Thank you your help, it is VERY much appreciated.