hi,
I have a 1D histogram
TH1F *h=new TH1F(“h”,“histogram”,100,0.,100.);
I would to get the number of bins from range 0.0 to 50.0 of the histogram. What function can I use to get the number of bins on the X-axis of this histogram. I understand it would be 50 here, but I just wanted to find out if I can do this “programatically”
Thanks,
Christine
couet
February 12, 2014, 8:37am
2
I guess something close to:
nbin_range = ((x2_range - x1_range)/(xmax-xmin))*nbin
brun
February 12, 2014, 8:46am
3
or simpler
nbin_range = h->GetXaxis()->FindBin(50.0) - h->GetXaxis()->FindBin(0.)
Rene
dangnl
March 4, 2015, 3:22am
5
Does this method only get the number of bins at x = 50 and x = 0, then subtract them? Or does it compute all the bins between x = 0 up to x = 50?
I’m having a similar issue with this code, I have :
xrange1 = frameHisto->GetXaxis()->FindBin(100.0) - frameHisto->GetXaxis()->FindBin(0.);
xrange2 = frameHisto->GetXaxis()->FindBin(300.0) - frameHisto->GetXaxis()->FindBin(200.0);
xrange3 = frameHisto->GetXaxis()->FindBin(500.0) - frameHisto->GetXaxis()->FindBin(400.0);
xrange4 = frameHisto->GetXaxis()->FindBin(600.0) - frameHisto->GetXaxis()->FindBin(500.0);
xrange1,2,3,4 would always return the same number of entries even though I’m looping through different histograms. Any ideas?
dangnl
March 4, 2015, 4:14am
6
also what is the difference between the method above and Th2I->Integral(binx,binx2) ?
Thank you in advance
moneta
March 4, 2015, 9:37am
7
Hi,
The function frameHisto->GetXaxis()->FindBin(100.0) returns the bin number corresponding to the x value = 100.
The function Th2I->Integral(binx,binx2) returns the sum of all the contents (integral) of the bins (the y values) between the bin number binx and binx2
Best Regards
Lorenzo
dangnl
March 10, 2015, 4:59pm
9
Ok thank you, also what if I wanted to reverse and find the X and Y value of a bin/or data point on a histogram, How would I do that?
i.e I have some data point on a histogram, I want to extract the X and Y location of that point. How?
Thanks
moneta
March 10, 2015, 5:06pm
10
use TH1::GetXaxis() and TH1::GetYAxis() to get the corresponding axis and then
TAxis::GetBinCenter(ixbin) and TAxis::GetBinCenter(iybin)
Lorenzo
dangnl
March 13, 2015, 9:36am
11
also, are there anyways to do a linear fit on a 2D histogram?
moneta
March 13, 2015, 9:51am
12
Hi,
Yes, you need to define a TF2 and use the “++” sign. Something like
TF2 * f2 = new TF2("f2","1 ++ x ++ y ++ x*x ++ y*y ++ x*x*y*y");
Lorenzo