Dear ROOTers,
I’m trying to use TMath::Median using some code kindly provided by Rene. Median() however always returns either 0 or such values as 2.92501e-301. Please see the attached code below. I call the function with
median1(histo);
assuming that histo is a TH1F *.
Thank you,
TY
Double_t MediMean::median1(TH1 *h1) {
//compute the median for 1-d histogram h1
Long64_t nbins = h1->GetXaxis()->GetNbins();
cout << "nbins : " << nbins << endl;
Double_t *x = new double[nbins];
Double_t *y = new double[nbins];
for (Int_t i=0;i<nbins>GetXaxis()->GetBinCenter(i+1);
y[i] = h1->GetBinContent(i+1);
cout << "y[" << i << "] : " << y[i] << endl;
}
Double_t median = TMath::Median(nbins,x,y);
delete [] x;
delete [] y;
return median;
}