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