|Message: Re: Segmentation error for get process name||Not Logged In (login)|
Click on the Forum title, e.g. on the "Forums by Category" page, to read a sequence of postings to the Forum and its threads all in one page. If you are only interested in one thread or the thread following a specific posting, click the thread or the posting, which takes you to a smaller page, which contains only the part you are interested in and may be easier to navigate.
Messages are "chained" if there are only replies at the first level, i.e. 1/1.html, 1/1/1.html etc. In case of "chained" messages the message number is replaced by the icon and there is no indentation.
Inline: Display the subject line only or also the text of the posting(s); for the choice "All" the "Outline" choices are switched off.
|1||0||1||no text / full text of posting|
|2||1||All||text for level 1 only / text for All postings|
Outline: Choose the depth of the posting thread, successive toggle controls provide increasing detail.
|1||2||1||2 levels / 1 level (original posting)|
|2||3||2||3 levels / 2 levels|
|3||3||All||3 levels / all levels (all postings)|
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:||Outline Depth:||Add message:|