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