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