Change from Particlegun to GPS

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

Geant4 Version:
Operating System:
CMake Version:

Dear All,
I am using the NeutronSource example. and I want to change the particle generator to GPS (It is gun type)
therefore I have replaced the and PrimaryGeneratorAction.hh
I copied the new two files from the B1 example
I just copied and past without changing.

Now I have issues with the
error: no matching constructor for initialization of ‘PrimaryGeneratorAction’
** PrimaryGeneratorAction* primary = new PrimaryGeneratorAction(fDetector);**

Do I need to change the and ActionInitialization.hh

Or I can solve it in more easier steps??

Thanks in advance

That error’s because the primary generator action in example B1 has a constructor with no arguments:

whilst that in NeutronSource takes a pointer to the detector construction. Just update any instantiations of PrimaryGeneratorAction to use the no-argument form, e.g.

// wrong:
// PrimaryGeneratorAction* primary = new PrimaryGeneratorAction(fDetector);**

//should work
PrimaryGeneratorAction* primary = new PrimaryGeneratorAction();

Thanks a lot,
In the “” I replaced the
PrimaryGeneratorAction* primary = new PrimaryGeneratorAction(fDetector);


PrimaryGeneratorAction* primary = new PrimaryGeneratorAction();


But currently I have issues with the run manager, it is defined as gunparticle. Do I need to delete this definition??
“src/ error: no member named ‘GetParticleGun’ in ‘PrimaryGeneratorAction’
= fPrimary->GetParticleGun()->GetParticleDefinition();
~~~~~~~~ ^
/Users/kafaal-khasawneh/JRTR/untitled folder/NeutronSource/src/ error: no member named ‘GetParticleGun’ in ‘PrimaryGeneratorAction’
G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();”

Probably - as you’re modifying the example’s PrimaryGeneratorAction you’ll need to decide if these are still needed or not depending on your use case.

Another possibility, perhaps better, is that as the NeutronSource example also uses G4ParticleGun:

you could try replacing that with G4GeneralParticleSource. Some of the use of this instead of G4ParticleGun would need modifying, but might be easier.