Small corrections to fix compilation errors
[u/mrichter/AliRoot.git] / ITS / AliITStrackerMI.cxx
CommitLineData
e43c066c 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
bf6adc12 16/* $Id$ */
17
e43c066c 18//-------------------------------------------------------------------------
19// Implementation of the ITS tracker class
15dd636f 20// It reads AliITSclusterV2 clusters and creates AliITStrackMI tracks
e43c066c 21// and fills with them the ESD
15dd636f 22// Origin: Marian Ivanov, CERN, Marian.Ivanov@cern.ch
e43c066c 23// dEdx analysis by: Boris Batyunya, JINR, Boris.Batiounia@cern.ch
f43e383b 24//
e43c066c 25//-------------------------------------------------------------------------
bf6adc12 26
27#include <TMatrixD.h>
e43c066c 28#include <TTree.h>
bf6adc12 29#include <TTreeStream.h>
30#include <TTree.h>
31
e43c066c 32#include "AliESD.h"
bf6adc12 33#include "AliESDV0MI.h"
34#include "AliHelix.h"
e43c066c 35#include "AliITSclusterV2.h"
bf6adc12 36#include "AliITSgeom.h"
e43c066c 37#include "AliITStrackerMI.h"
e43c066c 38
39ClassImp(AliITStrackerMI)
e43c066c 40
41
42
43AliITStrackerMI::AliITSlayer AliITStrackerMI::fgLayers[kMaxLayer]; // ITS layers
44
45AliITStrackerMI::AliITStrackerMI(const AliITSgeom *geom) : AliTracker() {
46 //--------------------------------------------------------------------
47 //This is the AliITStrackerMI constructor
48 //--------------------------------------------------------------------
628e7bb0 49 fCoeficients = 0;
50 fAfterV0 = kFALSE;
e43c066c 51 AliITSgeom *g=(AliITSgeom*)geom;
e43c066c 52 Float_t x,y,z;
53 Int_t i;
54 for (i=1; i<kMaxLayer+1; i++) {
55 Int_t nlad=g->GetNladders(i);
56 Int_t ndet=g->GetNdetectors(i);
57
58 g->GetTrans(i,1,1,x,y,z);
59 Double_t r=TMath::Sqrt(x*x + y*y);
60 Double_t poff=TMath::ATan2(y,x);
61 Double_t zoff=z;
62
63 g->GetTrans(i,1,2,x,y,z);
64 r += TMath::Sqrt(x*x + y*y);
65 g->GetTrans(i,2,1,x,y,z);
66 r += TMath::Sqrt(x*x + y*y);
67 g->GetTrans(i,2,2,x,y,z);
68 r += TMath::Sqrt(x*x + y*y);
69 r*=0.25;
70
71 new (fgLayers+i-1) AliITSlayer(r,poff,zoff,nlad,ndet);
72
73 for (Int_t j=1; j<nlad+1; j++) {
74 for (Int_t k=1; k<ndet+1; k++) { //Fill this layer with detectors
75 Float_t x,y,zshift; g->GetTrans(i,j,k,x,y,zshift);
76 Double_t rot[9]; g->GetRotMatrix(i,j,k,rot);
77
78 Double_t phi=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
79 phi+=TMath::Pi()/2;
80 if (i==1) phi+=TMath::Pi();
81 Double_t cp=TMath::Cos(phi), sp=TMath::Sin(phi);
82 Double_t r=x*cp+y*sp;
83
84 AliITSdetector &det=fgLayers[i-1].GetDetector((j-1)*ndet + k-1);
85 new(&det) AliITSdetector(r,phi);
86 }
87 }
88
89 }
90
91 fI=kMaxLayer;
92
93 fPass=0;
94 fConstraint[0]=1; fConstraint[1]=0;
95
96 Double_t xyz[]={kXV,kYV,kZV}, ers[]={kSigmaXV,kSigmaYV,kSigmaZV};
97 SetVertex(xyz,ers);
98
99 for (Int_t i=0; i<kMaxLayer; i++) fLayersNotToSkip[i]=kLayersNotToSkip[i];
100 fLastLayerToTrackTo=kLastLayerToTrackTo;
628e7bb0 101 for (Int_t i=0;i<100000;i++){
102 fBestTrackIndex[i]=0;
103 }
81e97e0d 104 //
105 fDebugStreamer = new TTreeSRedirector("ITSdebug.root");
106
628e7bb0 107}
e43c066c 108
628e7bb0 109AliITStrackerMI::~AliITStrackerMI()
110{
111 //
112 //destructor
113 //
114 if (fCoeficients) delete []fCoeficients;
81e97e0d 115 if (fDebugStreamer) {
116 //fDebugStreamer->Close();
117 delete fDebugStreamer;
118 }
e43c066c 119}
120
121void AliITStrackerMI::SetLayersNotToSkip(Int_t *l) {
122 //--------------------------------------------------------------------
123 //This function set masks of the layers which must be not skipped
124 //--------------------------------------------------------------------
125 for (Int_t i=0; i<kMaxLayer; i++) fLayersNotToSkip[i]=l[i];
126}
127
128Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
129 //--------------------------------------------------------------------
130 //This function loads ITS clusters
131 //--------------------------------------------------------------------
132 TBranch *branch=cTree->GetBranch("Clusters");
133 if (!branch) {
134 Error("LoadClusters"," can't get the branch !\n");
135 return 1;
136 }
137
138 TClonesArray dummy("AliITSclusterV2",10000), *clusters=&dummy;
139 branch->SetAddress(&clusters);
140
141 Int_t j=0;
142 Int_t detector=0;
143 for (Int_t i=0; i<kMaxLayer; i++) {
144 Int_t ndet=fgLayers[i].GetNdetectors();
145 Int_t jmax = j + fgLayers[i].GetNladders()*ndet;
146 for (; j<jmax; j++) {
147 if (!cTree->GetEvent(j)) continue;
148 Int_t ncl=clusters->GetEntriesFast();
149 SignDeltas(clusters,GetZ());
150 while (ncl--) {
151 AliITSclusterV2 *c=(AliITSclusterV2*)clusters->UncheckedAt(ncl);
152 detector = c->GetDetectorIndex();
153 fgLayers[i].InsertCluster(new AliITSclusterV2(*c));
154 }
155 clusters->Delete();
156 //add dead zone virtual "cluster"
157 if (i<2){
158 for (Float_t ydead = 0; ydead < 1.31 ; ydead+=(i+1.)*0.018){
159 Int_t lab[4] = {0,0,0,detector};
160 Int_t info[3] = {0,0,0};
161 Float_t hit[5]={0,0,0.004/12.,0.001/12.,0};
162 if (i==0) hit[0] =ydead-0.4;
163 if (i==1) hit[0]=ydead-3.75;
164 hit[1] =-0.04;
165 if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<2.)
166 fgLayers[i].InsertCluster(new AliITSclusterV2(lab, hit, info));
167 hit[1]=-7.05;
168 if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<2.)
169 fgLayers[i].InsertCluster(new AliITSclusterV2(lab, hit, info));
170 hit[1]=-7.15;
171 if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<2.)
172 fgLayers[i].InsertCluster(new AliITSclusterV2(lab, hit, info));
173 hit[1] =0.06;
174 if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<2.)
175 fgLayers[i].InsertCluster(new AliITSclusterV2(lab, hit, info));
176 hit[1]=7.05;
177 if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<2.)
178 fgLayers[i].InsertCluster(new AliITSclusterV2(lab, hit, info));
179 hit[1]=7.25;
180 if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<2.)
181 fgLayers[i].InsertCluster(new AliITSclusterV2(lab, hit, info));
182 }
183 }
184
185 }
186 //
187 fgLayers[i].ResetRoad(); //road defined by the cluster density
188 fgLayers[i].SortClusters();
189 }
190
191 return 0;
192}
193
194void AliITStrackerMI::UnloadClusters() {
195 //--------------------------------------------------------------------
196 //This function unloads ITS clusters
197 //--------------------------------------------------------------------
198 for (Int_t i=0; i<kMaxLayer; i++) fgLayers[i].ResetClusters();
199}
200
15dd636f 201static Int_t CorrectForDeadZoneMaterial(AliITStrackMI *t) {
e43c066c 202 //--------------------------------------------------------------------
203 // Correction for the material between the TPC and the ITS
204 // (should it belong to the TPC code ?)
205 //--------------------------------------------------------------------
206 Double_t riw=80., diw=0.0053, x0iw=30; // TPC inner wall ?
207 Double_t rcd=61., dcd=0.0053, x0cd=30; // TPC "central drum" ?
208 Double_t yr=12.8, dr=0.03; // rods ?
209 Double_t zm=0.2, dm=0.40; // membrane
210 //Double_t rr=52., dr=0.19, x0r=24., yyr=7.77; //rails
211 Double_t rs=50., ds=0.001; // something belonging to the ITS (screen ?)
212
213 if (t->GetX() > riw) {
214 if (!t->PropagateTo(riw,diw,x0iw)) return 1;
215 if (TMath::Abs(t->GetY())>yr) t->CorrectForMaterial(dr);
216 if (TMath::Abs(t->GetZ())<zm) t->CorrectForMaterial(dm);
217 if (!t->PropagateTo(rcd,dcd,x0cd)) return 1;
218 //Double_t x,y,z; t->GetGlobalXYZat(rr,x,y,z);
219 //if (TMath::Abs(y)<yyr) t->PropagateTo(rr,dr,x0r);
220 if (!t->PropagateTo(rs,ds)) return 1;
221 } else if (t->GetX() < rs) {
222 if (!t->PropagateTo(rs,-ds)) return 1;
223 //Double_t x,y,z; t->GetGlobalXYZat(rr,x,y,z);
224 //if (TMath::Abs(y)<yyr) t->PropagateTo(rr,-dr,x0r);
225 if (!t->PropagateTo(rcd,-dcd,x0cd)) return 1;
226 if (!t->PropagateTo(riw+0.001,-diw,x0iw)) return 1;
227 } else {
228 ::Error("CorrectForDeadZoneMaterial","track is already in the dead zone !");
229 return 1;
230 }
231
232 return 0;
233}
234
235Int_t AliITStrackerMI::Clusters2Tracks(AliESD *event) {
236 //--------------------------------------------------------------------
237 // This functions reconstructs ITS tracks
238 // The clusters must be already loaded !
239 //--------------------------------------------------------------------
240 TObjArray itsTracks(15000);
628e7bb0 241 fOriginal.Clear();
81e97e0d 242 fEsd = event; // store pointer to the esd
e43c066c 243 {/* Read ESD tracks */
244 Int_t nentr=event->GetNumberOfTracks();
245 Info("Clusters2Tracks", "Number of ESD tracks: %d\n", nentr);
246 while (nentr--) {
247 AliESDtrack *esd=event->GetTrack(nentr);
248
249 if ((esd->GetStatus()&AliESDtrack::kTPCin)==0) continue;
250 if (esd->GetStatus()&AliESDtrack::kTPCout) continue;
251 if (esd->GetStatus()&AliESDtrack::kITSin) continue;
51ad6848 252 if (esd->GetKinkIndex(0)>0) continue; //kink daughter
15dd636f 253 AliITStrackMI *t=0;
e43c066c 254 try {
15dd636f 255 t=new AliITStrackMI(*esd);
e43c066c 256 } catch (const Char_t *msg) {
628e7bb0 257 //Warning("Clusters2Tracks",msg);
e43c066c 258 delete t;
259 continue;
260 }
261 t->fD[0] = t->GetD(GetX(),GetY());
262 t->fD[1] = t->GetZat(GetX())-GetZ();
263 Double_t vdist = TMath::Sqrt(t->fD[0]*t->fD[0]+t->fD[1]*t->fD[1]);
628e7bb0 264 if (t->GetMass()<0.13) t->SetMass(0.13957); // MI look to the esd - mass hypothesys !!!!!!!!!!!
e43c066c 265 // write expected q
266 t->fExpQ = TMath::Max(0.8*t->fESDtrack->GetTPCsignal(),30.);
267
81e97e0d 268 if (esd->GetV0Index(0)>0 && t->fD[0]<30){
269 //track - can be V0 according to TPC
e43c066c 270 }
81e97e0d 271 else{
272 if (TMath::Abs(t->fD[0])>10) {
273 delete t;
274 continue;
275 }
276
277 if (TMath::Abs(vdist)>20) {
278 delete t;
279 continue;
280 }
281 if (TMath::Abs(1/t->Get1Pt())<0.120) {
282 delete t;
283 continue;
284 }
285
286 if (CorrectForDeadZoneMaterial(t)!=0) {
287 //Warning("Clusters2Tracks",
288 // "failed to correct for the material in the dead zone !\n");
289 delete t;
290 continue;
291 }
e43c066c 292 }
293 t->fReconstructed = kFALSE;
294 itsTracks.AddLast(t);
628e7bb0 295 fOriginal.AddLast(t);
e43c066c 296 }
297 } /* End Read ESD tracks */
298
299 itsTracks.Sort();
628e7bb0 300 fOriginal.Sort();
e43c066c 301 Int_t nentr=itsTracks.GetEntriesFast();
302 fTrackHypothesys.Expand(nentr);
81e97e0d 303 fBestHypothesys.Expand(nentr);
e43c066c 304 MakeCoeficients(nentr);
305 Int_t ntrk=0;
306 for (fPass=0; fPass<2; fPass++) {
307 Int_t &constraint=fConstraint[fPass]; if (constraint<0) continue;
308 for (Int_t i=0; i<nentr; i++) {
4c53440c 309// cerr<<fPass<<" "<<i<<'\r';
e43c066c 310 fCurrentEsdTrack = i;
15dd636f 311 AliITStrackMI *t=(AliITStrackMI*)itsTracks.UncheckedAt(i);
e43c066c 312 if (t==0) continue; //this track has been already tracked
313 if (t->fReconstructed&&(t->fNUsed<1.5)) continue; //this track was already "succesfully" reconstructed
314 if ( (TMath::Abs(t->GetD(GetX(),GetY())) >3.) && fConstraint[fPass]) continue;
315 if ( (TMath::Abs(t->GetZat(GetX())-GetZ())>3.) && fConstraint[fPass]) continue;
316
317 Int_t tpcLabel=t->GetLabel(); //save the TPC track label
318 fI = 6;
319 ResetTrackToFollow(*t);
320 ResetBestTrack();
81e97e0d 321 FollowProlongationTree(t,i,fConstraint[fPass]);
e43c066c 322
323 SortTrackHypothesys(fCurrentEsdTrack,20,0); //MI change
324 //
15dd636f 325 AliITStrackMI * besttrack = GetBestHypothesys(fCurrentEsdTrack,t,15);
e43c066c 326 if (!besttrack) continue;
327 besttrack->SetLabel(tpcLabel);
328 // besttrack->CookdEdx();
329 CookdEdx(besttrack);
330 besttrack->fFakeRatio=1.;
331 CookLabel(besttrack,0.); //For comparison only
e43c066c 332 UpdateESDtrack(besttrack,AliESDtrack::kITSin);
628e7bb0 333
334 /*
335 if ( besttrack->GetNumberOfClusters()<6 && fConstraint[fPass]) {
e43c066c 336 continue;
337 }
338 if (besttrack->fChi2MIP[0]+besttrack->fNUsed>3.5) continue;
339 if ( (TMath::Abs(besttrack->fD[0]*besttrack->fD[0]+besttrack->fD[1]*besttrack->fD[1])>0.1) && fConstraint[fPass]) continue;
340 //delete itsTracks.RemoveAt(i);
628e7bb0 341 */
342 if (fConstraint[fPass]&&(!besttrack->IsGoldPrimary())) continue; //to be tracked also without vertex constrain
343
344
e43c066c 345 t->fReconstructed = kTRUE;
346 ntrk++;
347 }
348 GetBestHypothesysMIP(itsTracks);
349 }
350
351 //GetBestHypothesysMIP(itsTracks);
81e97e0d 352 UpdateTPCV0(event);
353 FindV02(event);
628e7bb0 354 fAfterV0 = kTRUE;
355 //GetBestHypothesysMIP(itsTracks);
356 //
e43c066c 357 itsTracks.Delete();
358 //
359 Int_t entries = fTrackHypothesys.GetEntriesFast();
360 for (Int_t ientry=0;ientry<entries;ientry++){
361 TObjArray * array =(TObjArray*)fTrackHypothesys.UncheckedAt(ientry);
362 if (array) array->Delete();
363 delete fTrackHypothesys.RemoveAt(ientry);
364 }
365
366 fTrackHypothesys.Delete();
81e97e0d 367 fBestHypothesys.Delete();
628e7bb0 368 fOriginal.Clear();
369 delete []fCoeficients;
370 fCoeficients=0;
e43c066c 371 Info("Clusters2Tracks","Number of prolonged tracks: %d\n",ntrk);
628e7bb0 372
e43c066c 373 return 0;
374}
375
376
e43c066c 377Int_t AliITStrackerMI::PropagateBack(AliESD *event) {
378 //--------------------------------------------------------------------
379 // This functions propagates reconstructed ITS tracks back
380 // The clusters must be loaded !
381 //--------------------------------------------------------------------
382 Int_t nentr=event->GetNumberOfTracks();
383 Info("PropagateBack", "Number of ESD tracks: %d\n", nentr);
384
385 Int_t ntrk=0;
386 for (Int_t i=0; i<nentr; i++) {
387 AliESDtrack *esd=event->GetTrack(i);
388
389 if ((esd->GetStatus()&AliESDtrack::kITSin)==0) continue;
390 if (esd->GetStatus()&AliESDtrack::kITSout) continue;
391
15dd636f 392 AliITStrackMI *t=0;
e43c066c 393 try {
15dd636f 394 t=new AliITStrackMI(*esd);
e43c066c 395 } catch (const Char_t *msg) {
628e7bb0 396 //Warning("PropagateBack",msg);
e43c066c 397 delete t;
398 continue;
399 }
400 t->fExpQ = TMath::Max(0.8*t->fESDtrack->GetTPCsignal(),30.);
401
402 ResetTrackToFollow(*t);
403
404 // propagete to vertex [SR, GSI 17.02.2003]
405 // Start Time measurement [SR, GSI 17.02.2003], corrected by I.Belikov
406 if (fTrackToFollow.PropagateTo(3.,0.0028,65.19)) {
407 if (fTrackToFollow.PropagateToVertex()) {
408 fTrackToFollow.StartTimeIntegral();
409 }
410 fTrackToFollow.PropagateTo(3.,-0.0028,65.19);
411 }
412
413 fTrackToFollow.ResetCovariance(); fTrackToFollow.ResetClusters();
414 if (RefitAt(49.,&fTrackToFollow,t)) {
415 if (CorrectForDeadZoneMaterial(&fTrackToFollow)!=0) {
628e7bb0 416 //Warning("PropagateBack",
417 // "failed to correct for the material in the dead zone !\n");
e43c066c 418 delete t;
419 continue;
420 }
421 fTrackToFollow.SetLabel(t->GetLabel());
422 //fTrackToFollow.CookdEdx();
423 CookLabel(&fTrackToFollow,0.); //For comparison only
424 fTrackToFollow.UpdateESDtrack(AliESDtrack::kITSout);
425 //UseClusters(&fTrackToFollow);
426 ntrk++;
427 }
428 delete t;
429 }
430
431 Info("PropagateBack","Number of back propagated ITS tracks: %d\n",ntrk);
432
433 return 0;
434}
435
436Int_t AliITStrackerMI::RefitInward(AliESD *event) {
437 //--------------------------------------------------------------------
438 // This functions refits ITS tracks using the
439 // "inward propagated" TPC tracks
440 // The clusters must be loaded !
441 //--------------------------------------------------------------------
67c1e979 442 RefitV02(event);
e43c066c 443 Int_t nentr=event->GetNumberOfTracks();
444 Info("RefitInward", "Number of ESD tracks: %d\n", nentr);
445
446 Int_t ntrk=0;
447 for (Int_t i=0; i<nentr; i++) {
448 AliESDtrack *esd=event->GetTrack(i);
449
450 if ((esd->GetStatus()&AliESDtrack::kITSout) == 0) continue;
451 if (esd->GetStatus()&AliESDtrack::kITSrefit) continue;
452 if (esd->GetStatus()&AliESDtrack::kTPCout)
453 if ((esd->GetStatus()&AliESDtrack::kTPCrefit)==0) continue;
454
15dd636f 455 AliITStrackMI *t=0;
e43c066c 456 try {
15dd636f 457 t=new AliITStrackMI(*esd);
e43c066c 458 } catch (const Char_t *msg) {
628e7bb0 459 //Warning("RefitInward",msg);
e43c066c 460 delete t;
461 continue;
462 }
463 t->fExpQ = TMath::Max(0.8*t->fESDtrack->GetTPCsignal(),30.);
464 if (CorrectForDeadZoneMaterial(t)!=0) {
628e7bb0 465 //Warning("RefitInward",
466 // "failed to correct for the material in the dead zone !\n");
e43c066c 467 delete t;
468 continue;
469 }
470
471 ResetTrackToFollow(*t);
472 fTrackToFollow.ResetClusters();
473
474 if ((esd->GetStatus()&AliESDtrack::kTPCin)==0)
475 fTrackToFollow.ResetCovariance();
476
477 //Refitting...
478 if (RefitAt(3.7, &fTrackToFollow, t)) {
479 fTrackToFollow.SetLabel(t->GetLabel());
480 // fTrackToFollow.CookdEdx();
481 CookdEdx(&fTrackToFollow);
482
483 CookLabel(&fTrackToFollow,0.0); //For comparison only
484
485 if (fTrackToFollow.PropagateTo(3.,0.0028,65.19)) {//The beam pipe
486 Double_t a=fTrackToFollow.GetAlpha();
487 Double_t cs=TMath::Cos(a),sn=TMath::Sin(a);
488 Double_t xv= GetX()*cs + GetY()*sn;
489 Double_t yv=-GetX()*sn + GetY()*cs;
490
491 Double_t c=fTrackToFollow.GetC(), snp=fTrackToFollow.GetSnp();
492 Double_t x=fTrackToFollow.GetX(), y=fTrackToFollow.GetY();
493 Double_t tgfv=-(c*(x-xv)-snp)/(c*(y-yv) + TMath::Sqrt(1.-snp*snp));
494 Double_t fv=TMath::ATan(tgfv);
495
496 cs=TMath::Cos(fv); sn=TMath::Sin(fv);
497 x = xv*cs + yv*sn;
498 yv=-xv*sn + yv*cs; xv=x;
499
500 if (fTrackToFollow.Propagate(fv+a,xv)) {
501 fTrackToFollow.UpdateESDtrack(AliESDtrack::kITSrefit);
97f754fa 502 Float_t d=fTrackToFollow.GetD(GetX(),GetY());
503 Float_t z=fTrackToFollow.GetZ()-GetZ();
504 fTrackToFollow.GetESDtrack()->SetImpactParameters(d,z);
e43c066c 505 //UseClusters(&fTrackToFollow);
506 {
507 AliITSclusterV2 c; c.SetY(yv); c.SetZ(GetZ());
508 c.SetSigmaY2(GetSigmaY()*GetSigmaY());
509 c.SetSigmaZ2(GetSigmaZ()*GetSigmaZ());
510 Double_t chi2=fTrackToFollow.GetPredictedChi2(&c);
511 //Double_t chi2=GetPredictedChi2MI(&fTrackToFollow,&c,fI);
512 if (chi2<kMaxChi2)
513 if (fTrackToFollow.Update(&c,-chi2,0))
514 //if (UpdateMI(&fTrackToFollow,&c,-chi2,0))
515 fTrackToFollow.SetConstrainedESDtrack(chi2);
516 }
517 ntrk++;
518 }
519 }
520 }
521 delete t;
522 }
523
524 Info("RefitInward","Number of refitted tracks: %d\n",ntrk);
525
526 return 0;
527}
528
529AliCluster *AliITStrackerMI::GetCluster(Int_t index) const {
530 //--------------------------------------------------------------------
531 // Return pointer to a given cluster
532 //--------------------------------------------------------------------
533 Int_t l=(index & 0xf0000000) >> 28;
534 Int_t c=(index & 0x0fffffff) >> 00;
535 return fgLayers[l].GetCluster(c);
536}
537
538
81e97e0d 539void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdindex, Bool_t constrain)
e43c066c 540{
541 //--------------------------------------------------------------------
542 // Follow prolongation tree
543 //--------------------------------------------------------------------
81e97e0d 544 //
545 AliESDtrack * esd = otrack->fESDtrack;
546 if (esd->GetV0Index(0)>0){
547 //
548 // TEMPORARY SOLLUTION: map V0 indexes to point to proper track
549 // mapping of esd track is different as its track in Containers
550 // Need something more stable
551 // Indexes are set back againg to the ESD track indexes in UpdateTPCV0
552 for (Int_t i=0;i<3;i++){
553 Int_t index = esd->GetV0Index(i);
554 if (index==0) break;
555 AliESDV0MI * vertex = fEsd->GetV0MI(index);
556 if (vertex->GetStatus()<0) continue; // rejected V0
557 //
558 if (esd->GetSign()>0) {
559 vertex->SetIndex(0,esdindex);
560 }
561 else{
562 vertex->SetIndex(1,esdindex);
563 }
564 }
565 }
566 TObjArray *bestarray = (TObjArray*)fBestHypothesys.At(esdindex);
567 if (!bestarray){
568 bestarray = new TObjArray(5);
569 fBestHypothesys.AddAt(bestarray,esdindex);
570 }
e43c066c 571
81e97e0d 572 //
e43c066c 573 //setup tree of the prolongations
574 //
15dd636f 575 static AliITStrackMI tracks[7][100];
576 AliITStrackMI *currenttrack;
577 static AliITStrackMI currenttrack1;
578 static AliITStrackMI currenttrack2;
579 static AliITStrackMI backuptrack;
e43c066c 580 Int_t ntracks[7];
581 Int_t nindexes[7][100];
582 Float_t normalizedchi2[100];
583 for (Int_t ilayer=0;ilayer<6;ilayer++) ntracks[ilayer]=0;
584 otrack->fNSkipped=0;
15dd636f 585 new (&(tracks[6][0])) AliITStrackMI(*otrack);
e43c066c 586 ntracks[6]=1;
81e97e0d 587 for (Int_t i=0;i<7;i++) nindexes[i][0]=0;
e43c066c 588 //
589 //
590 // follow prolongations
591 for (Int_t ilayer=5;ilayer>=0;ilayer--){
592 //
593 AliITSlayer &layer=fgLayers[ilayer];
594 Double_t r=layer.GetR();
595 ntracks[ilayer]=0;
596 //
597 //
598 Int_t nskipped=0;
599 Float_t nused =0;
600 for (Int_t itrack =0;itrack<ntracks[ilayer+1];itrack++){
601 //set current track
602 if (ntracks[ilayer]>=100) break;
603 if (tracks[ilayer+1][nindexes[ilayer+1][itrack]].fNSkipped>0) nskipped++;
604 if (tracks[ilayer+1][nindexes[ilayer+1][itrack]].fNUsed>2.) nused++;
605 if (ntracks[ilayer]>15+ilayer){
606 if (itrack>1&&tracks[ilayer+1][nindexes[ilayer+1][itrack]].fNSkipped>0 && nskipped>4+ilayer) continue;
607 if (itrack>1&&tracks[ilayer+1][nindexes[ilayer+1][itrack]].fNUsed>2. && nused>3) continue;
608 }
609
15dd636f 610 new(&currenttrack1) AliITStrackMI(tracks[ilayer+1][nindexes[ilayer+1][itrack]]);
e43c066c 611 if (ilayer==3 || ilayer==1) {
612 Double_t rs=0.5*(fgLayers[ilayer+1].GetR() + r);
613 Double_t d=0.0034, x0=38.6;
614 if (ilayer==1) {rs=9.; d=0.0097; x0=42;}
615 if (!currenttrack1.PropagateTo(rs,d,x0)) {
616 continue;
617 }
618 }
619 //
620 //find intersection with layer
621 Double_t x,y,z;
622 if (!currenttrack1.GetGlobalXYZat(r,x,y,z)) {
623 continue;
624 }
625 Double_t phi=TMath::ATan2(y,x);
626 Int_t idet=layer.FindDetectorIndex(phi,z);
627 if (idet<0) {
628 continue;
629 }
630 //propagate to the intersection
631 const AliITSdetector &det=layer.GetDetector(idet);
632 phi=det.GetPhi();
15dd636f 633 new(&currenttrack2) AliITStrackMI(currenttrack1);
e43c066c 634 if (!currenttrack1.Propagate(phi,det.GetR())) {
635 continue;
636 }
637 currenttrack2.Propagate(phi,det.GetR()); //
638 currenttrack1.SetDetectorIndex(idet);
639 currenttrack2.SetDetectorIndex(idet);
640
641 //
642 //
643 Double_t dz=7.5*TMath::Sqrt(currenttrack1.GetSigmaZ2() + 16.*kSigmaZ2[ilayer]);
644 Double_t dy=7.5*TMath::Sqrt(currenttrack1.GetSigmaY2() + 16.*kSigmaY2[ilayer]);
645 //
646 Bool_t isBoundary=kFALSE;
647 if (currenttrack1.GetY()-dy< det.GetYmin()+0.2) isBoundary = kTRUE;
648 if (currenttrack1.GetY()+dy> det.GetYmax()-0.2) isBoundary = kTRUE;
649 if (currenttrack1.GetZ()-dz< det.GetZmin()+0.2) isBoundary = kTRUE;
650 if (currenttrack1.GetZ()+dz> det.GetZmax()-0.2) isBoundary = kTRUE;
651
652 if (isBoundary){ // track at boundary between detectors
653 Float_t maxtgl = TMath::Abs(currenttrack1.GetTgl());
654 if (maxtgl>1) maxtgl=1;
655 dz = TMath::Sqrt(dz*dz+0.25*maxtgl*maxtgl);
656 //
657 Float_t maxsnp = TMath::Abs(currenttrack1.GetSnp());
658 if (maxsnp>0.95) continue;
659 //if (maxsnp>0.5) maxsnp=0.5;
660 dy=TMath::Sqrt(dy*dy+0.25*maxsnp*maxsnp);
661 }
662
663 Double_t zmin=currenttrack1.GetZ() - dz;
664 Double_t zmax=currenttrack1.GetZ() + dz;
665 Double_t ymin=currenttrack1.GetY() + r*phi - dy;
666 Double_t ymax=currenttrack1.GetY() + r*phi + dy;
667 layer.SelectClusters(zmin,zmax,ymin,ymax);
668 //
669 // loop over all possible prolongations
670 //
671 Double_t msz=1./((currenttrack1.GetSigmaZ2() + 16.*kSigmaZ2[ilayer]));
672 Double_t msy=1./((currenttrack1.GetSigmaY2() + 16.*kSigmaY2[ilayer]));
81e97e0d 673 if (constrain){
e43c066c 674 msy/=60; msz/=60.;
675 }
676 else{
677 msy/=50; msz/=50.;
678 }
679 //
680 const AliITSclusterV2 *c=0; Int_t ci=-1;
681 Double_t chi2=12345.;
682 Int_t deadzone=0;
683 currenttrack = &currenttrack1;
684 while ((c=layer.GetNextCluster(ci))!=0) {
685 if (ntracks[ilayer]>95) break; //space for skipped clusters
686 Bool_t change =kFALSE;
687 if (c->GetQ()==0 && (deadzone==1)) continue;
688 Int_t idet=c->GetDetectorIndex();
689 if (currenttrack->GetDetectorIndex()!=idet) {
690 const AliITSdetector &det=layer.GetDetector(idet);
691 Double_t y,z;
692 if (!currenttrack2.GetProlongationFast(det.GetPhi(),det.GetR(),y,z)) continue;
693 Float_t pz = (z - c->GetZ()) , py=(y - c->GetY());
694 if (pz*pz*msz+py*py*msy>1.) continue;
695 //
15dd636f 696 new (&backuptrack) AliITStrackMI(currenttrack2);
e43c066c 697 change = kTRUE;
698 currenttrack =&currenttrack2;
699 if (!currenttrack->Propagate(det.GetPhi(),det.GetR())) {
15dd636f 700 new (currenttrack) AliITStrackMI(backuptrack);
e43c066c 701 change = kFALSE;
702 continue;
703 }
704 currenttrack->SetDetectorIndex(idet);
705 }
706 else{
707 Float_t pz = (currenttrack->GetZ() - c->GetZ()) , py=(currenttrack->GetY() - c->GetY());
708 if (pz*pz*msz+py*py*msy>1.) continue;
709 }
710
711 chi2=GetPredictedChi2MI(currenttrack,c,ilayer);
712 if (chi2<kMaxChi2s[ilayer]){
713 if (c->GetQ()==0) deadzone=1; // take dead zone only once
714 if (ntracks[ilayer]>=100) continue;
15dd636f 715 AliITStrackMI * updatetrack = new (&tracks[ilayer][ntracks[ilayer]]) AliITStrackMI(*currenttrack);
e43c066c 716 updatetrack->fClIndex[ilayer]=0;
717 if (change){
15dd636f 718 new (&currenttrack2) AliITStrackMI(backuptrack);
e43c066c 719 }
720 if (c->GetQ()!=0){
721 if (!UpdateMI(updatetrack,c,chi2,(ilayer<<28)+ci)) continue;
722 updatetrack->SetSampledEdx(c->GetQ(),updatetrack->GetNumberOfClusters()-1); //b.b.
723 }
724 else {
725 updatetrack->fNDeadZone++;
726 updatetrack->fDeadZoneProbability=GetDeadZoneProbability(updatetrack->GetZ(),TMath::Sqrt(updatetrack->GetSigmaZ2()));
727 }
728 if (c->IsUsed()){
729 updatetrack->fNUsed++;
730 }
731 Double_t x0;
732 Double_t d=layer.GetThickness(updatetrack->GetY(),updatetrack->GetZ(),x0);
733 updatetrack->CorrectForMaterial(d,x0);
81e97e0d 734 if (constrain) {
735 updatetrack->fConstrain = constrain;
e43c066c 736 fI = ilayer;
737 Double_t d=GetEffectiveThickness(0,0); //Think of this !!!!
738 Double_t xyz[]={GetX(),GetY(),GetZ()};
739 Double_t ptfactor = 1;
740 Double_t ers[]={GetSigmaX()*ptfactor,GetSigmaY()*ptfactor,GetSigmaZ()};
741 Bool_t isPrim = kTRUE;
742 if (ilayer<4){
743 updatetrack->fD[0] = updatetrack->GetD(GetX(),GetY());
744 updatetrack->fD[1] = updatetrack->GetZat(GetX())-GetZ();
745 if ( TMath::Abs(updatetrack->fD[0]/(1.+ilayer))>0.4 || TMath::Abs(updatetrack->fD[1]/(1.+ilayer))>0.4) isPrim=kFALSE;
746 }
747 if (isPrim) updatetrack->Improve(d,xyz,ers);
748 } //apply vertex constrain
749 ntracks[ilayer]++;
750 } // create new hypothesy
751 } // loop over possible cluster prolongation
81e97e0d 752 // if (constrain&&itrack<2&&currenttrack1.fNSkipped==0 && deadzone==0){
753 if (constrain&&itrack<2&&currenttrack1.fNSkipped==0 && deadzone==0&&ntracks[ilayer]<100){
15dd636f 754 AliITStrackMI* vtrack = new (&tracks[ilayer][ntracks[ilayer]]) AliITStrackMI(currenttrack1);
e43c066c 755 vtrack->fClIndex[ilayer]=0;
756 fI = ilayer;
757 Double_t d=GetEffectiveThickness(0,0); //Think of this !!!!
758 Double_t xyz[]={GetX(),GetY(),GetZ()};
759 Double_t ers[]={GetSigmaX(),GetSigmaY(),GetSigmaZ()};
760 vtrack->Improve(d,xyz,ers);
761 vtrack->fNSkipped++;
762 ntracks[ilayer]++;
763 }
628e7bb0 764
81e97e0d 765 if (constrain&&itrack<1&&TMath::Abs(currenttrack1.fP3)>1.1){ //big theta -- for low mult. runs
628e7bb0 766 AliITStrackMI* vtrack = new (&tracks[ilayer][ntracks[ilayer]]) AliITStrackMI(currenttrack1);
767 vtrack->fClIndex[ilayer]=0;
768 fI = ilayer;
769 Double_t d=GetEffectiveThickness(0,0); //Think of this !!!!
770 Double_t xyz[]={GetX(),GetY(),GetZ()};
771 Double_t ers[]={GetSigmaX(),GetSigmaY(),GetSigmaZ()};
772 vtrack->Improve(d,xyz,ers);
773 vtrack->fNDeadZone++;
774 ntracks[ilayer]++;
775 }
776
e43c066c 777
778 } //loop over track candidates
779 //
780 //
781 Int_t accepted=0;
782
783 Int_t golds=0;
784 for (Int_t itrack=0;itrack<ntracks[ilayer];itrack++){
785 normalizedchi2[itrack] = NormalizedChi2(&tracks[ilayer][itrack],ilayer);
786 if ( normalizedchi2[itrack]<3+0.5*ilayer) golds++;
787 if (ilayer>4) accepted++;
788 else{
81e97e0d 789 if ( constrain && normalizedchi2[itrack]<kMaxNormChi2C[ilayer]+1) accepted++;
790 if (!constrain && normalizedchi2[itrack]<kMaxNormChi2NonC[ilayer]+1) accepted++;
e43c066c 791 }
792 }
793 TMath::Sort(ntracks[ilayer],normalizedchi2,nindexes[ilayer],kFALSE);
794 ntracks[ilayer] = TMath::Min(accepted,7+2*ilayer);
795 if (ntracks[ilayer]<golds+2+ilayer) ntracks[ilayer]=TMath::Min(golds+2+ilayer,accepted);
796 if (ntracks[ilayer]>90) ntracks[ilayer]=90;
797 } //loop over layers
798 //printf("%d\t%d\t%d\t%d\t%d\t%d\n",ntracks[0],ntracks[1],ntracks[2],ntracks[3],ntracks[4],ntracks[5]);
81e97e0d 799 Int_t max = constrain? 20: 5;
e43c066c 800
628e7bb0 801 for (Int_t i=0;i<TMath::Min(max,ntracks[0]);i++) {
15dd636f 802 AliITStrackMI & track= tracks[0][nindexes[0][i]];
628e7bb0 803 if (track.GetNumberOfClusters()<2) continue;
81e97e0d 804 if (!constrain&&track.fNormChi2[0]>7.)continue;
15dd636f 805 AddTrackHypothesys(new AliITStrackMI(track), esdindex);
e43c066c 806 }
628e7bb0 807 for (Int_t i=0;i<TMath::Min(2,ntracks[1]);i++) {
15dd636f 808 AliITStrackMI & track= tracks[1][nindexes[1][i]];
e43c066c 809 if (track.GetNumberOfClusters()<4) continue;
81e97e0d 810 if (!constrain&&track.fNormChi2[1]>7.)continue;
811 if (constrain) track.fNSkipped+=1;
812 if (!constrain) {
e43c066c 813 track.fD[0] = track.GetD(GetX(),GetY());
4c53440c 814 track.fNSkipped+=4./(4.+8.*TMath::Abs(track.fD[0]));
e43c066c 815 if (track.fN+track.fNDeadZone+track.fNSkipped>6) {
816 track.fNSkipped = 6-track.fN+track.fNDeadZone;
817 }
818 }
15dd636f 819 AddTrackHypothesys(new AliITStrackMI(track), esdindex);
e43c066c 820 }
821 //}
822
81e97e0d 823 if (!constrain){
628e7bb0 824 for (Int_t i=0;i<TMath::Min(2,ntracks[2]);i++) {
15dd636f 825 AliITStrackMI & track= tracks[2][nindexes[2][i]];
628e7bb0 826 if (track.GetNumberOfClusters()<3) continue;
81e97e0d 827 if (!constrain&&track.fNormChi2[2]>7.)continue;
828 if (constrain) track.fNSkipped+=2;
829 if (!constrain){
e43c066c 830 track.fD[0] = track.GetD(GetX(),GetY());
4c53440c 831 track.fNSkipped+= 7./(7.+8.*TMath::Abs(track.fD[0]));
e43c066c 832 if (track.fN+track.fNDeadZone+track.fNSkipped>6) {
833 track.fNSkipped = 6-track.fN+track.fNDeadZone;
834 }
835 }
15dd636f 836 AddTrackHypothesys(new AliITStrackMI(track), esdindex);
e43c066c 837 }
838 }
81e97e0d 839
840 if (!constrain){
841 //
842 // register best tracks - important for V0 finder
843 //
844 for (Int_t ilayer=0;ilayer<5;ilayer++){
845 if (ntracks[ilayer]==0) continue;
846 AliITStrackMI & track= tracks[ilayer][nindexes[ilayer][0]];
847 if (track.GetNumberOfClusters()<1) continue;
848 CookLabel(&track,0);
849 bestarray->AddAt(new AliITStrackMI(track),ilayer);
850 }
851 }
852 //
853 // update TPC V0 information
854 //
855 if (otrack->fESDtrack->GetV0Index(0)>0){
856 Float_t fprimvertex[3]={GetX(),GetY(),GetZ()};
857 for (Int_t i=0;i<3;i++){
858 Int_t index = otrack->fESDtrack->GetV0Index(i);
859 if (index==0) break;
860 AliESDV0MI * vertex = fEsd->GetV0MI(index);
861 if (vertex->GetStatus()<0) continue; // rejected V0
862 //
863 if (otrack->fP4>0) {
864 vertex->SetIndex(0,esdindex);
865 }
866 else{
867 vertex->SetIndex(1,esdindex);
868 }
869 //find nearest layer with track info
870 Int_t nearestold = GetNearestLayer(vertex->GetXrp());
871 Int_t nearest = nearestold;
872 for (Int_t ilayer =nearest;ilayer<8;ilayer++){
873 if (ntracks[nearest]==0){
874 nearest = ilayer;
875 }
876 }
877 //
878 AliITStrackMI & track= tracks[nearest][nindexes[nearest][0]];
879 if (nearestold<5&&nearest<5){
880 Bool_t accept = track.fNormChi2[nearest]<10;
881 if (accept){
882 if (track.fP4>0) {
883 vertex->SetP(track);
884 vertex->Update(fprimvertex);
885 // vertex->SetIndex(0,track.fESDtrack->GetID());
886 if (track.GetNumberOfClusters()>2) AddTrackHypothesys(new AliITStrackMI(track), esdindex);
887 }else{
888 vertex->SetM(track);
889 vertex->Update(fprimvertex);
890 //vertex->SetIndex(1,track.fESDtrack->GetID());
891 if (track.GetNumberOfClusters()>2) AddTrackHypothesys(new AliITStrackMI(track), esdindex);
892 }
893 vertex->SetStatus(vertex->GetStatus()+1);
894 }else{
895 // vertex->SetStatus(-2); // reject V0 - not enough clusters
896 }
897 }
898 // if (nearestold>3){
899// Int_t indexlayer = (ntracks[0]>0)? 0:1;
900// if (ntracks[indexlayer]>0){
901// AliITStrackMI & track= tracks[indexlayer][nindexes[indexlayer][0]];
902// if (track.GetNumberOfClusters()>4&&track.fNormChi2[indexlayer]<4){
903// vertex->SetStatus(-1); // reject V0 - clusters before
904// }
905// }
906// }
907 }
908 }
e43c066c 909}
910
911
912AliITStrackerMI::AliITSlayer & AliITStrackerMI::GetLayer(Int_t layer) const
913{
914 //--------------------------------------------------------------------
915 //
916 //
917 return fgLayers[layer];
918}
919AliITStrackerMI::AliITSlayer::AliITSlayer() {
920 //--------------------------------------------------------------------
921 //default AliITSlayer constructor
922 //--------------------------------------------------------------------
923 fN=0;
924 fDetectors=0;
925 fSkip = 0;
926 fCurrentSlice=-1;
927 for (Int_t i=0; i<kMaxClusterPerLayer;i++) {
928 fClusterWeight[i]=0;
929 fClusterTracks[0][i]=-1;
930 fClusterTracks[1][i]=-1;
931 fClusterTracks[2][i]=-1;
932 fClusterTracks[3][i]=-1;
933 }
934}
935
936AliITStrackerMI::AliITSlayer::
937AliITSlayer(Double_t r,Double_t p,Double_t z,Int_t nl,Int_t nd) {
938 //--------------------------------------------------------------------
939 //main AliITSlayer constructor
940 //--------------------------------------------------------------------
941 fR=r; fPhiOffset=p; fZOffset=z;
942 fNladders=nl; fNdetectors=nd;
943 fDetectors=new AliITSdetector[fNladders*fNdetectors];
944
945 fN=0;
946 fI=0;
947 fSkip = 0;
948 fRoad=2*fR*TMath::Sqrt(3.14/1.);//assuming that there's only one cluster
949}
950
951AliITStrackerMI::AliITSlayer::~AliITSlayer() {
952 //--------------------------------------------------------------------
953 // AliITSlayer destructor
954 //--------------------------------------------------------------------
955 delete[] fDetectors;
956 for (Int_t i=0; i<fN; i++) delete fClusters[i];
957 for (Int_t i=0; i<kMaxClusterPerLayer;i++) {
958 fClusterWeight[i]=0;
959 fClusterTracks[0][i]=-1;
960 fClusterTracks[1][i]=-1;
961 fClusterTracks[2][i]=-1;
962 fClusterTracks[3][i]=-1;
963 }
964}
965
966void AliITStrackerMI::AliITSlayer::ResetClusters() {
967 //--------------------------------------------------------------------
968 // This function removes loaded clusters
969 //--------------------------------------------------------------------
970 for (Int_t i=0; i<fN; i++) delete fClusters[i];
971 for (Int_t i=0; i<kMaxClusterPerLayer;i++){
972 fClusterWeight[i]=0;
973 fClusterTracks[0][i]=-1;
974 fClusterTracks[1][i]=-1;
975 fClusterTracks[2][i]=-1;
976 fClusterTracks[3][i]=-1;
977 }
978
979 fN=0;
980 fI=0;
981}
982
983void AliITStrackerMI::AliITSlayer::ResetWeights() {
984 //--------------------------------------------------------------------
985 // This function reset weights of the clusters
986 //--------------------------------------------------------------------
987 for (Int_t i=0; i<kMaxClusterPerLayer;i++) {
988 fClusterWeight[i]=0;
989 fClusterTracks[0][i]=-1;
990 fClusterTracks[1][i]=-1;
991 fClusterTracks[2][i]=-1;
992 fClusterTracks[3][i]=-1;
993 }
994 for (Int_t i=0; i<fN;i++) {
995 AliITSclusterV2 * cl = (AliITSclusterV2*)GetCluster(i);
996 if (cl&&cl->IsUsed()) cl->Use();
997 }
998
999}
1000
1001void AliITStrackerMI::AliITSlayer::ResetRoad() {
1002 //--------------------------------------------------------------------
1003 // This function calculates the road defined by the cluster density
1004 //--------------------------------------------------------------------
1005 Int_t n=0;
1006 for (Int_t i=0; i<fN; i++) {
1007 if (TMath::Abs(fClusters[i]->GetZ())<fR) n++;
1008 }
1009 //if (n>1) fRoad=2*fR*TMath::Sqrt(3.14/n);
1010 if (n>1) fRoad=2*fR*TMath::Sqrt(3.14/n);
1011}
1012
628e7bb0 1013
e43c066c 1014Int_t AliITStrackerMI::AliITSlayer::InsertCluster(AliITSclusterV2 *c) {
1015 //--------------------------------------------------------------------
1016 //This function adds a cluster to this layer
1017 //--------------------------------------------------------------------
1018 if (fN==kMaxClusterPerLayer) {
1019 ::Error("InsertCluster","Too many clusters !\n");
1020 return 1;
1021 }
1022 fCurrentSlice=-1;
1d4090b7 1023 fClusters[fN]=c;
1024 fN++;
e43c066c 1025 AliITSdetector &det=GetDetector(c->GetDetectorIndex());
e43c066c 1026 if (c->GetY()<det.GetYmin()) det.SetYmin(c->GetY());
1027 if (c->GetY()>det.GetYmax()) det.SetYmax(c->GetY());
1028 if (c->GetZ()<det.GetZmin()) det.SetZmin(c->GetZ());
1029 if (c->GetZ()>det.GetZmax()) det.SetZmax(c->GetZ());
1030
1031 return 0;
1032}
1033
1034void AliITStrackerMI::AliITSlayer::SortClusters()
1035{
1036 //
1037 //sort clusters
1038 //
1d4090b7 1039 AliITSclusterV2 **clusters = new AliITSclusterV2*[fN];
1040 Float_t *z = new Float_t[fN];
1041 Int_t * index = new Int_t[fN];
1042 //
1043 for (Int_t i=0;i<fN;i++){
1044 z[i] = fClusters[i]->GetZ();
1045 }
1046 TMath::Sort(fN,z,index,kFALSE);
1047 for (Int_t i=0;i<fN;i++){
1048 clusters[i] = fClusters[index[i]];
1049 }
1050 //
1051 for (Int_t i=0;i<fN;i++){
1052 fClusters[i] = clusters[i];
1053 fZ[i] = fClusters[i]->GetZ();
1054 AliITSdetector &det=GetDetector(fClusters[i]->GetDetectorIndex());
1055 Double_t y=fR*det.GetPhi() + fClusters[i]->GetY();
1056 if (y>2.*fR*TMath::Pi()) y -= 2.*fR*TMath::Pi();
1057 fY[i] = y;
1058 }
1059 delete[] index;
1060 delete[] z;
1061 delete[] clusters;
1062 //
1063
e43c066c 1064 fYB[0]=10000000;
1065 fYB[1]=-10000000;
1066 for (Int_t i=0;i<fN;i++){
1067 if (fY[i]<fYB[0]) fYB[0]=fY[i];
1068 if (fY[i]>fYB[1]) fYB[1]=fY[i];
1069 fClusterIndex[i] = i;
1070 }
1071 //
1072 // fill slices
1073 fDy5 = (fYB[1]-fYB[0])/5.;
1074 fDy10 = (fYB[1]-fYB[0])/10.;
1075 fDy20 = (fYB[1]-fYB[0])/20.;
1076 for (Int_t i=0;i<6;i++) fN5[i] =0;
1077 for (Int_t i=0;i<11;i++) fN10[i]=0;
1078 for (Int_t i=0;i<21;i++) fN20[i]=0;
1079 //
1080 for (Int_t i=0;i<6;i++) {fBy5[i][0] = fYB[0]+(i-0.75)*fDy5; fBy5[i][1] = fYB[0]+(i+0.75)*fDy5;}
1081 for (Int_t i=0;i<11;i++) {fBy10[i][0] = fYB[0]+(i-0.75)*fDy10; fBy10[i][1] = fYB[0]+(i+0.75)*fDy10;}
1082 for (Int_t i=0;i<21;i++) {fBy20[i][0] = fYB[0]+(i-0.75)*fDy20; fBy20[i][1] = fYB[0]+(i+0.75)*fDy20;}
1083 //
1084 //
1d4090b7 1085 for (Int_t i=0;i<fN;i++)
1086 for (Int_t irot=-1;irot<=1;irot++){
1087 Float_t curY = fY[i]+irot*TMath::TwoPi()*fR;
1088 // slice 5
1089 for (Int_t slice=0; slice<6;slice++){
1090 if (fBy5[slice][0]<curY && curY<fBy5[slice][1]&&fN5[slice]<kMaxClusterPerLayer5){
1091 fClusters5[slice][fN5[slice]] = fClusters[i];
1092 fY5[slice][fN5[slice]] = curY;
1093 fZ5[slice][fN5[slice]] = fZ[i];
1094 fClusterIndex5[slice][fN5[slice]]=i;
1095 fN5[slice]++;
1096 }
e43c066c 1097 }
1d4090b7 1098 // slice 10
1099 for (Int_t slice=0; slice<11;slice++){
1100 if (fBy10[slice][0]<curY && curY<fBy10[slice][1]&&fN10[slice]<kMaxClusterPerLayer10){
1101 fClusters10[slice][fN10[slice]] = fClusters[i];
1102 fY10[slice][fN10[slice]] = curY;
1103 fZ10[slice][fN10[slice]] = fZ[i];
1104 fClusterIndex10[slice][fN10[slice]]=i;
1105 fN10[slice]++;
1106 }
e43c066c 1107 }
1d4090b7 1108 // slice 20
1109 for (Int_t slice=0; slice<21;slice++){
1110 if (fBy20[slice][0]<curY && curY<fBy20[slice][1]&&fN20[slice]<kMaxClusterPerLayer20){
1111 fClusters20[slice][fN20[slice]] = fClusters[i];
1112 fY20[slice][fN20[slice]] = curY;
1113 fZ20[slice][fN20[slice]] = fZ[i];
1114 fClusterIndex20[slice][fN20[slice]]=i;
1115 fN20[slice]++;
1116 }
1117 }
e43c066c 1118 }
1d4090b7 1119
1120 //
1121 // consistency check
1122 //
1123 for (Int_t i=0;i<fN-1;i++){
1124 if (fZ[i]>fZ[i+1]){
1125 printf("Bugg\n");
e43c066c 1126 }
1127 }
1d4090b7 1128 //
1129 for (Int_t slice=0;slice<21;slice++)
1130 for (Int_t i=0;i<fN20[slice]-1;i++){
1131 if (fZ20[slice][i]>fZ20[slice][i+1]){
1132 printf("Bugg\n");
1133 }
1134 }
1135
1136
e43c066c 1137}
1138
1139
e43c066c 1140Int_t AliITStrackerMI::AliITSlayer::FindClusterIndex(Float_t z) const {
1141 //--------------------------------------------------------------------
1142 // This function returns the index of the nearest cluster
1143 //--------------------------------------------------------------------
1144 Int_t ncl=0;
1145 const Float_t *zcl;
1146 if (fCurrentSlice<0) {
1147 ncl = fN;
1148 zcl = fZ;
1149 }
1150 else{
1151 ncl = fNcs;
1152 zcl = fZcs;;
1153 }
1154
1155 if (ncl==0) return 0;
1156 Int_t b=0, e=ncl-1, m=(b+e)/2;
1157 for (; b<e; m=(b+e)/2) {
1158 // if (z > fClusters[m]->GetZ()) b=m+1;
1159 if (z > zcl[m]) b=m+1;
1160 else e=m;
1161 }
1162 return m;
1163}
e43c066c 1164
1165
1166void AliITStrackerMI::AliITSlayer::
1167SelectClusters(Double_t zmin,Double_t zmax,Double_t ymin, Double_t ymax) {
1168 //--------------------------------------------------------------------
1169 // This function sets the "window"
1170 //--------------------------------------------------------------------
1171
628e7bb0 1172 Double_t circle=2*TMath::Pi()*fR;
e43c066c 1173 fYmin = ymin; fYmax =ymax;
1174 Float_t ymiddle = (fYmin+fYmax)*0.5;
1175 if (ymiddle<fYB[0]) {fYmin+=circle; fYmax+=circle;ymiddle+=circle;}
1176 else{
1177 if (ymiddle>fYB[1]) {fYmin-=circle; fYmax-=circle;ymiddle-=circle;}
1178 }
1179 //
1180 fCurrentSlice =-1;
1181 // defualt take all
1182 fClustersCs = fClusters;
1183 fClusterIndexCs = fClusterIndex;
1184 fYcs = fY;
1185 fZcs = fZ;
1186 fNcs = fN;
628e7bb0 1187 //
e43c066c 1188 //is in 20 slice?
1189 if (fCurrentSlice<0&&TMath::Abs(fYmax-fYmin)<1.49*fDy20){
1190 Int_t slice = int(0.5+(ymiddle-fYB[0])/fDy20);
1191 if (slice<0) slice=0;
1192 if (slice>20) slice=20;
1193 Bool_t isOK = (fYmin>fBy20[slice][0]&&fYmax<fBy20[slice][1]);
1194 if (isOK) {
1195 fCurrentSlice=slice;
1196 fClustersCs = fClusters20[fCurrentSlice];
1197 fClusterIndexCs = fClusterIndex20[fCurrentSlice];
1198 fYcs = fY20[fCurrentSlice];
1199 fZcs = fZ20[fCurrentSlice];
1200 fNcs = fN20[fCurrentSlice];
1201 }
1202 }
1203 //
1204 //is in 10 slice?
1205 if (fCurrentSlice<0&&TMath::Abs(fYmax-fYmin)<1.49*fDy10){
1206 Int_t slice = int(0.5+(ymiddle-fYB[0])/fDy10);
1207 if (slice<0) slice=0;
1208 if (slice>10) slice=10;
1209 Bool_t isOK = (fYmin>fBy10[slice][0]&&fYmax<fBy10[slice][1]);
1210 if (isOK) {
1211 fCurrentSlice=slice;
1212 fClustersCs = fClusters10[fCurrentSlice];
1213 fClusterIndexCs = fClusterIndex10[fCurrentSlice];
1214 fYcs = fY10[fCurrentSlice];
1215 fZcs = fZ10[fCurrentSlice];
1216 fNcs = fN10[fCurrentSlice];
1217 }
1218 }
1219 //
1220 //is in 5 slice?
1221 if (fCurrentSlice<0&&TMath::Abs(fYmax-fYmin)<1.49*fDy5){
1222 Int_t slice = int(0.5+(ymiddle-fYB[0])/fDy5);
1223 if (slice<0) slice=0;
1224 if (slice>5) slice=5;
1225 Bool_t isOK = (fYmin>fBy5[slice][0]&&fYmax<fBy5[slice][1]);
1226 if ( isOK){
1227 fCurrentSlice=slice;
1228 fClustersCs = fClusters5[fCurrentSlice];
1229 fClusterIndexCs = fClusterIndex5[fCurrentSlice];
1230 fYcs = fY5[fCurrentSlice];
1231 fZcs = fZ5[fCurrentSlice];
1232 fNcs = fN5[fCurrentSlice];
1233 }
1234 }
628e7bb0 1235 //
e43c066c 1236 fI=FindClusterIndex(zmin); fZmax=zmax;
1237 fImax = TMath::Min(FindClusterIndex(zmax)+1,fNcs);
1238 fSkip = 0;
1239 fAccepted =0;
1240}
1241
e43c066c 1242
628e7bb0 1243
1244
1245Int_t AliITStrackerMI::AliITSlayer::
1246FindDetectorIndex(Double_t phi, Double_t z) const {
1247 //--------------------------------------------------------------------
1248 //This function finds the detector crossed by the track
1249 //--------------------------------------------------------------------
1250 Double_t dphi=-(phi-fPhiOffset);
1251 if (dphi < 0) dphi += 2*TMath::Pi();
1252 else if (dphi >= 2*TMath::Pi()) dphi -= 2*TMath::Pi();
1253 Int_t np=Int_t(dphi*fNladders*0.5/TMath::Pi()+0.5);
1254 if (np>=fNladders) np-=fNladders;
1255 if (np<0) np+=fNladders;
1256
1257 Double_t dz=fZOffset-z;
1258 Int_t nz=Int_t(dz*(fNdetectors-1)*0.5/fZOffset+0.5);
1259 if (nz>=fNdetectors) return -1;
1260 if (nz<0) return -1;
1261
1262 return np*fNdetectors + nz;
1263}
1264
1265
e43c066c 1266const AliITSclusterV2 *AliITStrackerMI::AliITSlayer::GetNextCluster(Int_t &ci){
1267 //--------------------------------------------------------------------
1268 // This function returns clusters within the "window"
1269 //--------------------------------------------------------------------
1270
1271 if (fCurrentSlice<0){
1272 Double_t rpi2 = 2.*fR*TMath::Pi();
1273 for (Int_t i=fI; i<fImax; i++) {
1274 Double_t y = fY[i];
1275 if (fYmax<y) y -= rpi2;
1d4090b7 1276 if (fYmin>y) y += rpi2;
e43c066c 1277 if (y<fYmin) continue;
1278 if (y>fYmax) continue;
1279 if (fClusters[i]->GetQ()==0&&fSkip==2) continue;
1280 ci=i;
1281 fI=i+1;
1282 return fClusters[i];
1283 }
1284 }
1285 else{
1286 for (Int_t i=fI; i<fImax; i++) {
1287 if (fYcs[i]<fYmin) continue;
1288 if (fYcs[i]>fYmax) continue;
1289 if (fClustersCs[i]->GetQ()==0&&fSkip==2) continue;
1290 ci=fClusterIndexCs[i];
1291 fI=i+1;
1292 return fClustersCs[i];
1293 }
1294 }
1295 return 0;
1296}
1297
1298
1299
e43c066c 1300Double_t AliITStrackerMI::AliITSlayer::GetThickness(Double_t y,Double_t z,Double_t &x0)
1301const {
1302 //--------------------------------------------------------------------
1303 //This function returns the layer thickness at this point (units X0)
1304 //--------------------------------------------------------------------
1305 Double_t d=0.0085;
1306 x0=21.82;
1307 if (43<fR&&fR<45) { //SSD2
1308 Double_t dd=0.0034;
1309 d=dd;
1310 if (TMath::Abs(y-0.00)>3.40) d+=dd;
1311 if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
1312 if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
1313 for (Int_t i=0; i<12; i++) {
1314 if (TMath::Abs(z-3.9*(i+0.5))<0.15) {
1315 if (TMath::Abs(y-0.00)>3.40) d+=dd;
1316 d+=0.0034;
1317 break;
1318 }
1319 if (TMath::Abs(z+3.9*(i+0.5))<0.15) {
1320 if (TMath::Abs(y-0.00)>3.40) d+=dd;
1321 d+=0.0034;
1322 break;
1323 }
1324 if (TMath::Abs(z-3.4-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
1325 if (TMath::Abs(z+0.5+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
1326 }
1327 } else
1328 if (37<fR&&fR<41) { //SSD1
1329 Double_t dd=0.0034;
1330 d=dd;
1331 if (TMath::Abs(y-0.00)>3.40) d+=dd;
1332 if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
1333 if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
1334 for (Int_t i=0; i<11; i++) {
1335 if (TMath::Abs(z-3.9*i)<0.15) {
1336 if (TMath::Abs(y-0.00)>3.40) d+=dd;
1337 d+=dd;
1338 break;
1339 }
1340 if (TMath::Abs(z+3.9*i)<0.15) {
1341 if (TMath::Abs(y-0.00)>3.40) d+=dd;
1342 d+=dd;
1343 break;
1344 }
1345 if (TMath::Abs(z-1.85-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
1346 if (TMath::Abs(z+2.05+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
1347 }
1348 } else
1349 if (13<fR&&fR<26) { //SDD
1350 Double_t dd=0.0033;
1351 d=dd;
1352 if (TMath::Abs(y-0.00)>3.30) d+=dd;
1353
1354 if (TMath::Abs(y-1.80)<0.55) {
1355 d+=0.016;
1356 for (Int_t j=0; j<20; j++) {
1357 if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
1358 if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
1359 }
1360 }
1361 if (TMath::Abs(y+1.80)<0.55) {
1362 d+=0.016;
1363 for (Int_t j=0; j<20; j++) {
1364 if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
1365 if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
1366 }
1367 }
1368
1369 for (Int_t i=0; i<4; i++) {
1370 if (TMath::Abs(z-7.3*i)<0.60) {
1371 d+=dd;
1372 if (TMath::Abs(y-0.00)>3.30) d+=dd;
1373 break;
1374 }
1375 if (TMath::Abs(z+7.3*i)<0.60) {
1376 d+=dd;
1377 if (TMath::Abs(y-0.00)>3.30) d+=dd;
1378 break;
1379 }
1380 }
1381 } else
1382 if (6<fR&&fR<8) { //SPD2
1383 Double_t dd=0.0063; x0=21.5;
1384 d=dd;
1385 if (TMath::Abs(y-3.08)>0.5) d+=dd;
1386 //if (TMath::Abs(y-3.08)>0.45) d+=dd;
1387 if (TMath::Abs(y-3.03)<0.10) {d+=0.014;}
1388 } else
1389 if (3<fR&&fR<5) { //SPD1
1390 Double_t dd=0.0063; x0=21.5;
1391 d=dd;
1392 if (TMath::Abs(y+0.21)>0.6) d+=dd;
1393 //if (TMath::Abs(y+0.21)>0.45) d+=dd;
1394 if (TMath::Abs(y+0.10)<0.10) {d+=0.014;}
1395 }
1396
1397 return d;
1398}
1399
1400Double_t AliITStrackerMI::GetEffectiveThickness(Double_t y,Double_t z) const
1401{
1402 //--------------------------------------------------------------------
1403 //Returns the thickness between the current layer and the vertex (units X0)
1404 //--------------------------------------------------------------------
1405 Double_t d=0.0028*3*3; //beam pipe
1406 Double_t x0=0;
1407
1408 Double_t xn=fgLayers[fI].GetR();
1409 for (Int_t i=0; i<fI; i++) {
1410 Double_t xi=fgLayers[i].GetR();
1411 d+=fgLayers[i].GetThickness(y,z,x0)*xi*xi;
1412 }
1413
1414 if (fI>1) {
1415 Double_t xi=9.;
1416 d+=0.0097*xi*xi;
1417 }
1418
1419 if (fI>3) {
1420 Double_t xi=0.5*(fgLayers[3].GetR()+fgLayers[4].GetR());
1421 d+=0.0034*xi*xi;
1422 }
1423
1424 return d/(xn*xn);
1425}
1426
1427Int_t AliITStrackerMI::AliITSlayer::InRoad() const {
1428 //--------------------------------------------------------------------
1429 // This function returns number of clusters within the "window"
1430 //--------------------------------------------------------------------
1431 Int_t ncl=0;
1432 for (Int_t i=fI; i<fN; i++) {
1433 const AliITSclusterV2 *c=fClusters[i];
1434 if (c->GetZ() > fZmax) break;
1435 if (c->IsUsed()) continue;
1436 const AliITSdetector &det=GetDetector(c->GetDetectorIndex());
1437 Double_t y=fR*det.GetPhi() + c->GetY();
1438
1439 if (y>2.*fR*TMath::Pi()) y -= 2*fR*TMath::Pi();
1440 if (y>1.*fR*TMath::Pi() && fYmax<y) y -= 2*fR*TMath::Pi();
1441
1442 if (y<fYmin) continue;
1443 if (y>fYmax) continue;
1444 ncl++;
1445 }
1446 return ncl;
1447}
1448
1449Bool_t
15dd636f 1450AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *t,const AliITStrackMI *c) {
e43c066c 1451 //--------------------------------------------------------------------
1452 // This function refits the track "t" at the position "x" using
1453 // the clusters from "c"
1454 //--------------------------------------------------------------------
1455 Int_t index[kMaxLayer];
1456 Int_t k;
1457 for (k=0; k<kMaxLayer; k++) index[k]=-1;
1458 Int_t nc=c->GetNumberOfClusters();
1459 for (k=0; k<nc; k++) {
1460 Int_t idx=c->GetClusterIndex(k),nl=(idx&0xf0000000)>>28;
1461 index[nl]=idx;
1462 }
1463
1464 Int_t from, to, step;
1465 if (xx > t->GetX()) {
1466 from=0; to=kMaxLayer;
1467 step=+1;
1468 } else {
1469 from=kMaxLayer-1; to=-1;
1470 step=-1;
1471 }
1472
1473 for (Int_t i=from; i != to; i += step) {
1474 AliITSlayer &layer=fgLayers[i];
1475 Double_t r=layer.GetR();
1476
1477 {
1478 Double_t hI=i-0.5*step;
1479 if (TMath::Abs(hI-1.5)<0.01 || TMath::Abs(hI-3.5)<0.01) {
1480 Double_t rs=0.5*(fgLayers[i-step].GetR() + r);
1481 Double_t d=0.0034, x0=38.6;
1482 if (TMath::Abs(hI-1.5)<0.01) {rs=9.; d=0.0097; x0=42;}
1483 if (!t->PropagateTo(rs,-step*d,x0)) {
1484 return kFALSE;
1485 }
1486 }
1487 }
1488
1489 // remember old position [SR, GSI 18.02.2003]
1490 Double_t oldX=0., oldY=0., oldZ=0.;
1491 if (t->IsStartedTimeIntegral() && step==1) {
1492 t->GetGlobalXYZat(t->GetX(),oldX,oldY,oldZ);
1493 }
1494 //
1495
1496 Double_t x,y,z;
1497 if (!t->GetGlobalXYZat(r,x,y,z)) {
1498 return kFALSE;
1499 }
1500 Double_t phi=TMath::ATan2(y,x);
1501 Int_t idet=layer.FindDetectorIndex(phi,z);
1502 if (idet<0) {
1503 return kFALSE;
1504 }
1505 const AliITSdetector &det=layer.GetDetector(idet);
1506 phi=det.GetPhi();
1507 if (!t->Propagate(phi,det.GetR())) {
1508 return kFALSE;
1509 }
1510 t->SetDetectorIndex(idet);
1511
1512 const AliITSclusterV2 *cl=0;
1513 Double_t maxchi2=1000.*kMaxChi2;
1514
1515 Int_t idx=index[i];
1516 if (idx>0) {
1517 const AliITSclusterV2 *c=(AliITSclusterV2 *)GetCluster(idx);
67c1e979 1518 if (c){
1519 if (idet != c->GetDetectorIndex()) {
1520 idet=c->GetDetectorIndex();
1521 const AliITSdetector &det=layer.GetDetector(idet);
1522 if (!t->Propagate(det.GetPhi(),det.GetR())) {
1523 return kFALSE;
1524 }
1525 t->SetDetectorIndex(idet);
1526 }
1527 //Double_t chi2=t->GetPredictedChi2(c);
1528 Int_t layer = (idx & 0xf0000000) >> 28;;
1529 Double_t chi2=GetPredictedChi2MI(t,c,layer);
1530 if (chi2<maxchi2) {
1531 cl=c;
1532 maxchi2=chi2;
1533 } else {
1534 return kFALSE;
1535 }
1536 }
1537 }
1538 /*
1539 if (cl==0)
1540 if (t->GetNumberOfClusters()>2) {
1541 Double_t dz=4*TMath::Sqrt(t->GetSigmaZ2()+kSigmaZ2[i]);
1542 Double_t dy=4*TMath::Sqrt(t->GetSigmaY2()+kSigmaY2[i]);
1543 Double_t zmin=t->GetZ() - dz;
1544 Double_t zmax=t->GetZ() + dz;
1545 Double_t ymin=t->GetY() + phi*r - dy;
1546 Double_t ymax=t->GetY() + phi*r + dy;
1547 layer.SelectClusters(zmin,zmax,ymin,ymax);
1548
1549 const AliITSclusterV2 *c=0; Int_t ci=-1;
1550 while ((c=layer.GetNextCluster(ci))!=0) {
1551 if (idet != c->GetDetectorIndex()) continue;
1552 Double_t chi2=t->GetPredictedChi2(c);
1553 if (chi2<maxchi2) { cl=c; maxchi2=chi2; idx=ci; }
1554 }
1555 }
1556 */
1557 if (cl) {
1558 //if (!t->Update(cl,maxchi2,idx)) {
1559 if (!UpdateMI(t,cl,maxchi2,idx)) {
1560 return kFALSE;
1561 }
1562 t->SetSampledEdx(cl->GetQ(),t->GetNumberOfClusters()-1);
1563 }
1564
1565 {
1566 Double_t x0;
1567 Double_t d=layer.GetThickness(t->GetY(),t->GetZ(),x0);
1568 t->CorrectForMaterial(-step*d,x0);
1569 }
1570
1571 // track time update [SR, GSI 17.02.2003]
1572 if (t->IsStartedTimeIntegral() && step==1) {
1573 Double_t newX, newY, newZ;
1574 t->GetGlobalXYZat(t->GetX(),newX,newY,newZ);
1575 Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) +
1576 (oldZ-newZ)*(oldZ-newZ);
1577 t->AddTimeStep(TMath::Sqrt(dL2));
1578 }
1579 //
1580
1581 }
1582
1583 if (!t->PropagateTo(xx,0.,0.)) return kFALSE;
1584 return kTRUE;
1585}
1586
1587
1588Bool_t
1589AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *t,const Int_t *clindex) {
1590 //--------------------------------------------------------------------
1591 // This function refits the track "t" at the position "x" using
1592 // the clusters from array
1593 //--------------------------------------------------------------------
1594 Int_t index[kMaxLayer];
1595 Int_t k;
1596 for (k=0; k<kMaxLayer; k++) index[k]=-1;
1597 //
1598 for (k=0; k<kMaxLayer; k++) {
1599 index[k]=clindex[k];
1600 }
1601
1602 Int_t from, to, step;
1603 if (xx > t->GetX()) {
1604 from=0; to=kMaxLayer;
1605 step=+1;
1606 } else {
1607 from=kMaxLayer-1; to=-1;
1608 step=-1;
1609 }
1610
1611 for (Int_t i=from; i != to; i += step) {
1612 AliITSlayer &layer=fgLayers[i];
1613 Double_t r=layer.GetR();
1614 if (step<0 && xx>r) break; //
1615 {
1616 Double_t hI=i-0.5*step;
1617 if (TMath::Abs(hI-1.5)<0.01 || TMath::Abs(hI-3.5)<0.01) {
1618 Double_t rs=0.5*(fgLayers[i-step].GetR() + r);
1619 Double_t d=0.0034, x0=38.6;
1620 if (TMath::Abs(hI-1.5)<0.01) {rs=9.; d=0.0097; x0=42;}
1621 if (!t->PropagateTo(rs,-step*d,x0)) {
1622 return kFALSE;
e43c066c 1623 }
67c1e979 1624 }
1625 }
1626
1627 // remember old position [SR, GSI 18.02.2003]
1628 Double_t oldX=0., oldY=0., oldZ=0.;
1629 if (t->IsStartedTimeIntegral() && step==1) {
1630 t->GetGlobalXYZat(t->GetX(),oldX,oldY,oldZ);
1631 }
1632 //
1633
1634 Double_t x,y,z;
1635 if (!t->GetGlobalXYZat(r,x,y,z)) {
1636 return kFALSE;
1637 }
1638 Double_t phi=TMath::ATan2(y,x);
1639 Int_t idet=layer.FindDetectorIndex(phi,z);
1640 if (idet<0) {
1641 return kFALSE;
1642 }
1643 const AliITSdetector &det=layer.GetDetector(idet);
1644 phi=det.GetPhi();
1645 if (!t->Propagate(phi,det.GetR())) {
1646 return kFALSE;
1647 }
1648 t->SetDetectorIndex(idet);
1649
1650 const AliITSclusterV2 *cl=0;
1651 Double_t maxchi2=1000.*kMaxChi2;
1652
1653 Int_t idx=index[i];
1654 if (idx>0) {
1655 const AliITSclusterV2 *c=(AliITSclusterV2 *)GetCluster(idx);
1656 if (c){
1657 if (idet != c->GetDetectorIndex()) {
1658 idet=c->GetDetectorIndex();
1659 const AliITSdetector &det=layer.GetDetector(idet);
1660 if (!t->Propagate(det.GetPhi(),det.GetR())) {
1661 return kFALSE;
1662 }
1663 t->SetDetectorIndex(idet);
1664 }
1665 //Double_t chi2=t->GetPredictedChi2(c);
1666 Int_t layer = (idx & 0xf0000000) >> 28;;
1667 Double_t chi2=GetPredictedChi2MI(t,c,layer);
1668 if (chi2<maxchi2) {
1669 cl=c;
1670 maxchi2=chi2;
1671 } else {
1672 return kFALSE;
1673 }
e43c066c 1674 }
1675 }
1676 /*
1677 if (cl==0)
1678 if (t->GetNumberOfClusters()>2) {
1679 Double_t dz=4*TMath::Sqrt(t->GetSigmaZ2()+kSigmaZ2[i]);
1680 Double_t dy=4*TMath::Sqrt(t->GetSigmaY2()+kSigmaY2[i]);
1681 Double_t zmin=t->GetZ() - dz;
1682 Double_t zmax=t->GetZ() + dz;
1683 Double_t ymin=t->GetY() + phi*r - dy;
1684 Double_t ymax=t->GetY() + phi*r + dy;
1685 layer.SelectClusters(zmin,zmax,ymin,ymax);
1686
1687 const AliITSclusterV2 *c=0; Int_t ci=-1;
1688 while ((c=layer.GetNextCluster(ci))!=0) {
1689 if (idet != c->GetDetectorIndex()) continue;
1690 Double_t chi2=t->GetPredictedChi2(c);
1691 if (chi2<maxchi2) { cl=c; maxchi2=chi2; idx=ci; }
1692 }
1693 }
1694 */
1695 if (cl) {
1696 //if (!t->Update(cl,maxchi2,idx)) {
1697 if (!UpdateMI(t,cl,maxchi2,idx)) {
1698 return kFALSE;
1699 }
1700 t->SetSampledEdx(cl->GetQ(),t->GetNumberOfClusters()-1);
1701 }
1702
1703 {
1704 Double_t x0;
1705 Double_t d=layer.GetThickness(t->GetY(),t->GetZ(),x0);
1706 t->CorrectForMaterial(-step*d,x0);
1707 }
1708
1709 // track time update [SR, GSI 17.02.2003]
1710 if (t->IsStartedTimeIntegral() && step==1) {
1711 Double_t newX, newY, newZ;
1712 t->GetGlobalXYZat(t->GetX(),newX,newY,newZ);
1713 Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) +
1714 (oldZ-newZ)*(oldZ-newZ);
1715 t->AddTimeStep(TMath::Sqrt(dL2));
1716 }
1717 //
1718
1719 }
1720
1721 if (!t->PropagateTo(xx,0.,0.)) return kFALSE;
1722 return kTRUE;
1723}
1724
1725
67c1e979 1726
15dd636f 1727Double_t AliITStrackerMI::GetNormalizedChi2(AliITStrackMI * track, Int_t mode)
e43c066c 1728{
1729 //
1730 // calculate normalized chi2
1731 // return NormalizedChi2(track,0);
1732 Float_t chi2 = 0;
1733 Float_t sum=0;
1734 Float_t *erry = GetErrY(fCurrentEsdTrack), *errz = GetErrZ(fCurrentEsdTrack);
1735 // track->fdEdxMismatch=0;
1736 Float_t dedxmismatch =0;
1737 Float_t *ny = GetNy(fCurrentEsdTrack), *nz = GetNz(fCurrentEsdTrack);
1738 if (mode<100){
1739 for (Int_t i = 0;i<6;i++){
1740 if (track->fClIndex[i]>0){
1741 Float_t cerry, cerrz;
1742 if (ny[i]>0) {cerry = erry[i]; cerrz=errz[i];}
1743 else
1744 { cerry= track->fSigmaY[i]; cerrz = track->fSigmaZ[i];}
1745 cerry*=cerry;
1746 cerrz*=cerrz;
1747 Float_t cchi2 = (track->fDy[i]*track->fDy[i]/cerry)+(track->fDz[i]*track->fDz[i]/cerrz);
1748 if (i>1){
1749 Float_t ratio = track->fNormQ[i]/track->fExpQ;
1750 if (ratio<0.5) {
1751 cchi2+=(0.5-ratio)*10.;
1752 //track->fdEdxMismatch+=(0.5-ratio)*10.;
1753 dedxmismatch+=(0.5-ratio)*10.;
1754 }
1755 }
1756 if (i<2 ||i>3){
1757 AliITSclusterV2 * cl = (AliITSclusterV2*)GetCluster( track->fClIndex[i]);
1758 Double_t delta = cl->GetNy()+cl->GetNz()-ny[i]-nz[i];
1759 if (delta>1) chi2 +=0.5*TMath::Min(delta/2,2.);
1760 if (i<2) chi2+=2*cl->GetDeltaProbability();
1761 }
1762 chi2+=cchi2;
1763 sum++;
1764 }
1765 }
1766 if (TMath::Abs(track->fdEdxMismatch-dedxmismatch)>0.0001){
1767 track->fdEdxMismatch = dedxmismatch;
1768 }
1769 }
1770 else{
1771 for (Int_t i = 0;i<4;i++){
1772 if (track->fClIndex[i]>0){
1773 Float_t cerry, cerrz;
1774 if (ny[i]>0) {cerry = erry[i]; cerrz=errz[i];}
1775 else { cerry= track->fSigmaY[i]; cerrz = track->fSigmaZ[i];}
1776 cerry*=cerry;
1777 cerrz*=cerrz;
1778 chi2+= (track->fDy[i]*track->fDy[i]/cerry);
1779 chi2+= (track->fDz[i]*track->fDz[i]/cerrz);
1780 sum++;
1781 }
1782 }
1783 for (Int_t i = 4;i<6;i++){
1784 if (track->fClIndex[i]>0){
1785 Float_t cerry, cerrz;
1786 if (ny[i]>0) {cerry = erry[i]; cerrz=errz[i];}
1787 else { cerry= track->fSigmaY[i]; cerrz = track->fSigmaZ[i];}
1788 cerry*=cerry;
1789 cerrz*=cerrz;
1790 Float_t cerryb, cerrzb;
1791 if (ny[i+6]>0) {cerryb = erry[i+6]; cerrzb=errz[i+6];}
1792 else { cerryb= track->fSigmaY[i+6]; cerrzb = track->fSigmaZ[i+6];}
1793 cerryb*=cerryb;
1794 cerrzb*=cerrzb;
1795 chi2+= TMath::Min((track->fDy[i+6]*track->fDy[i+6]/cerryb),track->fDy[i]*track->fDy[i]/cerry);
1796 chi2+= TMath::Min((track->fDz[i+6]*track->fDz[i+6]/cerrzb),track->fDz[i]*track->fDz[i]/cerrz);
1797 sum++;
1798 }
1799 }
1800 }
1801 if (track->fESDtrack->GetTPCsignal()>85){
1802 Float_t ratio = track->fdEdx/track->fESDtrack->GetTPCsignal();
1803 if (ratio<0.5) {
1804 chi2+=(0.5-ratio)*5.;
1805 }
1806 if (ratio>2){
1807 chi2+=(ratio-2.0)*3;
1808 }
1809 }
1810 //
1811 Double_t match = TMath::Sqrt(track->fChi22);
1812 if (track->fConstrain) match/=track->GetNumberOfClusters();
1813 if (!track->fConstrain) match/=track->GetNumberOfClusters()-2.;
1814 if (match<0) match=0;
1815 Float_t deadzonefactor = (track->fNDeadZone>0) ? 3*(1.1-track->fDeadZoneProbability):0.;
1816 Double_t normchi2 = 2*track->fNSkipped+match+deadzonefactor+(1+(2*track->fNSkipped+deadzonefactor)/track->GetNumberOfClusters())*
1817 (chi2)/TMath::Max(double(sum-track->fNSkipped),
1818 1./(1.+track->fNSkipped));
1819
1820 return normchi2;
1821}
1822
1823
15dd636f 1824Double_t AliITStrackerMI::GetMatchingChi2(AliITStrackMI * track1, AliITStrackMI * track2)
e43c066c 1825{
1826 //
1827 // return matching chi2 between two tracks
15dd636f 1828 AliITStrackMI track3(*track2);
e43c066c 1829 track3.Propagate(track1->GetAlpha(),track1->GetX());
1830 TMatrixD vec(5,1);
1831 vec(0,0)=track1->fP0-track3.fP0;
1832 vec(1,0)=track1->fP1-track3.fP1;
1833 vec(2,0)=track1->fP2-track3.fP2;
1834 vec(3,0)=track1->fP3-track3.fP3;
1835 vec(4,0)=track1->fP4-track3.fP4;
1836 //
1837 TMatrixD cov(5,5);
1838 cov(0,0) = track1->fC00+track3.fC00;
1839 cov(1,1) = track1->fC11+track3.fC11;
1840 cov(2,2) = track1->fC22+track3.fC22;
1841 cov(3,3) = track1->fC33+track3.fC33;
1842 cov(4,4) = track1->fC44+track3.fC44;
1843
1844 cov(0,1)=cov(1,0) = track1->fC10+track3.fC10;
1845 cov(0,2)=cov(2,0) = track1->fC20+track3.fC20;
1846 cov(0,3)=cov(3,0) = track1->fC30+track3.fC30;
1847 cov(0,4)=cov(4,0) = track1->fC40+track3.fC40;
1848 //
1849 cov(1,2)=cov(2,1) = track1->fC21+track3.fC21;
1850 cov(1,3)=cov(3,1) = track1->fC31+track3.fC31;
1851 cov(1,4)=cov(4,1) = track1->fC41+track3.fC41;
1852 //
1853 cov(2,3)=cov(3,2) = track1->fC32+track3.fC32;
1854 cov(2,4)=cov(4,2) = track1->fC42+track3.fC42;
1855 //
1856 cov(3,4)=cov(4,3) = track1->fC43+track3.fC43;
1857
1858 cov.Invert();
1859 TMatrixD vec2(cov,TMatrixD::kMult,vec);
1860 TMatrixD chi2(vec2,TMatrixD::kTransposeMult,vec);
1861 return chi2(0,0);
1862}
1863
1864Double_t AliITStrackerMI::GetDeadZoneProbability(Double_t zpos, Double_t zerr)
1865{
1866 //
1867 // return probability that given point - characterized by z position and error is in dead zone
1868 //
1869 Double_t probability =0;
1870 Double_t absz = TMath::Abs(zpos);
1871 Double_t nearestz = (absz<2)? 0.:7.1;
1872 if (TMath::Abs(absz-nearestz)>0.25+3*zerr) return 0;
1873 Double_t zmin=0, zmax=0;
1874 if (zpos<-6.){
1875 zmin = -7.25; zmax = -6.95;
1876 }
1877 if (zpos>6){
1878 zmin = 7.0; zmax =7.3;
1879 }
1880 if (absz<2){
1881 zmin = -0.75; zmax = 1.5;
1882 }
1883 probability = (TMath::Erf((zpos-zmin)/zerr) - TMath::Erf((zpos-zmax)/zerr))*0.5;
1884 return probability;
1885}
1886
1887
15dd636f 1888Double_t AliITStrackerMI::GetTruncatedChi2(AliITStrackMI * track, Float_t fac)
e43c066c 1889{
1890 //
1891 // calculate normalized chi2
1892 Float_t chi2[6];
1893 Float_t *erry = GetErrY(fCurrentEsdTrack), *errz = GetErrZ(fCurrentEsdTrack);
1894 Float_t ncl = 0;
1895 for (Int_t i = 0;i<6;i++){
1896 if (TMath::Abs(track->fDy[i])>0){
1897 chi2[i]= (track->fDy[i]/erry[i])*(track->fDy[i]/erry[i]);
1898 chi2[i]+= (track->fDz[i]/errz[i])*(track->fDz[i]/errz[i]);
1899 ncl++;
1900 }
1901 else{chi2[i]=10000;}
1902 }
1903 Int_t index[6];
1904 TMath::Sort(6,chi2,index,kFALSE);
1905 Float_t max = float(ncl)*fac-1.;
1906 Float_t sumchi=0, sumweight=0;
1907 for (Int_t i=0;i<max+1;i++){
1908 Float_t weight = (i<max)?1.:(max+1.-i);
1909 sumchi+=weight*chi2[index[i]];
1910 sumweight+=weight;
1911 }
1912 Double_t normchi2 = sumchi/sumweight;
1913 return normchi2;
1914}
1915
1916
15dd636f 1917Double_t AliITStrackerMI::GetInterpolatedChi2(AliITStrackMI * forwardtrack, AliITStrackMI * backtrack)
e43c066c 1918{
1919 //
1920 // calculate normalized chi2
1921 // if (forwardtrack->fNUsed>0.3*float(forwardtrack->GetNumberOfClusters())) return 10000;
1922 Int_t npoints = 0;
1923 Double_t res =0;
1924 for (Int_t i=0;i<6;i++){
1925 if ( (backtrack->fSigmaY[i]<0.000000001) || (forwardtrack->fSigmaY[i]<0.000000001)) continue;
1926 Double_t sy1 = forwardtrack->fSigmaY[i];
1927 Double_t sz1 = forwardtrack->fSigmaZ[i];
1928 Double_t sy2 = backtrack->fSigmaY[i];
1929 Double_t sz2 = backtrack->fSigmaZ[i];
1930 if (i<2){ sy2=1000.;sz2=1000;}
1931 //
1932 Double_t dy0 = (forwardtrack->fDy[i]/(sy1*sy1) +backtrack->fDy[i]/(sy2*sy2))/(1./(sy1*sy1)+1./(sy2*sy2));
1933 Double_t dz0 = (forwardtrack->fDz[i]/(sz1*sz1) +backtrack->fDz[i]/(sz2*sz2))/(1./(sz1*sz1)+1./(sz2*sz2));
1934 //
1935 Double_t nz0 = dz0*TMath::Sqrt((1./(sz1*sz1)+1./(sz2*sz2)));
1936 Double_t ny0 = dy0*TMath::Sqrt((1./(sy1*sy1)+1./(sy2*sy2)));
1937 //
1938 res+= nz0*nz0+ny0*ny0;
1939 npoints++;
1940 }
1941 if (npoints>1) return
1942 TMath::Max(TMath::Abs(0.3*forwardtrack->Get1Pt())-0.5,0.)+
1943 //2*forwardtrack->fNUsed+
1944 res/TMath::Max(double(npoints-forwardtrack->fNSkipped),
1945 1./(1.+forwardtrack->fNSkipped));
1946 return 1000;
1947}
1948
1949
1950
1951
1952
1953Float_t *AliITStrackerMI::GetWeight(Int_t index) {
1954 //--------------------------------------------------------------------
1955 // Return pointer to a given cluster
1956 //--------------------------------------------------------------------
1957 Int_t l=(index & 0xf0000000) >> 28;
1958 Int_t c=(index & 0x0fffffff) >> 00;
1959 return fgLayers[l].GetWeight(c);
1960}
1961
15dd636f 1962void AliITStrackerMI::RegisterClusterTracks(AliITStrackMI* track,Int_t id)
e43c066c 1963{
1964 //---------------------------------------------
1965 // register track to the list
628e7bb0 1966 //
1967 if (track->fESDtrack->GetKinkIndex(0)!=0) return; //don't register kink tracks
1968 //
1969 //
e43c066c 1970 for (Int_t icluster=0;icluster<track->GetNumberOfClusters();icluster++){
1971 Int_t index = track->GetClusterIndex(icluster);
1972 Int_t l=(index & 0xf0000000) >> 28;
1973 Int_t c=(index & 0x0fffffff) >> 00;
1974 if (c>fgLayers[l].fN) continue;
1975 for (Int_t itrack=0;itrack<4;itrack++){
1976 if (fgLayers[l].fClusterTracks[itrack][c]<0){
1977 fgLayers[l].fClusterTracks[itrack][c]=id;
1978 break;
1979 }
1980 }
1981 }
1982}
15dd636f 1983void AliITStrackerMI::UnRegisterClusterTracks(AliITStrackMI* track, Int_t id)
e43c066c 1984{
1985 //---------------------------------------------
1986 // unregister track from the list
1987 for (Int_t icluster=0;icluster<track->GetNumberOfClusters();icluster++){
1988 Int_t index = track->GetClusterIndex(icluster);
1989 Int_t l=(index & 0xf0000000) >> 28;
1990 Int_t c=(index & 0x0fffffff) >> 00;
1991 if (c>fgLayers[l].fN) continue;
1992 for (Int_t itrack=0;itrack<4;itrack++){
1993 if (fgLayers[l].fClusterTracks[itrack][c]==id){
1994 fgLayers[l].fClusterTracks[itrack][c]=-1;
1995 }
1996 }
1997 }
1998}
15dd636f 1999Float_t AliITStrackerMI::GetNumberOfSharedClusters(AliITStrackMI* track,Int_t id, Int_t list[6], AliITSclusterV2 *clist[6])
e43c066c 2000{
2001 //-------------------------------------------------------------
2002 //get number of shared clusters
2003 //-------------------------------------------------------------
2004 Float_t shared=0;
2005 for (Int_t i=0;i<6;i++) { list[i]=-1, clist[i]=0;}
2006 // mean number of clusters
2007 Float_t *ny = GetNy(id), *nz = GetNz(id);
2008
2009
2010 for (Int_t icluster=0;icluster<track->GetNumberOfClusters();icluster++){
2011 Int_t index = track->GetClusterIndex(icluster);
2012 Int_t l=(index & 0xf0000000) >> 28;
2013 Int_t c=(index & 0x0fffffff) >> 00;
2014 if (c>fgLayers[l].fN) continue;
2015 if (ny[l]==0){
2016 printf("problem\n");
2017 }
2018 AliITSclusterV2 *cl = (AliITSclusterV2*)GetCluster(index);
2019 Float_t weight=1;
2020 //
2021 Float_t deltan = 0;
2022 if (l>3&&cl->GetNy()+cl->GetNz()>6) continue;
2023 if (l>2&&track->fNormQ[l]/track->fExpQ>3.5) continue;
2024 if (l<2 || l>3){
2025 deltan = (cl->GetNy()+cl->GetNz()-ny[l]-nz[l]);
2026 }
2027 else{
2028 deltan = (cl->GetNz()-nz[l]);
2029 }
2030 if (deltan>2.0) continue; // extended - highly probable shared cluster
2031 weight = 2./TMath::Max(3.+deltan,2.);
2032 //
2033 for (Int_t itrack=0;itrack<4;itrack++){
2034 if (fgLayers[l].fClusterTracks[itrack][c]>=0 && fgLayers[l].fClusterTracks[itrack][c]!=id){
2035 list[l]=index;
2036 clist[l] = (AliITSclusterV2*)GetCluster(index);
2037 shared+=weight;
2038 break;
2039 }
2040 }
2041 }
2042 track->fNUsed=shared;
2043 return shared;
2044}
2045
15dd636f 2046Int_t AliITStrackerMI::GetOverlapTrack(AliITStrackMI *track, Int_t trackID, Int_t &shared, Int_t clusterlist[6],Int_t overlist[6])
e43c066c 2047{
2048 //
2049 // find first shared track
2050 //
2051 // mean number of clusters
2052 Float_t *ny = GetNy(trackID), *nz = GetNz(trackID);
2053 //
2054 for (Int_t i=0;i<6;i++) overlist[i]=-1;
2055 Int_t sharedtrack=100000;
2056 Int_t tracks[24],trackindex=0;
2057 for (Int_t i=0;i<24;i++) {tracks[i]=-1;}
2058 //
2059 for (Int_t icluster=0;icluster<6;icluster++){
2060 if (clusterlist[icluster]<0) continue;
2061 Int_t index = clusterlist[icluster];
2062 Int_t l=(index & 0xf0000000) >> 28;
2063 Int_t c=(index & 0x0fffffff) >> 00;
2064 if (ny[l]==0){
2065 printf("problem\n");
2066 }
2067 if (c>fgLayers[l].fN) continue;
2068 //if (l>3) continue;
2069 AliITSclusterV2 *cl = (AliITSclusterV2*)GetCluster(index);
2070 //
2071 Float_t deltan = 0;
2072 if (l>3&&cl->GetNy()+cl->GetNz()>6) continue;
2073 if (l>2&&track->fNormQ[l]/track->fExpQ>3.5) continue;
2074 if (l<2 || l>3){
2075 deltan = (cl->GetNy()+cl->GetNz()-ny[l]-nz[l]);
2076 }
2077 else{
2078 deltan = (cl->GetNz()-nz[l]);
2079 }
2080 if (deltan>2.0) continue; // extended - highly probable shared cluster
2081 //
2082 for (Int_t itrack=3;itrack>=0;itrack--){
2083 if (fgLayers[l].fClusterTracks[itrack][c]<0) continue;
2084 if (fgLayers[l].fClusterTracks[itrack][c]!=trackID){
2085 tracks[trackindex] = fgLayers[l].fClusterTracks[itrack][c];
2086 trackindex++;
2087 }
2088 }
2089 }
2090 if (trackindex==0) return -1;
2091 if (trackindex==1){
2092 sharedtrack = tracks[0];
2093 }else{
2094 if (trackindex==2) sharedtrack =TMath::Min(tracks[0],tracks[1]);
2095 else{
2096 //
2097 Int_t track[24], cluster[24];
2098 for (Int_t i=0;i<trackindex;i++){ track[i]=-1; cluster[i]=0;}
2099 Int_t index =0;
2100 //
2101 for (Int_t i=0;i<trackindex;i++){
2102 if (tracks[i]<0) continue;
2103 track[index] = tracks[i];
2104 cluster[index]++;
2105 for (Int_t j=i+1;j<trackindex;j++){
2106 if (tracks[j]<0) continue;
2107 if (tracks[j]==tracks[i]){
2108 cluster[index]++;
2109 tracks[j]=-1;
2110 }
2111 }
2112 index++;
2113 }
2114 Int_t max=0;
2115 for (Int_t i=0;i<index;i++){
2116 if (cluster[index]>max) {
2117 sharedtrack=track[index];
2118 max=cluster[index];
2119 }
2120 }
2121 }
2122 }
2123
2124 if (sharedtrack>=100000) return -1;
2125 //
2126 // make list of overlaps
2127 shared =0;
2128 for (Int_t icluster=0;icluster<6;icluster++){
2129 if (clusterlist[icluster]<0) continue;
2130 Int_t index = clusterlist[icluster];
2131 Int_t l=(index & 0xf0000000) >> 28;
2132 Int_t c=(index & 0x0fffffff) >> 00;
2133 if (c>fgLayers[l].fN) continue;
2134 AliITSclusterV2 *cl = (AliITSclusterV2*)GetCluster(index);
2135 if (l==0 || l==1){
2136 if (cl->GetNy()>2) continue;
2137 if (cl->GetNz()>2) continue;
2138 }
2139 if (l==4 || l==5){
2140 if (cl->GetNy()>3) continue;
2141 if (cl->GetNz()>3) continue;
2142 }
2143 //
2144 for (Int_t itrack=3;itrack>=0;itrack--){
2145 if (fgLayers[l].fClusterTracks[itrack][c]<0) continue;
2146 if (fgLayers[l].fClusterTracks[itrack][c]==sharedtrack){
2147 overlist[l]=index;
2148 shared++;
2149 }
2150 }
2151 }
2152 return sharedtrack;
2153}
2154
2155
15dd636f 2156AliITStrackMI * AliITStrackerMI::GetBest2Tracks(Int_t trackID1, Int_t trackID2, Float_t th0, Float_t th1){
e43c066c 2157 //
2158 // try to find track hypothesys without conflicts
2159 // with minimal chi2;
2160 TClonesArray *arr1 = (TClonesArray*)fTrackHypothesys.At(trackID1);
2161 Int_t entries1 = arr1->GetEntriesFast();
2162 TClonesArray *arr2 = (TClonesArray*)fTrackHypothesys.At(trackID2);
15dd636f 2163 if (!arr2) return (AliITStrackMI*) arr1->UncheckedAt(0);
e43c066c 2164 Int_t entries2 = arr2->GetEntriesFast();
15dd636f 2165 if (entries2<=0) return (AliITStrackMI*) arr1->UncheckedAt(0);
e43c066c 2166 //
15dd636f 2167 AliITStrackMI * track10=(AliITStrackMI*) arr1->UncheckedAt(0);
2168 AliITStrackMI * track20=(AliITStrackMI*) arr2->UncheckedAt(0);
e43c066c 2169 if (TMath::Abs(1./track10->Get1Pt())>0.5+TMath::Abs(1/track20->Get1Pt())) return track10;
2170
2171 for (Int_t itrack=0;itrack<entries1;itrack++){
15dd636f 2172 AliITStrackMI * track=(AliITStrackMI*) arr1->UncheckedAt(itrack);
e43c066c 2173 UnRegisterClusterTracks(track,trackID1);
2174 }
2175 //
2176 for (Int_t itrack=0;itrack<entries2;itrack++){
15dd636f 2177 AliITStrackMI * track=(AliITStrackMI*) arr2->UncheckedAt(itrack);
e43c066c 2178 UnRegisterClusterTracks(track,trackID2);
2179 }
2180 Int_t index1=0;
2181 Int_t index2=0;
2182 Float_t maxconflicts=6;
2183 Double_t maxchi2 =1000.;
2184 //
2185 // get weight of hypothesys - using best hypothesy
2186 Double_t w1,w2;
2187
2188 Int_t list1[6],list2[6];
2189 AliITSclusterV2 *clist1[6], *clist2[6] ;
2190 RegisterClusterTracks(track10,trackID1);
2191 RegisterClusterTracks(track20,trackID2);
2192 Float_t conflict1 = GetNumberOfSharedClusters(track10,trackID1,list1,clist1);
2193 Float_t conflict2 = GetNumberOfSharedClusters(track20,trackID2,list2,clist2);
2194 UnRegisterClusterTracks(track10,trackID1);
2195 UnRegisterClusterTracks(track20,trackID2);
2196 //
2197 // normalized chi2
2198 Float_t chi21 =0,chi22=0,ncl1=0,ncl2=0;
2199 Float_t nerry[6],nerrz[6];
2200 Float_t *erry1=GetErrY(trackID1),*errz1 = GetErrZ(trackID1);
2201 Float_t *erry2=GetErrY(trackID2),*errz2 = GetErrZ(trackID2);
2202 for (Int_t i=0;i<6;i++){
2203 if ( (erry1[i]>0) && (erry2[i]>0)) {
2204 nerry[i] = TMath::Min(erry1[i],erry2[i]);
2205 nerrz[i] = TMath::Min(errz1[i],errz2[i]);
2206 }else{
2207 nerry[i] = TMath::Max(erry1[i],erry2[i]);
2208 nerrz[i] = TMath::Max(errz1[i],errz2[i]);
2209 }
2210 if (TMath::Abs(track10->fDy[i])>0.000000000000001){
2211 chi21 += track10->fDy[i]*track10->fDy[i]/(nerry[i]*nerry[i]);
2212 chi21 += track10->fDz[i]*track10->fDz[i]/(nerrz[i]*nerrz[i]);
2213 ncl1++;
2214 }
2215 if (TMath::Abs(track20->fDy[i])>0.000000000000001){
2216 chi22 += track20->fDy[i]*track20->fDy[i]/(nerry[i]*nerry[i]);
2217 chi22 += track20->fDz[i]*track20->fDz[i]/(nerrz[i]*nerrz[i]);
2218 ncl2++;
2219 }
2220 }
2221 chi21/=ncl1;
2222 chi22/=ncl2;
2223 //
2224 //
2225 Float_t d1 = TMath::Sqrt(track10->fD[0]*track10->fD[0]+track10->fD[1]*track10->fD[1])+0.1;
2226 Float_t d2 = TMath::Sqrt(track20->fD[0]*track20->fD[0]+track20->fD[1]*track20->fD[1])+0.1;
2227 Float_t s1 = TMath::Sqrt(track10->GetSigmaY2()*track10->GetSigmaZ2());
2228 Float_t s2 = TMath::Sqrt(track20->GetSigmaY2()*track20->GetSigmaZ2());
2229 //
2230 w1 = (d2/(d1+d2)+ 2*s2/(s1+s2)+
2231 +s2/(s1+s2)*0.5*(chi22+2.)/(chi21+chi22+4.)
2232 +1.*TMath::Abs(1./track10->Get1Pt())/(TMath::Abs(1./track10->Get1Pt())+TMath::Abs(1./track20->Get1Pt()))
2233 );
2234 w2 = (d1/(d1+d2)+ 2*s1/(s1+s2)+
2235 s1/(s1+s2)*0.5*(chi21+2.)/(chi21+chi22+4.)
2236 +1.*TMath::Abs(1./track20->Get1Pt())/(TMath::Abs(1./track10->Get1Pt())+TMath::Abs(1./track20->Get1Pt()))
2237 );
2238
2239 Double_t sumw = w1+w2;
2240 w1/=sumw;
2241 w2/=sumw;
2242 if (w1<w2*0.5) {
2243 w1 = (d2+0.5)/(d1+d2+1.);
2244 w2 = (d1+0.5)/(d1+d2+1.);
2245 }
2246 // Float_t maxmax = w1*track10->fChi2MIP[0]+w2*track20->fChi2MIP[0]+w1*conflict1+w2*conflict2+1.;
2247 //Float_t maxconflicts0 = w1*conflict1+w2*conflict2;
2248 //
2249 // get pair of "best" hypothesys
2250 //
2251 Float_t * ny1 = GetNy(trackID1), * nz1 = GetNz(trackID1);
2252 Float_t * ny2 = GetNy(trackID2), * nz2 = GetNz(trackID2);
2253
2254 for (Int_t itrack1=0;itrack1<entries1;itrack1++){
15dd636f 2255 AliITStrackMI * track1=(AliITStrackMI*) arr1->UncheckedAt(itrack1);
e43c066c 2256 //if (track1->fFakeRatio>0) continue;
2257 RegisterClusterTracks(track1,trackID1);
2258 for (Int_t itrack2=0;itrack2<entries2;itrack2++){
15dd636f 2259 AliITStrackMI * track2=(AliITStrackMI*) arr2->UncheckedAt(itrack2);
e43c066c 2260
2261 // Float_t current = w1*track1->fChi2MIP[0]+w2*track2->fChi2MIP[0];
2262 //if (track2->fFakeRatio>0) continue;
2263 Float_t nskipped=0;
2264 RegisterClusterTracks(track2,trackID2);
2265 Int_t list1[6],list2[6];
2266 AliITSclusterV2 *clist1[6], *clist2[6] ;
2267 Float_t cconflict1 = GetNumberOfSharedClusters(track1,trackID1,list1,clist1);
2268 Float_t cconflict2 = GetNumberOfSharedClusters(track2,trackID2,list2,clist2);
2269 UnRegisterClusterTracks(track2,trackID2);
2270 //
2271 if (track1->fConstrain) nskipped+=w1*track1->fNSkipped;
2272 if (track2->fConstrain) nskipped+=w2*track2->fNSkipped;
2273 if (nskipped>0.5) continue;
2274 //
2275 //if ( w1*conflict1+w2*conflict2>maxconflicts0) continue;
2276 if (conflict1+1<cconflict1) continue;
2277 if (conflict2+1<cconflict2) continue;
2278 Float_t conflict=0;
2279 Float_t sumchi2=0;
2280 Float_t sum=0;
2281 for (Int_t i=0;i<6;i++){
2282 //
2283 Float_t c1 =0.; // conflict coeficients
2284 Float_t c2 =0.;
2285 if (clist1[i]&&clist2[i]){
2286 Float_t deltan = 0;
2287 if (i<2 || i>3){
2288 deltan = (clist1[i]->GetNy()+clist1[i]->GetNz()-TMath::Max(ny1[i],ny2[i])-TMath::Max(nz1[i],nz2[i]));
2289 }
2290 else{
2291 deltan = (clist1[i]->GetNz()-TMath::Max(nz1[i],nz2[i]));
2292 }
2293 c1 = 2./TMath::Max(3.+deltan,2.);
2294 c2 = 2./TMath::Max(3.+deltan,2.);
2295 }
2296 else{
2297 if (clist1[i]){
2298 Float_t deltan = 0;
2299 if (i<2 || i>3){
2300 deltan = (clist1[i]->GetNy()+clist1[i]->GetNz()-ny1[i]-nz1[i]);
2301 }
2302 else{
2303 deltan = (clist1[i]->GetNz()-nz1[i]);
2304 }
2305 c1 = 2./TMath::Max(3.+deltan,2.);
2306 c2 = 0;
2307 }
2308
2309 if (clist2[i]){
2310 Float_t deltan = 0;
2311 if (i<2 || i>3){
2312 deltan = (clist2[i]->GetNy()+clist2[i]->GetNz()-ny2[i]-nz2[i]);
2313 }
2314 else{
2315 deltan = (clist2[i]->GetNz()-nz2[i]);
2316 }
2317 c2 = 2./TMath::Max(3.+deltan,2.);
2318 c1 = 0;
2319 }
2320 }
2321 //
2322 Double_t chi21=0,chi22=0;
2323 if (TMath::Abs(track1->fDy[i])>0.) {
2324 chi21 = (track1->fDy[i]/track1->fSigmaY[i])*(track1->fDy[i]/track1->fSigmaY[i])+
2325 (track1->fDz[i]/track1->fSigmaZ[i])*(track1->fDz[i]/track1->fSigmaZ[i]);
2326 //chi21 = (track1->fDy[i]*track1->fDy[i])/(nerry[i]*nerry[i])+
2327 // (track1->fDz[i]*track1->fDz[i])/(nerrz[i]*nerrz[i]);
2328 }else{
2329 if (TMath::Abs(track1->fSigmaY[i]>0.)) c1=1;
2330 }
2331 //
2332 if (TMath::Abs(track2->fDy[i])>0.) {
2333 chi22 = (track2->fDy[i]/track2->fSigmaY[i])*(track2->fDy[i]/track2->fSigmaY[i])+
2334 (track2->fDz[i]/track2->fSigmaZ[i])*(track2->fDz[i]/track2->fSigmaZ[i]);
2335 //chi22 = (track2->fDy[i]*track2->fDy[i])/(nerry[i]*nerry[i])+
2336 // (track2->fDz[i]*track2->fDz[i])/(nerrz[i]*nerrz[i]);
2337 }
2338 else{
2339 if (TMath::Abs(track2->fSigmaY[i]>0.)) c2=1;
2340 }
2341 sumchi2+=w1*(1.+c1)*(1+c1)*(chi21+c1)+w2*(1.+c2)*(1+c2)*(chi22+c2);
2342 if (chi21>0) sum+=w1;
2343 if (chi22>0) sum+=w2;
2344 conflict+=(c1+c2);
2345 }
2346 Double_t norm = sum-w1*track1->fNSkipped-w2*track2->fNSkipped;
2347 if (norm<0) norm =1/(w1*track1->fNSkipped+w2*track2->fNSkipped);
2348 Double_t normchi2 = 2*conflict+sumchi2/sum;
2349 if ( normchi2 <maxchi2 ){
2350 index1 = itrack1;
2351 index2 = itrack2;
2352 maxconflicts = conflict;
2353 maxchi2 = normchi2;
2354 }
2355 }
2356 UnRegisterClusterTracks(track1,trackID1);
2357 }
2358 //
2359 // if (maxconflicts<4 && maxchi2<th0){
2360 if (maxchi2<th0*2.){
2361 Float_t orig = track10->fFakeRatio*track10->GetNumberOfClusters();
15dd636f 2362 AliITStrackMI* track1=(AliITStrackMI*) arr1->UncheckedAt(index1);
e43c066c 2363 track1->fChi2MIP[5] = maxconflicts;
2364 track1->fChi2MIP[6] = maxchi2;
2365 track1->fChi2MIP[7] = 0.01+orig-(track1->fFakeRatio*track1->GetNumberOfClusters());
2366 // track1->UpdateESDtrack(AliESDtrack::kITSin);
2367 track1->fChi2MIP[8] = index1;
2368 fBestTrackIndex[trackID1] =index1;
2369 UpdateESDtrack(track1, AliESDtrack::kITSin);
2370 }
2371 else if (track10->fChi2MIP[0]<th1){
2372 track10->fChi2MIP[5] = maxconflicts;
2373 track10->fChi2MIP[6] = maxchi2;
2374 // track10->UpdateESDtrack(AliESDtrack::kITSin);
2375 UpdateESDtrack(track10,AliESDtrack::kITSin);
2376 }
2377
2378 for (Int_t itrack=0;itrack<entries1;itrack++){
15dd636f 2379 AliITStrackMI * track=(AliITStrackMI*) arr1->UncheckedAt(itrack);
e43c066c 2380 UnRegisterClusterTracks(track,trackID1);
2381 }
2382 //
2383 for (Int_t itrack=0;itrack<entries2;itrack++){
15dd636f 2384 AliITStrackMI * track=(AliITStrackMI*) arr2->UncheckedAt(itrack);
e43c066c 2385 UnRegisterClusterTracks(track,trackID2);
2386 }
2387
2388 if (track10->fConstrain&&track10->fChi2MIP[0]<kMaxChi2PerCluster[0]&&track10->fChi2MIP[1]<kMaxChi2PerCluster[1]
2389 &&track10->fChi2MIP[2]<kMaxChi2PerCluster[2]&&track10->fChi2MIP[3]<kMaxChi2PerCluster[3]){
2390 // if (track10->fChi2MIP[0]<kMaxChi2PerCluster[0]&&track10->fChi2MIP[1]<kMaxChi2PerCluster[1]
2391 // &&track10->fChi2MIP[2]<kMaxChi2PerCluster[2]&&track10->fChi2MIP[3]<kMaxChi2PerCluster[3]){
2392 RegisterClusterTracks(track10,trackID1);
2393 }
2394 if (track20->fConstrain&&track20->fChi2MIP[0]<kMaxChi2PerCluster[0]&&track20->fChi2MIP[1]<kMaxChi2PerCluster[1]
2395 &&track20->fChi2MIP[2]<kMaxChi2PerCluster[2]&&track20->fChi2MIP[3]<kMaxChi2PerCluster[3]){
2396 //if (track20->fChi2MIP[0]<kMaxChi2PerCluster[0]&&track20->fChi2MIP[1]<kMaxChi2PerCluster[1]
2397 // &&track20->fChi2MIP[2]<kMaxChi2PerCluster[2]&&track20->fChi2MIP[3]<kMaxChi2PerCluster[3]){
2398 RegisterClusterTracks(track20,trackID2);
2399 }
2400 return track10;
2401
2402}
2403
2404void AliITStrackerMI::UseClusters(const AliKalmanTrack *t, Int_t from) const {
2405 //--------------------------------------------------------------------
2406 // This function marks clusters assigned to the track
2407 //--------------------------------------------------------------------
2408 AliTracker::UseClusters(t,from);
2409
2410 AliITSclusterV2 *c=(AliITSclusterV2 *)GetCluster(t->GetClusterIndex(0));
2411 //if (c->GetQ()>2) c->Use();
2412 if (c->GetSigmaZ2()>0.1) c->Use();
2413 c=(AliITSclusterV2 *)GetCluster(t->GetClusterIndex(1));
2414 //if (c->GetQ()>2) c->Use();
2415 if (c->GetSigmaZ2()>0.1) c->Use();
2416
2417}
2418
2419
15dd636f 2420void AliITStrackerMI::AddTrackHypothesys(AliITStrackMI * track, Int_t esdindex)
e43c066c 2421{
2422 //------------------------------------------------------------------
2423 // add track to the list of hypothesys
2424 //------------------------------------------------------------------
2425
2426 if (esdindex>=fTrackHypothesys.GetEntriesFast()) fTrackHypothesys.Expand(esdindex*2+10);
2427 //
2428 TObjArray * array = (TObjArray*) fTrackHypothesys.At(esdindex);
2429 if (!array) {
2430 array = new TObjArray(10);
2431 fTrackHypothesys.AddAt(array,esdindex);
2432 }
2433 array->AddLast(track);
2434}
2435
2436void AliITStrackerMI::SortTrackHypothesys(Int_t esdindex, Int_t maxcut, Int_t mode)
2437{
2438 //-------------------------------------------------------------------
2439 // compress array of track hypothesys
2440 // keep only maxsize best hypothesys
2441 //-------------------------------------------------------------------
2442 if (esdindex>fTrackHypothesys.GetEntriesFast()) return;
2443 if (! (fTrackHypothesys.At(esdindex)) ) return;
2444 TObjArray * array = (TObjArray*) fTrackHypothesys.At(esdindex);
2445 Int_t entries = array->GetEntriesFast();
2446 //
2447 //- find preliminary besttrack as a reference
2448 Float_t minchi2=10000;
2449 Int_t maxn=0;
15dd636f 2450 AliITStrackMI * besttrack=0;
e43c066c 2451 for (Int_t itrack=0;itrack<array->GetEntriesFast();itrack++){
15dd636f 2452 AliITStrackMI * track = (AliITStrackMI*)array->At(itrack);
e43c066c 2453 if (!track) continue;
2454 Float_t chi2 = NormalizedChi2(track,0);
2455 //
2456 Int_t tpcLabel=track->fESDtrack->GetTPCLabel();
2457 track->SetLabel(tpcLabel);
2458 CookdEdx(track);
2459 track->fFakeRatio=1.;
2460 CookLabel(track,0.); //For comparison only
2461 //
2462 //if (chi2<kMaxChi2PerCluster[0]&&track->fFakeRatio==0){
2463 if (chi2<kMaxChi2PerCluster[0]){
2464 if (track->GetNumberOfClusters()<maxn) continue;
2465 maxn = track->GetNumberOfClusters();
2466 if (chi2<minchi2){
2467 minchi2=chi2;
2468 besttrack=track;
2469 }
2470 }
2471 else{
628e7bb0 2472 if (track->fConstrain || track->fN>5){ //keep best short tracks - without vertex constrain
2473 delete array->RemoveAt(itrack);
2474 }
e43c066c 2475 }
2476 }
2477 if (!besttrack) return;
2478 //
2479 //
2480 //take errors of best track as a reference
2481 Float_t *erry = GetErrY(esdindex), *errz = GetErrZ(esdindex);
2482 Float_t *ny = GetNy(esdindex), *nz = GetNz(esdindex);
2483 for (Int_t i=0;i<6;i++) {
2484 if (besttrack->fClIndex[i]>0){
2485 erry[i] = besttrack->fSigmaY[i]; erry[i+6] = besttrack->fSigmaY[i+6];
2486 errz[i] = besttrack->fSigmaZ[i]; errz[i+6] = besttrack->fSigmaZ[i+6];
2487 ny[i] = besttrack->fNy[i];
2488 nz[i] = besttrack->fNz[i];
2489 }
2490 }
2491 //
2492 // calculate normalized chi2
2493 //
2494 Float_t * chi2 = new Float_t[entries];
2495 Int_t * index = new Int_t[entries];
2496 for (Int_t i=0;i<entries;i++) chi2[i] =10000;
2497 for (Int_t itrack=0;itrack<entries;itrack++){
15dd636f 2498 AliITStrackMI * track = (AliITStrackMI*)array->At(itrack);
e43c066c 2499 if (track){
2500 track->fChi2MIP[0] = GetNormalizedChi2(track, mode);
2501 if (track->fChi2MIP[0]<kMaxChi2PerCluster[0])
2502 chi2[itrack] = track->fChi2MIP[0];
628e7bb0 2503 else{
2504 if (track->fConstrain || track->fN>5){ //keep best short tracks - without vertex constrain
2505 delete array->RemoveAt(itrack);
2506 }
2507 }
e43c066c 2508 }
2509 }
2510 //
2511 TMath::Sort(entries,chi2,index,kFALSE);
15dd636f 2512 besttrack = (AliITStrackMI*)array->At(index[0]);
e43c066c 2513 if (besttrack&&besttrack->fChi2MIP[0]<kMaxChi2PerCluster[0]){
2514 for (Int_t i=0;i<6;i++){
2515 if (besttrack->fClIndex[i]>0){
2516 erry[i] = besttrack->fSigmaY[i]; erry[i+6] = besttrack->fSigmaY[i+6];
2517 errz[i] = besttrack->fSigmaZ[i]; erry[i+6] = besttrack->fSigmaY[i+6];
2518 ny[i] = besttrack->fNy[i];
2519 nz[i] = besttrack->fNz[i];
2520 }
2521 }
2522 }
2523 //
2524 // calculate one more time with updated normalized errors
2525 for (Int_t i=0;i<entries;i++) chi2[i] =10000;
2526 for (Int_t itrack=0;itrack<entries;itrack++){
15dd636f 2527 AliITStrackMI * track = (AliITStrackMI*)array->At(itrack);
e43c066c 2528 if (track){
2529 track->fChi2MIP[0] = GetNormalizedChi2(track,mode);
2530 if (track->fChi2MIP[0]<kMaxChi2PerCluster[0])
2531 chi2[itrack] = track->fChi2MIP[0]-0*(track->GetNumberOfClusters()+track->fNDeadZone);
628e7bb0 2532 else
2533 {
2534 if (track->fConstrain || track->fN>5){ //keep best short tracks - without vertex constrain
2535 delete array->RemoveAt(itrack);
2536 }
2537 }
e43c066c 2538 }
2539 }
2540 entries = array->GetEntriesFast();
2541 //
628e7bb0 2542 //
e43c066c 2543 if (entries>0){
2544 TObjArray * newarray = new TObjArray();
2545 TMath::Sort(entries,chi2,index,kFALSE);
15dd636f 2546 besttrack = (AliITStrackMI*)array->At(index[0]);
e43c066c 2547 if (besttrack){
2548 //
2549 for (Int_t i=0;i<6;i++){
2550 if (besttrack->fNz[i]>0&&besttrack->fNy[i]>0){
2551 erry[i] = besttrack->fSigmaY[i]; erry[i+6] = besttrack->fSigmaY[i+6];
2552 errz[i] = besttrack->fSigmaZ[i]; errz[i+6] = besttrack->fSigmaZ[i+6];
2553 ny[i] = besttrack->fNy[i];
2554 nz[i] = besttrack->fNz[i];
2555 }
2556 }
2557 besttrack->fChi2MIP[0] = GetNormalizedChi2(besttrack,mode);
2558 Float_t minchi2 = TMath::Min(besttrack->fChi2MIP[0]+5.+besttrack->fNUsed, double(kMaxChi2PerCluster[0]));
2559 Float_t minn = besttrack->GetNumberOfClusters()-3;
2560 Int_t accepted=0;
2561 for (Int_t i=0;i<entries;i++){
15dd636f 2562 AliITStrackMI * track = (AliITStrackMI*)array->At(index[i]);
e43c066c 2563 if (!track) continue;
2564 if (accepted>maxcut) break;
2565 track->fChi2MIP[0] = GetNormalizedChi2(track,mode);
628e7bb0 2566 if (track->fConstrain || track->fN>5){ //keep best short tracks - without vertex constrain
2567 if (track->GetNumberOfClusters()<6 && (track->fChi2MIP[0]+track->fNUsed>minchi2)){
2568 delete array->RemoveAt(index[i]);
2569 continue;
2570 }
e43c066c 2571 }
628e7bb0 2572 Bool_t shortbest = !track->fConstrain && track->fN<6;
2573 if ((track->fChi2MIP[0]+track->fNUsed<minchi2 && track->GetNumberOfClusters()>=minn) ||shortbest){
2574 if (!shortbest) accepted++;
e43c066c 2575 //
2576 newarray->AddLast(array->RemoveAt(index[i]));
2577 for (Int_t i=0;i<6;i++){
2578 if (nz[i]==0){
2579 erry[i] = track->fSigmaY[i]; erry[i+6] = track->fSigmaY[i+6];
2580 errz[i] = track->fSigmaZ[i]; errz[i] = track->fSigmaZ[i+6];
2581 ny[i] = track->fNy[i];
2582 nz[i] = track->fNz[i];
2583 }
2584 }
2585 }
2586 else{
2587 delete array->RemoveAt(index[i]);
2588 }
2589 }
2590 array->Delete();
2591 delete fTrackHypothesys.RemoveAt(esdindex);
2592 fTrackHypothesys.AddAt(newarray,esdindex);
2593 }
2594 else{
2595 array->Delete();
2596 delete fTrackHypothesys.RemoveAt(esdindex);
2597 }
2598 }
2599 delete [] chi2;
2600 delete [] index;
2601}
2602
2603
2604
15dd636f 2605AliITStrackMI * AliITStrackerMI::GetBestHypothesys(Int_t esdindex, AliITStrackMI * original, Int_t checkmax)
e43c066c 2606{
2607 //-------------------------------------------------------------
2608 // try to find best hypothesy
2609 // currently - minimal chi2 of track+backpropagated track+matching to the tpc track
2610 //-------------------------------------------------------------
2611 if (fTrackHypothesys.GetEntriesFast()<=esdindex) return 0;
2612 TObjArray * array = (TObjArray*) fTrackHypothesys.At(esdindex);
2613 if (!array) return 0;
2614 Int_t entries = array->GetEntriesFast();
2615 if (!entries) return 0;
2616 Float_t minchi2 = 100000;
15dd636f 2617 AliITStrackMI * besttrack=0;
e43c066c 2618 //
15dd636f 2619 AliITStrackMI * backtrack = new AliITStrackMI(*original);
2620 AliITStrackMI * forwardtrack = new AliITStrackMI(*original);
628e7bb0 2621 Double_t xyzv[]={GetX(),GetY(),GetZ()};
2622 Double_t ersv[]={GetSigmaX()/3.,GetSigmaY()/3.,GetSigmaZ()/3.};
e43c066c 2623 //
2624 for (Int_t i=0;i<entries;i++){
15dd636f 2625 AliITStrackMI * track = (AliITStrackMI*)array->At(i);
e43c066c 2626 if (!track) continue;
628e7bb0 2627 Float_t sigmarfi,sigmaz;
2628 GetDCASigma(track,sigmarfi,sigmaz);
2629 track->fDnorm[0] = sigmarfi;
2630 track->fDnorm[1] = sigmaz;
2631 //
e43c066c 2632 track->fChi2MIP[1] = 1000000;
2633 track->fChi2MIP[2] = 1000000;
2634 track->fChi2MIP[3] = 1000000;
2635 //
2636 // backtrack
15dd636f 2637 backtrack = new(backtrack) AliITStrackMI(*track);
628e7bb0 2638 if (track->fConstrain){
2639 if (!backtrack->PropagateTo(3.,0.0028,65.19)) continue;
2640 if (!backtrack->Improve(0,xyzv,ersv)) continue;
2641 if (!backtrack->PropagateTo(2.,0.0028,0)) continue;
2642 if (!backtrack->Improve(0,xyzv,ersv)) continue;
2643 if (!backtrack->PropagateTo(1.,0.0028,0)) continue;
2644 if (!backtrack->Improve(0,xyzv,ersv)) continue;
2645 if (!backtrack->PropagateToVertex()) continue;
2646 backtrack->ResetCovariance();
81e97e0d 2647 if (!backtrack->Improve(0,xyzv,ersv)) continue;
628e7bb0 2648 }else{
2649 backtrack->ResetCovariance();
2650 }
e43c066c 2651 backtrack->ResetClusters();
628e7bb0 2652
e43c066c 2653 Double_t x = original->GetX();
2654 if (!RefitAt(x,backtrack,track)) continue;
628e7bb0 2655 //
e43c066c 2656 track->fChi2MIP[1] = NormalizedChi2(backtrack,0);
2657 //for (Int_t i=2;i<6;i++){track->fDy[i]+=backtrack->fDy[i]; track->fDz[i]+=backtrack->fDz[i];}
2658 if (track->fChi2MIP[1]>kMaxChi2PerCluster[1]*6.) continue;
2659 track->fChi22 = GetMatchingChi2(backtrack,original);
2660
2661 if ((track->fConstrain) && track->fChi22>90.) continue;
2662 if ((!track->fConstrain) && track->fChi22>30.) continue;
2663 if ( track->fChi22/track->GetNumberOfClusters()>11.) continue;
2664
2665
2666 if (!(track->fConstrain)&&track->fChi2MIP[1]>kMaxChi2PerCluster[1]) continue;
2667 Bool_t isOK=kTRUE;
e43c066c 2668 if(!isOK) continue;
2669 //
2670 //forward track - without constraint
15dd636f 2671 forwardtrack = new(forwardtrack) AliITStrackMI(*original);
e43c066c 2672 forwardtrack->ResetClusters();
2673 x = track->GetX();
628e7bb0 2674 RefitAt(x,forwardtrack,track);
e43c066c 2675 track->fChi2MIP[2] = NormalizedChi2(forwardtrack,0);
2676 if (track->fChi2MIP[2]>kMaxChi2PerCluster[2]*6.0) continue;
2677 if (!(track->fConstrain)&&track->fChi2MIP[2]>kMaxChi2PerCluster[2]) continue;
2678
2679 track->fD[0] = forwardtrack->GetD(GetX(),GetY());
2680 track->fD[1] = forwardtrack->GetZat(GetX())-GetZ();
2681 forwardtrack->fD[0] = track->fD[0];
2682 forwardtrack->fD[1] = track->fD[1];
2683 {
2684 Int_t list[6];
2685 AliITSclusterV2* clist[6];
2686 track->fChi2MIP[4] = GetNumberOfSharedClusters(track,esdindex,list,clist);
2687 if ( (!track->fConstrain) && track->fChi2MIP[4]>1.0) continue;
2688 }
2689
2690 track->fChi2MIP[3] = GetInterpolatedChi2(forwardtrack,backtrack);
2691 if ( (track->fChi2MIP[3]>6.*kMaxChi2PerCluster[3])) continue;
2692 if ( (!track->fConstrain) && (track->fChi2MIP[3]>2*kMaxChi2PerCluster[3])) {
2693 track->fChi2MIP[3]=1000;
2694 continue;
2695 }
2696 Double_t chi2 = track->fChi2MIP[0]+track->fNUsed;
2697 //
2698 for (Int_t ichi=0;ichi<5;ichi++){
2699 forwardtrack->fChi2MIP[ichi] = track->fChi2MIP[ichi];
2700 }
2701 if (chi2 < minchi2){
15dd636f 2702 //besttrack = new AliITStrackMI(*forwardtrack);
99c2ee26 2703 besttrack = track;
e43c066c 2704 besttrack->SetLabel(track->GetLabel());
2705 besttrack->fFakeRatio = track->fFakeRatio;
2706 minchi2 = chi2;
2707 original->fD[0] = forwardtrack->GetD(GetX(),GetY());
2708 original->fD[1] = forwardtrack->GetZat(GetX())-GetZ();
2709 }
2710 }
2711 delete backtrack;
2712 delete forwardtrack;
2713 Int_t accepted=0;
2714 for (Int_t i=0;i<entries;i++){
15dd636f 2715 AliITStrackMI * track = (AliITStrackMI*)array->At(i);
e43c066c 2716 if (!track) continue;
628e7bb0 2717
e43c066c 2718 if (accepted>checkmax || track->fChi2MIP[3]>kMaxChi2PerCluster[3]*6. ||
2719 (track->GetNumberOfClusters()<besttrack->GetNumberOfClusters()-1.)||
2720 track->fChi2MIP[0]>besttrack->fChi2MIP[0]+2.*besttrack->fNUsed+3.){
628e7bb0 2721 if (track->fConstrain || track->fN>5){ //keep best short tracks - without vertex constrain
2722 delete array->RemoveAt(i);
2723 continue;
2724 }
e43c066c 2725 }
2726 else{
2727 accepted++;
2728 }
2729 }
2730 //
2731 array->Compress();
2732 SortTrackHypothesys(esdindex,checkmax,1);
2733 array = (TObjArray*) fTrackHypothesys.At(esdindex);
afdf9b9c 2734 if (!array) return 0; // PH What can be the reason? Check SortTrackHypothesys
15dd636f 2735 besttrack = (AliITStrackMI*)array->At(0);
e43c066c 2736 if (!besttrack) return 0;
2737 besttrack->fChi2MIP[8]=0;
2738 fBestTrackIndex[esdindex]=0;
2739 entries = array->GetEntriesFast();
15dd636f 2740 AliITStrackMI *longtrack =0;
e43c066c 2741 minchi2 =1000;
2742 Float_t minn=besttrack->GetNumberOfClusters()+besttrack->fNDeadZone;
2743 for (Int_t itrack=entries-1;itrack>0;itrack--){
15dd636f 2744 AliITStrackMI * track = (AliITStrackMI*)array->At(itrack);
e43c066c 2745 if (!track->fConstrain) continue;
2746 if (track->GetNumberOfClusters()+track->fNDeadZone<minn) continue;
2747 if (track->fChi2MIP[0]-besttrack->fChi2MIP[0]>0.0) continue;
2748 if (track->fChi2MIP[0]>4.) continue;
2749 minn = track->GetNumberOfClusters()+track->fNDeadZone;
2750 longtrack =track;
2751 }
2752 //if (longtrack) besttrack=longtrack;
2753
2754 Int_t list[6];
2755 AliITSclusterV2 * clist[6];
2756 Float_t shared = GetNumberOfSharedClusters(besttrack,esdindex,list,clist);
2757 if (besttrack->fConstrain&&besttrack->fChi2MIP[0]<kMaxChi2PerCluster[0]&&besttrack->fChi2MIP[1]<kMaxChi2PerCluster[1]
2758 &&besttrack->fChi2MIP[2]<kMaxChi2PerCluster[2]&&besttrack->fChi2MIP[3]<kMaxChi2PerCluster[3]){
e43c066c 2759 RegisterClusterTracks(besttrack,esdindex);
2760 }
2761 //
2762 //
2763 if (shared>0.0){
2764 Int_t nshared;
2765 Int_t overlist[6];
2766 Int_t sharedtrack = GetOverlapTrack(besttrack, esdindex, nshared, list, overlist);
2767 if (sharedtrack>=0){
2768 //
2769 besttrack = GetBest2Tracks(esdindex,sharedtrack,10,5.5);
2770 if (besttrack){
2771 shared = GetNumberOfSharedClusters(besttrack,esdindex,list,clist);
2772 }
2773 else return 0;
2774 }
2775 }
2776
2777 if (shared>2.5) return 0;
2778 if (shared>1.0) return besttrack;
2779 //
628e7bb0 2780 // Don't sign clusters if not gold track
2781 //
2782 if (!besttrack->IsGoldPrimary()) return besttrack;
2783 if (besttrack->fESDtrack->GetKinkIndex(0)!=0) return besttrack; //track belong to kink
2784 //
e43c066c 2785 if (fConstraint[fPass]){
2786 //
2787 // sign clusters
2788 //
2789 Float_t *ny = GetNy(esdindex), *nz = GetNz(esdindex);
2790 for (Int_t i=0;i<6;i++){
2791 Int_t index = besttrack->fClIndex[i];
2792 if (index<=0) continue;
2793 Int_t ilayer = (index & 0xf0000000) >> 28;
2794 if (besttrack->fSigmaY[ilayer]<0.00000000001) continue;
2795 AliITSclusterV2 *c = (AliITSclusterV2*)GetCluster(index);
2796 if (!c) continue;
2797 if (ilayer>3&&c->GetNy()+c->GetNz()>6) continue;
2798 if ( (c->GetNy()+c->GetNz() )> ny[i]+nz[i]+0.7) continue; //shared track
2799 if ( c->GetNz()> nz[i]+0.7) continue; //shared track
2800 if ( ilayer>2&& besttrack->fNormQ[ilayer]/besttrack->fExpQ>1.5) continue;
2801 //if ( c->GetNy()> ny[i]+0.7) continue; //shared track
2802
2803 Bool_t cansign = kTRUE;
2804 for (Int_t itrack=0;itrack<entries; itrack++){
15dd636f 2805 AliITStrackMI * track = (AliITStrackMI*)array->At(i);
e43c066c 2806 if (!track) continue;
2807 if (track->fChi2MIP[0]>besttrack->fChi2MIP[0]+2.*shared+1.) break;
2808 if ( (track->fClIndex[ilayer]>0) && (track->fClIndex[ilayer]!=besttrack->fClIndex[ilayer])){
2809 cansign = kFALSE;
2810 break;
2811 }
2812 }
2813 if (cansign){
2814 if (TMath::Abs(besttrack->fDy[ilayer]/besttrack->fSigmaY[ilayer])>3.) continue;
2815 if (TMath::Abs(besttrack->fDz[ilayer]/besttrack->fSigmaZ[ilayer])>3.) continue;
2816 if (!c->IsUsed()) c->Use();
2817 }
2818 }
2819 }
2820 return besttrack;
2821}
2822
2823
2824
2825void AliITStrackerMI::GetBestHypothesysMIP(TObjArray &itsTracks)
2826{
2827 //
2828 // get "best" hypothesys
628e7bb0 2829 //
e43c066c 2830
2831 Int_t nentries = itsTracks.GetEntriesFast();
2832 for (Int_t i=0;i<nentries;i++){
15dd636f 2833 AliITStrackMI* track = (AliITStrackMI*)itsTracks.At(i);
e43c066c 2834 if (!track) continue;
2835 TObjArray * array = (TObjArray*) fTrackHypothesys.At(i);
2836 if (!array) continue;
2837 if (array->GetEntriesFast()<=0) continue;
2838 //
15dd636f 2839 AliITStrackMI* longtrack=0;
e43c066c 2840 Float_t minn=0;
2841 Float_t maxchi2=1000;
2842 for (Int_t j=0;j<array->GetEntriesFast();j++){
15dd636f 2843 AliITStrackMI* track = (AliITStrackMI*)array->At(j);
e43c066c 2844 if (!track) continue;
628e7bb0 2845 if (track->fGoldV0) {
2846 longtrack = track; //gold V0 track taken
2847 break;
2848 }
e43c066c 2849 if (track->GetNumberOfClusters()+track->fNDeadZone<minn) continue;
628e7bb0 2850 Float_t chi2 = track->fChi2MIP[0];
2851 if (fAfterV0){
2852 if (!track->fGoldV0&&track->fConstrain==kFALSE) chi2+=5;
2853 }
2854 if (track->GetNumberOfClusters()+track->fNDeadZone>minn) maxchi2 = track->fChi2MIP[0];
2855 //
2856 if (chi2 > maxchi2) continue;
e43c066c 2857 minn= track->GetNumberOfClusters()+track->fNDeadZone;
628e7bb0 2858 maxchi2 = chi2;
e43c066c 2859 longtrack=track;
e43c066c 2860 }
628e7bb0 2861 //
2862 //
2863 //
15dd636f 2864 AliITStrackMI * besttrack = (AliITStrackMI*)array->At(0);
e43c066c 2865 if (!longtrack) {longtrack = besttrack;}
2866 else besttrack= longtrack;
628e7bb0 2867 //
e43c066c 2868 if (besttrack){
2869 Int_t list[6];
2870 AliITSclusterV2 * clist[6];
2871 Float_t shared = GetNumberOfSharedClusters(longtrack,i,list,clist);
2872 //
2873 track->fNUsed = shared;
2874 track->fNSkipped = besttrack->fNSkipped;
2875 track->fChi2MIP[0] = besttrack->fChi2MIP[0];
2876 if (shared>0){
2877 Int_t nshared;
2878 Int_t overlist[6];
2879 //
2880 Int_t sharedtrack = GetOverlapTrack(longtrack, i, nshared, list, overlist);
2881 //if (sharedtrack==-1) sharedtrack=0;
2882 if (sharedtrack>=0){
2883 besttrack = GetBest2Tracks(i,sharedtrack,10,5.5);
2884 }
2885 }
628e7bb0 2886 if (besttrack&&fAfterV0){
2887 UpdateESDtrack(besttrack,AliESDtrack::kITSin);
2888 }
e43c066c 2889 if (besttrack&&fConstraint[fPass])
2890 UpdateESDtrack(besttrack,AliESDtrack::kITSin);
2891 //if (besttrack&&besttrack->fConstrain)
2892 // UpdateESDtrack(besttrack,AliESDtrack::kITSin);
2893 if (besttrack->fChi2MIP[0]+besttrack->fNUsed>1.5){
2894 if ( (TMath::Abs(besttrack->fD[0])>0.1) && fConstraint[fPass]) {
2895 track->fReconstructed= kFALSE;
2896 }
2897 if ( (TMath::Abs(besttrack->fD[1])>0.1) && fConstraint[fPass]){
2898 track->fReconstructed= kFALSE;
2899 }
2900 }
2901
2902 }
2903 }
2904}
2905
2906
15dd636f 2907void AliITStrackerMI::CookLabel(AliITStrackMI *track,Float_t wrong) const {
e43c066c 2908 //--------------------------------------------------------------------
2909 //This function "cooks" a track label. If label<0, this track is fake.
2910 //--------------------------------------------------------------------
2911 Int_t tpcLabel=-1;
2912
2913 if ( track->fESDtrack) tpcLabel = TMath::Abs(track->fESDtrack->GetTPCLabel());
2914
2915 track->fChi2MIP[9]=0;
2916 Int_t nwrong=0;
2917 for (Int_t i=0;i<track->GetNumberOfClusters();i++){
2918 Int_t cindex = track->GetClusterIndex(i);
2919 Int_t l=(cindex & 0xf0000000) >> 28;
2920 AliITSclusterV2 *cl = (AliITSclusterV2*)GetCluster(cindex);
2921 Int_t isWrong=1;
2922 for (Int_t ind=0;ind<3;ind++){
2923 if (tpcLabel>0)
2924 if (cl->GetLabel(ind)==tpcLabel) isWrong=0;
2925 }
2926 track->fChi2MIP[9]+=isWrong*(2<<l);
2927 nwrong+=isWrong;
2928 }
2929 track->fFakeRatio = double(nwrong)/double(track->GetNumberOfClusters());
2930 if (tpcLabel>0){
2931 if (track->fFakeRatio>wrong) track->fLab = -tpcLabel;
2932 else
2933 track->fLab = tpcLabel;
2934 }
2935
2936}
2937
2938
2939
15dd636f 2940void AliITStrackerMI::CookdEdx(AliITStrackMI* track)
e43c066c 2941{
2942 //
2943 //
2944 // Int_t list[6];
2945 //AliITSclusterV2 * clist[6];
2946 // Int_t shared = GetNumberOfSharedClusters(track,index,list,clist);
2947 Float_t dedx[4];
2948 Int_t accepted=0;
2949 track->fChi2MIP[9]=0;
2950 for (Int_t i=0;i<track->GetNumberOfClusters();i++){
2951 Int_t cindex = track->GetClusterIndex(i);
2952 Int_t l=(cindex & 0xf0000000) >> 28;
2953 AliITSclusterV2 *cl = (AliITSclusterV2*)GetCluster(cindex);
2954 Int_t lab = TMath::Abs(track->fESDtrack->GetTPCLabel());
2955 Int_t isWrong=1;
2956 for (Int_t ind=0;ind<3;ind++){
2957 if (cl->GetLabel(ind)==lab) isWrong=0;
2958 }
2959 track->fChi2MIP[9]+=isWrong*(2<<l);
2960 if (l<2) continue;
2961 //if (l>3 && (cl->GetNy()>4) || (cl->GetNz()>4)) continue; //shared track
2962 //if (l>3&& !(cl->GetType()==1||cl->GetType()==10)) continue;
2963 //if (l<4&& !(cl->GetType()==1)) continue;
2964 dedx[accepted]= track->fdEdxSample[i];
2965 //dedx[accepted]= track->fNormQ[l];
2966 accepted++;
2967 }
2968 if (accepted<1) {
2969 track->SetdEdx(0);
2970 return;
2971 }
2972 Int_t indexes[4];
2973 TMath::Sort(accepted,dedx,indexes,kFALSE);
2974 Double_t low=0.;
2975 Double_t up=0.51;
2976 Double_t nl=low*accepted, nu =up*accepted;
2977 Float_t sumamp = 0;
2978 Float_t sumweight =0;
2979 for (Int_t i=0; i<accepted; i++) {
2980 Float_t weight =1;
2981 if (i<nl+0.1) weight = TMath::Max(1.-(nl-i),0.);
2982 if (i>nu-1) weight = TMath::Max(nu-i,0.);
2983 sumamp+= dedx[indexes[i]]*weight;
2984 sumweight+=weight;
2985 }
2986 track->SetdEdx(sumamp/sumweight);
2987}
2988
2989
2990void AliITStrackerMI::MakeCoeficients(Int_t ntracks){
2991 //
2992 //
628e7bb0 2993 if (fCoeficients) delete []fCoeficients;
e43c066c 2994 fCoeficients = new Float_t[ntracks*48];
2995 for (Int_t i=0;i<ntracks*48;i++) fCoeficients[i]=-1.;
2996}
2997
2998
15dd636f 2999Double_t AliITStrackerMI::GetPredictedChi2MI(AliITStrackMI* track, const AliITSclusterV2 *cluster,Int_t layer)
e43c066c 3000{
3001 //
3002 //
3003 //
3004 Float_t erry,errz;
3005 Float_t theta = track->GetTgl();
3006 Float_t phi = track->GetSnp();
3007 phi = TMath::Sqrt(phi*phi/(1.-phi*phi));
3008 GetError(layer,cluster,theta,phi,track->fExpQ,erry,errz);
3009 Double_t chi2 = track->GetPredictedChi2MI(cluster->GetY(),cluster->GetZ(),erry,errz);
3010 Float_t ny,nz;
3011 GetNTeor(layer,cluster, theta,phi,ny,nz);
3012 Double_t delta = cluster->GetNy()+cluster->GetNz()-nz-ny;
3013 if (delta>1){
3014 chi2+=0.5*TMath::Min(delta/2,2.);
3015 chi2+=2.*cluster->GetDeltaProbability();
3016 }
3017 //
3018 track->fNy[layer] =ny;
3019 track->fNz[layer] =nz;
3020 track->fSigmaY[layer] = erry;
3021 track->fSigmaZ[layer] = errz;
3022 //track->fNormQ[layer] = cluster->GetQ()/TMath::Sqrt(1+theta*theta+phi*phi);
3023 track->fNormQ[layer] = cluster->GetQ()/TMath::Sqrt((1.+ track->fP3*track->fP3)/(1.- track->fP2*track->fP2));
3024 return chi2;
3025
3026}
3027
15dd636f 3028Int_t AliITStrackerMI::UpdateMI(AliITStrackMI* track, const AliITSclusterV2* cl,Double_t chi2,Int_t index) const
e43c066c 3029{
3030 //
3031 //
3032 //
3033 Int_t layer = (index & 0xf0000000) >> 28;
3034 track->fClIndex[layer] = index;
3035 if ( (layer>1) &&track->fNormQ[layer]/track->fExpQ<0.5 ) {
3036 chi2+= (0.5-track->fNormQ[layer]/track->fExpQ)*10.;
3037 track->fdEdxMismatch+=(0.5-track->fNormQ[layer]/track->fExpQ)*10.;
3038 }
3039 return track->UpdateMI(cl->GetY(),cl->GetZ(),track->fSigmaY[layer],track->fSigmaZ[layer],chi2,index);
3040}
3041
3042void AliITStrackerMI::GetNTeor(Int_t layer, const AliITSclusterV2* /*cl*/, Float_t theta, Float_t phi, Float_t &ny, Float_t &nz)
3043{
3044 //
3045 //get "mean shape"
3046 //
3047 if (layer==0){
3048 ny = 1.+TMath::Abs(phi)*3.2;
3049 nz = 1.+TMath::Abs(theta)*0.34;
3050 return;
3051 }
3052 if (layer==1){
3053 ny = 1.+TMath::Abs(phi)*3.2;
3054 nz = 1.+TMath::Abs(theta)*0.28;
3055 return;
3056 }
3057
3058 if (layer>3){
3059 ny = 2.02+TMath::Abs(phi)*1.95;
3060 nz = 2.02+TMath::Abs(phi)*2.35;
3061 return;
3062 }
4c53440c 3063 ny = 6.6-2.7*TMath::Abs(phi);
e43c066c 3064 nz = 2.8-3.11*TMath::Abs(phi)+0.45*TMath::Abs(theta);
3065}
3066
3067
3068
3069Int_t AliITStrackerMI::GetError(Int_t layer, const AliITSclusterV2*cl, Float_t theta, Float_t phi,Float_t expQ, Float_t &erry, Float_t &errz)
3070{
3071 //calculate cluster position error
3072 //
3073 Float_t nz,ny;
3074 GetNTeor(layer, cl,theta,phi,ny,nz);
3075 erry = TMath::Sqrt(cl->GetSigmaY2());
3076 errz = TMath::Sqrt(cl->GetSigmaZ2());
3077 //
3078 // PIXELS
3079 if (layer<2){
3080
3081 if (TMath::Abs(ny-cl->GetNy())>0.6) {
3082 if (ny<cl->GetNy()){
3083 erry*=0.4+TMath::Abs(ny-cl->GetNy());
3084 errz*=0.4+TMath::Abs(ny-cl->GetNy());
3085 }else{
3086 erry*=0.7+0.5*TMath::Abs(ny-cl->GetNy());
3087 errz*=0.7+0.5*TMath::Abs(ny-cl->GetNy());
3088 }
3089 }
3090 if (TMath::Abs(nz-cl->GetNz())>1.) {
3091 erry*=TMath::Abs(nz-cl->GetNz());
3092 errz*=TMath::Abs(nz-cl->GetNz());
3093 }
3094 erry*=0.85;
3095 errz*=0.85;
3096 erry= TMath::Min(erry,float(0.005));
3097 errz= TMath::Min(errz,float(0.03));
3098 return 10;
3099 }
3100
3101//STRIPS
3102 if (layer>3){
1d4090b7 3103 //factor 1.8 appears in new simulation
3104 //
3105 Float_t scale=1.8;
e43c066c 3106 if (cl->GetNy()==100||cl->GetNz()==100){
1d4090b7 3107 erry = 0.004*scale;
3108 errz = 0.2*scale;
e43c066c 3109 return 100;
3110 }
3111 if (cl->GetNy()+cl->GetNz()>12){
1d4090b7 3112 erry = 0.06*scale;
3113 errz = 0.57*scale;
e43c066c 3114 return 100;
3115 }
3116 Float_t normq = cl->GetQ()/(TMath::Sqrt(1+theta*theta+phi*phi));
3117 Float_t chargematch = TMath::Max(double(normq/expQ),2.);
3118 //
3119 if (cl->GetType()==1 || cl->GetType()==10 ){
3120 if (chargematch<1.0 || (cl->GetNy()+cl->GetNz()<nz+ny+0.5)){
1d4090b7 3121 errz = 0.043*scale;
3122 erry = 0.00094*scale;
e43c066c 3123 return 101;
3124 }
3125 if (cl->GetNy()+cl->GetNz()<nz+ny+1.2){
1d4090b7 3126 errz = 0.06*scale;
3127 erry =0.0013*scale;
e43c066c 3128 return 102;
3129 }
1d4090b7 3130 erry = 0.0027*scale;
3131 errz = TMath::Min(0.028*(chargematch+cl->GetNy()+cl->GetNz()-nz+ny),0.15)*scale;
e43c066c 3132 return 103;
3133 }
3134 if (cl->GetType()==2 || cl->GetType()==11 ){
1d4090b7 3135 erry = TMath::Min(0.0010*(1+chargematch+cl->GetNy()+cl->GetNz()-nz+ny),0.05)*scale;
3136 errz = TMath::Min(0.025*(1+chargematch+cl->GetNy()+cl->GetNz()-nz+ny),0.5)*scale;
e43c066c 3137 return 104;
3138 }
3139
3140 if (cl->GetType()>100 ){
3141 if ((chargematch+cl->GetNy()+cl->GetNz()-nz-ny<1.5)){
1d4090b7 3142 errz = 0.05*scale;
3143 erry = 0.00096*scale;
e43c066c 3144 return 105;
3145 }
3146 if (cl->GetNy()+cl->GetNz()-nz-ny<1){
1d4090b7 3147 errz = 0.10*scale;
3148 erry = 0.0025*scale;
e43c066c 3149 return 106;
3150 }
3151
1d4090b7 3152 errz = TMath::Min(0.05*(chargematch+cl->GetNy()+cl->GetNz()-nz-ny),0.4)*scale;
3153 erry = TMath::Min(0.003*(chargematch+cl->GetNy()+cl->GetNz()-nz-ny),0.05)*scale;
e43c066c 3154 return 107;
3155 }
3156 Float_t diff = cl->GetNy()+cl->GetNz()-ny-nz;
3157 if (diff<1) diff=1;
3158 if (diff>4) diff=4;
3159
3160 if (cl->GetType()==5||cl->GetType()==6||cl->GetType()==7||cl->GetType()==8){
3161 errz = 0.14*diff;
3162 erry = 0.003*diff;
3163 return 108;
3164 }
3165 erry = 0.04*diff;
3166 errz = 0.06*diff;
3167 return 109;
3168 }
3169 //DRIFTS
3170 Float_t normq = cl->GetQ()/(TMath::Sqrt(1+theta*theta+phi*phi));
3171 Float_t chargematch = normq/expQ;
3172 Float_t factorz=1;
3173 Int_t cnz = cl->GetNz()%10;
3174 //charge match
3175 if (cl->GetType()==1){
3176 if (chargematch<1.25){
3177 erry = 0.0028*(1.+6./cl->GetQ()); // gold clusters
3178 }
3179 else{
3180 erry = 0.003*chargematch;
3181 if (cl->GetNz()==3) erry*=1.5;
3182 }
3183 if (chargematch<1.0){
3184 errz = 0.0011*(1.+6./cl->GetQ());
3185 }
3186 else{
3187 errz = 0.002*(1+2*(chargematch-1.));
3188 }
3189 if (cnz>nz+0.6) {
3190 erry*=(cnz-nz+0.5);
3191 errz*=1.4*(cnz-nz+0.5);
3192 }
3193 }
3194 if (cl->GetType()>1){
3195 if (chargematch<1){
3196 erry = 0.00385*(1.+6./cl->GetQ()); // gold clusters
3197 errz = 0.0016*(1.+6./cl->GetQ());
3198 }
3199 else{
3200 errz = 0.0014*(1+3*(chargematch-1.));
3201 erry = 0.003*(1+3*(chargematch-1.));
3202 }
3203 if (cnz>nz+0.6) {
3204 erry*=(cnz-nz+0.5);
3205 errz*=1.4*(cnz-nz+0.5);
3206 }
3207 }
3208
3209 if (TMath::Abs(cl->GetY())>2.5){
3210 factorz*=1+2*(TMath::Abs(cl->GetY())-2.5);
3211 }
3212 if (TMath::Abs(cl->GetY())<1){
3213 factorz*=1.+0.5*TMath::Abs(TMath::Abs(cl->GetY())-1.);
3214 }
3215 factorz= TMath::Min(factorz,float(4.));
3216 errz*=factorz;
3217
3218 erry= TMath::Min(erry,float(0.05));
3219 errz= TMath::Min(errz,float(0.05));
3220 return 200;
3221}
3222
3223
3224
628e7bb0 3225void AliITStrackerMI::GetDCASigma(AliITStrackMI* track, Float_t & sigmarfi, Float_t &sigmaz)
3226{
3227 //
3228 //DCA sigmas parameterization
3229 //to be paramterized using external parameters in future
3230 //
3231 //
3232 sigmarfi = 0.004+1.4 *TMath::Abs(track->fP4)+332.*track->fP4*track->fP4;
3233 sigmaz = 0.011+4.37*TMath::Abs(track->fP4);
628e7bb0 3234}
3235
3236
e43c066c 3237void AliITStrackerMI::SignDeltas( TObjArray *ClusterArray, Float_t vz)
3238{
3239 //
3240 //
3241 Int_t entries = ClusterArray->GetEntriesFast();
3242 if (entries<4) return;
3243 AliITSclusterV2* cluster = (AliITSclusterV2*)ClusterArray->At(0);
3244 Int_t layer = cluster->GetLayer();
3245 if (layer>1) return;
3246 Int_t index[10000];
3247 Int_t ncandidates=0;
3248 Float_t r = (layer>0)? 7:4;
3249 //
3250 for (Int_t i=0;i<entries;i++){
3251 AliITSclusterV2* cl0 = (AliITSclusterV2*)ClusterArray->At(i);
3252 Float_t nz = 1+TMath::Abs((cl0->GetZ()-vz)/r);
3253 if (cl0->GetNy()+cl0->GetNz()<=5+2*layer+nz) continue;
3254 index[ncandidates] = i; //candidate to belong to delta electron track
3255 ncandidates++;
3256 if (cl0->GetNy()+cl0->GetNz()>9+2*layer+nz) {
3257 cl0->SetDeltaProbability(1);
3258 }
3259 }
3260 //
3261 //
3262 //
3263 for (Int_t i=0;i<ncandidates;i++){
3264 AliITSclusterV2* cl0 = (AliITSclusterV2*)ClusterArray->At(index[i]);
3265 if (cl0->GetDeltaProbability()>0.8) continue;
3266 //
3267 Int_t ncl = 0;
3268 Float_t y[100],z[100],sumy,sumz,sumy2, sumyz, sumw;
3269 sumy=sumz=sumy2=sumyz=sumw=0.0;
3270 for (Int_t j=0;j<ncandidates;j++){
3271 if (i==j) continue;
3272 AliITSclusterV2* cl1 = (AliITSclusterV2*)ClusterArray->At(index[j]);
3273 //
3274 Float_t dz = cl0->GetZ()-cl1->GetZ();
3275 Float_t dy = cl0->GetY()-cl1->GetY();
3276 if (TMath::Sqrt(dz*dz+dy*dy)<0.2){
3277 Float_t weight = cl1->GetNy()+cl1->GetNz()-2;
3278 y[ncl] = cl1->GetY();
3279 z[ncl] = cl1->GetZ();
3280 sumy+= y[ncl]*weight;
3281 sumz+= z[ncl]*weight;
3282 sumy2+=y[ncl]*y[ncl]*weight;
3283 sumyz+=y[ncl]*z[ncl]*weight;
3284 sumw+=weight;
3285 ncl++;
3286 }
3287 }
3288 if (ncl<4) continue;
3289 Float_t det = sumw*sumy2 - sumy*sumy;
3290 Float_t delta=1000;
3291 if (TMath::Abs(det)>0.01){
3292 Float_t z0 = (sumy2*sumz - sumy*sumyz)/det;
3293 Float_t k = (sumyz*sumw - sumy*sumz)/det;
3294 delta = TMath::Abs(cl0->GetZ()-(z0+k*cl0->GetY()));
3295 }
3296 else{
3297 Float_t z0 = sumyz/sumy;
3298 delta = TMath::Abs(cl0->GetZ()-z0);
3299 }
3300 if ( delta<0.05) {
3301 cl0->SetDeltaProbability(1-20.*delta);
3302 }
3303 }
3304}
3305
3306
15dd636f 3307void AliITStrackerMI::UpdateESDtrack(AliITStrackMI* track, ULong_t flags) const
e43c066c 3308{
3309 //
3310 //
3311 track->UpdateESDtrack(flags);
15dd636f 3312 AliITStrackMI * oldtrack = (AliITStrackMI*)(track->fESDtrack->GetITStrack());
99c2ee26 3313 if (oldtrack) delete oldtrack;
15dd636f 3314 track->fESDtrack->SetITStrack(new AliITStrackMI(*track));
628e7bb0 3315 if (TMath::Abs(track->fDnorm[1])<0.000000001){
3316 printf("Problem\n");
3317 }
e43c066c 3318}
3319
3320
3321
81e97e0d 3322Int_t AliITStrackerMI::GetNearestLayer(const Double_t *xr) const{
3323 //
3324 //Get nearest upper layer close to the point xr.
3325 // rough approximation
3326 //
bf6adc12 3327 const Float_t kRadiuses[6]={4,6.5,15.03,24.,38.5,43.7};
81e97e0d 3328 Float_t radius = TMath::Sqrt(xr[0]*xr[0]+xr[1]*xr[1]);
3329 Int_t res =6;
3330 for (Int_t i=0;i<6;i++){
bf6adc12 3331 if (radius<kRadiuses[i]){
81e97e0d 3332 res =i;
3333 break;
3334 }
3335 }
3336 return res;
3337}
e43c066c 3338
51ad6848 3339
81e97e0d 3340void AliITStrackerMI::UpdateTPCV0(AliESD *event){
3341 //
3342 //try to update, or reject TPC V0s
3343 //
3344 Int_t nv0s = event->GetNumberOfV0MIs();
3345 Int_t nitstracks = fTrackHypothesys.GetEntriesFast();
51ad6848 3346
81e97e0d 3347 for (Int_t i=0;i<nv0s;i++){
3348 AliESDV0MI * vertex = event->GetV0MI(i);
3349 Int_t ip = vertex->GetIndex(0);
3350 Int_t im = vertex->GetIndex(1);
3351 //
3352 TObjArray * arrayp = (ip<nitstracks) ? (TObjArray*)fTrackHypothesys.At(ip):0;
3353 TObjArray * arraym = (im<nitstracks) ? (TObjArray*)fTrackHypothesys.At(im):0;
3354 AliITStrackMI * trackp = (arrayp!=0) ? (AliITStrackMI*)arrayp->At(0):0;
3355 AliITStrackMI * trackm = (arraym!=0) ? (AliITStrackMI*)arraym->At(0):0;
3356 //
3357 //
3358 if (trackp){
3359 if (trackp->fN+trackp->fNDeadZone>5.5){
3360 if (trackp->fConstrain&&trackp->fChi2MIP[0]<3) vertex->SetStatus(-100);
3361 if (!trackp->fConstrain&&trackp->fChi2MIP[0]<2) vertex->SetStatus(-100);
3362 }
3363 }
51ad6848 3364
81e97e0d 3365 if (trackm){
3366 if (trackm->fN+trackm->fNDeadZone>5.5){
3367 if (trackm->fConstrain&&trackm->fChi2MIP[0]<3) vertex->SetStatus(-100);
3368 if (!trackm->fConstrain&&trackm->fChi2MIP[0]<2) vertex->SetStatus(-100);
3369 }
3370 }
3371 if (vertex->GetStatus()==-100) continue;
3372 //
3373 Int_t clayer = GetNearestLayer(vertex->GetXrp());
3374 vertex->SetNBefore(clayer); //
3375 vertex->SetChi2Before(9*clayer); //
3376 vertex->SetNAfter(6-clayer); //
3377 vertex->SetChi2After(0); //
3378 //
3379 if (clayer >1 ){ // calculate chi2 before vertex
3380 Float_t chi2p = 0, chi2m=0;
3381 //
3382 if (trackp){
3383 for (Int_t ilayer=0;ilayer<clayer;ilayer++){
3384 if (trackp->fClIndex[ilayer]>0){
3385 chi2p+=trackp->fDy[ilayer]*trackp->fDy[ilayer]/(trackp->fSigmaY[ilayer]*trackp->fSigmaY[ilayer])+
3386 trackp->fDz[ilayer]*trackp->fDz[ilayer]/(trackp->fSigmaZ[ilayer]*trackp->fSigmaZ[ilayer]);
3387 }
3388 else{
3389 chi2p+=9;
3390 }
3391 }
3392 }else{
3393 chi2p = 9*clayer;
3394 }
3395 //
3396 if (trackm){
3397 for (Int_t ilayer=0;ilayer<clayer;ilayer++){
3398 if (trackm->fClIndex[ilayer]>0){
3399 chi2m+=trackm->fDy[ilayer]*trackm->fDy[ilayer]/(trackm->fSigmaY[ilayer]*trackm->fSigmaY[ilayer])+
3400 trackm->fDz[ilayer]*trackm->fDz[ilayer]/(trackm->fSigmaZ[ilayer]*trackm->fSigmaZ[ilayer]);
3401 }
3402 else{
3403 chi2m+=9;
3404 }
3405 }
3406 }else{
3407 chi2m = 9*clayer;
3408 }
3409 vertex->SetChi2Before(TMath::Min(chi2p,chi2m));
3410 if (TMath::Min(chi2p,chi2m)/Float_t(clayer)<4) vertex->SetStatus(-10); // track exist before vertex
3411 }
3412
3413 if (clayer < 5 ){ // calculate chi2 after vertex
3414 Float_t chi2p = 0, chi2m=0;
3415 //
3416 if (trackp&&TMath::Abs(trackp->fP3)<1.){
3417 for (Int_t ilayer=clayer;ilayer<6;ilayer++){
3418 if (trackp->fClIndex[ilayer]>0){
3419 chi2p+=trackp->fDy[ilayer]*trackp->fDy[ilayer]/(trackp->fSigmaY[ilayer]*trackp->fSigmaY[ilayer])+
3420 trackp->fDz[ilayer]*trackp->fDz[ilayer]/(trackp->fSigmaZ[ilayer]*trackp->fSigmaZ[ilayer]);
3421 }
3422 else{
3423 chi2p+=9;
3424 }
3425 }
3426 }else{
3427 chi2p = 0;
3428 }
3429 //
3430 if (trackm&&TMath::Abs(trackm->fP3)<1.){
3431 for (Int_t ilayer=clayer;ilayer<6;ilayer++){
3432 if (trackm->fClIndex[ilayer]>0){
3433 chi2m+=trackm->fDy[ilayer]*trackm->fDy[ilayer]/(trackm->fSigmaY[ilayer]*trackm->fSigmaY[ilayer])+
3434 trackm->fDz[ilayer]*trackm->fDz[ilayer]/(trackm->fSigmaZ[ilayer]*trackm->fSigmaZ[ilayer]);
3435 }
3436 else{
3437 chi2m+=9;
3438 }
3439 }
3440 }else{
3441 chi2m = 0;
3442 }
3443 vertex->SetChi2After(TMath::Max(chi2p,chi2m));
3444 if (TMath::Max(chi2m,chi2p)/Float_t(6-clayer)>9) vertex->SetStatus(-20); // track not found in ITS
3445 }
3446 }
3447 //
3448}
51ad6848 3449
67c1e979 3450
3451
81e97e0d 3452void AliITStrackerMI::FindV02(AliESD *event)
e43c066c 3453{
3454 //
81e97e0d 3455 // V0 finder
3456 //
3457 // Cuts on DCA - R dependent
3458 // max distance DCA between 2 tracks cut
3459 // maxDist = TMath::Min(kMaxDist,kMaxDist0+pvertex->GetRr()*kMaxDist);
3460 //
3461 const Float_t kMaxDist0 = 0.1;
3462 const Float_t kMaxDist1 = 0.1;
3463 const Float_t kMaxDist = 1;
3464 const Float_t kMinPointAngle = 0.85;
3465 const Float_t kMinPointAngle2 = 0.99;
3466 const Float_t kMinR = 0.5;
3467 const Float_t kMaxR = 220;
3468 //const Float_t kCausality0Cut = 0.19;
3469 //const Float_t kLikelihood01Cut = 0.25;
3470 //const Float_t kPointAngleCut = 0.9996;
3471 const Float_t kCausality0Cut = 0.19;
3472 const Float_t kLikelihood01Cut = 0.45;
3473 const Float_t kLikelihood1Cut = 0.5;
3474 const Float_t kCombinedCut = 0.55;
3475
3476 //
3477 //
3478 TTreeSRedirector &cstream = *fDebugStreamer;
3479 Int_t ntracks = event->GetNumberOfTracks();
3480 Int_t nitstracks = fTrackHypothesys.GetEntriesFast();
3481 fOriginal.Expand(ntracks);
3482 fTrackHypothesys.Expand(ntracks);
3483 fBestHypothesys.Expand(ntracks);
3484 //
3485 AliHelix * helixes = new AliHelix[ntracks+2];
3486 TObjArray trackarray(ntracks+2); //array with tracks - with vertex constrain
3487 TObjArray trackarrayc(ntracks+2); //array of "best tracks" - without vertex constrain
3488 TObjArray trackarrayl(ntracks+2); //array of "longest tracks" - without vertex constrain
3489 Bool_t * forbidden = new Bool_t [ntracks+2];
3490 Int_t *itsmap = new Int_t [ntracks+2];
3491 Float_t *dist = new Float_t[ntracks+2];
3492 Float_t *normdist0 = new Float_t[ntracks+2];
3493 Float_t *normdist1 = new Float_t[ntracks+2];
3494 Float_t *normdist = new Float_t[ntracks+2];
3495 Float_t *norm = new Float_t[ntracks+2];
3496 Float_t *maxr = new Float_t[ntracks+2];
3497 Float_t *minr = new Float_t[ntracks+2];
3498 Float_t *minPointAngle= new Float_t[ntracks+2];
3499 //
3500 AliESDV0MI *pvertex = new AliESDV0MI;
3501 AliITStrackMI * dummy= new AliITStrackMI;
3502 dummy->SetLabel(0);
3503 AliITStrackMI trackat0; //temporary track for DCA calculation
e43c066c 3504 //
81e97e0d 3505 Float_t primvertex[3]={GetX(),GetY(),GetZ()};
628e7bb0 3506 //
81e97e0d 3507 // make its - esd map
e43c066c 3508 //
81e97e0d 3509 for (Int_t itrack=0;itrack<ntracks+2;itrack++) {
3510 itsmap[itrack] = -1;
3511 forbidden[itrack] = kFALSE;
3512 maxr[itrack] = kMaxR;
3513 minr[itrack] = kMinR;
3514 minPointAngle[itrack] = kMinPointAngle;
3515 }
3516 for (Int_t itrack=0;itrack<nitstracks;itrack++){
3517 AliITStrackMI * original = (AliITStrackMI*)(fOriginal.At(itrack));
3518 Int_t esdindex = original->fESDtrack->GetID();
3519 itsmap[esdindex] = itrack;
3520 }
3521 //
3522 // create its tracks from esd tracks if not done before
3523 //
3524 for (Int_t itrack=0;itrack<ntracks;itrack++){
3525 if (itsmap[itrack]>=0) continue;
3526 AliITStrackMI * tpctrack = new AliITStrackMI(*(event->GetTrack(itrack)));
3527 tpctrack->fD[0] = tpctrack->GetD(GetX(),GetY());
3528 tpctrack->fD[1] = tpctrack->GetZat(GetX())-GetZ();
3529 if (tpctrack->fD[0]<20 && tpctrack->fD[1]<20){
3530 // tracks which can reach inner part of ITS
3531 // propagate track to outer its volume - with correction for material
3532 CorrectForDeadZoneMaterial(tpctrack);
3533 }
3534 itsmap[itrack] = nitstracks;
3535 fOriginal.AddAt(tpctrack,nitstracks);
3536 nitstracks++;
3537 }
3538 //
3539 // fill temporary arrays
3540 //
3541 for (Int_t itrack=0;itrack<ntracks;itrack++){
3542 AliESDtrack * esdtrack = event->GetTrack(itrack);
3543 Int_t itsindex = itsmap[itrack];
3544 AliITStrackMI *original = (AliITStrackMI*)fOriginal.At(itsmap[itrack]);
3545 if (!original) continue;
3546 AliITStrackMI *bestConst = 0;
3547 AliITStrackMI *bestLong = 0;
3548 AliITStrackMI *best = 0;
3549 //
628e7bb0 3550 //