Message: Re: Segmentation error for get process name Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Feedback Re: Segmentation error for get process name 

Forum: Event and Track Management
Re: Question Segmentation error for get process name (David Sangcheol Lee)
Date: 06 Apr, 2018
From: Michael H. Kelsey <Michael H. Kelsey>

On Wed, 04 Apr 2018 08:02:18 GMT, David Sangcheol Lee wrote:
> Hello, I am trying to get the energy spectra of neutrons undergo capture
> process so I implemented this line of the code
> 
> G4Track * theTrack = theStep->GetTrack(); . . . processName =
> theStep->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName();
[...]
> so I basically get the energy from the nCapture process but I get the
> segmentation error. I cannot understand where it got wrong.

In general, it is always safest to check whether a pointer exists (is not NULL) before dereferencing it. We often skip this in Geant4 code, especially with long chains of pointers.

In your case, you are looking at the pre-step point of a track. If you are looking at one of your _primary_ tracks, then there is no process which defined the step, and hence that pointer is null. When you try to get the name, you segfault because you're derefencing a null pointer.

The simplest way for you to protect against this is to simply test if the track is a primary:

   if (theTrack->GetParentID() == 0) return;       // Do not process primaries

  -- Michael Kelsey

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 More: Re: Segmentation error for get process name   (David Sangcheol Lee - 07 Apr, 2018)
 Add Message Add Message
to: "Re: Segmentation error for get process name"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]