# Multiple loop indices in TTree::Draw()?

**URL:** <https://root-forum.cern.ch/t/multiple-loop-indices-in-ttree-draw/65073>\
**Category:** ROOT\
**Tags:** tree\
**Created:** [November 27, 2026, 9:42am UTC](https://root-forum.cern.ch/t/multiple-loop-indices-in-ttree-draw/65073 "2026-11-27T09:42:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![treesaregood](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/treesaregood/32/40118_2.png) [@treesaregood](https://root-forum.cern.ch/u/treesaregood)\
**Post date:** [November 27, 2026, 9:42am UTC](https://root-forum.cern.ch/t/multiple-loop-indices-in-ttree-draw/65073/1 "2026-11-27T09:42:37Z")

</div>

* * *

_ROOT Version:_ 6.40.04  
_Platform:_ linuxx8664gcc  
_Compiler:_ gcc

* * *

Hi,

Would it be possible to expose multiple independent loop indices in `TTree::Draw()`, to plot coincidences between hits in variable-length arrays from the command-line?  
I find myself wanting to do this very often. 🙂

For example, with gamma detector hit arrays `GAe[GAn]`, `GAt[GAn]` and charged-particle detector hit arrays `CDe[CDn]`, `CDt[CDn]`:

Gamma-gamma coincidences with a timing cut:

```auto
t->Draw("GAe[i0$]:GAe[i1$]",
        "(i0$ != i1$) && (fabs(GAt[i0$] - GAt[i1$]) < 10)");

```

Particle-gated gamma-gamma coincidences (with a graphical cut `mycut` on the `CD` arrays) (effectively a triple-loop):

```auto
t->Draw("GAe[i1$]:GAe[i2$]",
        "mycut && (i1$ != i2$) && "
        "(fabs(GAt[i1$] - CDt[i0$]) < 100) && "
        "(fabs(GAt[i2$] - CDt[i0$]) < 100) && "
        "(fabs(GAt[i1$] - GAt[i2$]) < 10)");

```

(here `mycut` would implicitly references the `CD` arrays via `i0$` as the first dimension, or an explicitly notation might be useful too).

Since TTreeFormula / TTreeFormulaManager already handles multi-index nested loops when matrices are involved, it seems the underlying machinery is there and the missing link is exposing explicit dimension indices (like `i0$`, `i1$`, `i2$`, analogous to `Iteration$`) in the parser?

Best regards,  
Håkan

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 27, 2026, 12:17pm UTC](https://root-forum.cern.ch/t/multiple-loop-indices-in-ttree-draw/65073/2 "2026-11-27T12:17:18Z")

</div>

Maybe @pcanal knows if there’s a solution
