]> git.uio.no Git - u/mrichter/AliRoot.git/blame - JETAN/AliDAJetFinder.cxx
Update
[u/mrichter/AliRoot.git] / JETAN / AliDAJetFinder.cxx
CommitLineData
9e4cc50d 1
7c679be0 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>
386b2e2f 25#include <TRandom2.h>
7c679be0 26#include <TClonesArray.h>
36b5cc43 27#include "AliJetReaderHeader.h"
7c679be0 28#include "AliJetReader.h"
29#include "AliDAJetHeader.h"
30#include "AliDAJetFinder.h"
31
7c679be0 32ClassImp(AliDAJetFinder)
33
34
35//-----------------------------------------------------------------------------------
36AliDAJetFinder::AliDAJetFinder():
36b5cc43 37 AliJetFinder(),
7c679be0 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),
386b2e2f 46 fNin(0),
47 fNeff(0)
7c679be0 48{
49 // Constructor
50}
51
52//-----------------------------------------------------------------------------------
53AliDAJetFinder::~AliDAJetFinder()
54{
55 // Destructor
7c679be0 56}
57
58//-----------------------------------------------------------------------------------
59void AliDAJetFinder::FindJets()
60{
61// Find the jets in current event
62//
63 Float_t betaStop=100.;
386b2e2f 64 fDebug = fHeader->GetDebug();
7c679be0 65
66 Double_t dEtSum=0;
36b5cc43 67 Double_t *xData[2];
386b2e2f 68 TVectorD *vPx = new TVectorD();
69 TVectorD *vPy = new TVectorD();
70 TMatrixD *mPyx= new TMatrixD();
71 TMatrixD *mY = new TMatrixD();
36b5cc43 72 InitDetAnn(dEtSum,xData,vPx,vPy,mPyx,mY);
95345ec0 73 if (fNin < fNclustMax){
74 delete [] xData[0], delete [] xData[1];
75 delete vPx;
76 delete vPy;
77 delete mPyx;
78 delete mY;
79 return;
80 }
36b5cc43 81 Int_t nc=1, nk;
82 DoubleClusters(nc,nk,vPy,mY);
7c679be0 83 do{ //loop over beta
84 fBeta*=fAlpha;
36b5cc43 85 Annealing(nk,xData,vPx,vPy,mPyx,mY);
86 NumCl(nc,nk,vPy,mPyx,mY);
7c679be0 87 }while((fBeta<betaStop || nc<4) && nc<fNclustMax);
88
386b2e2f 89 Int_t *xx=new Int_t[fNeff];
36b5cc43 90 EndDetAnn(nk,xData,xx,dEtSum,vPx,vPy,mPyx,mY);
91 StoreJets(nk,xData,xx,mY);
7c679be0 92 delete [] xx;
93
36b5cc43 94 delete [] xData[0], delete [] xData[1];
95 delete mPyx;
96 delete mY;
97 delete vPx;
98 delete vPy;
99
7c679be0 100}
101
102//-----------------------------------------------------------------------------------
36b5cc43 103void AliDAJetFinder::InitDetAnn(Double_t &dEtSum,Double_t **xData,TVectorD *vPx,TVectorD *vPy,TMatrixD *mPyx,TMatrixD *mY)
7c679be0 104{
105//Initialise the variables used by the algorithm
106 fBeta=0.1;
386b2e2f 107 fNclustMax = ((AliDAJetHeader*)fHeader)->GetFixedCl() ?
36b5cc43 108 ((AliDAJetHeader*)fHeader)->GetNclustMax() :
9e4cc50d 109 TMath::Max((Int_t)TMath::Sqrt(fNin),5);
386b2e2f 110 Float_t etaEff = ((AliDAJetHeader*)fHeader)->GetEtaEff();
e53baffe 111 TClonesArray *lvArray = fReader->GetMomentumArray();
112 Int_t nEntr = lvArray->GetEntries();
113 fNin=0;
114 for (Int_t iEn=0; iEn<nEntr; iEn++) if (fReader->GetCutFlag(iEn)==1) fNin++;
386b2e2f 115
116 fNeff = ((AliDAJetHeader*)fHeader)->GetNeff();
117 fNeff = TMath::Max(fNeff,fNin);
118 Double_t *xEta = new Double_t[fNeff];
119 Double_t *xPhi = new Double_t[fNeff];
36b5cc43 120 xData[0]=xEta; xData[1]=xPhi;
386b2e2f 121 vPx->ResizeTo(fNeff);
e53baffe 122 Int_t iIn=0;
123 for (Int_t iEn=0; iEn<nEntr; iEn++){
124 if (fReader->GetCutFlag(iEn)==0) continue;
125 TLorentzVector *lv=(TLorentzVector*)lvArray->At(iEn);
36b5cc43 126 xEta[iIn] = lv->Eta();
127 xPhi[iIn] = lv->Phi()<0 ? lv->Phi() + 2*TMath::Pi() : lv->Phi();
128 (*vPx)(iIn)=lv->Pt();
129 dEtSum+=(*vPx)(iIn);
e53baffe 130 iIn++;
7c679be0 131 }
386b2e2f 132 TRandom2 r;
133 r.SetSeed(0);
d072acbe 134 for (iIn=fNin; iIn<fNeff; iIn++){
386b2e2f 135 xEta[iIn]=r.Uniform(-1*etaEff,etaEff);
136 xPhi[iIn]=r.Uniform(0.,2*TMath::Pi());
137 (*vPx)(iIn)=r.Uniform(0.01,0.02);
138 dEtSum+=(*vPx)(iIn);
139 }
140 for (iIn=0; iIn<fNeff; iIn++) (*vPx)(iIn)=(*vPx)(iIn)/dEtSum;
7c679be0 141
142 Int_t njdim=2*fNclustMax+1;
386b2e2f 143 mPyx->ResizeTo(fNeff,njdim);
36b5cc43 144 mY->ResizeTo(4,njdim);
145 vPy->ResizeTo(njdim);
146 mY->Zero();mPyx->Zero();vPy->Zero();
147 (*vPy)(0)=1;
148 TMatrixDColumn(*mPyx,0)=1;
7c679be0 149 Double_t ypos=0,xpos=0;
386b2e2f 150 for (iIn=0; iIn<fNeff; iIn++){
36b5cc43 151 (*mY)(0,0)+=(*vPx)(iIn)*xEta[iIn];
152 ypos+=(*vPx)(iIn)*TMath::Sin(xPhi[iIn]);
153 xpos+=(*vPx)(iIn)*TMath::Cos(xPhi[iIn]);
7c679be0 154 }
36b5cc43 155 (*mY)(1,0)=(atan2(ypos,xpos)>0) ? atan2(ypos,xpos) : atan2(ypos,xpos)+2*TMath::Pi();
7c679be0 156}
157
158//-----------------------------------------------------------------------------------
1240edf5 159void AliDAJetFinder::DoubleClusters(Int_t nc,Int_t &nk, TVectorD *vPy, TMatrixD *mY) const
7c679be0 160{
1240edf5 161// Return double clusters
7c679be0 162 for(Int_t iClust=0; iClust<nc; iClust++){
36b5cc43 163 (*vPy)(iClust)=(*vPy)(iClust)/2;
164 (*vPy)(nc+iClust)=(*vPy)(iClust);
165 for(Int_t iComp=0; iComp<3; iComp++) (*mY)(iComp,nc+iClust)=(*mY)(iComp,iClust);
7c679be0 166 }
167 nk=2*nc;
168}
169
170//-----------------------------------------------------------------------------------
c0a5117c 171void AliDAJetFinder::Annealing(Int_t nk,Double_t **xData, TVectorD *vPx, TVectorD *vPy, TMatrixD *mPyx, TMatrixD *mY)
7c679be0 172{
173// Main part of the algorithm
174 const Double_t pi=TMath::Pi();
175 TVectorD *py = new TVectorD(nk);
176 TVectorD *p = new TVectorD(nk);
177 TMatrixD *y = new TMatrixD(4,nk);
178 TMatrixD *y1 = new TMatrixD(4,nk);
179 TMatrixD *ry = new TMatrixD(2,nk);
386b2e2f 180 Double_t *xEta = xData[0];
181 Double_t *xPhi = xData[1];
7c679be0 182 Double_t Dist(TVectorD,TVectorD);
183
36b5cc43 184 Double_t df[2]={fReader->GetReaderHeader()->GetFiducialEtaMax(),pi};
7c679be0 185 TVectorD vPart(2);
186 Double_t *m = new Double_t[nk];
187 Double_t chi,chi1;
188 do{
189 Int_t nloop=0;
190 for (Int_t iClust=0; iClust<nk; iClust++){
36b5cc43 191 for (Int_t i=0; i<3; i++)(*y1)(i,iClust)=(*mY)(i,iClust);
192 (*py)(iClust)=(*vPy)(iClust);
7c679be0 193 }
194 //perturbation of codevectors
195 Double_t seed=1000000*gRandom->Rndm(24);
196 ry->Randomize(-0.5,0.5,seed);
197 for (Int_t i=0; i<2; i++){
198 for (Int_t iClust=0; iClust<nk/2; iClust++)
199 (*y1)(i,iClust)+=((*ry)(i,iClust)+TMath::Sign(0.5,(*ry)(i,iClust)))*fDelta*df[i];
200 for (Int_t iClust=nk/2; iClust<nk; iClust++)
201 (*y1)(i,iClust)-=((*ry)(i,iClust-nk/2)+TMath::Sign(0.5,(*ry)(i,iClust-nk/2)))*fDelta*df[i];
202 }
203 do{
204 //recalculate conditional probabilities
205 nloop++;
386b2e2f 206 for (Int_t iIn=0; iIn<fNeff; iIn++){
36b5cc43 207 vPart(0)=xEta[iIn]; vPart(1)=xPhi[iIn];
7c679be0 208 for(Int_t iClust=0; iClust<nk; iClust++){
36b5cc43 209 (*mPyx)(iIn,iClust)=-log((*py)(iClust))+fBeta*Dist(vPart,TMatrixDColumn(*y1,iClust));
210 m[iClust]=(*mPyx)(iIn,iClust);
7c679be0 211 }
212 Double_t pyxNorm=0;
213 Double_t minPyx=TMath::MinElement(nk,m);
214 for (Int_t iClust=0; iClust<nk; iClust++){
36b5cc43 215 (*mPyx)(iIn,iClust)-=minPyx;
216 (*mPyx)(iIn,iClust)=exp(-(*mPyx)(iIn,iClust));
217 pyxNorm+=(*mPyx)(iIn,iClust);
7c679be0 218 }
36b5cc43 219 for (Int_t iClust=0; iClust<nk; iClust++) (*mPyx)(iIn,iClust)/=pyxNorm;
7c679be0 220 }
221 p->Zero();
222 y->Zero();
223 //recalculate codevectors
224 for (Int_t iClust=0; iClust<nk; iClust++){
225 Double_t xpos=0,ypos=0,pxy;
386b2e2f 226 for (Int_t iIn=0; iIn<fNeff; iIn++) (*p)(iClust)+=(*vPx)(iIn)*(*mPyx)(iIn,iClust);
227 for (Int_t iIn=0; iIn<fNeff; iIn++){
36b5cc43 228 pxy=(*vPx)(iIn)*(*mPyx)(iIn,iClust)/(*p)(iClust);
229 ypos+=pxy*TMath::Sin(xPhi[iIn]);
230 xpos+=pxy*TMath::Cos(xPhi[iIn]);
231 (*y)(0,iClust)+=pxy*xEta[iIn];
7c679be0 232 }
233 (*y)(1,iClust)=(atan2(ypos,xpos)>0) ? atan2(ypos,xpos) : atan2(ypos,xpos)+2*pi;
234 }
235 //verify codevectors' stability
236 chi=0;
237 for (Int_t iClust=0; iClust<nk; iClust++){
238 chi1=TMath::CosH((*y1)(0,iClust)-(*y)(0,iClust))-TMath::Cos((*y1)(1,iClust)-(*y)(1,iClust));
239 chi1/=(2*TMath::CosH((*y1)(0,iClust))*TMath::CosH((*y)(0,iClust)));
240 chi1*=chi1;
241 if (chi1>chi) chi=chi1;
242 }
243 chi=TMath::Sqrt(chi);
244 for (Int_t iClust=0; iClust<nk; iClust++){
245 for (Int_t i=0; i<2; i++) (*y1)(i,iClust)=(*y)(i,iClust);
246 (*py)(iClust)=(*p)(iClust);
247 }
248 if (nloop>fNloopMax){
249 if (chi<fEpsMax || nloop>500) break;
250 }
251 }while (chi>fEps);
252 }while (chi>fEpsMax);
253 for (Int_t iClust=0; iClust<nk; iClust++){ //set codevectors and probability equal to those calculated
36b5cc43 254 for (Int_t i=0; i<2; i++) (*mY)(i,iClust)=(*y)(i,iClust);
255 (*vPy)(iClust)=(*p)(iClust);
7c679be0 256 }
257 delete py;
258 delete p;
259 delete y;
260 delete y1;
261 delete ry;
c0a5117c 262 delete [] m;
7c679be0 263}
264
265//-----------------------------------------------------------------------------------
c0a5117c 266void AliDAJetFinder::NumCl(Int_t &nc,Int_t &nk,TVectorD *vPy, TMatrixD *mPyx,TMatrixD *mY)
7c679be0 267{
1240edf5 268 // Number of clusters
7c679be0 269 static Bool_t growcl=true;
270
271 if (nk==2) growcl=true;
272 if (growcl){
273//verify if two codevectors are equal within fAvDist
274 Int_t *nSame = new Int_t[nk];
275 Int_t **iSame = new Int_t*[nk];
276 Int_t **cont = new Int_t*[nk];
277 for (Int_t iClust=0; iClust<nk; iClust++) cont[iClust]=new Int_t[nk],iSame[iClust]=new Int_t[nk];
278 for (Int_t iClust=0; iClust<nk; iClust++){
279 iSame[iClust][iClust]=1;
280 for (Int_t iClust1=iClust+1; iClust1<nk; iClust1++){
36b5cc43 281 Double_t eta = (*mY)(0,iClust) ; Double_t phi = (*mY)(1,iClust);
282 Double_t eta1 = (*mY)(0,iClust1); Double_t phi1 = (*mY)(1,iClust1);
7c679be0 283 Double_t distCl=(TMath::CosH(eta-eta1)-TMath::Cos(phi-phi1))/(2*TMath::CosH(eta)*TMath::CosH(eta1));
284 if (distCl < fAvDist) iSame[iClust][iClust1]=iSame[iClust1][iClust]=1;
852db00e 285 else iSame[iClust][iClust1]=iSame[iClust1][iClust]=0;
7c679be0 286 }
287 }
288 ReduceClusters(iSame,nk,nc,cont,nSame);
289 if (nc >= fNclustMax) growcl=false;
290//recalculate the nc distinct codevectors
386b2e2f 291 TMatrixD *pyx = new TMatrixD(fNeff,2*nc);
7c679be0 292 TVectorD *py = new TVectorD(nk);
293 TMatrixD *y1 = new TMatrixD(3,nk);
294 for (Int_t iClust=0; iClust<nc; iClust++){
295 for(Int_t j=0; j<nSame[iClust]; j++){
296 Int_t iClust1 = cont[iClust][j];
386b2e2f 297 for (Int_t iIn=0; iIn<fNeff; iIn++) (*pyx)(iIn,iClust)+=(*mPyx)(iIn,iClust1);
36b5cc43 298 (*py)(iClust)+=(*vPy)(iClust1);
299 for (Int_t i=0; i<2; i++) (*y1)(i,iClust)+=(*mY)(i,iClust1);
7c679be0 300 }
301 for (Int_t i=0; i<2; i++) (*y1)(i,iClust)/=nSame[iClust];
302 }
852db00e 303 for (Int_t iClust=0; iClust<nk; iClust++) delete [] cont[iClust], delete [] iSame[iClust];
304 delete [] iSame;
305 delete [] cont;
306 delete [] nSame;
7c679be0 307 if (nc > nk/2){
308 for (Int_t iClust=0; iClust<nc; iClust++){
386b2e2f 309 for (Int_t iIn=0; iIn<fNeff; iIn++) (*mPyx)(iIn,iClust)=(*pyx)(iIn,iClust);
36b5cc43 310 for (Int_t iComp=0; iComp<2; iComp++) (*mY)(iComp,iClust)=(*y1)(iComp,iClust);
311 (*vPy)(iClust)=(*py)(iClust);
7c679be0 312 }
313 nk=nc;
36b5cc43 314 if (growcl) DoubleClusters(nc,nk,vPy,mY);
7c679be0 315 }
7c679be0 316 delete pyx;
317 delete py;
318 delete y1;
319 }
320
321}
322
323//-----------------------------------------------------------------------------------
c0a5117c 324void AliDAJetFinder::ReduceClusters(Int_t **iSame,Int_t nc,Int_t &ncout,Int_t **cont,Int_t *nSameOut) const
7c679be0 325{
1240edf5 326// Reduction step
7c679be0 327 Int_t *nSame = new Int_t[nc];
328 Int_t *iperm = new Int_t[nc];
329 Int_t *go = new Int_t[nc];
330 for (Int_t iCl=0; iCl<nc; iCl++){
331 nSame[iCl]=0;
852db00e 332 for (Int_t jCl=0; jCl<nc; jCl++) nSame[iCl]+=iSame[iCl][jCl], cont[iCl][jCl]=0;
7c679be0 333 iperm[iCl]=iCl;
334 go[iCl]=1;
335 }
336 TMath::Sort(nc,nSame,iperm,true);
337 Int_t l=0;
338 for (Int_t iCl=0; iCl<nc; iCl++){
339 Int_t k=iperm[iCl];
340 if (go[k] == 1){
341 Int_t m=0;
342 for (Int_t jCl=0; jCl<nc; jCl++){
343 if (iSame[k][jCl] == 1){
344 cont[l][m]=jCl;
345 go[jCl]=0;
346 m++;
347 }
348 }
349 nSameOut[l]=m;
350 l++;
351 }
352 }
353 ncout=l;
354 delete [] nSame;
355 delete [] iperm;
356 delete [] go;
357}
358
359//-----------------------------------------------------------------------------------
386b2e2f 360void AliDAJetFinder::EndDetAnn(Int_t &nk,Double_t **xData,Int_t *xx,Double_t etx,TVectorD *vPx,TVectorD *vPy,TMatrixD *mPyx,TMatrixD *mY)
7c679be0 361{
362//now assign each particle to only one cluster
363 Double_t *clusters=new Double_t[nk];
386b2e2f 364 for (Int_t iIn=0; iIn<fNeff; iIn++){
36b5cc43 365 for (Int_t iClust=0; iClust<nk; iClust++) clusters[iClust]=(*mPyx)(iIn,iClust);
7c679be0 366 xx[iIn]=TMath::LocMax(nk,clusters);
367 }
386b2e2f 368 delete [] clusters;
7c679be0 369
370//recalculate codevectors, having all p(y|x)=0 or 1
386b2e2f 371 Double_t *xEta = xData[0];
372 Double_t *xPhi = xData[1];
36b5cc43 373 mY->Zero();
374 mPyx->Zero();
375 vPy->Zero();
7c679be0 376 for (Int_t iIn=0; iIn<fNin; iIn++){
377 Int_t iClust=xx[iIn];
36b5cc43 378 (*mPyx)(iIn,iClust)=1;
379 (*vPy)(iClust)+=(*vPx)(iIn);
380 (*mY)(0,iClust)+=(*vPx)(iIn)*xEta[iIn];
381 (*mY)(3,iClust)+=(*vPx)(iIn)*etx;
7c679be0 382 }
383 Int_t k=0;
384 for (Int_t iClust=0; iClust<nk; iClust++){
36b5cc43 385 if ((*vPy)(iClust)>0){
7c679be0 386 Double_t xpos=0,ypos=0,pxy;
387 for (Int_t iIn=0; iIn<fNin; iIn++){
36b5cc43 388 pxy=(*vPx)(iIn)*(*mPyx)(iIn,iClust)/(*vPy)(iClust);
389 ypos+=pxy*TMath::Sin(xPhi[iIn]);
390 xpos+=pxy*TMath::Cos(xPhi[iIn]);
7c679be0 391 if (xx[iIn]==iClust) xx[iIn]=k;
392 }
36b5cc43 393 (*mY)(0,k)=(*mY)(0,iClust)/(*vPy)(iClust);
394 (*mY)(1,k)=(atan2(ypos,xpos)>0) ? atan2(ypos,xpos) : atan2(ypos,xpos)+2*TMath::Pi();
395 (*mY)(3,k)=(*mY)(3,iClust);
7c679be0 396 k++;
397 }
398 }
399 nk=k;
400}
401
402//-----------------------------------------------------------------------------------
386b2e2f 403void AliDAJetFinder::StoreJets(Int_t nk, Double_t **xData, Int_t *xx, TMatrixD *mY)
7c679be0 404{
405//evaluate significant clusters properties
406 const Double_t pi=TMath::Pi();
36b5cc43 407 AliJetReaderHeader *rHeader=fReader->GetReaderHeader();
386b2e2f 408 Float_t dFidEtaMax = rHeader->GetFiducialEtaMax();
409 Float_t dFidEtaMin = rHeader->GetFiducialEtaMin();
410 Float_t dFiducialEta= dFidEtaMax - dFidEtaMin;
411 Double_t *xEta = xData[0];
412 Double_t *xPhi = xData[1];
413 Int_t nEff = 0;
414 for (Int_t i=0; i<fNeff; i++) if (xEta[i]<dFidEtaMax && xEta[i]>dFidEtaMin) nEff++;
415 Double_t dMeanDist=TMath::Sqrt(2*dFiducialEta*pi/nEff);
7c679be0 416 Bool_t *isJet = new Bool_t[nk];
417 Double_t *etNoBg= new Double_t[nk];
418 Double_t *dDeltaEta=new Double_t[nk];
419 Double_t *dDeltaPhi=new Double_t[nk];
420 Double_t *surf = new Double_t[nk];
421 Double_t *etDens= new Double_t[nk];
386b2e2f 422 for (Int_t iClust=0; iClust<nk; iClust++){
7c679be0 423 isJet[iClust]=false;
424 Double_t dEtaMin=10.,dEtaMax=-10.,dPhiMin=10.,dPhiMax=0.;
386b2e2f 425 for (Int_t iIn=0; iIn<fNeff; iIn++){
426 if (xx[iIn]!=iClust || xEta[iIn]>dFidEtaMax || xEta[iIn]<dFidEtaMin) continue;
36b5cc43 427 if (xEta[iIn] < dEtaMin) dEtaMin=xEta[iIn];
428 if (xEta[iIn] > dEtaMax) dEtaMax=xEta[iIn];
429 Double_t dPhi=xPhi[iIn]-(*mY)(1,iClust);
7c679be0 430 if (dPhi > pi ) dPhi-=2*pi;
431 else if (dPhi < (-1)*pi) dPhi+=2*pi;
432 if (dPhi < dPhiMin) dPhiMin=dPhi;
433 else if (dPhi > dPhiMax) dPhiMax=dPhi;
434 }
435 dDeltaEta[iClust]=dEtaMax-dEtaMin+dMeanDist;
436 dDeltaPhi[iClust]=dPhiMax-dPhiMin+dMeanDist;
437 surf[iClust]=0.25*pi*dDeltaEta[iClust]*dDeltaPhi[iClust];
36b5cc43 438 etDens[iClust]=(*mY)(3,iClust)/surf[iClust];
7c679be0 439 }
440
9e4cc50d 441 if (((AliDAJetHeader*)fHeader)->GetSelJets()){
7c679be0 442 for (Int_t iClust=0; iClust<nk; iClust++){
386b2e2f 443 if (!isJet[iClust] && (*mY)(0,iClust)<dFidEtaMax && (*mY)(0,iClust)>dFidEtaMin){
7c679be0 444 Double_t etDensMed=0.;
445 Double_t etDensSqr=0.;
446 Int_t norm=0;
447 for (Int_t iClust1=0; iClust1<nk; iClust1++){
386b2e2f 448 if(iClust1!=iClust && (*mY)(0,iClust)<dFidEtaMax && (*mY)(0,iClust)>dFidEtaMin){
7c679be0 449 etDensMed+=etDens[iClust1];
450 etDensSqr+=TMath::Power(etDens[iClust1],2);
451 norm++;
452 }
453 }
454 etDensMed/=TMath::Max(norm,1);
455 etDensSqr/=TMath::Max(norm,1);
456 Double_t deltaEtDens=TMath::Sqrt(etDensSqr-TMath::Power(etDensMed,2));
36b5cc43 457 if ((*mY)(3,iClust) > (etDensMed+deltaEtDens)*surf[iClust]) isJet[iClust]=kTRUE;
458 etNoBg[iClust]=(*mY)(3,iClust)-etDensMed*surf[iClust];
7c679be0 459 }
460 }
461 for (Int_t iClust=0; iClust<nk; iClust++){
462 if (isJet[iClust]){
463 Double_t etDensMed=0;
36b5cc43 464 Double_t extSurf=2*dFiducialEta*pi;
7c679be0 465 for (Int_t iClust1=0; iClust1<nk; iClust1++){
36b5cc43 466 if (!isJet[iClust1]) etDensMed+=(*mY)(3,iClust1);
7c679be0 467 else extSurf-=surf[iClust1];
468 }
469 etDensMed/=extSurf;
36b5cc43 470 etNoBg[iClust]=(*mY)(3,iClust)-etDensMed*surf[iClust];
10bd125d 471 if (etNoBg[iClust]<((AliDAJetHeader*)fHeader)->GetEtMin()){
472 isJet[iClust]=kFALSE;
473 iClust=-1;
474 }
7c679be0 475 }
476 }
477 } else {
386b2e2f 478 for (Int_t iClust=0; iClust<nk; iClust++){
479 isJet[iClust]=true;
480 etNoBg[iClust]=(*mY)(3,iClust);
481 }
7c679be0 482 }
483 delete [] etDens;
484 delete [] surf;
485
486//now add selected jets to the list
af816924 487 Int_t *iSort = new Int_t[nk];
386b2e2f 488 TMath::Sort(nk,etNoBg,iSort,true);
489 Int_t iCl = 0;
7c679be0 490 TRefArray *refs = 0;
491 Bool_t fromAod = !strcmp(fReader->ClassName(),"AliJetAODReader");
492 if (fromAod) refs = fReader->GetReferences();
493 for (Int_t iClust=0; iClust<nk; iClust++){ //clusters loop
af816924 494 iCl=iSort[iClust];
495 if (isJet[iCl]){ //choose cluster
7c679be0 496 Float_t px,py,pz,en;
af816924 497 px = (*mY)(3,iCl)*TMath::Cos((*mY)(1,iCl));
498 py = (*mY)(3,iCl)*TMath::Sin((*mY)(1,iCl));
499 pz = (*mY)(3,iCl)/TMath::Tan(2.0 * TMath::ATan(TMath::Exp(-(*mY)(0,iCl))));
7c679be0 500 en = TMath::Sqrt(px * px + py * py + pz * pz);
501 AliAODJet jet(px, py, pz, en);
e53baffe 502 if (fromAod){
503 Int_t iIn=0;
504 Int_t nEntr = fReader->GetMomentumArray()->GetEntries();
505 for (Int_t iEn=0; iEn<nEntr; iEn++){
506 if (fReader->GetCutFlag(iEn)==0) continue;
af816924 507 if (xx[iIn]==iCl) jet.AddTrack(refs->At(iEn));
e53baffe 508 iIn++;
509 }
510 }
7c679be0 511 AddJet(jet);
dd677561 512 if (fDebug > 0) printf("jet %d, Eta: %f, Phi: %f, Et: %f\n",iCl,jet.Eta(),jet.Phi(),jet.Pt());
7c679be0 513 }
514 }
515 delete [] dDeltaEta; delete [] dDeltaPhi;
516 delete [] etNoBg;
517 delete [] isJet;
af816924 518 delete [] iSort;
7c679be0 519}
520
521//-----------------------------------------------------------------------------------
522Double_t Dist(TVectorD x,TVectorD y)
523{
524// Squared distance
525 const Double_t pi=TMath::Pi();
526 Double_t dphi=TMath::Abs(x(1)-y(1));
527 if (dphi > pi) dphi=2*pi-dphi;
528 Double_t dist=pow(x(0)-y(0),2)+pow(dphi,2);
529 return dist;
530}