Flag particles individually with LOUSE

Dear Fluka experts,

I’m simulating cosmic ray cascades and I’m interested in the muon production point and the muon flux at some height where a detector is set. To do so, I’m using the user routines USRDRAW and STURPF.

In the USRDRAW routine, I activate the BXDRAW entry which gives me the muons crossing from a region to a new region (line 74 in the usrdraw file attached).

In the USRDRAW entry, I get the muons creation point, energy, etc. by recording them using the muon ancestor ID’s (line 173 in the usrdraw).

I’d like to know where, muons crossing some plane, were created and reconstruct the atmosphere profiles of the muons that reached the detector. I was trying to flag them using the integer variable LOUSE in STURPF, so I can identify if the muon created is the same as reaching the detector.
Unfortunately, when I implement a counter at my USRDRAW entry I get for each muon the same LOUSE number = 1. So in each interaction, my variable LOUSE reset to 0.

How can I implement this counter correctly to identify each muon individually?

My usrdraw and sturpf files:

usrdraw_double_det.f (8.2 KB)
stuprf_double_det.f (2.0 KB)

As always, many thanks for your help.

Cheers,

Jordi

Dear @tuneu,

I think the problem is related to the way you are setting the value of LOUSE.

First of all, who is LOUSE? LOUSE is a variable from the FLUKA COMMON FLKSTK, which contains information about the particles in the stack (not all of them). You can find more detailed information about the different stacks in FLUKA here: Particle stacks in FLUKA.

When you are trying to redefine the value of LOUSE, you are doing so to a variable in FLKSTK that is not even related to the muon you want to follow (and it may not necessarily be a muon). When you transport the muon, the information in the FLKSTK is copied to the COMMON ‘trackr’, and the stack index in FLKSTK is decreased by 1. This means that you are trying to modify the LOUSE value of another particle.

Therefore, I recommend that you properly define the value of LOUSE in your stupr.f routine. I noticed that you were trying to define a COMMON ‘FOLLOW’ with the variable LLOUSE_COM. Did this not work for you?

In the USDRAW routine, you should be dumping the LLOUSE variable. Here, you want the information from the TRACKR COMMON, where the value LOUSE was copied when the muon was unloaded to be transported.

Also, I did not understand why you need the USDRAW routine and why you want to increase the value of the muon there. Don’t you want to flag a muon when you start to transport it?

Here is one way you can proceed (if I understand correctly):

  1. In stupr.f, you can dump the information of the muon that was created (position, energy, etc.) and define the value of LOUSE that will be copied in LLOUSE.
  2. With the BXDRAW routine, you can catch the moment when the muons cross the regions and dump the relevant information plus LLOUSE to identify the muon.

I hope this has been clear. Let me know if you have any further questions.

Cheers, André

1 Like

Dear André,

Thanks for your reply. Reflecting on your points, maybe the approach I’m trying is not the best option:

Also, I did not understand why you need the USDRAW routine and why you want to increase the value of the muon there. Don’t you want to flag a muon when you start to transport it?

I use the usrdraw routine to get the point, energy, etc. where muon was created. The idea of that is to write in the output all the positions where muons appeared for the first time. Just one point, without considering further transport of that muon. Then, the muon will reach the detector or not. The bxdraw gives this information. What I’m missing is how to relate these muons from usrdraw and bxdraw.

If I understood correctly, only using the bxdraw routine could be enough? For example, if one muon reaches the detector can I get the muon position, energy etc. where it was created? When I used stuprf.f for this purpose I only got the muon ancestor which is itself one step before during the muon transport.
Is there any example to extract this information?

Many thanks,

Jordi

Dear @tuneu,

When the routine STUPR is called you are loading the secondary particles from the GENSTK to the FLKSTK. You could use the information from the GENSTK. In particular the one related to the particle IS is “KPART”

Thus, you can do the following:

  1. In your stupr.f, create a counter that will be incremented every time you load a muon. To do that, you could define an INTEGER with an initial value equal to 0 and with the command SAVE to be able to maintain the modified value after calling the routine:

            INTEGER COUNTER
            SAVE COUNTER
            DATA COUNTER / 0 / 
    

Then, when you try to load a muon:

          IF((KPART(NPSECN).eq.10).or.(KPART(NPSECN).eq.11)) THEN
                 COUNTER = COUNTER + 1
                 LOUSE(NPFLKA) = COUNTER
                 WRITE(60,*) ... [dump the info. Here you can dump the initial values of the muon**]
          ENDIF

NPSECN is the index of the current secondary

** For more variables of the GENSTK, see here at the bottom of the page (
Accessing Secondary Particle Information - #5 by nnikolop)

In this way you are flagging the muons when you load them into the FLKSTK, and dump the information of these particles in your output.

  1. Use BXDRAW to dump the info you are interested when the muons cross the regions that you want.

This should be sufficient for your needs.
If you’re having difficulty with the problem, you can share the input files with me.

Best,
André

1 Like

Dear @adonadon

Thanks a lot for your comments, they’re been very useful!

Nonetheless, some doubts appeared. This is the implementation you suggested:

IF((KPART(NPSECN).eq.10).or.(KPART(NPSECN).eq.11)) THEN
        COUNTER = COUNTER + 1
        LOUSE(NPFLKA) = COUNTER
        WRITE(60,*) KPART(1), XTRACK(0), YTRACK(0), ZTRACK(0), TKI(1), COUNTER 
ENDIF

I dumped kpart and tki from GENSTK with index (1) and XTRACK, YTRACK and ZTRACK from TRACKR with index (0). The position x, y and z is not avaiable in GENSTK, right? Those indexes will return the initial position and energy of the muon?

In my output, I get something like this:

          10   225.94706355686068        1292.1782682113505        1662817.8515096414       0.12887806109496308                1
          10   4718.8907785279625        14506.279129920327        1661842.6469648415       0.12486454263538430                2
          11   351.65777840614868        1259.9055549997124        1662058.4078775926       0.10108527473932437                3
          11   1184.1245407779652        7348.7489370211770        1657245.4271926756        9.8826404257676109E-002           4
          11   1553.3540574426836        10032.173993097775        1655165.5854481258        9.7774861446088282E-002           5
          11   1606.1711765920804        10423.737299361625        1654868.5147565219        9.7482338958464712E-002           6
          11   1791.2648044244640        11861.894650946655        1653785.6067897191        9.6775876549689888E-002           7
          11   2289.6603003076848        16040.752266172511        1650701.7443127511        9.5097688762023042E-002           8

The last column is the COUNTER implemented.
But, I’m not sure if those muons are new. For example, the muon number COUNTER= 4 it seems to be propagated in the medium decreasing slightly in energy and altitude (ZTRACK). Did I declare something wrong?

The first time a muon crosses the detector ICODE 19 is the one with COUNTER= 707. This part worked as expected :smile:

          10  -4397.8071630997983       -96741.760229013395        145507.13993427603        1.4215971004597385              707
          19          10   1.4211488010224085        1.5231469070112862        2.3552879297050888E-004           4  -4403.5539562226913       -96775.057259018693        145199.69112509879       -1.8437750318897658E-002 -0.10766018020490503      -0.99401676794781768               10           4   1.5274187392201140       -4397.8071630997983       -96741.760229013395        145507.13993427603        1.5237599252358252       -1.8466085968631224E-002 -0.10799438144261542      -0.99397998835279677              707

Thanks for your help!

Cheers,

Jordi

Dear @tuneu,

Glad to see that it is (almost) working!

The only problem I see is the way you are dumping the information in your stupr.f routine.
If you want to dump the information of the muon you are flagging, you should do the following:

    WRITE(60,*) KPART(NPSECN), XX, YY, ZZ, TKI(NPSECN), COUNTER 

Writing in your output file:

    particle ID (10 or 11), mu-x_init, mu-y_init, mu-z_init, mu-kinEn, your flag.

Cheers,
André

Dear @adonadon

I’ve implemented the way you suggested to dump the information but nothing has changed. I also included the muon parent ID to verify that it is transported ( parent ID == ID) as we see from Counter numbers from 5 to 21. The Counter = 22 it’s a new muon indeed. In the output below there are 5 muons (1,2,3,4,22).

           1          10   225.94706355686068        1292.1782682113505        1662817.8515096414       0.12887806109496308                1
          13          10   4718.8907785279625        14506.279129920327        1661842.6469648415       0.12486454263538430                2
          14          11   351.65777840614868        1259.9055549997124        1662058.4078775926       0.10108527473932437                3
          14          11   1184.1245407779652        7348.7489370211770        1657245.4271926756        9.8826404257676109E-002           4
          11          11   1553.3540574426836        10032.173993097775        1655165.5854481258        9.7774861446088282E-002           5
          11          11   1606.1711765920804        10423.737299361625        1654868.5147565219        9.7482338958464712E-002           6
          11          11   1791.2648044244640        11861.894650946655        1653785.6067897191        9.6775876549689888E-002           7
          11          11   2289.6603003076848        16040.752266172511        1650701.7443127511        9.5097688762023042E-002           8
          11          11   2428.3829253597432        17252.069793148752        1649824.8509524956        9.4557799844677035E-002           9
          11          11   2623.8720229791488        19012.251760449264        1648563.0516913757        9.3847168759536845E-002          10
          11          11   3420.7295800527413        26903.024681109051        1642852.3468332589        9.0704543066578713E-002          11
          11          11   3906.7211083440829        31105.746085906358        1639773.0850931744        8.9042098697947408E-002          12
          11          11   6094.3788679022227        53098.329421805334        1623907.7584248218        8.0200413501243142E-002          13
          11          11   6149.4948918340206        54360.324291993165        1622977.4372409268        7.9510765924360904E-002          14
          11          11   6255.5225091877983        58708.322973202063        1619889.0237587509        7.7591087942855158E-002          15
          11          11   6376.5968348681527        67373.406078083222        1613777.4499480983        7.3828129017979222E-002          16
          11          11   6429.2889358508264        70198.817120460095        1611719.9350686572        7.2497821481348965E-002          17
          11          11   6430.8682876288540        70286.835554610050        1611656.4718411302        7.1870187809050551E-002          18
          11          11   6473.0347119619410        72525.604732520151        1610079.7471749051        7.0852056416357764E-002          19
          11          11   6521.0880615900223        73637.300999901825        1609259.7482117377        7.0207964967894942E-002          20
          11          11   6855.8893929583355        85459.873139592994        1600409.4527221976        6.4316192395905122E-002          21
           1          11   913.51683057382616        206.36580918496378        1662524.9755133651        7.8807050747289262E-002          22

Taking into account all this I set a new condition eliminating the lines where the parent ID is not equal to ID. The output now seems correct showing the first 5 muons without being transported.

           1          10   225.94706355686068        1292.1782682113505        1662817.8515096414       0.12887806109496308                1
          13          10   4718.8907785279625        14506.279129920327        1661842.6469648415       0.12486454263538430                2
          14          11   351.65777840614868        1259.9055549997124        1662058.4078775926       0.10108527473932437                3
          14          11   1184.1245407779652        7348.7489370211770        1657245.4271926756        9.8826404257676109E-002           4
           1          11   913.51683057382616        206.36580918496378        1662524.9755133651        7.8807050747289262E-002           5

I don’t know if this is the most direct way to get this information but is working, so any further comments are welcome. Meanwhile, I gonna mark your second answer as a solution but all your comments have been very valuable.

All the best,

Jordi

1 Like

Dear @tuneu,

One last comment.

Be careful in the way you are filtering the muons that are “not new”.
When STUPR.F is called in one of these cases, the value of LOUSE might be reassigned as 0, losing the flag that you gave previously.

You should be able to check the value of LLOUSE (from TRACKR COMMON) in STUPR. In LLOUSE you have the flag value of the parent (the muon) that you assigned previouly. Then, you must pass in stupr the LLOUSE value to LOUSE(NPFLKA) when this muon is loaded into the FLKSTK.

I hope I am not confusing you. The only thing that I tell you is that you might be losing the track of your muons because the LOUSE value is redefined everytime a muon is copied from the GENSTK to FLKSTK. Then, you have to copy the LLOUSE value of the parent muon to the LOUSE value of this new (“not new”) muon.

Best,
André

Dear @adonadon

Be careful in the way you are filtering the muons that are “not new”.

Do you refer to the condition parent ID .ne. ID or to use the numeric indexes e.g. TKI(1). In the indexes case, I’ve implemented TKI(NPSECN) as you suggested.

Anyway, I’ll be alert on the outputs counter numbers to check if it resets and take the action you’re commenting if it is so.

Thanks!!

Jordi

1 Like