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