track->GetCreatorProcess()->GetProcessName() doesn't work

Hello, in the StackingAction I need to save the eenrgy of primary photons or emitted photons by radioactive decay.
Then I select:

if ((parentID == 0 && particleName == "gamma") || (track->GetCreatorProcess()->GetProcessName() == "RadioactiveDecay" && particleName == "gamma")) {
.....
}

but using the radioactive decay as primary particles

/gps/particle ion
/gps/ion 55 137 0 0
/gps/energy 0. eV

no particles pass the selection. Then I tried to print the process

G4cout <<"Process is " << track->GetCreatorProcess()->GetProcessName() << G4endl;

but the simulation crashes.

Moreover, it also crashes if I define

G4String processname=track->GetCreatorProcess()->GetProcessName() ;

Then it looks likes to be a problem in the use of track->GetCreatorProcess()->GetProcessName() ;

This is the function:

G4ClassificationOfNewTrack
StackingAction::ClassifyNewTrack(const G4Track* track)
{  
//This code looks for gammas emitted by nuclear decays
  //and counts how many primary particles are emitted in the decay

  G4int parentID = track->GetParentID();
  G4String particleName =  track->GetDefinition()->GetParticleName();
  G4String particleType = track->GetDefinition()->GetParticleType();
  
  G4cout <<"Process is " << track->GetCreatorProcess()->GetProcessName() << G4endl;
  G4int pdggamma;
  G4double energy;
  
  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
  
 

 if ((parentID == 0 && particleName == "gamma") || (track->GetCreatorProcess()->GetProcessName() == "RadioactiveDecay" && particleName == "gamma")) {
  	pdggamma = track->GetParticleDefinition()->GetPDGEncoding();
  	energy = track->GetDynamicParticle()->GetKineticEnergy();
  	analysisManager->FillNtupleDColumn(2,0, pdggamma);
  	//if (energy > 0) {
      analysisManager->FillNtupleDColumn(2,1, energy/keV);
      analysisManager->AddNtupleRow(2);  	
       analysisManager->FillH1(1, energy/keV);
   // }
  }
  return fUrgent;
}

StackingAction.cc (4.0 KB)
StackingAction.hh (2.4 KB)

is there always a creatorprocess? are you maybe dereferencing a null pointer? you could assert that

track->GetCreatorProcess()

does not return null

Hi,

It seems that you want to get the beginning point of gamma ray from the source.
As far as I know, “parentID” is the track ID of the creator track.
And the primary particles have 0 of parentID.

Please refer to G4GeneralParticleSource.cc in GEANT4 source to understand about gps.

I want to suggest that you should use “/tracking/verbose 1” in your macro file to see if gammas really have parentID as 0. Or you can print out by your StackingAction source.

Hi @weller

I tried to print the process.

  G4String processType = track->GetCreatorProcess()->GetProcessName();
    
  if (processType) {
  G4cout <<"Process is " << processType  << G4endl;
  }
  else {
  G4cout <<	"No process type "<< G4endl;
  	
  }

but the simulation still crashes and it even doesn’t write "“No process type”.

If I delete these lines, it works fine, then the problem is give by them.

Hi @JeongHyeokPark

If I simulate the radioactive decay, the parentID can’t be 0 because gammas are produced by radioactive decay…then the parentID==0 is the ion.
Indeed, I printed the parentID of the gamma

if (particleType =="gamma"){
  	G4cout <<	"parentID = "<< parentID << G4endl;
  }

and, as you can see, it is >0.

parentID.txt (4.4 KB)

you still need the check if (track->GetCreatorProcess()) { somewhere before dereferencing…

I checked it printing

if (track->GetCreatorProcess()) {
  G4cout <<"Creator process is " <<  track->GetCreatorProcess() << G4endl;
  }
  else {
G4cout <<	"No creator process type "<< G4endl;
  	
  }

and the track->GetCreatorProcess() works as you can see in the attached file

creator process.txt (109.1 KB)

Then the problem is related to the `GetProcessName() function.

EDIT
I just found this @mkelsey post

in which he says to check both the creatorProcess and the GetProcessName…then I tried to print

 if (track->GetCreatorProcess()) {
  G4cout <<"Creator process is " <<  track->GetCreatorProcess() << G4endl;
 	if (track->GetCreatorProcess()->GetProcessName()){
 		G4cout <<"Process Name is  is " <<  track->GetCreatorProcess()->GetProcessName() << G4endl;
 	}
 	 else {
			G4cout <<	"No process name "<< G4endl;
		}
	}
  else {
	G4cout <<	"No creator process type "<< G4endl;
  }

and it works without crashing…

G4WT0 > Process Name is  is phot
G4WT1 > Creator process is 000001DA0A0B8030
G4WT0 > Creator process is 000001DA0C585450
G4WT1 > Process Name is  is RadioactiveDecayBase
G4WT0 > Process Name is  is phot
G4WT1 > Creator process is 000001DA0A0B8030
G4WT0 > Creator process is 000001DA0C585450
G4WT1 > Process Name is  is RadioactiveDecayBase
G4WT0 > Process Name is  is phot
G4WT1 > Creator process is 000001DA0A0B8030
G4WT0 > Creator process is 000001DA0C585450
G4WT0 > Process Name is  is phot
G4WT1 > Process Name is  is RadioactiveDecayBase
G4WT0 > No creator process type

but it prints "RadioactiveDecayBase " instead of “RadioactiveDecay”
Are there differences between "RadioactiveDecayBase " and “RadioactiveDecay”?

`

The process name changed in different releases as the developers made decisions about how to organize the code. It makes writing your application more complicated :frowning:

thank you @mkelsey I see

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