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