Is it possible to restrict certain phenomenons from physicslist?

I have tried to restrict some aspects of the physicslist i am writting here, but evrytime i run the geant4, it gives segmentation break. Look what i have writted:

      else if (particleName == "e-")
	{
	  //electron

	  pmanager->AddProcess(new G4eMultipleScattering(),-1, 1,1);
	  pmanager->AddProcess(new G4eBremsstrahlung(),   -1, 3,3);
	 /* pmanager->AddProcess(new G4eIonisation(),       -1, 2,2);*/
	
	  G4Step *aStep = new G4Step;
	  G4Track *track = aStep->GetTrack();
	  track->SetTrackStatus(fStopAndKill);
	  
	  double ene = aStep->GetPreStepPoint()->GetTotalEnergy();
	  G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
	  
	  if (ene >= 21.564*eV){
	  pmanager->AddProcess(new G4eIonisation(),       -1, 2,2);
	  }
	} 

I was expecting that, using this code, the ionisation just occurs for particles in which the energy is greater than or eual 21.564*eV. But, as already said, when i try to open the simulation it gives segmentation fault. Is it because the code is wrong? Or it is not possible to simulate with this physicslist?

That code is never going to do anything. Your physics list is built (obviously) before any event is generated or any tracks produced. Let’s look at what you’ve actually written:

  G4Step *aStep = new G4Step;

Here you’re creating a new, empty G4Step object. Because it has a well-written constructor, all of its data members are initialized to zero.

  G4Track *track = aStep->GetTrack();

Since the G4Step is empty, this is a null pointer.

  track->SetTrackStatus(fStopAndKill);

Your code will crash with a segmentation fault here, because you’re dereferencing a null pointer. But let’s pretend that doesn’t happen…

  double ene = aStep->GetPreStepPoint()->GetTotalEnergy();

Since the G4Step is empty, this is a null pointer. Your code will crash with a segmentation fault here, because you’re dereferencing a null pointer. But let’s pretend that doesn’t happen. You’d end up with ene=0.

  G4StepPoint *preStepPoint = aStep->GetPreStepPoint();

Since the G4Step is empty, this is a null pointer.

1 Like

I see. Thank you for the expanation. So there are no way to improve this code to work? Since it is runned before any event? Or maybe there is a way?

You cannot have different physics lists for different energies. Some processes, or categories of processes (like “all EM processes”) where you can configure them with an energy range of validity. The Developers Guide has a whole chapter on this.

1 Like