Problem constructing TH2F

Dear experts,

I experience the following problem, I am trying to use the TH2F constructor:

TH2F(const char* name, const char* title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, const Double_t* ybins)

via the following commands in root interactively:

root [0] const Float_t b_f[9]={0.,0.1,0.16,0.2,0.25,0.3,0.35,0.4,0.6}; root [1] TH2F*h=new TH2F("a","a",10,0,1,9,b_f)

but I fail with the following message:

Error: Can't call TH2F::TH2F("a","a",10,0,1,9,b_f) in current scope (tmpfile):1: Possible candidates are... (in TH2F) /opt/products/root/5.18.00/lib/libHist.so -1:-1 0 public: TH2F TH2F::TH2F(void); /opt/products/root/5.18.00/lib/libHist.so -1:-1 0 public: TH2F TH2F::TH2F(const char* name,const char* title,Int_t nbinsx,Double_t xlow,Double_t xup,Int_t nbinsy,Double_t ylow,Double_t yup); /opt/products/root/5.18.00/lib/libHist.so -1:-1 0 public: TH2F TH2F::TH2F(const char* name,const char* title,Int_t nbinsx,const Double_t* xbins,Int_t nbinsy,Double_t ylow,Double_t yup); /opt/products/root/5.18.00/lib/libHist.so -1:-1 0 public: TH2F TH2F::TH2F(const char* name,const char* title,Int_t nbinsx,Double_t xlow,Double_t xup,Int_t nbinsy,const Double_t* ybins); /opt/products/root/5.18.00/lib/libHist.so -1:-1 0 public: TH2F TH2F::TH2F(const char* name,const char* title,Int_t nbinsx,const Double_t* xbins,Int_t nbinsy,const Double_t* ybins); /opt/products/root/5.18.00/lib/libHist.so -1:-1 0 public: TH2F TH2F::TH2F(const char* name,const char* title,Int_t nbinsx,const Float_t* xbins,Int_t nbinsy,const Float_t* ybins); /opt/products/root/5.18.00/lib/libHist.so -1:-1 0 public: TH2F TH2F::TH2F(const TMatrixFBase& m); /opt/products/root/5.18.00/lib/libHist.so -1:-1 0 public: TH2F TH2F::TH2F(const TH2F& h2f); (in TH2) (in TH1) *** Interpreter error recovered ***

and I really have no idea why!

root version is 5.18, any help or advice will he highly appreciated!!!

The right way is:

Double_t b_f[9]={0.,0.1,0.16,0.2,0.25,0.3,0.35,0.4,0.6};
TH2F*h=new TH2F("a","a",10,0,1,8,b_f);

This is really strange, Floats were working ALWAYS for all the rest of the constructors of TH2F (TH1F respectively), this is why I didn’t try to use doubles at all… thanks however!

That’s not only Float into Double, the number of bins should be 8… not 9

oh, no!

believe me it was correct, I was trying to compile and I couldn’t, and now when i changed the floats to double it all vanished like with wand…

(Number of bins = array_dimension) gives:

root [0] Double_t b_f[9]={0.,0.1,0.16,0.2,0.25,0.3,0.35,0.4,0.6};
root [1] TH2F*h=new TH2F("a","a",10,0,1,9,b_f)
Error in <TAxis::TAxis::Set>: bins must be in increasing order
root [2]

(Number of bins = array_dimension-1) gives:

root [0] Double_t b_f[9]={0.,0.1,0.16,0.2,0.25,0.3,0.35,0.4,0.6};
root [1] TH2F*h=new TH2F("a","a",10,0,1,8,b_f)
root [2]

That’s logic, the array defines the bins’ boundaries.

[quote]believe me it was correct
[/quote]
No. I do not believe.

[quote]I was trying to compile and I couldn’t
[/quote]
I can see a little contradiction here: “it was correct” and at the same moment “I couldn’t” - so decide, if it is correct and you can compile it, or it’s incorrect and you can not compile it. Compiler usually knows C++ better, than you :slight_smile:))

You know, float and double are two different types, pointer to float and pointer to double are different types, and pointer to float can not be implicitly converted into pointer to double (and that’s a very good and right thing about pointers). It’s a pity, that CINT can do this:

float arr[10];
double *p = arr;

which is illegal and very serious error in a code.

//duplicate was deleted

Hi
This comment of yours solve a problem I had. Why is it 8 instead of 9? Could you please clarify this?

This small detail was not obvious in the ROOT documentation.
Thanks.
Kris

To define “n” bins you need “n+1” bins’ limits :


 v1  v2  v3   v3
 +---+---+---+
  b1  b2  b3

the 3 bins bi (i=1,3) need 4 values vi (i=1,4) to be define.

Thanks a lot!