# Storing efficiency numbers into array

**URL:** <https://root-forum.cern.ch/t/storing-efficiency-numbers-into-array/44150>\
**Category:** Newbie\
**Created:** [March 24, 2021, 6:16pm UTC](https://root-forum.cern.ch/t/storing-efficiency-numbers-into-array/44150 "2021-03-24T18:16:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [March 24, 2021, 6:16pm UTC](https://root-forum.cern.ch/t/storing-efficiency-numbers-into-array/44150/1 "2021-03-24T18:16:53Z")

</div>

Hi all,  
I am trying to store obtained values into an array, for this I thought it’s better to use vector, however when I call it, just to check - cout \<\< digitArray[0] \<\< endl; I get “-nan” output. The value I want to fill this array with is there and is “double\_t” .

So, I am doing following. I am filling two histograms and taking the fraction of their integrals, then I have a number and I want to store that number in an array (or vector). Why isn’t my solution working?..

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [March 24, 2021, 6:54pm UTC](https://root-forum.cern.ch/t/storing-efficiency-numbers-into-array/44150/2 "2021-03-24T18:54:40Z")

</div>

Hi,

suppose `int1` is the integral of your first histogram and `int2` is the one of your second histogram. Then you store their ratio in a vector:

```auto
        constexpr Double_t int1 = 8.5, int2 = 34.1;
        std::vector<Double_t> myVec = {int1/int2};
        printf("My fraction is %f\n", myVec.at(0));

```

---

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [March 24, 2021, 10:37pm UTC](https://root-forum.cern.ch/t/storing-efficiency-numbers-into-array/44150/3 "2021-03-24T22:37:36Z")

</div>

Thanks @yus! It worked perfectly fine! So, now if I want to build a TGraph with these numbers, I can’t do it since I used a vector, not an array, right? Or is it possible to build TGraph from vector entries?

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [March 25, 2021, 8:28am UTC](https://root-forum.cern.ch/t/storing-efficiency-numbers-into-array/44150/4 "2021-03-25T08:28:48Z")

</div>

You can use

```c++
std::vector<double> x = {...};
std::vector<double> y = {...};
assert(x.size() == y.size() && "x and y vectors must have the same size!");
TGraph g(TGraph(x.size(),&x[0],&y[0]);

```

---

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [March 25, 2021, 4:04pm UTC](https://root-forum.cern.ch/t/storing-efficiency-numbers-into-array/44150/5 "2021-03-25T16:04:26Z")

</div>

Hi,  
Thanks for your reply. This will build TGraph with only first numbers of the vector, right ? How can I make so that it builds with all numbers in the vector?

I tried something like : for(Double\_t x : myFirstVec && Double\_t y : mySecondVec) {  
TGraph g(TGraph(x.size(), x, y);  
}

but well, it does not really work. Since i cannot draw it outside the for loop

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [March 25, 2021, 4:35pm UTC](https://root-forum.cern.ch/t/storing-efficiency-numbers-into-array/44150/6 "2021-03-25T16:35:25Z")

</div>

> [@beg1nner](#):
>
> This will build TGraph with only first numbers of the vector, right ?

No, this is for all of them. Check this out in ROOT prompt:

```auto
std::vector<double> x = {0., 1., 2., 3., 4.};
std::vector<double> y = {0., 1., 2., 3., 4.};
TGraph g(TGraph(x.size(),&x[0],&y[0]));
g.Draw("AC*");

```

---

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [March 25, 2021, 5:26pm UTC](https://root-forum.cern.ch/t/storing-efficiency-numbers-into-array/44150/7 "2021-03-25T17:26:10Z")

</div>

Thank you so much! It worked perfectly!🙂
