-//_________________________________________________________________________
-Int_t AliTOFpidESD::LoadClusters(TTree *dTree, AliTOFGeometry *geom) {
- //--------------------------------------------------------------------
- //This function loads the TOF clusters
- //--------------------------------------------------------------------
- TBranch *branch=dTree->GetBranch("TOF");
- if (!branch) {
- Error("LoadClusters"," can't get the branch with the TOF digits !\n");
- return 1;
- }
-
- TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
- branch->SetAddress(&digits);
-
- dTree->GetEvent(0);
- Int_t nd=digits->GetEntriesFast();
- Info("LoadClusters","number of digits: %d",nd);
-
- for (Int_t i=0; i<nd; i++) {
- AliTOFdigit *d=(AliTOFdigit*)digits->UncheckedAt(i);
- Int_t dig[5]; Float_t g[3];
- dig[0]=d->GetSector();
- dig[1]=d->GetPlate();
- dig[2]=d->GetStrip();
- dig[3]=d->GetPadz();
- dig[4]=d->GetPadx();
-
- geom->GetPos(dig,g);
-
- Double_t h[5];
- h[0]=TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
- h[1]=TMath::ATan2(g[1],g[0]); h[2]=g[2];
- h[3]=d->GetTdc(); h[4]=d->GetAdc();
-
- AliTOFcluster *cl=new AliTOFcluster(h,d->GetTracks(),i);
- InsertCluster(cl);
- }
-
- return 0;
-}
-
-//_________________________________________________________________________
-void AliTOFpidESD::UnloadClusters() {
- //--------------------------------------------------------------------
- //This function unloads TOF clusters
- //--------------------------------------------------------------------
- for (Int_t i=0; i<fN; i++) delete fClusters[i];
- fN=0;
-}
-
-//_________________________________________________________________________
-Int_t AliTOFpidESD::InsertCluster(AliTOFcluster *c) {
- //--------------------------------------------------------------------
- //This function adds a cluster to the array of clusters sorted in Z
- //--------------------------------------------------------------------
- if (fN==kMaxCluster) {
- Error("InsertCluster","Too many clusters !\n");
- return 1;
- }
-
- if (fN==0) {fClusters[fN++]=c; return 0;}
- Int_t i=FindClusterIndex(c->GetZ());
- memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTOFcluster*));
- fClusters[i]=c; fN++;
-
- return 0;
-}
-
-//_________________________________________________________________________
-Int_t AliTOFpidESD::FindClusterIndex(Double_t z) const {
- //--------------------------------------------------------------------
- // This function returns the index of the nearest cluster
- //--------------------------------------------------------------------
- if (fN==0) return 0;
- if (z <= fClusters[0]->GetZ()) return 0;
- if (z > fClusters[fN-1]->GetZ()) return fN;
- Int_t b=0, e=fN-1, m=(b+e)/2;
- for (; b<e; m=(b+e)/2) {
- if (z > fClusters[m]->GetZ()) b=m+1;
- else e=m;
- }
- return m;
-}
-
-static int cmp(const void *p1, const void *p2) {
- AliESDtrack *t1=*((AliESDtrack**)p1);
- AliESDtrack *t2=*((AliESDtrack**)p2);
- Double_t c1[15]; t1->GetExternalCovariance(c1);
- Double_t c2[15]; t2->GetExternalCovariance(c2);
- if (c1[0]*c1[2] <c2[0]*c2[2]) return -1;
- if (c1[0]*c1[2]==c2[0]*c2[2]) return 0;
- return 1;
-}
-