I have issue that after calling GetXbins() in TAxis class I get null-size pointer to array. Maybe I am doing something wrong, please see my code. Histo_Mratio is populated T2D (I am drawing it for a check.)
MRxbins=[0.,0.4]
OldBins=TArrayD()
OldBins= Histo_Mratio.GetXaxis().GetXbins() #nOldBins = OldBins.GetSize()
nOldBins = 10
print nOldBins
for ibin in xrange(nOldBins):
binEdge=OldBins.GetAt(ibin)
print binEdge
if binEdge>MRxbins[1]:
MRxbins.append(binEdge)
if binEdge<MRxbins[0]:
MRxbins.prepend(binEdge)
If your histogram is a “fix bin size” one then “GetXbins” makes no sense (“GetSize” for this array returns 0 as it is not used at all).
BTW. You should have something like:
TH2D *Histo_Mratio = ((TH2D *)((datafile.Get(“Mratio_dRqs”))->Clone(“Mratio_dRqs”)))
Ok. I see. I thought it would return array of low edges even for fixed size histograms. And actually, I still think it would make sense. But o.k…
I wanted to use that to merge two bins given histogram. Is there any claver function that could merge just range of bins which are specified and rest of the binnig remains as it was in given histogram?
Try to play with something like this (it should work for fix and variable bin size histograms): TH2D *Histo_Mratio = ((TH2D *)((datafile.Get("Mratio_dRqs"))->Clone("Mratio_dRqs")));
Int_t N = Histo_Mratio->GetXaxis()->GetNbins();
// bin 1 is the first bin, bin (N + 1) is the "overflow bin"
for (Int_t i = 1; i <= (N + 1); i++) cout << Histo_Mratio->GetXaxis()->GetBinLowEdge(i) << endl;
May be such loop can be done in GetXbins to build the vector in case of fixed binning.
I am do not know if that will be useful or not.
Lorenzo may have an idea about that.
Actually, I think, for a 2D histogram you should use something like:
Int_t gbin = someTH2->FindBin(someXvalue, someYvalue);
If you use:
Int_t gbin = someTH2->GetXaxis()->FindBin(someXvalue);
then you will get the “global bin” number for the corresponding “underflow bin” in “Y”.