Primitive Scorer producing nans in low density materials

Hello all, as ever a novice looking for guidance on something that confuses me.
Long story short I am trying to measure dosimetry delivered by x-ray imaging, to do this I constructed an object using G4PVParameterisation and attached a dosimetry primitive scorer to it. My issue is that the results from this detector occasionally produce nans or much larger values than what I would measure in a scoring mesh.
Following are examples of this where the left image is from a macro based scoring mesh and right is from my sensitive detector.

In the sensitive detector image there are a bunch of brighter streaks appear that are not in the scoring mesh image. Occasionally these artefacts also include nans, I assume from some kind of divide by zero error. It predominantly occurs in low density materials such as G4_AIR and only very rarely appears in a material like G4_WATER. It seems to be from electrons being created as secondary particles but I don’t know what part of my code could be causing it given the how it varies depending on the material.

Information about the code;

  • Following is the code I use for my ConstructSDandField
  • Then we have the code I am using to build the parameterisation
  • The entire file I am using when creating each run
    Run.cc (5.4 KB)
  • And how I am accessing data from the sensitive detector
    image
    image
    image

These are based off the DICOM example for dosimetry.
I’m pretty stumped as to why these errors are only occurring sometimes and in seemingly such specific circumstances, I really hope someone here can help troubleshoot.
Cheers,
James

1 Like

I want to do an update but I can no longer edit the question etc so I am just going to reply instead.

I restarted using the RE02 example instead and slowly modified it by adding features of my old code back into it. I found at least one part causing my nans is where I run SetRegularStructureID(1). My understanding was that this can just be applied to simple geoemtries to use a more efficient form of navigation through the volume, why would it be causing nans to be made?
Following are pictures of the simplified code showing how I am using the G4Parameterisation



Running with SetRegularStructureID creates nans, running without does not. Unfortunately the manual does not really provide a description for the command but it allows greater speed which I definitely need in my code, what’s more I don’t see a reason for it not to be working.
The phantom I’m looks like the following in each slice

Any insight into this issue would be greatly appreciated