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