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