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