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