# TTree::Draw() loop over elements in std::vector\<double\>

**URL:** <https://root-forum.cern.ch/t/ttree-draw-loop-over-elements-in-std-vector-double/54822>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [May 12, 2023, 12:17am UTC](https://root-forum.cern.ch/t/ttree-draw-loop-over-elements-in-std-vector-double/54822 "2023-05-12T00:17:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [May 12, 2023, 12:17am UTC](https://root-forum.cern.ch/t/ttree-draw-loop-over-elements-in-std-vector-double/54822/1 "2023-05-12T00:17:48Z")

</div>

Dear experts

I want to draw some waveform in a ROOT file `root -l somefile.root` which needs loops over a std::vector stored in 1 entry.  
I tried `t->Draw("vector:Iteration$","Entry$==1", "APL")`, just the same method as array, but it didn’t work. How can I achieve this with std::vector?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 12, 2023, 8:09am UTC](https://root-forum.cern.ch/t/ttree-draw-loop-over-elements-in-std-vector-double/54822/2 "2023-05-12T08:09:54Z")

</div>

This should work:  
`t->Draw("v:Iteration$", "Length$(v) > 0", "APL", 1, 0); // nentries = 1, firstentry = 0`

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [May 16, 2023, 7:59am UTC](https://root-forum.cern.ch/t/ttree-draw-loop-over-elements-in-std-vector-double/54822/3 "2023-05-16T07:59:05Z")

</div>

This gives a seg fault again… maybe the length of vector is too long that something run out of memory?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 16, 2023, 8:05am UTC](https://root-forum.cern.ch/t/ttree-draw-loop-over-elements-in-std-vector-double/54822/4 "2023-05-16T08:05:19Z")

</div>

Try: `t->Scan("Length$(v)");`

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [May 16, 2023, 8:08am UTC](https://root-forum.cern.ch/t/ttree-draw-loop-over-elements-in-std-vector-double/54822/5 "2023-05-16T08:08:06Z")

</div>

The length is 12500 for every entry

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 16, 2023, 8:34am UTC](https://root-forum.cern.ch/t/ttree-draw-loop-over-elements-in-std-vector-double/54822/6 "2023-05-16T08:34:34Z")

</div>

`12500` is a “small number” (no ROOT problems expected).

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [May 16, 2023, 8:37am UTC](https://root-forum.cern.ch/t/ttree-draw-loop-over-elements-in-std-vector-double/54822/7 "2023-05-16T08:37:17Z")

</div>

I just tried both local ROOT(v6-26-02) and ROOT on server (v6-22-02), it worked in local but gave seg fault on server…maybe it’s a version problem?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 16, 2023, 8:38am UTC](https://root-forum.cern.ch/t/ttree-draw-loop-over-elements-in-std-vector-double/54822/8 "2023-05-16T08:38:54Z")

</div>

Maybe it’s some bug in ROOT 6.22 (try the newest ROOT version)?
