Storing efficiency numbers into array

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?..


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:

        constexpr Double_t int1 = 8.5, int2 = 34.1;
        std::vector<Double_t> myVec = {int1/int2};
        printf("My fraction is %f\n",;
1 Like

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?

You can use

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]);

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

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

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]));

Thank you so much! It worked perfectly!:slight_smile: