# MGDRAW file combining USRDRAW and BXDRAW

Dear Fluka users,

I’m working on a question concerning GCR and muons. In the end, I’d like to retrieve information from muons crossing from one region to another.
I’ve succeeded in getting information from MGDRAW routine using BXDRAW section. Basically, the code used is this:

ENTRY BXDRAW ( ICODE, MREG, NEWREG, XSCO, YSCO, ZSCO )

IF ( .NOT. LFCOPE ) THEN
LFCOPE = .TRUE.
IF ( KOMPUT .EQ. 2 ) THEN
FILNAM = '/'//CFDRAW(1:8)//' DUMP A'
ELSE
FILNAM = 'muonBXD'
END IF
OPEN ( UNIT = 51, FILE = FILNAM, STATUS = 'NEW')
END IF
C
IF(jtrack.eq.1.and.ltrack.eq.1.and.MREG.eq.2.and.NEWREG.eq.3)THEN
eprim = etrack-am(jtrack)
idprim = jtrack
END IF
C
IF(jtrack.eq.10.or.jtrack.eq.11)THEN
emuon=etrack-am(jtrack)
IF(MREG.eq.102.and.NEWREG.eq.103)WRITE(51,*)ICODE,jtrack,
&   emuon,eprim,idprim, xsco, ysco, zsco, Atrack, Iptrck, Eptrck,
&   Wtrack, Wscrng
END IF
RETURN


Similarly, using only the USRDRAW section I get information from particles of interest in a specific region.

What I’d like is to combine both sections and write the information in a single file. Specifically, I’m interested, besides the information from USRBDX, in the process creator which is given by USRDRAW’s ICODE.

When I try to combine both sections, the simulation run without errors but it doesn’t write anything into the output file. As I’ve read in the manual, I assume combining sections in the MGDRAW file is perfectly possible. What is wrong with the logic in the code?

mgdraw_comb.f (6.9 KB)

Jordi Tuneu

Dear Jordi,

I can’t test without your Flair project file, but it seems the problem is that in Fortran (and in any programming language) the local variables are deleted between each call. (You can assume that ENTRYs are separate subroutines in Fortran with a common heading.)

You can save a variable with the SAVE statement, so it will keep its value. However this will lead to that your bdxcode variable will be always 19, so it won’t be useful filter for the output.

Cheers,
David

Dear David,

Thanks a lot for your advice. Unfortunately, the code is not filling anything yet. Please find attached the flair file, the input file, and the atmomat.card. Also, I include the mgdraw_bdx.f which works, and the mgdraw_comb.f one I try to fix.

mgdraw_bdx.f (6.7 KB)
atmomat.cards (28.7 KB)
mgdraw_box_geometry.inp (10.3 KB)
mgdraw_box_geometry.flair (9.3 KB)
mgdraw_comb.f (6.9 KB)

You can save a variable with the SAVE statement, so it will keep its value. However this will lead to that your bdxcode variable will be always 19, so it won’t be useful filter for the output.

The logic for the particle info I’m trying to register is:

From BXDRAW
If the particle is a \mu^- or a \mu^+ (save the muon energy) → if these muons cross from region A to region B (save the BXDRAW ICODE which is 19 under bdxcode).

From USRDRAW
If the bdxcode is 19 (All muons crossing from region A to region B) → write the USRDRAW ICODE and other information previously stored from BXDRAW and from trackr.inc file.

In resume, the mgdrw_bdx.f works fine for me except because I’d like to include for all particles crossing a boundary the USRDRAW ICODE (Creator process). Maybe there is an easy way to extract this and I’m complicating it.

All the best,

Jordi

Dear Jordi,

the SAVE statement is used at variable declaration not when the value is assigned. (See variable LFCOPE)

However there are some algorithmic problems with your code:

• Once bdxcode is set to 19, it will remain 19 and the test in the USDRAW entry becomes meaningless.

• The USDRAW entry is called when an interaction is happening (in region MREG, at the position XSCO, YSCO, ZSCO), it is not related at all to boundary crossings.

• Also there is no guarantee that the interaction scored with USDRAW and the muon which crossed the region are related at all.

If I understood you correctly you want to dump all secondaries created by muons, which previously crossed a region boundary. If this is true, you may use the LLOUSE, ISPUSR, or SPAUSR user variables in the trackr.inc common to mark the muons passing the boundary in BXDRAW, and use this information to filter the secondaries generated in USDRAW.

Cheers,
David

Dear David,

If this is true, you may use the LLOUSE, ISPUSR, or SPAUSR user variables in the trackr.inc common to mark the muons passing the boundary in BXDRAW, and use this information to filter the secondaries generated in USDRAW.