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