# Coincidence time between two detectors

**URL:** <https://fluka-forum.web.cern.ch/t/coincidence-time-between-two-detectors/8456>\
**Category:** Advanced Features and User Routines\
**Created:** [24 June 2026 17:24 UTC](https://fluka-forum.web.cern.ch/t/coincidence-time-between-two-detectors/8456 "2026-06-24T17:24:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sxm3816](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/sxm3816/32/8163_2.png) [@sxm3816](https://fluka-forum.web.cern.ch/u/sxm3816)\
**Post date:** [24 June 2026 17:24 UTC](https://fluka-forum.web.cern.ch/t/coincidence-time-between-two-detectors/8456/1 "2026-06-24T17:24:54Z")

</div>

### Versions

> Please provide the used software versions.

_FLUKA_:FLUKA Version 4-5.1  
_Flair_: 3.4-5.4  
_Operating system_: FEDORA 42  
_Compiler_:

### Description

> Dear all
> 
> Greetings! I am trying to simulate the coincidence timing between two detectors. The setup is similar to the one shown in - [FLUKA for fast timing method](https://fluka-forum.web.cern.ch/t/fluka-for-fast-timing-method/6025)
> 
> In short, I have a Na22 source. I have two detectors around the source. one is for 1.2 MeV gamma while the other is for 511 keV one. I want to simulate the time difference between the detection of these two gamma photons. For this, I have modified the mgdraw.f file to include the following section-
> 
> ```auto
> ENTRY USDRAW ( ICODE, MREG, XSCO, YSCO, ZSCO )
> IF ( .NOT. LFCOPE ) THEN
> LFCOPE = .TRUE.
> 
> ```
> 
> ! the files will record the gamma energy dep in the detectors  
> OPEN ( UNIT = 92, FILE = “colldet1”, STATUS = ‘UNKNOWN’)  
> OPEN ( UNIT = 93, FILE = “colldet2”, STATUS = ‘UNKNOWN’)  
> END IF  
> ! IF( ICODE .EQ. 110) THEN  
> DO KP = 1, NP  
> ! now check if the particle is gamma and is product of annihilation and in the correct region  
> IF (KPART(KP) .EQ.7 .AND. MREG .EQ.4 ) THEN  
> WRITE(92,‘(1P,4G25.15)’) ZSCO, TKI (KP),  
> & ATRACK, NCASE  
> ELSE IF (KPART(KP) .EQ.7 .AND. MREG .EQ.5 ) THEN  
> WRITE(93,‘(1P,4G25.15)’) ZSCO, TKI (KP),  
> & ATRACK, NCASE  
> !  
> END IF  
> ENDDO  
> !  
> RETURN

My question is that is there a way to modify USDRAW so that it outputs which gamma ray initiated the energy deposition- 1.2 MeV or the 511 keV one?

thanks and regards

saurabh

### Input files

> [triple\_coink1.flair](https://fluka-forum.web.cern.ch/uploads/short-url/7MEZLw3rB9hgQQIDLWCqy255HV2.flair) (2.0 KB)
> 
> [mgdraw\_pos\_ann\_gamma\_timing.f](https://fluka-forum.web.cern.ch/uploads/short-url/44lTHFbkT1pAvv7Ejyhlt6gr1Sg.f) (15.6 KB)
> 
> Please upload all relevant files. (FLUKA input file, Flair project file, user routines, and data files)

---

<div class="post-metadata">

**Author:** ![alserban](https://fluka-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@alserban](https://fluka-forum.web.cern.ch/u/alserban)\
**Post date:** [26 June 2026 15:07 UTC](https://fluka-forum.web.cern.ch/t/coincidence-time-between-two-detectors/8456/3 "2026-06-26T15:07:43Z")

</div>

Dear Saurabh,

Thank you for your question. I am currently looking into it and will get back to you soon.

Best regards,

Alexandra

---

<div class="post-metadata">

**Author:** ![sxm3816](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/sxm3816/32/8163_2.png) [@sxm3816](https://fluka-forum.web.cern.ch/u/sxm3816)\
**Post date:** [29 June 2026 05:05 UTC](https://fluka-forum.web.cern.ch/t/coincidence-time-between-two-detectors/8456/4 "2026-06-29T05:05:02Z")

</div>

Thank you for the reply. One way might be that we distinguish the 511 keV and 1.2 MeV based on their origin. 511 keV comes from annihilation event while 1.2 MeV is emitted when the Ne atom transitions to the ground state. Will it be possible to distinguish these two events in USDRAW? This method may not work for other isotope, say Co60. thanks & regards

---

<div class="post-metadata">

**Author:** ![alserban](https://fluka-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@alserban](https://fluka-forum.web.cern.ch/u/alserban)\
**Post date:** [6 July 2026 11:33 UTC](https://fluka-forum.web.cern.ch/t/coincidence-time-between-two-detectors/8456/5 "2026-07-06T11:33:45Z")

</div>

Dear Saurabh,

Thanks for the follow-up, and my apologies for the wait.

There are two main points to be addressed:

1. 

> I want to simulate the time difference between the detection of these two gamma photons.

Decaying radioisotopes as source terms in FLUKA are treated in **semi-analogue mode**. This implies that decay products are explicitly sampled and transported, but they are sampled from **inclusive spectra** : on average you get the right number, kind, and energy of decay products, but one loses possible correlations among them, _i.e._, **no correlated** gamma cascade is reproduced.

1. 

> My question is that is there a way to modify USDRAW so that it outputs which gamma ray initiated the energy deposition- 1.2 MeV or the 511 keV one?

Gammas themselves do not deposit energy directly, but they create secondary electrons (and positrons) which then travel and deposit the actual energy in your detector.

If you only track the gamma in `USDRAW`, you will miss the actual energy deposited by the electron shower. Instead, you need to score the energy in two places inside `mgdraw.f`, using a tagging system to trace where that energy came from:

- _continuous energy loss_: as tracked electrons travel through your detector, they continuously deposit energy along their step. This must be scored at the very top of `mgdraw.f` (before the other entries) using the `DTRACK` array.
- _point-like energy deposition_: when an electron’s kinetic energy falls below the transport threshold (which defaults to 100 keV under the `PRECISIOn` default settings without any `EMFCUT` card applied), FLUKA stops tracking it and dumps its remaining energy locally. This must be scored in the `ENDRAW` entry of `mgdraw.f` using the `RULL` variable.

To identify which gamma initiated the shower you can use the `ISPUSR` integer array which allows you to tag a particle and propagate that tag to all of its daughter particles.

For this, in addition to the `mgdraw.f` that you are already using, you will need the `stupre.f` and `stuprf.f` user routines. Whenever a new particle is created and put on a stack, `STUPRE` or `STUPRF` is called depending on the type of interaction that created the particle.

Whenever a gamma is created you can intercept it as follows:

- if its energy is around 1.27 MeV (the prompt gamma from the Na transition), tag it as 1 in `stuprf.f` (triggered by primary generations, as well as hadronic and photonuclear interactions) using the main stack variables (`ILOFLK = 7` and `TKEFLK` in **GeV** ).
- if its energy is around 511 keV (originating from secondary positron annihilation), tag it as 2 in `stupre.f` (triggered by pure electromagnetic interactions) using the EMF stack variables (`ICHEMF = 0` and `ETEMF` in **MeV** ).
- if it is a secondary electron, it inherits the tag of its parent.

Now that every electron in the shower carries the tag (1 or 2) of the gamma that spawned it, you can score the actual deposited energy in your detectors.

Finally, to get the total energy deposited in the detector for a single coincidence event, you will need to post-process the output and sum up all the `DTRACK` (from the continous energy loss) and`RULL` (from the point-like energy depositions) values that share the same event number (`NCASE`), region (`MREG`), and tag (`ISPUSR`).

P.S. 1: As you pointed out, origin-based tagging (_e.g._, only checking if the parent is a positron) fails for 60Co since both gammas are emitted directly from the nucleus. Checking the initial energy of the gamma is therefore a way to overcome this.

P.S. 2: For good measure, I recommend starting from the `mgdraw_empty.f` user routine. And then you can safely select `Score: All (WHAT(4) = 0)` in the `USERDUMP` card.

Hope this helps!

Best regards,

Alexandra

---

<div class="post-metadata">

**Author:** ![sxm3816](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/sxm3816/32/8163_2.png) [@sxm3816](https://fluka-forum.web.cern.ch/u/sxm3816)\
**Post date:** [19 July 2026 15:44 UTC](https://fluka-forum.web.cern.ch/t/coincidence-time-between-two-detectors/8456/6 "2026-07-19T15:44:49Z")

</div>

Dear Alexandra,

Sorry it took me so long to reply. I was making very slow progress, actually none at all. I realized that for my simulation, instead of using Na22 as source, it will be better that i use the source\_newgen to emit 3 gamma photons at the same time- one 1.2 MeV and two 511 keV. The relevant part of the source\_newgen code is here-

```auto
 particle_code = 7

  momentum_energy = 0.0012
  call sample_isotropic_direction( direction_cosx, direction_cosy, direction_cosz )
  call set_primary()
  
  momentum_energy = 0.000511
  call sample_isotropic_direction( direction_cosx, direction_cosy, direction_cosz )
  call set_primary()

  momentum_energy = 0.000511
  call sample_isotropic_direction( direction_cosx, direction_cosy, direction_cosz )
  call set_primary()
  
  return

```

Then, I use the SODROW part in MGDRAW to assign the kinetic energy of the primary particle to SPAUSR(1).

```auto
      ENTRY SODRAW
* capture the kinetic energy of the primary particle (TKEFLK)
* and save it to the first user variable slot in the
* tracking common block
      SPAUSR(1) = TKEFLK(1)
      RETURN

```

Following this, I use the USDRAW part of MGDRAW to write the parent particle energy-

```auto
 ENTRY USDRAW ( ICODE, MREG, XSCO, YSCO, ZSCO )
  IF ( .NOT. LFCOPE ) THEN
     LFCOPE = .TRUE.
     WRITE ( 89, * ) '#Information about particles in region', MREG
	 WRITE ( 89, * ) '#NCASE,ICODE,JTRACK,LTRACK, ETRACK'
	 WRITE ( 88, * ) '#Information about parent particles in region', MREG
	 WRITE ( 88, * ) '#NCASE,ICODE,JTRACK,ETRACK'
  END IF

  IF ( MREG .EQ.4) THEN

```

- 

```auto
  current particles attributes		 
   WRITE ( 89, * ) NCASE,ICODE,JTRACK,LTRACK, ETRACK

```

- 

```auto
  the number of secondary particles and the corresponding particle ID		 
   WRITE ( 89, * ) NP, (KPART(I),I=1,NP)
    END IF 

```

- 

```auto
  parent particles attributes	  
   WRITE ( 88, * ) SPAUSR(1)

```

The output of this is all zeros in the 88 file. I thought that it could be because of source\_newgen.f. But changing the source to plain photon of 2 MeV yielded the same result.

can you please help?

apologies for the delay.

sincerely

saurabh

[triple\_coink1.flair](https://fluka-forum.web.cern.ch/uploads/short-url/vlI1IWDG2PjCjNGt3O1H2eLBx4z.flair) (2.3 KB)

[stupre.f](https://fluka-forum.web.cern.ch/uploads/short-url/9yvIGS4C4Bt2ynJ7wnLFQWW3ekv.f) (3.8 KB)

[source\_newgen\_gamma\_timing1.f](https://fluka-forum.web.cern.ch/uploads/short-url/3imRLRGxEi7MJryufAwajZNS9sd.f) (4.8 KB)

[mgdraw\_with\_parent\_particle\_energy.f](https://fluka-forum.web.cern.ch/uploads/short-url/em65LvLAfNZLbnpZGEX95yTKu20.f) (10.8 KB)

---

<div class="post-metadata">

**Author:** ![alserban](https://fluka-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@alserban](https://fluka-forum.web.cern.ch/u/alserban)\
**Post date:** [20 July 2026 14:44 UTC](https://fluka-forum.web.cern.ch/t/coincidence-time-between-two-detectors/8456/7 "2026-07-20T14:44:53Z")

</div>

Dear Saurabh,

Thank you for your follow-up.

Now that you are using `source_newgen.f` to generate your gammas directly as primary particles, you can invoke the `ISPARK` and `SPAREK` arrays within the source routine itself to tag them at production, as shown below:

 ![](https://fluka-forum.web.cern.ch/uploads/default/original/2X/e/eee555fc57aa7b6b41bdf99e8c314d9f5af29b7c.png)

Proceeding like this, you no longer need the `stupre.f` or `stuprf.f` routines. Additionally, the kinetic energy assignment in the `SODRAW` entry of `mgdraw.f` should be removed.

Regarding `mgdraw.f`, please refer back to my previous reply, and in particular to the places where the continuous and point-like energy depositions need to be scored.

P.S.: Make sure to uncomment the `SOURCE` card in your input file.

I hope this helps.

Best regards,

Alexandra

---

<div class="post-metadata">

**Author:** ![sxm3816](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/sxm3816/32/8163_2.png) [@sxm3816](https://fluka-forum.web.cern.ch/u/sxm3816)\
**Post date:** [25 July 2026 17:00 UTC](https://fluka-forum.web.cern.ch/t/coincidence-time-between-two-detectors/8456/8 "2026-07-25T17:00:46Z")

</div>

Dear Alexandra,

Thanks! That worked nicely.

sincerely

saurabh

---

<div class="post-metadata">

**Author:** ![horvathd](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/horvathd/32/10584_2.png) [@horvathd](https://fluka-forum.web.cern.ch/u/horvathd)\
**Post date:** [10 August 2026 14:05 UTC](https://fluka-forum.web.cern.ch/t/coincidence-time-between-two-detectors/8456/9 "2026-08-10T14:05:26Z")

</div>

Closed on 10 August 2026 14:05 UTC


