Getting histogram x axis value/plotting a TGraph

Hi all,

Apologies in advance, it’s probably a simple question but I don’t know much C++ and found the documentation hard to understand. I have a TH1F made like this:
TH1F *b = new TH1F(“b”, “NTrack”, 120, 0, 120);
For a given bin number i, I want to check whether the x-axis value is >k or <k and I’m not sure how. I’ve tried this:

for (int k=0;k<randomBigNumber;k++){
for (int i=0; i<b->GetNbinsX(); i++){
        double_t a = static_cast<double>(i);
        if(b->GetXaxis()->GetCenter(a)>k){gluons+=b->GetBinContent(i);}
}
for (int i=0;i<g->GetNbinsX();i++){
        double_t a = static_cast<double>(i);
        double_t *ptr = &a;
        if(g->GetXaxis()->GetCenter(*ptr)<k){quarks+=g->GetBinContent(i);}
}

But it tells me **cannot initialize a parameter of type 'Double_t ’ (aka 'double ') with an lvalue of type ‘double_t’ (aka ‘double’)
The same error for both for loops. Once I’ve done this I need to plot the resulting values of gluons vs quarks, and I don’t know how to do this either! I should fill an array and use that to plot a TGraph somehow but I’m not sure what the syntax should look like.

Thanks in advance for any help!

According to the doc of GetCenter, a should be an array

for (int i = 1; i <= b->GetNbinsX(); i++)
  if(b->GetBinCenter(i) > k) gluons += b->GetBinContent(i);

This triggers the same type of error, essentially that the argument of GetBinCenter can’t be an integer. I tried declaring it as a double but this just results in the error message in my first post. :frowning:

Thanks for the link! :slight_smile: But what should the array contain? I can’t give it the x, y values of the bin because that’s what I’m trying to find. Or does it mean just an uninitialised array?

TH1::GetBinCenter
TH1::GetBinContent