Can't call TH1D::FindFirstBinAbove(h1->GetMaximum()/2)

Hello,

i have a simple code to read in data from an ascii file, which looks roughly like this:

0 0
1 1
2 3
3 6
4 8
5 9
6 7
7 4
8 2
9 0

The first column is the channel number and the second colum is the number of incidences per channel. My programm makes a histogram out of this. This works. The only thing that doesn’t work is to calculate the first respectively last bin above the half maximum. My code is listed below:

using namespace std;

void readIn(){

ifstream in;
in.open("AsciiFile.asc");

Double_t channel, incidence;
channel = 0;

// histo 
TH1D  *h1 =new TH1D("histo","time diff",8191,0.,100.); // *

// read in incidences per channel
while(in){

	in >> channel >> incidence;

	h1->Fill((channel/8191)*100,incidence); // **

}// read in end

cout << h1->GetMaximum() << endl;

    // this is the part that doesn't work...
int firstBin = h1->FindFirstBinAbove(h1->GetMaximum()/2);
int lastBin = h1->FindLastBinAbove(h1->GetMaximum()/2);
double fwhm = h1->GetBinCenter(firstBin) - h1->GetBinCenter(lastBin);	

}

As you can see I calibrate the x-Axis of the histogram at point * and **.
The intervall 0 to 8191 should be converted to 0 to 100 (The number of lines of the Ascii-File is 8191).
This did work too, if I drew the histogram.
The only thing that didn’t work was the last part. Root said:
Can’t call TH1D::FindFirstBinAbove(h1->GetMaximum()/2) in current scope HistoFromAscii.C
Possible candidates are…
(in TH1D)
(in TH1)
*** interpreter error recovered ***

Thanks in advance!
With kind regards,

Richard

You need ROOT version 5.24 or newer.
BTW. When you report a problem, do remember to specify the versions of your ROOT, of your operating system and of your compiler.

Okey, thank you! Next time I will remember! :slight_smile: