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