Set the Particle Mass

We plan to change the mass of particles in G4Run to do the simulation through G4 class functions. For example, set the neutral eta particle mass as 1GeV. But there is not a function for set the mass of the G4ParticleDefinition class function, only a GetPDGMass. I am thinking about changing it through G4PrimaryParticle class function. But it didn’t works, and here is my codes, and I do not know how to initialize the pointer here.
G4PrimaryParticle* particle_1 = theParticleIterator1->value();
std::cout << " " << particle->GetPDGMass() << " " << std::endl;

It says the pointer cannot be converted to the G4PrimaryParticle type. Do anyone know how to initialize the pointer or set the mass of the particle here? Thanks!

You can set the primary particle mass with SetMass() as you have it above. That overrides the default PDG mass that is set in the G4ParticleDefinition. To see the “dynamical mass” you set for the particle, use particle_1->GetMass().

If you want to do something similar when creating secondary tracks, you can set the mass of the G4DynamicParticle which is a data member of G4Track. Again, the value you set applies only to that track, and overrides the default PDG mass from the G4ParticleDefinition.

Thanks for your reply, it seems works, but why I tried to use particle->GetPDGMass() to see, it seems still the original value? Is that a problem?

Because you’re asking to see the default PDG mass. That’s the name of the function. If you want to see the mass value you set, then you should be calling particle_1->GetMass(). Reading the .hh file might be helpful to you.