# chain-\>Draw("var:chain-\>GetTreeNumber()")

**URL:** <https://root-forum.cern.ch/t/chain-draw-var-chain-gettreenumber/61909>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [October 10, 2024, 2:57pm UTC](https://root-forum.cern.ch/t/chain-draw-var-chain-gettreenumber/61909 "2024-10-10T14:57:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfglinux\_gmail](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mfglinux_gmail/32/21046_2.png) [@mfglinux\_gmail](https://root-forum.cern.ch/u/mfglinux_gmail)\
**Post date:** [October 10, 2024, 2:57pm UTC](https://root-forum.cern.ch/t/chain-draw-var-chain-gettreenumber/61909/1 "2024-10-10T14:57:12Z")

</div>

Hello

Is there a way to use TTree::Draw to plot a variable vs the tree index inside its chain? for instance, if I have 10 TTree’s inside the chain, then the X axis should run from 0…9.

This was actually asked [here](https://root-forum.cern.ch/t/chain-tree-entry-id-access-in-draw/4677) but I did not find the follow up.

Thank you very much

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [October 10, 2024, 3:23pm UTC](https://root-forum.cern.ch/t/chain-draw-var-chain-gettreenumber/61909/2 "2024-10-10T15:23:11Z")

</div>

```auto
tree->Draw("X:LocalEntry$");

```

---

<div class="post-metadata">

**Author:** ![mfglinux\_gmail](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mfglinux_gmail/32/21046_2.png) [@mfglinux\_gmail](https://root-forum.cern.ch/u/mfglinux_gmail)\
**Post date:** [October 10, 2024, 3:32pm UTC](https://root-forum.cern.ch/t/chain-draw-var-chain-gettreenumber/61909/3 "2024-10-10T15:32:49Z")

</div>

Excuse me, I was probably not very clear.

If I have 10 trees with 9999 entries each, I want to plot a variable of the chain vs the number of the tree.

chain-\>Draw(“Power:NumberOfTree”,“”,“prof”)

So the variable NumberOfTree would evaluate between 0 and 9 and not between 0-9999. The variable NumberOfTree should be just an index that expresses the position of the tree in the chain.

This is useful to monitor the value of variable across each tree that takes part of the chain.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [October 10, 2024, 4:11pm UTC](https://root-forum.cern.ch/t/chain-draw-var-chain-gettreenumber/61909/4 "2024-10-10T16:11:44Z")

</div>

You can use the `This` identifier to access the TChain object and call any function on it (in your case you want `TChain::GeTreeNumber`. For example (`Draw` and `Scan` use the same syntax), the following prints the `px` (on of the branch) and the `NumberOfTree` for the first 10 entries of each of the `TTrees`.

```auto
ch.Scan("px:This->GetTreeNumber()","LocalEntry$<10")

```

---

<div class="post-metadata">

**Author:** ![mfglinux\_gmail](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mfglinux_gmail/32/21046_2.png) [@mfglinux\_gmail](https://root-forum.cern.ch/u/mfglinux_gmail)\
**Post date:** [October 11, 2024, 6:46pm UTC](https://root-forum.cern.ch/t/chain-draw-var-chain-gettreenumber/61909/5 "2024-10-11T18:46:23Z")

</div>

Awesome, thank you very much!
