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