Error with User PhysicsList (segmentation violation)

Hello everyone,

I’m trying to carry on a simulation where I’ve to study photons in a liquid hydrogen target. A beam of negative pion hits the target, does charge exchange (CEX) and the produced neutral pion decades in two photons. At my current energy the CEX process isn’t that much frequent.

So I had in mind to implement a PhysicsList where negative pions where only allowed to do CEX, neutral pion to decay and nothing more.

The way I do this is by creating two files that I’m copying here:

// physics.hh

#ifndef PHYSICS_HH
#define PHYSICS_HH

#include "G4VUserPhysicsList.hh"

#include "G4PionMinus.hh"
#include "G4PionZero.hh"
#include "G4Proton.hh"
#include "G4Neutron.hh"
#include "G4Gamma.hh"

#include "G4ChargeExchangeProcess.hh"
#include "G4Decay.hh"

class MyUserPhysicsList : public G4VUserPhysicsList
{
public:
    MyUserPhysicsList();
    ~MyUserPhysicsList();

    virtual void ConstructParticle();
    virtual void ConstructProcess();
    virtual void ConstructEM();

    void ContructGeneral();
};

#endif
// physics.cc

#include "physics.hh"

MyUserPhysicsList::MyUserPhysicsList()
{
}

MyUserPhysicsList::~MyUserPhysicsList()
{
}

void MyUserPhysicsList::ConstructParticle()
{
    G4PionMinus::Definition();
    G4PionZero::Definition();
    G4Proton::Definition();
    G4Neutron::Definition();    
    G4Gamma::Definition();
}

void MyUserPhysicsList::ConstructProcess()
{
    AddTransportation();
    ConstructEM();
    ContructGeneral();
}

void MyUserPhysicsList::ConstructEM()
{
    G4PhysicsListHelper *ph = G4PhysicsListHelper::GetPhysicsListHelper();
    auto particleIterator = GetParticleIterator();
    particleIterator->reset();
    while ((*particleIterator)())
    {
        G4ParticleDefinition *particleDefinition = particleIterator->value();
        if (particleDefinition == G4Gamma::Definition())
        {
            ph->RegisterProcess(new G4Decay(), particleDefinition);
        }
    }
}

void MyUserPhysicsList::ContructGeneral()
{
    G4PhysicsListHelper *ph = G4PhysicsListHelper::GetPhysicsListHelper();
    auto particleIterator = GetParticleIterator();
    particleIterator->reset();
    while ((*particleIterator)())
    {
        G4ParticleDefinition *particleDefinition = particleIterator->value();
        if (particleDefinition == G4PionMinus::Definition())
        {
            ph->RegisterProcess(new G4ChargeExchangeProcess(), particleDefinition);
        }
        else if (particleDefinition == G4PionZero::Definition())
        {
            ph->RegisterProcess(new G4ChargeExchangeProcess(), particleDefinition);
            ph->RegisterProcess(new G4Decay(), particleDefinition);
        }
        else if (particleDefinition == G4Proton::Definition())
        {
            ph->RegisterProcess(new G4ChargeExchangeProcess(), particleDefinition);
        }
        else if (particleDefinition == G4Neutron::Definition())
        {
            ph->RegisterProcess(new G4ChargeExchangeProcess(), particleDefinition);
        }
    }
}

In the main file sim.cc I write:

int main(int argc, const char ** argv)
{
   ...
   G4RunManager *runManager = new G4RunManager();
   runManager->SetUserInitialization(new MyUserPhysicsList());
   ...
}

No error are given when I compile the program. When I run it, I just get the following output:



          ################################
          !!! G4Backtrace is activated !!!
          ################################


**************************************************************
 Geant4 version Name: geant4-11-00-patch-02 [MT]   (25-May-2022)
                       Copyright : Geant4 Collaboration
                      References : NIM A 506 (2003), 250-303
                                 : IEEE-TNS 53 (2006), 270-278
                                 : NIM A 835 (2016), 186-225
                             WWW : http://geant4.org/
**************************************************************

Checking overlaps for volume physCyl_o:0 (G4Tubs) ... OK! 
Checking overlaps for volume physCyl_v:0 (G4Tubs) ... OK! 
Checking overlaps for volume physCyl_i:0 (G4Tubs) ... OK! 
Checking overlaps for volume physLH2:0 (G4Tubs) ... OK! 
Checking overlaps for volume physDegrad:0 (G4Tubs) ... OK! 

### CAUGHT SIGNAL: 11 ### address: 0x48,  signal =  SIGSEGV, value =   11, description = segmentation violation. Invalid permissions for mapped object.

Backtrace:
[PID=57565, TID=-1][0/6]> 0   libG4run.dylib                      0x0000000106cf06d0 _ZNK19G4PhysicsListHelper17CheckParticleListEv + 372
[PID=57565, TID=-1][1/6]> 1   libG4run.dylib                      0x0000000106d09a8c _ZN18G4RunManagerKernel17InitializePhysicsEv + 716
[PID=57565, TID=-1][2/6]> 2   libG4run.dylib                      0x0000000106cf9f6c _ZN12G4RunManager17InitializePhysicsEv + 64
[PID=57565, TID=-1][3/6]> 3   libG4run.dylib                      0x0000000106cf9d4c _ZN12G4RunManager10InitializeEv + 328
[PID=57565, TID=-1][4/6]> 4   sim                                 0x00000001046f92e4 main + 1340
[PID=57565, TID=-1][5/6]> 5   dyld                                0x00000001047c908c start + 520

[1]    57565 abort      ./sim -v

I’ve been using Geant4 for 3 weeks, I’m quite new here. Don’t hesitate to report any mistake I make.
Any help would be appreciated.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.