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