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