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