This is my StepingAction Class:
#include "MySteppingAction.hh"
#include "MyEventAction.hh"
#include "G4Step.hh"
#include "G4TouchableHistory.hh"
#include "G4Track.hh"
#include "G4ParticleDefinition.hh"
#include "G4IonTable.hh"
#include "G4ParticleTypes.hh"
#include <iostream>
MySteppingAction::MySteppingAction(MyEventAction* eventAction) : eventAction(eventAction) {}
MySteppingAction::~MySteppingAction(){}
void MySteppingAction::UserSteppingAction(const G4Step* step) {
G4Track* track = step->GetTrack();
G4ParticleDefinition* particle = track->GetDefinition();
G4VPhysicalVolume* nextVol = track->GetNextVolume();
G4VPhysicalVolume* Vol = track->GetVolume();
std::cout << Vol->GetName() << "\t" << nextVol->GetName() << std::endl;
// Check if the particle is an ion
if (particle->GetParticleType() != "nucleus") {
// Kill the track if it is not an ion
track->SetTrackStatus(fStopAndKill);
}
}
And this code is working fine if I comment this line of above code:
std::cout << Vol->GetName() << “\t” << nextVol->GetName() << std::endl;
And if I uncomment this, it throws segmentation fault like shown in the attached figure.
May someone tell me what is problem with code here?