# How to store and plot an array embedded into a vector

**URL:** <https://root-forum.cern.ch/t/how-to-store-and-plot-an-array-embedded-into-a-vector/18905>\
**Category:** ROOT\
**Created:** [March 2, 2015, 1:40pm UTC](https://root-forum.cern.ch/t/how-to-store-and-plot-an-array-embedded-into-a-vector/18905 "2015-03-02T13:40:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [March 2, 2015, 1:40pm UTC](https://root-forum.cern.ch/t/how-to-store-and-plot-an-array-embedded-into-a-vector/18905/1 "2015-03-02T13:40:48Z")

</div>

Hello, I am a bit lost about how to store into a TTree a vector of array and how to access it in order to plot the data inside each array.

Basically, I have a set of array of 8192 unsigned short.  
So I store each array in a vector defined as

```auto

```

Than I define a TTree with a branch like that

`TTree *t = new TTree("t","t");
t->Branch("A","std::vector <unsigned short>","&(A)[8192])`  
I am not sure if it is the good way to define the branch but if so, how to access to the data contained in A in order to draw them?  
I would like to do something like

```auto

```

and get an histogram of 8192 bins relative to the 10th box of the vector A.

I hope it is pretty clear. If not, please tell me; I will try to explain better.

---

<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:** [March 2, 2015, 2:31pm UTC](https://root-forum.cern.ch/t/how-to-store-and-plot-an-array-embedded-into-a-vector/18905/2 "2015-03-02T14:31:24Z")

</div>

Have a look at the [${ROOTSYS}/tutorials/tree/hvector.C](https://root.cern.ch/root/html534/tutorials/tree/hvector.C.html) (simple vectors) and [$ROOTSYS/tutorials/tree/tree2.C](https://root.cern.ch/root/html534/tutorials/tree/tree2.C.html) (fixed and variable length arrays, see also [ROOT User’s Guide -\> Trees -\> Example 2: A Tree with a C Structure](https://root.cern.ch/root/html534/guides/users-guide/Trees.html#example-2-a-tree-with-a-c-structure)) and [${ROOTSYS}/tutorials/tree/tree3.C](https://root.cern.ch/root/html534/tutorials/tree/tree3.C.html) (variable length arrays) tutorials.

---

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [March 2, 2015, 3:08pm UTC](https://root-forum.cern.ch/t/how-to-store-and-plot-an-array-embedded-into-a-vector/18905/3 "2015-03-02T15:08:21Z")

</div>

Thanks for the reply. So if I understood correctly hvector.C, the way to draw an histogram that contains what is stored in a vector is to fill the histogram bin by bin

[code]for (UInt\_t j = 0; j \< vpx-\>size(); ++j) {

```
     h->Fill(vpx->at(j));          

  }[/code]

```

Is there another way to draw directly the content of an array? Maybe I should attach in the TTree a vector of TH1S …
