GetCreatorProcess error

  G4Track* track = new G4Track;
  auto creatorProcess = track->GetCreatorProcess();
  
  if (G4Electron::ElectronDefinition() == aStep->GetTrack()->GetDefinition()){
    if (creatorProcess->GetProcessName() == "LowEnergyIoni") {
    cFile << edep << "\n";}
  }

When i try to run it:

error: invalid use of incomplete type ‘const class G4VProcess’
   58 |     if (creatorProcess->GetProcessName() == "LowEnergyIoni") {

I am not sure how to fix it. I want to get the energy of particles that have been created by a specific process.

#include "G4VProcess.hh"

If you want to make use of the member functions of a class, you must include the class definition in your .cc file.

1 Like

Oh. Thank you. Now it runs, but gives segmentation fault at terminal :frowning:

You should check pointers to be sure they are not null before dereferencing them. Primary tracks, for example, do not have a creator process, so the pointer will be null.

if (creatorProcess && creatorProcess->GetProcessName() == ".....")
1 Like

But your code is fundamentally broken. If you do

G4Track* track = new G4Track;

you are explicitly creating a brand new, empty object. You’re not accessing a track which is being propagated by Geant4 through your geometry. Of course all of its content is going to be empty, or zeroes, or null pointers.

I would highly recommend reading the Geant4 documentation to understand how the simulation works, and where and how in the code you write to access information.

1 Like