TH2: y bin size depending on x value

Dear all,

I would like to create a TH2 where the binning of one axis depends on the range of the other axis.

For example, assuming an x-axis with 10 bins from 0. to 10., I would like to define a y-axis with 20 bins from 0. to 10. if x is less than 5 and 10 bins otherwise.

Is this possible? Many thanks for your help! Best regards,

Florian

Use the TH2 constructor with variable bin size

TH2(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup ,Int_t nbinsy,const Double_t *ybins);
Rene

[quote=“brun”]Use the TH2 constructor with variable bin size

TH2(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup ,Int_t nbinsy,const Double_t *ybins);
Rene[/quote]

Dear Rene,

thanks for your reply, but wouldn’t the y-binning then be the same for all x values? Let me rephrase my problem. Assume two histograms declared in the following way:

TH2D* h1 = new TH2D("h1", "", 10, 0., 5., 20, 0., 10.);
TH2D* h2 = new TH2D("h2", "", 10, 5., 10., 10, 0., 10.);

They differ in the y-axis bin size depending on the x-value. My question is whether it is possible to define a single TH2 histogram with these binnings?

How would this work with the constructor you suggested?

Many thanks and best regards, Florian

Sorry, I misunderstood your question.
A possible solution is to use the not-well-documented class TKDtree

Rene