Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect against wrong primary particle mass #1233

Closed
atolosadelgado opened this issue Feb 22, 2024 · 14 comments
Closed

Protect against wrong primary particle mass #1233

atolosadelgado opened this issue Feb 22, 2024 · 14 comments

Comments

@atolosadelgado
Copy link
Contributor

Hi,

ddsim allows to load primary particles from an external file, but it seems there is no sanity check for the mass of the particles.

Question: would be worth to check the mass of the primary particles before starting the simulation? This issue would affect the builtin particle gun, which allows to define a total energy of primary particle smaller than the mass (e.g., an alpha particle with 1 MeV).

Best,
Alvaro

@andresailer
Copy link
Member

Doesn't this rather mean to check against insufficient total energy, and not check against the mass of the particle? For my education, what happens if one simulates the alpha with 1 MeV total energy?

I am also not sure if you refer to the particle.tbl file, which allows one to define additional particles, but it doesn't allow one to overwrite particles Geant4 already knows.

// don't add if the particle already exists
G4ParticleDefinition* p = theParticleTable->FindParticle(pdg);
if ( !p ) {

There is no way for us to know what the correct mass of a particle is. If there are MC records used as input, which define include the mass of particles, we could check that that mass is consistent with the mass of the defined, but this doesn't sound like the issue you are raising here.

Cheers,
Andre

@atolosadelgado
Copy link
Contributor Author

Hi,

For my education, what happens if one simulates the alpha with 1 MeV total energy?

ddsim still assigns a positive kinetic energy to the alpha, but well below 1 MeV. Simulation runs but the output is wrong. It can be very misleading.

we could check that that mass is consistent with the mass of the defined

Yes, that would be my point. Sorry I was not clear enough.

Best,
Alvaro

@andresailer
Copy link
Member

Yes, that would be my point. Sorry I was not clear enough.

But my proposal would do nothing for the 1 MeV Alpha case? The mass of the Alpha isn't changed, is it?

@atolosadelgado
Copy link
Contributor Author

The alpha at 1 MeV should still trigger an exception because the tabulated mass is bigger than the input value of E_kin+mass*c**2.

@andresailer
Copy link
Member

What is the tabulated mass? What is E_kin and mass in the 1 MeV alpha case?
(I need to understand, or I can't even begin to implement anything to check this)

@atolosadelgado
Copy link
Contributor Author

Geant4 maintains a table with all possible particles and their properties. Accessing the static properties of particles can be done as follows:

// Geant4 example: extended/electromagnetic/TestEm18/src/PrimaryGeneratorAction.cc
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
...
G4ParticleDefinition* particle = G4ParticleTable::GetParticleTable()->FindParticle("alpha");
G4double particle_mass = particle->GetPDGMass();
G4bool particle_stable   = particle->GetPDGStable();

The mass of the alpha particle is retrieved using the above snippet.

The DD4hep native particle gun requires the energy parameter to include the mass of the particle, so specifying 1 MeV for an alpha particle is incorrect. If the mass is not accounted for, it could lead to erroneous simulations.

Similar issues may arise when setting up the primaries from a hepmc3 file.

In my opinion, it would be safer to throw an exception when encountering such inconsistencies before starting the actual simulation.

There is a dedicated way to declare new particles for Geant4; it is not possible to run a simulation with an incorrect mass for a known particle.

@MarkusFrankATcernch
Copy link
Contributor

Hi Alvaro,

I verified again in the code:

  • The Geant4ParticleGenerator with the property "Energy" / "energy" implicitly uses energy as kinetic energy.
  • When the G4 primary is created it has the proper energy (Geant4InputHandling.cpp:351):
    sqrt(momentum2 + mass2)

I cannot see anything wrong with that - except that the property name is perhaps not entirely detailed.
What do I miss?

It is true, if an input file contains 3-momentum and energy and at the same time the particle mass
loaded from external file is largely bigger than what was used to generate the input file, this might end up with
a computed "negative" mass or momentum.
Is this what you meant?

@atolosadelgado
Copy link
Contributor Author

atolosadelgado commented May 2, 2024

It is true, if an input file contains 3-momentum and energy and at the same time the particle mass
loaded from external file is largely bigger than what was used to generate the input file, this might end up with
a computed "negative" mass or momentum.
Is this what you meant?

Yes, that it is. Additionally, even with positive mass, there might be a mismatch between the derived mass from input 3momentum+energy and the mass value used by Geant4. For example, if the input is E=5, pc=4, the derived mass would be mc2 = 3, but the internal Geant4 value for that particle mass may be 2.5.

In case the derived mass value is smaller than 10 eV, the dynamical mass is set to zero. In case is larger by more than 10 eV than the PDG value, the input mass is taken. This behavior is implemented here.

Thank you for taking a look to this :)

@atolosadelgado
Copy link
Contributor Author

I had a quick chat with some Geant4 people, and I will open a review of the G4PrimaryParticle class to add a sanity check there.

A piece of code may be added in the hepMC3 reader in order to check the mass consistency of the derived value from the input and the value from Geant4/PDG. What do you think?

@MarkusFrankATcernch
Copy link
Contributor

Ideally the check is done in a central piece of code where the data of all readers, generators and guns are processed.
I suspect this is somewhere in Geant4InputHandling.cpp.

@andresailer
Copy link
Member

Maybe here

static G4PrimaryParticle* createG4Primary(const Geant4ParticleHandle p) {

@MarkusFrankATcernch
Copy link
Contributor

@andresailer This is a very good place. all is present and also the particle definitions are queried from Geant4.
I will put the fix there.

@atolosadelgado
Copy link
Contributor Author

after reading a bit more Geant4 code, I noticed that G4PrimaryParticle actually implements a check for negative masses here.

I have asked some colleagues from the FCC physics performance studies group, if implementing a check for the input particle mass would be an obstacle for their work or not (just to be sure).

@MarkusFrankATcernch
Copy link
Contributor

Please see MR #1259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants