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