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