Infomation about parent particle

Dear Fluka experts,

I’m trying to save the information of the parent particle (espcially for muons) using the following example:

However, I encountered several problems.

The informations (PID, Etot, X, Y, Z) are not saved for every particle

When I try to do the same thing for photons and electrons using strupre.f routine I get the error:

Fortran runtime error: Index ‘0’ of dimension 2 of array ‘iespak’ below lower bound of 1

I tried to solve the last problem by changing ESPARK(1, NPNW) to ESPARK(1, 1).
Then the code compile correctly but I don’t know if it is right to do so.

I also saved the X, Y, Z position by using X/Y/ZTRACK(0), but i read in another topic that this might not be correct if there are fields in the simulation.

Even in this second case i don’t get information for all particles.

I linked an example of the dump i got here:

Thank you in advance,


ftelos.f (2.1 KB)
magfld.f (7.8 KB)
mgdraw_cps_2023-02-21.f (18.1 KB)
stupre.f (4.0 KB)
stuprf.f (1.8 KB)

Hello Antonino,

In principle, you could save the information of the parent particles without using stupre.f and stuprf.f routines.
When you have an interaction, entry USDRAW of mgdraw is called with the corresponding code of that type of interaction. Then, the properties of the secondaries produced in that interaction are stored in common GENSTK.

At the moment of the interaction, you might want to save some of the properties of the parent in the
TRACKR user variables SPAUSR(1-11) (for real values such as coordinates, energy, etc.) and ISPUSR(1-11) (for integer values such as the particle type).

In your case, this can be:

          SPAUSR(1) = XSCO
          SPAUSR(2) = YSCO
          SPAUSR(3) = ZSCO
          SPAUSR(4) = ETRACK
          ISPUSR(1) = JTRACK
          ISPUSR(2) = ICODE

These variables are now in TRACKR, which contains information about the current particle (the one which had the interaction). The secondaries of the current particle inherit them when they are transfered to the FLUKA stack.

This is done by the routines stupre.f and stuprf.f, which by default copy SPAUSR in SPAREK just before loading a particle into stack. Finally, when new particle is taken from the stack in order to transport it, this particle is filled into TRACKR, copying the SPAREK variables again in SPAUSR.

Following this logic:

  1. You save the information of the parent interaction into SPAUSR directly in USDRAW entry of the mgdraw.f routine.
  2. All the variables are copied in SPAREK when the secondaries are loaded on the stack.
  3. When the particle is downloaded from the stack for the transport (and therefore the scoring), the properties are copied back in SPAUSR.

I took the liberty to attach here a small working example (different from your case), where an electron beam imping on a small slab of copper.
test.inp (1.0 KB)
mgdraw.f (11.2 KB)

The usage of stupre.f and stuprf.f should be used if you need to do some more
sophisticated operations than just copying SPAUSR to SPAREK and ISPUSR to ISPARK. They could be used (for instance) for tracking the informations of the grand-parents (or higher order ancestors).

Allow me a final quick comment on your usage of stupre.f. The following lines:

      IESPAK(1, 1) = A
      ESPARK(1, 1) = B
      ESPARK(2, 1) = C
      ESPARK(3, 1) = D

should instead be:

          IESPAK(1, NPNW) = A
          ESPARK(1, NPNW) = B
          ESPARK(2, NPNW) = C
          ESPARK(3, NPNW) = D

I would finally encourage you to use variables in the EMFSTK when working with within the stupre.f routine. You can find them in

Let me know if this solved your problem!


Thank you very much Daniele for your very detailed answer, it was really helpful.

Sorry if I didn’t specify it well in my initial question, but what I was trying to do was to know the production vertex of the particles I was interested in (like muons) and the process that produced them. But what you have explained me should be sufficient for my purpose. Thanks again.

I’ll try what you wrote right away, and I’ll let you know.
EDIT: Tried the code and it works fine!