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