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