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