# Getting data from vector\<double\> branches

**URL:** <https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [March 7, 2019, 5:45am UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058 "2019-03-07T05:45:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [March 7, 2019, 5:45am UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058/1 "2019-03-07T05:45:46Z")

</div>

I have a TTree with different branches like

```auto
 *Br 7 :branch_x : vector<double> *
 *Entries : 19996000 : Total Size= 282525118 bytes File Size = 36126745 *
 *Baskets : 11387 : Basket Size= 32000 bytes Compression= 7.81

```

but when I open it in the TBrowser, the histograms have ~150000 entries. In fact, that is the number of entries I am expecting.

First, I would like to understand why when typing tree-\>Print() I see more entries than I can see in the histogram in TBrowser.

Also, I have been having a lot of problems getting the value of each entry. I followed some tutorials and other questions in this forum but nothing worked. What would be the best way to access each entry?  
So far I have been working with double objects, and I would just loop over the entries of the TTree to get the variable. Is there a similar way to work with `vector<double>` objects?

Thank you!

---

<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:** [March 7, 2019, 9:06am UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058/2 "2019-03-07T09:06:30Z")

</div>

See for example the [hvector.C tutorial](https://root.cern.ch/root/html/tutorials/tree/hvector.C.html). And using [TTreeReader](https://root.cern.ch/doc/master/classTTreeReader.html) or [RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html) could also do it (maybe @eguiraud can give you more details)

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 7, 2019, 9:30am UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058/3 "2019-03-07T09:30:48Z")

</div>

I don’t know why the number of entry is different in `TTree::Print` (may be a bug that you can report on [jira](https://sft.its.cern.ch/jira/projects/ROOT)).

To read a `vector<double>`:

```auto
TTreeReader r(treePtr);
TTreeReaderArray<double> arr(r, "branch_x");
while (r.Next()) {
  for (auto e : arr)
    std::cout << e << std::endl;
}

```

Hope this helps!  
Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [March 7, 2019, 9:56am UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058/4 "2019-03-07T09:56:36Z")

</div>

TTree::Print shows as “Entries” the number of vectors (one for each “Fill” call) stored in the branch, while the histogram in TBrowser contains all the entries of all the vectors in the branch.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 7, 2019, 10:01am UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058/5 "2019-03-07T10:01:30Z")

</div>

Thank you! What threw me off is that `Entries` printed by `TTree::Print` is higher than the reported number of entries according to the histogram – maybe a lot of the vectors are empty…?

---

<div class="post-metadata">

**Author:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [March 8, 2019, 9:58pm UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058/6 "2019-03-08T21:58:49Z")

</div>

How can I access to an specific entry with this idea? The `while (r.Next())` loop will go over every entry. How can I make it to just go from entry 500 to entry 1000, for example?

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 9, 2019, 9:12am UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058/7 "2019-03-09T09:12:25Z")

</div>

Hi,  
please check the [TTreeReader](https://root.cern.ch/doc/master/classTTreeReader.html) documentation, it has a couple different ways to loop on a custom entry range (`SetEntry`, `SetEntriesRange`).

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![nvhviet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nvhviet/32/23224_2.png) [@nvhviet](https://root-forum.cern.ch/u/nvhviet)\
**Post date:** [August 30, 2021, 9:25pm UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058/8 "2021-08-30T21:25:17Z")

</div>

Hello,  
I have a similar situation.  
#Entries in TBrowser is less then #Entries in tree-\>Print().  
And it is exactly what you mentioned, many vectors are empty.

I need to get #Entries in TBrowser.  
Do you have any hints which Root documents that I should look at to get this value?

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [August 31, 2021, 7:31am UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058/9 "2021-08-31T07:31:45Z")

</div>

Hi @nvhviet ,  
note that this is a very old thread. The histogram displayed by the TBrowser shows the number of values the histogram was filled with. Empty vectors count as zero, vectors with many elements count as N. `TTree::Print` instead lists the _number of vectors_, i.e. the number of entries in the TTree. These are two different numbers.

If this does not help please open a new topic describing your problem, I am not sure I understand what value you want to see in the TBrowser (try right-clicking on the TTree in the browser, that allows you calling some of its methods).

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![nvhviet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nvhviet/32/23224_2.png) [@nvhviet](https://root-forum.cern.ch/u/nvhviet)\
**Post date:** [September 1, 2021, 9:23pm UTC](https://root-forum.cern.ch/t/getting-data-from-vector-double-branches/33058/10 "2021-09-01T21:23:08Z")

</div>

Hello Enrico,  
Thank you for your response.  
I follow this example:  
[ROOT: tutorials/tree/hvector.C File Reference (cern.ch)](https://root.cern.ch/doc/master/hvector_8C.html)

I set the vector-type branch address and fill it into a TH1 histogram.  
Then I use the GetEntries() of the histogram to get the Entries displayed by TBrowser.

My problem is solved.  
Thank you.  
Viet
