Hello,
I would like to change (not randomly) the energy of the primary particles for each event. To do this I have tried to get the event ID at the PrimaryGeneratorAction and use if-else statements. The code compiles and starts successfully; however, it crashes as soon as I generate the first event. Below, I paste part of the code I am using (for brevity, I present only two energies):
void B4PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
int eID = 0;
const G4Event* evt = G4RunManager::GetRunManager()->GetCurrentEvent();
eID = evt->GetEventID();
if(eID = 1){
fParticleGun->SetParticleEnergy(1MeV);
G4ParticleDefinition particleDefinition
= G4ParticleTable::GetParticleTable()->FindParticle(“gamma”);
fParticleGun->SetParticleDefinition(particleDefinition);
}
else{
fParticleGun->SetParticleEnergy(1GeV);
G4ParticleDefinition particleDefinition
= G4ParticleTable::GetParticleTable()->FindParticle(“gamma”);
fParticleGun->SetParticleDefinition(particleDefinition);
}
…
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(xD,yD,zD));
fParticleGun->SetParticlePosition(G4ThreeVector(xR, yR, z0));
fParticleGun->GeneratePrimaryVertex(anEvent);
}
Possibly, my approach is not the most efficient but I have a MATLAB code to automatically write all the if-else statements with the appropriate energies.
Hope my question and problem is understandable.
Thanks in advance,
Ivan Munoz