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