The following function did work in root_v5.18/00 w/o the need to compile it:
Double_t Median(Int_t n, const Double_t *arr)
{
if (n == 1) return arr[0];
// Create index and sort array
Int_t *index = 0;
if (!(index = new Int_t[n])) {return 1;}
TMath::Sort(n, arr, index);
// Find median
Int_t k;
Double_t median = 0;
if ((n % 2) == 0){
k = (Int_t)TMath::Floor(n / 2.0) - 1;
median = (arr[index[k]] + arr[index[k+1]])/2;
} else {
k = (Int_t)TMath::Floor(n / 2.0);
median = arr[index[k]];
}//if
delete [] index;
return median;
}//Median
However, in root_v15.20/00 I get the following error:
Error: Function Sort(n,arr,index) is not defined in current scope
Replacing index with:
Long64_t *index = 0;
//or:
// long long *index = 0;
if (!(index = new Long64_t[n])) {return 1;}
results in the following error:
Error: Symbol TMath is not defined in current scope
The problem is clearly the change in the definition of TMath::Sort() between root_v5.18/00 and root_v15.20/00.
It would be great if CINT could handle the new definitions w/o the need to compile, or alternatively the
old definition of TMath::Sort() could be added to TMath.