]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliDAJetFinder.cxx
using new TPC offline functions (r27421) to significantly speed up the reconstruction...
[u/mrichter/AliRoot.git] / JETAN / AliDAJetFinder.cxx
1
2 //  **************************************************************************
3 //  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 //  *                                                                        *
5 //  * Author: The ALICE Off-line Project.                                    *
6 //  * Contributors are mentioned in the code where appropriate.              *
7 //  *                                                                        *
8 //  * Permission to use, copy, modify and distribute this software and its   *
9 //  * documentation strictly for non-commercial purposes is hereby granted   *
10 //  * without fee, provided that the above copyright notice appears in all   *
11 //  * copies and that both the copyright notice and this permission notice   *
12 //  * appear in the supporting documentation. The authors make no claims     *
13 //  * about the suitability of this software for any purpose. It is          *
14 //  * provided "as is" without express or implied warranty.                  *
15 //  **************************************************************************
16
17 //-----------------------------------------------------------------------------------
18 // Jet finder based on Deterministic Annealing
19 // For further informations about the DA working features see:
20 // Phys.Lett. B601 (2004) 56-63 (http://arxiv.org/abs/hep-ph/0407214)
21 // Author: Davide Perrino (davide.perrino@ba.infn.it, davide.perrino@cern.ch)
22 //-----------------------------------------------------------------------------------
23
24 #include <TMath.h>
25 #include <TRandom.h>
26 #include <TClonesArray.h>
27 #include "AliJetReaderHeader.h"
28 #include "AliJetReader.h"
29 #include "AliDAJetHeader.h"
30 #include "AliDAJetFinder.h"
31
32 ClassImp(AliDAJetFinder)
33
34
35 //-----------------------------------------------------------------------------------
36 AliDAJetFinder::AliDAJetFinder():
37         AliJetFinder(),
38         fAlpha(1.01),
39         fDelta(1e-8),
40         fAvDist(1e-6),
41         fEps(1e-4),
42         fEpsMax(1e-2),
43         fNloopMax(100),
44         fBeta(0.1),
45         fNclustMax(0),
46         fNin(0)
47 {
48         // Constructor
49 }
50
51 //-----------------------------------------------------------------------------------
52 AliDAJetFinder::~AliDAJetFinder()
53 {
54         // Destructor
55 }
56
57 //-----------------------------------------------------------------------------------
58 void AliDAJetFinder::FindJets()  
59 {
60 // Find the jets in current event
61 // 
62         Float_t betaStop=100.;
63
64         Double_t dEtSum=0;
65         Double_t *xData[2];
66     TVectorD *vPx = new TVectorD();
67     TVectorD *vPy = new TVectorD();
68     TMatrixD *mPyx= new TMatrixD();
69     TMatrixD *mY  = new TMatrixD();
70         InitDetAnn(dEtSum,xData,vPx,vPy,mPyx,mY);
71         if (!fNin) return;
72
73         Int_t nc=1, nk;
74         DoubleClusters(nc,nk,vPy,mY);
75         do{                                     //loop over beta
76                 fBeta*=fAlpha;
77                 Annealing(nk,xData,vPx,vPy,mPyx,mY);
78                 NumCl(nc,nk,vPy,mPyx,mY);
79         }while((fBeta<betaStop || nc<4) && nc<fNclustMax);
80
81         Int_t *xx=new Int_t[fNin];
82         EndDetAnn(nk,xData,xx,dEtSum,vPx,vPy,mPyx,mY);
83         StoreJets(nk,xData,xx,mY);
84         delete [] xx;
85
86         delete [] xData[0], delete [] xData[1];
87         delete mPyx;
88         delete mY;
89         delete vPx;
90         delete vPy;
91
92 }
93
94 //-----------------------------------------------------------------------------------
95 void AliDAJetFinder::InitDetAnn(Double_t &dEtSum,Double_t **xData,TVectorD *vPx,TVectorD *vPy,TMatrixD *mPyx,TMatrixD *mY)
96 {
97 //Initialise the variables used by the algorithm
98         fBeta=0.1;
99         TClonesArray *lvArray = fReader->GetMomentumArray();
100         fNin = lvArray->GetEntries();
101         fNclustMax= ((AliDAJetHeader*)fHeader)->GetFixedCl() ? 
102             ((AliDAJetHeader*)fHeader)->GetNclustMax() : 
103             TMath::Max((Int_t)TMath::Sqrt(fNin),5);
104         Double_t *xEta = new Double_t[fNin];
105     Double_t *xPhi = new Double_t[fNin];
106         xData[0]=xEta; xData[1]=xPhi;
107         vPx->ResizeTo(fNin);
108         for (Int_t iIn=0; iIn<fNin; iIn++){
109                 TLorentzVector *lv=(TLorentzVector*)lvArray->At(iIn);
110                 xEta[iIn] = lv->Eta();
111                 xPhi[iIn] = lv->Phi()<0 ? lv->Phi() + 2*TMath::Pi() : lv->Phi();
112                 (*vPx)(iIn)=lv->Pt();
113                 dEtSum+=(*vPx)(iIn);
114         }
115         for (Int_t iIn=0; iIn<fNin; iIn++) (*vPx)(iIn)=(*vPx)(iIn)/dEtSum;
116
117         Int_t njdim=2*fNclustMax+1;
118         mPyx->ResizeTo(fNin,njdim);
119         mY->ResizeTo(4,njdim);
120         vPy->ResizeTo(njdim);
121         mY->Zero();mPyx->Zero();vPy->Zero();
122         (*vPy)(0)=1;
123         TMatrixDColumn(*mPyx,0)=1;
124         Double_t ypos=0,xpos=0;
125         for (Int_t iIn=0; iIn<fNin; iIn++){
126                 (*mY)(0,0)+=(*vPx)(iIn)*xEta[iIn];
127                 ypos+=(*vPx)(iIn)*TMath::Sin(xPhi[iIn]);
128                 xpos+=(*vPx)(iIn)*TMath::Cos(xPhi[iIn]);
129         }
130         (*mY)(1,0)=(atan2(ypos,xpos)>0) ? atan2(ypos,xpos) : atan2(ypos,xpos)+2*TMath::Pi();
131         lvArray->Delete();
132 }
133
134 //-----------------------------------------------------------------------------------
135 void AliDAJetFinder::DoubleClusters(Int_t nc,Int_t &nk,TVectorD *vPy,TMatrixD *mY)
136 {
137         for(Int_t iClust=0; iClust<nc; iClust++){
138                 (*vPy)(iClust)=(*vPy)(iClust)/2;
139                 (*vPy)(nc+iClust)=(*vPy)(iClust);
140                 for(Int_t iComp=0; iComp<3; iComp++) (*mY)(iComp,nc+iClust)=(*mY)(iComp,iClust);
141         }
142         nk=2*nc;
143 }
144
145 //-----------------------------------------------------------------------------------
146 void AliDAJetFinder::Annealing(Int_t nk,Double_t **xData,TVectorD *vPx,TVectorD *vPy,TMatrixD *mPyx,TMatrixD *mY)
147 {
148 // Main part of the algorithm
149         const Double_t pi=TMath::Pi();
150         TVectorD *py = new TVectorD(nk);
151         TVectorD *p  = new TVectorD(nk);
152         TMatrixD *y  = new TMatrixD(4,nk);
153         TMatrixD *y1 = new TMatrixD(4,nk);
154         TMatrixD *ry = new TMatrixD(2,nk);
155     Double_t *xEta = xData[0];
156     Double_t *xPhi = xData[1];
157         Double_t Dist(TVectorD,TVectorD);
158
159         Double_t df[2]={fReader->GetReaderHeader()->GetFiducialEtaMax(),pi};
160         TVectorD vPart(2);
161         Double_t *m = new Double_t[nk];
162         Double_t chi,chi1;
163         do{
164                 Int_t nloop=0;
165                 for (Int_t iClust=0; iClust<nk; iClust++){
166                         for (Int_t i=0; i<3; i++)(*y1)(i,iClust)=(*mY)(i,iClust);
167                         (*py)(iClust)=(*vPy)(iClust);
168                 }
169         //perturbation of codevectors
170                 Double_t seed=1000000*gRandom->Rndm(24);
171                 ry->Randomize(-0.5,0.5,seed);
172                 for (Int_t i=0; i<2; i++){
173                         for (Int_t iClust=0; iClust<nk/2; iClust++)
174                                 (*y1)(i,iClust)+=((*ry)(i,iClust)+TMath::Sign(0.5,(*ry)(i,iClust)))*fDelta*df[i];
175                         for (Int_t iClust=nk/2; iClust<nk; iClust++)
176                                 (*y1)(i,iClust)-=((*ry)(i,iClust-nk/2)+TMath::Sign(0.5,(*ry)(i,iClust-nk/2)))*fDelta*df[i];
177                 }
178                 do{
179         //recalculate conditional probabilities
180                         nloop++;
181                         for (Int_t iIn=0; iIn<fNin; iIn++){
182                                 vPart(0)=xEta[iIn]; vPart(1)=xPhi[iIn];
183                                 for(Int_t iClust=0; iClust<nk; iClust++){
184                                         (*mPyx)(iIn,iClust)=-log((*py)(iClust))+fBeta*Dist(vPart,TMatrixDColumn(*y1,iClust));
185                                         m[iClust]=(*mPyx)(iIn,iClust);
186                                 }
187                                 Double_t pyxNorm=0;
188                                 Double_t minPyx=TMath::MinElement(nk,m);
189                                 for (Int_t iClust=0; iClust<nk; iClust++){
190                                         (*mPyx)(iIn,iClust)-=minPyx;
191                                         (*mPyx)(iIn,iClust)=exp(-(*mPyx)(iIn,iClust));
192                                         pyxNorm+=(*mPyx)(iIn,iClust);
193                                 }
194                                 for (Int_t iClust=0; iClust<nk; iClust++) (*mPyx)(iIn,iClust)/=pyxNorm;
195                         }
196                         p->Zero();
197                         y->Zero();
198         //recalculate codevectors
199                         for (Int_t iClust=0; iClust<nk; iClust++){
200                                 Double_t xpos=0,ypos=0,pxy;
201                                 for (Int_t iIn=0; iIn<fNin; iIn++) (*p)(iClust)+=(*vPx)(iIn)*(*mPyx)(iIn,iClust);
202                                 for (Int_t iIn=0; iIn<fNin; iIn++){
203                                         pxy=(*vPx)(iIn)*(*mPyx)(iIn,iClust)/(*p)(iClust);
204                                         ypos+=pxy*TMath::Sin(xPhi[iIn]);
205                                         xpos+=pxy*TMath::Cos(xPhi[iIn]);
206                                         (*y)(0,iClust)+=pxy*xEta[iIn];
207                                 }
208                                 (*y)(1,iClust)=(atan2(ypos,xpos)>0) ? atan2(ypos,xpos) : atan2(ypos,xpos)+2*pi;
209                         }
210         //verify codevectors' stability
211                         chi=0;
212                         for (Int_t iClust=0; iClust<nk; iClust++){
213                                 chi1=TMath::CosH((*y1)(0,iClust)-(*y)(0,iClust))-TMath::Cos((*y1)(1,iClust)-(*y)(1,iClust));
214                                 chi1/=(2*TMath::CosH((*y1)(0,iClust))*TMath::CosH((*y)(0,iClust)));
215                                 chi1*=chi1;
216                                 if (chi1>chi) chi=chi1;
217                         }
218                         chi=TMath::Sqrt(chi);
219                         for (Int_t iClust=0; iClust<nk; iClust++){
220                                 for (Int_t i=0; i<2; i++) (*y1)(i,iClust)=(*y)(i,iClust);
221                                 (*py)(iClust)=(*p)(iClust);
222                         }
223                         if (nloop>fNloopMax){
224                                 if (chi<fEpsMax || nloop>500) break;
225                         }
226                 }while (chi>fEps);
227         }while (chi>fEpsMax);
228         for (Int_t iClust=0; iClust<nk; iClust++){                              //set codevectors and probability equal to those calculated
229                 for (Int_t i=0; i<2; i++) (*mY)(i,iClust)=(*y)(i,iClust);
230                 (*vPy)(iClust)=(*p)(iClust);
231         }
232     delete py;
233     delete p;
234     delete y;
235     delete y1;
236     delete ry;
237         delete [] m;
238 }
239
240 //-----------------------------------------------------------------------------------
241 void AliDAJetFinder::NumCl(Int_t &nc,Int_t &nk,TVectorD *vPy,TMatrixD *mPyx,TMatrixD *mY)
242 {
243         static Bool_t growcl=true;
244         
245         if (nk==2) growcl=true;
246         if (growcl){
247 //verify if two codevectors are equal within fAvDist
248                 Int_t *nSame = new Int_t[nk];
249                 Int_t **iSame = new Int_t*[nk];
250                 Int_t **cont = new Int_t*[nk];
251                 for (Int_t iClust=0; iClust<nk; iClust++) cont[iClust]=new Int_t[nk],iSame[iClust]=new Int_t[nk];
252                 for (Int_t iClust=0; iClust<nk; iClust++){
253                         iSame[iClust][iClust]=1;
254                         for (Int_t iClust1=iClust+1; iClust1<nk; iClust1++){
255                                 Double_t eta  = (*mY)(0,iClust) ; Double_t phi  = (*mY)(1,iClust);
256                                 Double_t eta1 = (*mY)(0,iClust1); Double_t phi1 = (*mY)(1,iClust1);
257                                 Double_t distCl=(TMath::CosH(eta-eta1)-TMath::Cos(phi-phi1))/(2*TMath::CosH(eta)*TMath::CosH(eta1));
258                                 if (distCl < fAvDist) iSame[iClust][iClust1]=iSame[iClust1][iClust]=1;
259                                 else iSame[iClust][iClust1]=iSame[iClust1][iClust]=0;
260                         }
261                 }
262                 ReduceClusters(iSame,nk,nc,cont,nSame);
263                 if (nc >= fNclustMax) growcl=false;
264 //recalculate the nc distinct codevectors
265                 TMatrixD *pyx = new TMatrixD(fNin,2*nc);
266                 TVectorD *py = new TVectorD(nk);
267                 TMatrixD *y1  = new TMatrixD(3,nk);
268                 for (Int_t iClust=0; iClust<nc; iClust++){
269                         for(Int_t j=0; j<nSame[iClust]; j++){
270                                 Int_t iClust1 = cont[iClust][j];
271                                 for (Int_t iIn=0; iIn<fNin; iIn++) (*pyx)(iIn,iClust)+=(*mPyx)(iIn,iClust1);
272                                 (*py)(iClust)+=(*vPy)(iClust1);
273                                 for (Int_t i=0; i<2; i++) (*y1)(i,iClust)+=(*mY)(i,iClust1);
274                         }
275                         for (Int_t i=0; i<2; i++) (*y1)(i,iClust)/=nSame[iClust];
276                 }
277                 for (Int_t iClust=0; iClust<nk; iClust++) delete [] cont[iClust], delete [] iSame[iClust];
278                 delete [] iSame;
279                 delete [] cont;
280                 delete [] nSame;
281                 if (nc > nk/2){
282                         for (Int_t iClust=0; iClust<nc; iClust++){
283                                 for (Int_t iIn=0; iIn<fNin; iIn++) (*mPyx)(iIn,iClust)=(*pyx)(iIn,iClust);
284                                 for (Int_t iComp=0; iComp<2; iComp++) (*mY)(iComp,iClust)=(*y1)(iComp,iClust);
285                                 (*vPy)(iClust)=(*py)(iClust);
286                         }
287                         nk=nc;
288                         if (growcl) DoubleClusters(nc,nk,vPy,mY);
289                 }
290                 delete pyx;
291                 delete py;
292                 delete y1;
293         }
294
295 }
296
297 //-----------------------------------------------------------------------------------
298 void AliDAJetFinder::ReduceClusters(Int_t **iSame,Int_t nc,Int_t &ncout,Int_t **cont,Int_t *nSameOut)
299 {
300         Int_t *nSame = new Int_t[nc];
301         Int_t *iperm = new Int_t[nc];
302         Int_t *go = new Int_t[nc];
303         for (Int_t iCl=0; iCl<nc; iCl++){
304                 nSame[iCl]=0;
305                 for (Int_t jCl=0; jCl<nc; jCl++) nSame[iCl]+=iSame[iCl][jCl], cont[iCl][jCl]=0;
306                 iperm[iCl]=iCl;
307                 go[iCl]=1;
308         }
309         TMath::Sort(nc,nSame,iperm,true);
310         Int_t l=0;
311         for (Int_t iCl=0; iCl<nc; iCl++){
312                 Int_t k=iperm[iCl];
313                 if (go[k] == 1){
314                         Int_t m=0;
315                         for (Int_t jCl=0; jCl<nc; jCl++){
316                                 if (iSame[k][jCl] == 1){
317                                         cont[l][m]=jCl;
318                                         go[jCl]=0;
319                                         m++;
320                                 }
321                         }
322                         nSameOut[l]=m;
323                         l++;
324                 }
325         }
326         ncout=l;
327         delete [] nSame;
328         delete [] iperm;
329         delete [] go;
330 }
331
332 //-----------------------------------------------------------------------------------
333 void AliDAJetFinder::EndDetAnn(Int_t &nk,Double_t **xData,Int_t *xx,Double_t etx,
334                                TVectorD *vPx,TVectorD *vPy,TMatrixD *mPyx,TMatrixD *mY)
335 {
336 //now assign each particle to only one cluster
337         Double_t *clusters=new Double_t[nk];
338         for (Int_t iIn=0; iIn<fNin; iIn++){
339                 for (Int_t iClust=0; iClust<nk; iClust++) clusters[iClust]=(*mPyx)(iIn,iClust);
340                 xx[iIn]=TMath::LocMax(nk,clusters);
341         }
342     delete [] clusters;
343         
344 //recalculate codevectors, having all p(y|x)=0 or 1
345     Double_t *xEta = xData[0];
346     Double_t *xPhi = xData[1];
347         mY->Zero();
348         mPyx->Zero();
349         vPy->Zero();
350         for (Int_t iIn=0; iIn<fNin; iIn++){
351                 Int_t iClust=xx[iIn];
352                 (*mPyx)(iIn,iClust)=1;
353                 (*vPy)(iClust)+=(*vPx)(iIn);
354                 (*mY)(0,iClust)+=(*vPx)(iIn)*xEta[iIn];
355                 (*mY)(3,iClust)+=(*vPx)(iIn)*etx;
356         }
357         Int_t k=0;
358         for (Int_t iClust=0; iClust<nk; iClust++){
359                 if ((*vPy)(iClust)>0){
360                         Double_t xpos=0,ypos=0,pxy;
361                         for (Int_t iIn=0; iIn<fNin; iIn++){
362                                 pxy=(*vPx)(iIn)*(*mPyx)(iIn,iClust)/(*vPy)(iClust);
363                                 ypos+=pxy*TMath::Sin(xPhi[iIn]);
364                                 xpos+=pxy*TMath::Cos(xPhi[iIn]);
365                                 if (xx[iIn]==iClust) xx[iIn]=k;
366                         }
367                         (*mY)(0,k)=(*mY)(0,iClust)/(*vPy)(iClust);
368                         (*mY)(1,k)=(atan2(ypos,xpos)>0) ? atan2(ypos,xpos) : atan2(ypos,xpos)+2*TMath::Pi();
369                         (*mY)(3,k)=(*mY)(3,iClust);
370                         k++;
371                 }
372         }
373         nk=k;
374 }
375
376 //-----------------------------------------------------------------------------------
377 void AliDAJetFinder::StoreJets(Int_t nk,Double_t **xData,Int_t *xx,TMatrixD *mY)
378 {
379 //evaluate significant clusters properties
380         const Double_t pi=TMath::Pi();
381         AliJetReaderHeader *rHeader=fReader->GetReaderHeader();
382         Float_t dFiducialEta=rHeader->GetFiducialEtaMax()-rHeader->GetFiducialEtaMin();
383         Double_t dMeanDist=TMath::Sqrt(2*dFiducialEta*pi/fNin);
384     Double_t *xEta = xData[0];
385     Double_t *xPhi = xData[1];
386         Bool_t   *isJet = new Bool_t[nk];
387         Double_t *etNoBg= new Double_t[nk];
388         Double_t *dDeltaEta=new Double_t[nk];
389         Double_t *dDeltaPhi=new Double_t[nk];
390         Double_t *surf  = new Double_t[nk];
391         Double_t *etDens= new Double_t[nk];
392         for (Int_t iClust=0; iClust<nk; iClust++){                                                                      //clusters loop
393                 isJet[iClust]=false;
394                 Double_t dEtaMin=10.,dEtaMax=-10.,dPhiMin=10.,dPhiMax=0.;
395                 for (Int_t iIn=0; iIn<fNin; iIn++){
396                         if (xx[iIn]!=iClust) continue;
397                         if (xEta[iIn] < dEtaMin) dEtaMin=xEta[iIn];
398                         if (xEta[iIn] > dEtaMax) dEtaMax=xEta[iIn];
399                         Double_t dPhi=xPhi[iIn]-(*mY)(1,iClust);
400                         if      (dPhi > pi     ) dPhi-=2*pi;
401                         else if (dPhi < (-1)*pi) dPhi+=2*pi;
402                         if      (dPhi < dPhiMin) dPhiMin=dPhi;
403                         else if (dPhi > dPhiMax) dPhiMax=dPhi;
404                 }
405                 dDeltaEta[iClust]=dEtaMax-dEtaMin+dMeanDist;
406                 dDeltaPhi[iClust]=dPhiMax-dPhiMin+dMeanDist;
407                 surf[iClust]=0.25*pi*dDeltaEta[iClust]*dDeltaPhi[iClust];
408                 etDens[iClust]=(*mY)(3,iClust)/surf[iClust];
409         }
410
411         if (((AliDAJetHeader*)fHeader)->GetSelJets()){
412                 for (Int_t iClust=0; iClust<nk; iClust++){
413                         if (!isJet[iClust]){
414                                 Double_t etDensMed=0.;
415                                 Double_t etDensSqr=0.;
416                                 Int_t norm=0;
417                                 for (Int_t iClust1=0; iClust1<nk; iClust1++){
418                                         if(iClust1!=iClust){
419                                                 etDensMed+=etDens[iClust1];
420                                                 etDensSqr+=TMath::Power(etDens[iClust1],2);
421                                                 norm++;
422                                         }
423                                 }
424                                 etDensMed/=TMath::Max(norm,1);
425                                 etDensSqr/=TMath::Max(norm,1);
426                                 Double_t deltaEtDens=TMath::Sqrt(etDensSqr-TMath::Power(etDensMed,2));
427                                 if ((*mY)(3,iClust) > (etDensMed+deltaEtDens)*surf[iClust]) isJet[iClust]=kTRUE;
428                                 etNoBg[iClust]=(*mY)(3,iClust)-etDensMed*surf[iClust];
429                         }
430                 }
431                 for (Int_t iClust=0; iClust<nk; iClust++){
432                         if (isJet[iClust]){
433                                 Double_t etDensMed=0;
434                                 Double_t extSurf=2*dFiducialEta*pi;
435                                 for (Int_t iClust1=0; iClust1<nk; iClust1++){
436                                         if (!isJet[iClust1]) etDensMed+=(*mY)(3,iClust1);
437                                         else extSurf-=surf[iClust1];
438                                 }
439                                 etDensMed/=extSurf;
440                                 etNoBg[iClust]=(*mY)(3,iClust)-etDensMed*surf[iClust];
441                                 if (etNoBg[iClust]<((AliDAJetHeader*)fHeader)->GetEtMin()){
442                                         isJet[iClust]=kFALSE;
443                                         iClust=-1;
444                                 }
445                         }
446                 }
447         } else {
448                 for (Int_t iClust=0; iClust<nk; iClust++) isJet[iClust]=true;
449         }
450         delete [] etDens;
451         delete [] surf;
452         
453 //now add selected jets to the list
454         Int_t *inJet = new Int_t[fNin];
455         TRefArray *refs = 0;
456         Bool_t fromAod = !strcmp(fReader->ClassName(),"AliJetAODReader");
457         if (fromAod) refs = fReader->GetReferences();
458         for (Int_t iClust=0; iClust<nk; iClust++){                                                                      //clusters loop
459                 if (isJet[iClust]){                                                                                                             //choose cluster
460                         Float_t px,py,pz,en;
461                         px = (*mY)(3,iClust)*TMath::Cos((*mY)(1,iClust));
462                         py = (*mY)(3,iClust)*TMath::Sin((*mY)(1,iClust));
463                         pz = (*mY)(3,iClust)/TMath::Tan(2.0 * TMath::ATan(TMath::Exp(-(*mY)(0,iClust))));
464                         en = TMath::Sqrt(px * px + py * py + pz * pz);
465                         AliAODJet jet(px, py, pz, en);
466                         if (fromAod) 
467                             for (Int_t iIn=0; iIn<fNin; iIn++) if (xx[iIn]==iClust) jet.AddTrack(refs->At(iIn));
468                         AddJet(jet);
469                         printf("jet %d, Eta: %f, Phi: %f, Et: %f\n",iClust,jet.Eta(),jet.Phi(),jet.Pt());
470                 }
471         }
472         delete [] dDeltaEta; delete [] dDeltaPhi;
473         delete [] etNoBg;
474         delete [] isJet;
475         delete [] inJet;
476 }
477
478 //-----------------------------------------------------------------------------------
479 Double_t Dist(TVectorD x,TVectorD y)
480 {
481 // Squared distance
482         const Double_t pi=TMath::Pi();
483         Double_t dphi=TMath::Abs(x(1)-y(1));
484         if (dphi > pi) dphi=2*pi-dphi;
485         Double_t dist=pow(x(0)-y(0),2)+pow(dphi,2);
486         return dist;
487 }