Problem 923

Summary: segmentation fault when using G4NeutronHPxxxxx with version 8.x
Product: Geant4 Reporter: Eric.Berthoumieux
Component: processes/hadronic/managementAssignee: kurasige
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 8.0   
Hardware: PC   
OS: Linux   

Description Eric.Berthoumieux 2007-01-09 07:38:25 CET
Hello,
I made a very simple simulation aiming to count the number of neutrons (in the
eV range) interacting with a gold sample.
My program was running perfectly with geant 4.7.1.p01 but crashes with both
geant 4.8.0 and 4.8.2

My PhysicsList is the following:
{
  theParticleIterator->reset();
  while( (*theParticleIterator)() ){
    G4ParticleDefinition* particle = theParticleIterator->value();
    G4ProcessManager* pmanager = particle->GetProcessManager();
    G4String particleName = particle->GetParticleName();

    if (particleName == "gamma") {
    // gamma

      pmanager->AddDiscreteProcess(new G4PhotoElectricEffect);
      pmanager->AddDiscreteProcess(new G4ComptonScattering);
      pmanager->AddDiscreteProcess(new G4GammaConversion);

    } else if (particleName == "e-") {
    //electron

      pmanager->AddProcess(new G4MultipleScattering,-1,1,1);
      pmanager->AddProcess(new G4eIonisation,       -1,2,2);
      pmanager->AddProcess(new G4eBremsstrahlung,   -1,-1,3);

    } else if (particleName == "e+") {
    //positron

      pmanager->AddProcess(new G4MultipleScattering,-1,1,1);
      pmanager->AddProcess(new G4eIonisation,       -1,2,2);
      pmanager->AddProcess(new G4eBremsstrahlung,   -1,-1,3);
      pmanager->AddProcess(new G4eplusAnnihilation,  0,-1,4);

    } else if (particleName == "neutron") {
      G4HadronCaptureProcess *hcapProc = new G4HadronCaptureProcess;
      G4NeutronHPCapture *hcap = new G4NeutronHPCapture;
      hcapProc->RegisterMe(hcap);
      hcapProc->AddDataSet(new G4NeutronHPCaptureData);
//      hcapProc->BuildPhysicsTable(*particle);
      pmanager->AddDiscreteProcess(hcapProc);
      G4HadronElasticProcess *hElasProc = new G4HadronElasticProcess;
      G4NeutronHPElastic *hElas = new G4NeutronHPElastic;
      hElasProc->RegisterMe(hElas);
      hElasProc->AddDataSet(new G4NeutronHPElasticData);
//      hElasProc->BuildPhysicsTable(*particle);
      pmanager->AddDiscreteProcess(hElasProc);

//      hcapProc->DumpPhysicsTable(*particle);
//      hElasProc->DumpPhysicsTable(*particle);
    }
  }
}

And the problem I have is the following (only with 8.0 and 8.2)

Idle> run/beamOn

Program received signal SIGSEGV, Segmentation fault.
0x0816fddf in G4VUserPhysicsList::PreparePhysicsTable ()
(gdb) backtrace
#0  0x0816fddf in G4VUserPhysicsList::PreparePhysicsTable ()
#1  0x0816f699 in G4VUserPhysicsList::BuildPhysicsTable ()
#2  0x0815f99e in G4RunManagerKernel::BuildPhysicsTables ()
#3  0x0815f851 in G4RunManagerKernel::RunInitialization ()
#4  0x0816265f in G4RunManager::RunInitialization ()
#5  0x081624bc in G4RunManager::BeamOn ()
#6  0x0816c737 in G4RunMessenger::SetNewValue ()
#7  0x08312ccf in G4UIcommand::DoIt ()
#8  0x083261bd in G4UImanager::ApplyCommand ()
#9  0x0807f584 in G4UIterminal::ExecuteCommand ()
#10 0x0807f0d7 in G4UIterminal::SessionStart ()
#11 0x0804f126 in main ()

Is there something wrong in my PhysicsList (the neutron part) when upgrading
from 4.7.1 to 4.8.x
Comment 1 kurasige 2007-01-17 18:27:59 CET
The reason of crash is changes in implementation of G4ParticleDefinition. From
the release 8.0, all G4ParticleDefinition objects are created dynamically.(No
static objects).
 By this change, users are requested to list up "all particle type" in his/her
physics list except for resonances and heavy ions. "All particle type" means not
only particles which users want to shoot (i.e. primary particles) but also
particles which processes can create (i.e. secondary particles).
 (see release note for release 8.0 )

 In the old releases, most of particles were created as 'singleton'. Secondary
particles were automatically created if processes declared using these particles
in their source codes.

So, in this case of using neutron processes, users should declare
   proton,      anti_proton,
   pi+,         pi-,              pi0
   kaon+,       kaon-,            kaon0L,             kaon0S,
 as well as  neutron.