Adding GetPolarization() Function to G4HadProjectile Causing Segmentation Fault with Inelastic Processes

I’m trying something a little unorthodox here, so I’m not sure if anyone has any suggestions but hoping for a little guidance.

I’ve been working on testing some spin polarization effects in low energy neutron scattering using the ParticleHP model. In order to do this, I need to store and call the spin polarization of the neutrons. This is possible for a G4DynamicParticle using GetPolarization(), but for the ParticleHP model, the neutron is stored as a G4HadProjectile. I was able to add a GetPolarization() function to a custom G4HadProjectile class that works as intended when I am simulating elastic scattering. However, when I try to add inelastic processes (G4HadronPhysicsQGSP_BIC_HP and G4IonPhysicsXS), I get a segmentation fault when running the simulation. Everything is able to compile, but it seems that the GetPolarization function I added is causing issues with some process in the classes I used for inelastic physics. I’ve been investigating where the problem is coming from but haven’t been able to find anything. I am wondering if anyone has any insight or guidance into what process might be causing problems because of a GetPolarization function I add to the G4HadProjectile class. Thank you.

If you modified G4HadProjectile.hh, did you recompile all of the G4 code that uses it? Or did you introduce a different version of it only in your application code? Adding a virtual function changes the memory layout of the object, and if different code (in different libraries) were compiled with different memory layouts, then you’ll end up with a segfault eventually.

This seems to have fixed the issue, thank you! I originally would recompile all of G4 source code each time I edited any source files, but I switched to including the custom files when I just build the simulation. Good to know this doesn’t work the way I thought it did. Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.