Definition of energy spectrum

Hello
I want to use spectrum instead of point energy for simulation, I got help from the macro file, but I get the error COMMAND NOT FOUND </gps/particle gamma>. Does anyone know the reason?

Did you include G4GeneralParticleSource as your primary generator in your C++ code?

Yes, but I get an undefined error. Can you explain step by step what should be done to define the energy spectrum, because I am a newbie, I would be grateful if you could help, thanks

It has nothing to do with “defining the energy spectrum.” In your PrimaryGeneratorAction, you probably currently have a data member pointer which is pointing to G4ParticleGun (because that’s the simplest generator, and it’s used in the examples). Replace that with G4GeneralParticleSource using normal C++ coding techniques.

You may also look at some of the exmaples in examples/extended/eventgenerator/.

1 Like

I did as you said, but the error no declaration matches ‘PrimaryGeneratorAction::PrimaryGeneratorAction()’
PrimaryGeneratorAction::PrimaryGeneratorAction()
Came

If you’re not comfortable with C++ programming, you probably need to either use an example without changing it, or you need some guidance on how to program in C++. There are lots of resources for that available, even though it’s not considered the “latest and greatest” any more.