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