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