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