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