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