Re: Problem in using TMath::Sort function

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Wed, 06 Sep 2006 07:10:48 +0200


You are misusing TMath::Sort.
The second argument is the array to be sorted. This array is not modified. The result of Sort is in the output array index.

Rene Brun

SUDHIR BHARDWAJ wrote:
> Daer Root Team,
>
> I am using TMath::Sort(Long64_t n1, const Float_t *a, Long64_t *index,
> Bool_t down) function with the following program.
> ***********************************************************
>
>
> #include <TMath.h>
>
> void sort()
> {
> const Int_t event = 1;
> Int_t ntracks;
> Float_t rand[30000];
> Int_t index[30000];
> for(Int_t ev=0;ev<event;ev++)
> {
> ntracks = 10;
>
> for(Int_t tra = 0;tra<=ntracks;tra++)
> {
> index[tra] = tra;
> rand[tra] = gRandom->Rndm(1);
> cout<<"rand 1 = "<<rand[tra]<<endl;
> TMath::Sort(ntracks,rand,index);
>
> cout<<"rand 2 = "<<rand[tra]<<endl;
> }
> //cout<<TMath::Median(ntracks,rand)<<endl;
> }
> }
>
> ************************************************************
>
>
>
> It does not sort with it.
> Please tell me where I am wrong.
> What should I do for sorting this array ?
>
> Thanks in advance,
> with regards,
> sudhir
>
>
> --
> Sudhir Bhardwaj
Received on Wed Sep 06 2006 - 07:10:50 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:00 MET