]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/AliITSUTrackerGlo.cxx
Made reco interface to belong to AliITSUReconstruct, can be borrowed by
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUTrackerGlo.cxx
CommitLineData
32d38de2 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
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 **************************************************************************/
15
16/*
17 TO CHECK
18 GetBz usage
19
20 */
21
22//-------------------------------------------------------------------------
23// Implementation of the ITS Upgrade tracker mother class.
24//-------------------------------------------------------------------------
25#include <TTree.h>
26#include <Riostream.h>
27#include <TMath.h>
28
29#include "AliITSUTrackerGlo.h"
30#include "AliESDEvent.h"
31#include "AliESDtrack.h"
32#include "AliITSURecoDet.h"
33#include "AliITSURecoSens.h"
34#include "AliITSUReconstructor.h"
35#include "AliITSReconstructor.h"
36#include "AliITSUSeed.h"
37#include "AliITSUAux.h"
c61e50c3 38#include "AliITSUClusterPix.h"
32d38de2 39using namespace AliITSUAux;
40using namespace TMath;
41
42
e2d2481c 43
c8d1f258 44//----------------- tmp stuff -----------------
c8d1f258 45
32d38de2 46ClassImp(AliITSUTrackerGlo)
e2d2481c 47
48const Double_t AliITSUTrackerGlo::fgkToler = 1e-6;// tolerance for layer on-surface check
49
50
32d38de2 51//_________________________________________________________________________
52AliITSUTrackerGlo::AliITSUTrackerGlo(AliITSUReconstructor* rec)
53: fReconstructor(rec)
54 ,fITS(0)
0091e9f0 55 ,fCurrESDtrack(0)
32d38de2 56 ,fCurrMass(kPionMass)
716ccba7 57 ,fHypStore(100)
58 ,fCurrHyp(0)
c61e50c3 59 ,fSeedsPool("AliITSUSeed",0)
b8b59e05 60 ,fFreeSeedsID(0)
61 ,fNFreeSeeds(0)
62 ,fLastSeedID(0)
42c3d4bd 63 ,fDefTrackConds(0)
64 ,fCurrTrackCond(0)
c51c3124 65 ,fTrackPhase(-1)
8b16dbae 66 ,fClInfo(0)
32d38de2 67{
68 // Default constructor
69 if (rec) Init(rec);
70}
71
72//_________________________________________________________________________
73AliITSUTrackerGlo::~AliITSUTrackerGlo()
74{
75 // Default destructor
76 //
8b16dbae 77 delete[] fClInfo;
32d38de2 78 //
79}
80
81//_________________________________________________________________________
82void AliITSUTrackerGlo::Init(AliITSUReconstructor* rec)
83{
84 // init with external reconstructor
c61e50c3 85 //
3d4dc3e2 86 fITS = rec->GetITSInterface();
8b16dbae 87 int nLr = fITS->GetNLayersActive();
88 fClInfo = new Int_t[nLr<<1];
c61e50c3 89 //
90 fSeedsPool.ExpandCreateFast(1000); // RS TOCHECK
b8b59e05 91 fFreeSeedsID.Set(1000);
c61e50c3 92 //
32d38de2 93}
94
42c3d4bd 95//_________________________________________________________________________
96void AliITSUTrackerGlo::CreateDefaultTrackCond()
97{
98 // creates default tracking conditions to be used when recoparam does not provide them
99 int nLr = fITS->GetNLayersActive();
100 fClInfo = new Int_t[nLr<<1];
101 //
102 AliITSUTrackCond* cond = new AliITSUTrackCond();
103 //
104 cond->SetNLayers(fITS->GetNLayersActive());
105 cond->AddNewCondition(nLr);
106 cond->AddGroupPattern( 0xffff ); // require all layers hit
107 //
108 fDefTrackConds.AddLast(cond);
109 //
110 AliInfo("Created conditions: ");
111 for (int i=0;i<fDefTrackConds.GetEntriesFast();i++) fDefTrackConds[i]->Print();
112 //
113}
114
115
32d38de2 116//_________________________________________________________________________
117Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
118{
119 //
42c3d4bd 120 TObjArray *trackConds = 0;
32d38de2 121 //
e7d83d38 122 SetTrackingPhase(kClus2Tracks);
b8b59e05 123 ResetSeedsPool();
716ccba7 124 int nTrESD = esdEv->GetNumberOfTracks();
c51c3124 125 AliInfo(Form("Will try to find prolongations for %d tracks",nTrESD));
126 AliITSUReconstructor::GetRecoParam()->Print();
716ccba7 127 fHypStore.Delete();
128 if (fHypStore.GetSize()<nTrESD) fHypStore.Expand(nTrESD+100);
129 //
32d38de2 130 fITS->ProcessClusters();
716ccba7 131 //
42c3d4bd 132 int nTrackCond = AliITSUReconstructor::GetRecoParam()->GetNTrackingConditions();
133 if (nTrackCond<1) {
134 if (!fDefTrackConds.GetEntriesFast()) {
135 AliInfo("No tracking conditions found in recoparams, creating default one requesting all layers hit");
136 CreateDefaultTrackCond();
137 }
138 trackConds = &fDefTrackConds;
139 nTrackCond = trackConds->GetEntriesFast();
140 }
141 else trackConds = AliITSUReconstructor::GetRecoParam()->GetTrackingConditions();
142 //
143 for (int icnd=0;icnd<nTrackCond;icnd++) {
144 fCurrTrackCond = (AliITSUTrackCond*)trackConds->UncheckedAt(icnd);
145 // select ESD tracks to propagate
146 for (int itr=0;itr<nTrESD;itr++) {
147 AliESDtrack *esdTr = esdEv->GetTrack(itr);
148 AliInfo(Form("Processing track %d | MCLabel: %d",itr,esdTr->GetTPCLabel()));
149 if (!NeedToProlong(esdTr)) continue; // are we interested in this track?
150 FindTrack(esdTr, itr);
151 }
152 //
153 AliInfo(Form("SeedsPool: %d, BookedUpTo: %d, free: %d",fSeedsPool.GetSize(),fSeedsPool.GetEntriesFast(),fNFreeSeeds));
154 fHypStore.Print();
155 FinalizeHypotheses();
156 }
716ccba7 157 //
32d38de2 158 return 0;
159}
160
161//_________________________________________________________________________
c51c3124 162Int_t AliITSUTrackerGlo::PropagateBack(AliESDEvent *esdEv)
32d38de2 163{
164 //
c51c3124 165 // Do outward fits in ITS
166 //
e7d83d38 167 SetTrackingPhase(kPropBack);
c51c3124 168 int nTrESD = esdEv->GetNumberOfTracks();
e7d83d38 169 AliInfo(Form("Will propagate back %d tracks",nTrESD));
c51c3124 170 //
171 double bz0 = GetBz();
172 Double_t xyzTrk[3],xyzVtx[3]={GetX(),GetY(),GetZ()};
173 AliITSUTrackHyp dummyTr,*currTr=0;
174 const double kWatchStep=10.; // for larger steps watch arc vs segment difference
175 Double_t times[AliPID::kSPECIES];
176 //
177 //
178 for (int itr=0;itr<nTrESD;itr++) {
179 AliESDtrack *esdTr = esdEv->GetTrack(itr);
180 // Start time integral and add distance from current position to vertex
181 if (esdTr->IsOn(AliESDtrack::kITSout)) continue; // already done
182 //
183 esdTr->GetXYZ(xyzTrk);
184 Double_t dst = 0.; // set initial track lenght, tof
185 {
186 double dxs = xyzTrk[0] - xyzVtx[0];
187 double dys = xyzTrk[1] - xyzVtx[1];
188 double dzs = xyzTrk[2] - xyzVtx[2];
189 // RS: for large segment steps d use approximation of cicrular arc s by
190 // s = 2R*asin(d/2R) = d/p asin(p) \approx d/p (p + 1/6 p^3) = d (1+1/6 p^2)
191 // where R is the track radius, p = d/2R = 2C*d (C is the abs curvature)
192 // Hence s^2/d^2 = (1+1/6 p^2)^2
193 dst = dxs*dxs + dys*dys;
194 if (dst > kWatchStep*kWatchStep) { // correct circular part for arc/segment factor
195 double crv = Abs(esdTr->GetC(bz0));
196 double fcarc = 1.+crv*crv*dst/6.;
197 dst *= fcarc*fcarc;
198 }
199 dst += dzs*dzs;
200 dst = Sqrt(dst);
201 }
202 //
203 esdTr->SetStatus(AliESDtrack::kTIME);
204 //
205 if (!esdTr->IsOn(AliESDtrack::kITSin)) { // case of tracks w/o ITS prolongation: just set the time integration
e2d2481c 206 dummyTr.AliExternalTrackParam::operator=(*esdTr);
c51c3124 207 dummyTr.StartTimeIntegral();
e2d2481c 208 dummyTr.AddTimeStep(dst);
c51c3124 209 dummyTr.GetIntegratedTimes(times);
210 esdTr->SetIntegratedTimes(times);
211 esdTr->SetIntegratedLength(dummyTr.GetIntegratedLength());
212 continue;
213 }
214 //
215 currTr = GetTrackHyp(itr);
216 currTr->StartTimeIntegral();
217 currTr->AddTimeStep(dst);
e2d2481c 218 printf("Before resetCov: "); currTr->AliExternalTrackParam::Print();
219 currTr->ResetCovariance(10000);
68a0f687 220 if (RefitTrack(currTr,fITS->GetRMax())) { // propagate to exit from the ITS/TPC screen
221 UpdateESDTrack(currTr,AliESDtrack::kITSout);
222 }
e7d83d38 223 else {
224 AliInfo(Form("Refit Failed for track %d",itr));
225 }
c51c3124 226 //
227 }
32d38de2 228 //
32d38de2 229 return 0;
230}
231
232//_________________________________________________________________________
e7d83d38 233Int_t AliITSUTrackerGlo::RefitInward(AliESDEvent *esdEv)
32d38de2 234{
235 //
e7d83d38 236 // refit the tracks inward, using current cov.matrix
237 //
238 SetTrackingPhase(kRefitInw);
239 Int_t nTrESD = esdEv->GetNumberOfTracks();
240 AliInfo(Form("Will refit inward %d tracks",nTrESD));
241 AliITSUTrackHyp *currTr=0;
242 //
243 for (int itr=0;itr<nTrESD;itr++) {
244 AliESDtrack *esdTr = esdEv->GetTrack(itr);
245 // Start time integral and add distance from current position to vertex
246 UInt_t trStat = esdTr->GetStatus();
247 if ( !(trStat & AliESDtrack::kITSout) ) continue;
248 if ( trStat & AliESDtrack::kITSrefit ) continue; // already done
249 if ( (trStat & AliESDtrack::kTPCout) && !(trStat & AliESDtrack::kTPCrefit) ) continue;
250 //
251 currTr = GetTrackHyp(itr);
252 currTr->AliExternalTrackParam::operator=(*esdTr); // fetch current ESDtrack kinematics
253 if (RefitTrack(currTr,fITS->GetRMin())) { // propagate up to inside radius of the beam pipe
254 UpdateESDTrack(currTr,AliESDtrack::kITSrefit);
255 }
256 else {
257 AliInfo(Form("Refit Failed for track %d",itr));
258 }
259 }
32d38de2 260 //
32d38de2 261 return 0;
262}
263
264//_________________________________________________________________________
265Int_t AliITSUTrackerGlo::LoadClusters(TTree * treeRP)
266{
267 // read from tree (if pointer provided) or directly from the ITS reco interface
268 //
269 return fReconstructor->LoadClusters(treeRP);
270}
271
272//_________________________________________________________________________
273void AliITSUTrackerGlo::UnloadClusters()
274{
275 //
276 // To be implemented
277 //
278
279 Info("UnloadClusters","To be implemented");
280}
281//_________________________________________________________________________
282AliCluster * AliITSUTrackerGlo::GetCluster(Int_t /*index*/) const
283{
284 //
285 // To be implemented
286 //
287
288 Info("GetCluster","To be implemented");
289 return 0x0;
290}
291
292//_________________________________________________________________________
293Bool_t AliITSUTrackerGlo::NeedToProlong(AliESDtrack* esdTr)
294{
295 // do we need to match this track to ITS?
296 //
297 static double bz = GetBz();
298 if (!esdTr->IsOn(AliESDtrack::kTPCin) ||
299 esdTr->IsOn(AliESDtrack::kTPCout) ||
300 esdTr->IsOn(AliESDtrack::kITSin) ||
301 esdTr->GetKinkIndex(0)>0) return kFALSE;
302 //
c61e50c3 303 if (esdTr->Pt()<AliITSUReconstructor::GetRecoParam()->GetMinPtForProlongation()) return kFALSE;
32d38de2 304 //
305 float dtz[2];
306 esdTr->GetDZ(GetX(),GetY(),GetZ(),bz,dtz);
307 // if track is not V0 candidata but has large offset wrt IP, reject it. RS TOCHECK
c61e50c3 308 if ( !(esdTr->GetV0Index(0)>0 && dtz[0]>AliITSUReconstructor::GetRecoParam()->GetMaxDforV0dghtrForProlongation())
309 && (Abs(dtz[0])>AliITSUReconstructor::GetRecoParam()->GetMaxDForProlongation() ||
310 Abs(dtz[1])>AliITSUReconstructor::GetRecoParam()->GetMaxDZForProlongation())) return kFALSE;
32d38de2 311 //
312 return kTRUE;
313}
314
315//_________________________________________________________________________
716ccba7 316void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr, Int_t esdID)
32d38de2 317{
318 // find prolongaion candidates finding for single seed
319 //
3e4e3c23 320 AliITSUSeed seedUC; // copy of the seed from the upper layer
321 AliITSUSeed seedT; // transient seed between the seedUC and new prolongation hypothesis
322 //
3e4e3c23 323 if (!InitHypothesis(esdTr,esdID)) return; // initialize prolongations hypotheses tree
32d38de2 324 //
173b3073 325 AliITSURecoSens *hitSens[AliITSURecoSens::kNNeighbors+1];
f8832015 326 //
c61e50c3 327 TObjArray clArr; // container for transfer of clusters matching to seed
32d38de2 328 //
3e4e3c23 329 int nLrActive = fITS->GetNLayersActive();
330 for (int ila=nLrActive;ila--;) {
32d38de2 331 int ilaUp = ila+1; // prolong seeds from layer above
3e4e3c23 332 //
333 // for the outermost layer the seed is created from the ESD track
334 int nSeedsUp = (ilaUp==nLrActive) ? 1 : fCurrHyp->GetNSeeds(ilaUp);
335 //
32d38de2 336 for (int isd=0;isd<nSeedsUp;isd++) {
3e4e3c23 337 AliITSUSeed* seedU;
338 if (ilaUp==nLrActive) {
339 seedU = 0;
340 seedUC.InitFromESDTrack(esdTr);
341 }
342 else {
343 seedU = fCurrHyp->GetSeed(ilaUp,isd); // seed on prev.active layer to prolong
344 seedUC = *seedU; // its copy will be prolonged
b8b59e05 345 seedUC.SetParent(seedU);
3e4e3c23 346 }
943e1898 347 seedUC.ResetFMatrix(); // reset the matrix for propagation to next layer
32d38de2 348 // go till next active layer
c8d1f258 349 AliInfo(Form("working on Lr:%d Seed:%d of %d",ila,isd,nSeedsUp));
f8832015 350 if (!TransportToLayer(&seedUC, fITS->GetLrIDActive(ilaUp), fITS->GetLrIDActive(ila)) ) {
32d38de2 351 //
0091e9f0 352 AliInfo("Transport failed");
32d38de2 353 // Check if the seed satisfies to track definition
b8b59e05 354 if (NeedToKill(&seedUC,kTransportFailed) && seedU) KillSeed(seedU,kTRUE);
32d38de2 355 continue; // RS TODO: decide what to do with tracks stopped on higher layers w/o killing
356 }
357 AliITSURecoLayer* lrA = fITS->GetLayerActive(ila);
f8832015 358 if (!GetRoadWidth(&seedUC, ila)) { // failed to find road width on the layer
b8b59e05 359 if (NeedToKill(&seedUC,kRWCheckFailed) && seedU) KillSeed(seedU,kTRUE);
32d38de2 360 continue;
361 }
173b3073 362 int nsens = lrA->FindSensors(&fTrImpData[kTrPhi0], hitSens); // find detectors which may be hit by the track
0091e9f0 363 AliInfo(Form("Will check %d sensors on lr:%d ",nsens,ila));
32d38de2 364 //
943e1898 365 double bz = GetBz();
32d38de2 366 for (int isn=nsens;isn--;) {
f8832015 367 seedT = seedUC;
c61e50c3 368 AliITSURecoSens* sens = hitSens[isn];
f8832015 369 //
943e1898 370 // We need to propagate the seed to sensor on lrA staying the frame of the sensor from prev.layer,
371 // since the transport matrix should be defined in this frame.
372 double xs; // X in the TF of current seed, corresponding to intersection with sensor plane
373 if (!seedT.GetTrackingXAtXAlpha(sens->GetXTF(),sens->GetPhiTF(),bz, xs)) continue;
8b16dbae 374 if (!PropagateSeed(&seedT,xs,fCurrMass)) continue;
375 // if (!seedT.PropagateToX(xs,bz)) continue;
716ccba7 376 // if (!seedT.Rotate(sens->GetPhiTF())) continue;
377 if (!seedT.RotateToAlpha(sens->GetPhiTF())) continue;
943e1898 378 //
f8832015 379 int clID0 = sens->GetFirstClusterId();
c61e50c3 380 for (int icl=sens->GetNClusters();icl--;) {
f8832015 381 int res = CheckCluster(&seedT,ila,clID0+icl);
382 //
383 if (res==kStopSearchOnSensor) break; // stop looking on this sensor
384 if (res==kClusterNotMatching) continue; // cluster does not match
385 // cluster is matching and it was added to the hypotheses tree
c61e50c3 386 }
32d38de2 387 }
f8832015 388 // cluster search is done. Do we need ta have a version of this seed skipping current layer
389 seedT.SetLr(ila);
716ccba7 390 if (!NeedToKill(&seedT,kMissingCluster)) {
391 AliITSUSeed* seedSkp = NewSeedFromPool(&seedT);
392 double penalty = -AliITSUReconstructor::GetRecoParam()->GetMissPenalty(ila);
393 // to do: make penalty to account for probability to miss the cluster for good reason
394 seedSkp->SetChi2Cl(penalty);
395 AddProlongationHypothesis(seedSkp,ila);
396 }
32d38de2 397 }
716ccba7 398 ((TObjArray*)fCurrHyp->GetLayerSeeds(ila))->Sort();
c8d1f258 399 printf(">>> All hypotheses on lr %d: \n",ila);
716ccba7 400 for (int ih=0;ih<fCurrHyp->GetNSeeds(ila);ih++) {
401 printf(" #%3d ",ih); fCurrHyp->GetSeed(ila,ih)->Print();
402 //
403 /*
404 if (ila!=0) continue;
405 double vecL[5] = {0};
406 double matL[15] = {0};
407 AliITSUSeed* sp = fCurrHyp->GetSeed(ila,ih);
408 while(sp->GetParent()) {
409 sp->Smooth(vecL,matL);
410 if (sp->GetLayerID()>=fITS->GetNLayersActive()-1) break;
411 sp = (AliITSUSeed*)sp->GetParent();
412 }
413 */
c8d1f258 414 }
32d38de2 415 }
416 //
716ccba7 417 SaveCurrentTrackHypotheses();
418 //
32d38de2 419}
420
421//_________________________________________________________________________
3e4e3c23 422Bool_t AliITSUTrackerGlo::InitHypothesis(AliESDtrack *esdTr, Int_t esdID)
32d38de2 423{
c61e50c3 424 // init prolongaion candidates finding for single seed
716ccba7 425 fCurrHyp = GetTrackHyp(esdID);
426 if (fCurrHyp) return kTRUE;
427 //
32d38de2 428 fCurrMass = esdTr->GetMass();
0091e9f0 429 fCurrESDtrack = esdTr;
32d38de2 430 if (fCurrMass<kPionMass*0.9) fCurrMass = kPionMass; // don't trust to mu, e identification from TPCin
c61e50c3 431 //
3e4e3c23 432 fCurrHyp = new AliITSUTrackHyp(fITS->GetNLayersActive());
433 fCurrHyp->SetESDTrack(esdTr);
716ccba7 434 fCurrHyp->SetUniqueID(esdID);
c51c3124 435 fCurrHyp->SetMass(fCurrMass);
716ccba7 436 SetTrackHyp(fCurrHyp,esdID);
3e4e3c23 437 //
32d38de2 438 return kTRUE;
439 // TO DO
440}
441
442//_________________________________________________________________________
443Bool_t AliITSUTrackerGlo::TransportToLayer(AliITSUSeed* seed, Int_t lFrom, Int_t lTo)
444{
445 // transport seed from layerFrom to the entrance of layerTo
446 //
8b16dbae 447 //
448 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
449 //
32d38de2 450 int dir = lTo > lFrom ? 1:-1;
451 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
452 Bool_t checkFirst = kTRUE;
453 while(lFrom!=lTo) {
32d38de2 454 if (lrFr) {
e2d2481c 455 if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
456 checkFirst = kFALSE;
32d38de2 457 }
458 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
459 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
460 //
461 // go the entrance of the layer, assuming no materials in between
8b16dbae 462 double xToGo = lrTo->GetR(-dir);
dde91d5d 463 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
44785f3e 464 if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) return kFALSE;
32d38de2 465 lrFr = lrTo;
466 }
467 return kTRUE;
468 //
469}
470
3e4e3c23 471//_________________________________________________________________________
472Bool_t AliITSUTrackerGlo::TransportToLayer(AliExternalTrackParam* seed, Int_t lFrom, Int_t lTo)
473{
474 // transport track from layerFrom to the entrance of layerTo
475 //
8b16dbae 476 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
477 //
3e4e3c23 478 int dir = lTo > lFrom ? 1:-1;
479 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
480 Bool_t checkFirst = kTRUE;
481 while(lFrom!=lTo) {
3e4e3c23 482 if (lrFr) {
e2d2481c 483 if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
484 checkFirst = kFALSE;
3e4e3c23 485 }
486 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
487 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
488 //
e2d2481c 489 if (!GoToExitFromLayer(seed,lrTo,dir)) return kFALSE; // go the entrance of the layer, assuming no materials in between
3e4e3c23 490 lrFr = lrTo;
491 }
492 return kTRUE;
493 //
494}
495
e2d2481c 496//_________________________________________________________________________
497Bool_t AliITSUTrackerGlo::GoToExitFromLayer(AliITSUSeed* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
498{
499 // go to the exit from lr in direction dir, applying material corrections in steps specific for this layer
500 // If check is requested, do this only provided the track has not exited the layer already
501 double xToGo = lr->GetR(dir);
502 if (check) { // do we need to track till the surface of the current layer ?
503 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
e7d83d38 504 // AliInfo(Form(" dir:%d Cur: %e Tgt: %e",dir,Sqrt(curR2),xToGo));
e2d2481c 505 if (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // on the surface or outside of the layer
506 else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // on the surface or outside of the layer
507 }
508 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
509 // go via layer to its boundary, applying material correction.
510 if (!PropagateSeed(seed,xToGo,fCurrMass, lr->GetMaxStep())) return kFALSE;
e7d83d38 511 //
e2d2481c 512 return kTRUE;
513 //
514}
515
516//_________________________________________________________________________
517Bool_t AliITSUTrackerGlo::GoToExitFromLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
518{
519 // go to the exit from lr in direction dir, applying material corrections in steps specific for this layer
520 // If check is requested, do this only provided the track has not exited the layer already
521 double xToGo = lr->GetR(dir);
522 if (check) { // do we need to track till the surface of the current layer ?
523 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
524 if (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // on the surface or outside of the layer
525 else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // on the surface or outside of the layer
526 }
527 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
528 // go via layer to its boundary, applying material correction.
529 if (!PropagateSeed(seed,xToGo,fCurrMass, lr->GetMaxStep())) return kFALSE;
e7d83d38 530 //
e2d2481c 531 return kTRUE;
532 //
533}
534
535
536//_________________________________________________________________________
537Bool_t AliITSUTrackerGlo::GoToEntranceToLayer(AliITSUSeed* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
538{
539 // go to the entrance of lr in direction dir, w/o applying material corrections.
540 // If check is requested, do this only provided the track did not reach the layer already
541 double xToGo = lr->GetR(-dir);
542 if (check) { // do we need to track till the surface of the current layer ?
543 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
544 if (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // already passed
545 else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // already passed
546 }
547 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
548 // go via layer to its boundary, applying material correction.
549 if (!PropagateSeed(seed,xToGo,fCurrMass, 100, kFALSE)) return kFALSE;
550 return kTRUE;
551 //
552}
553
554//_________________________________________________________________________
555Bool_t AliITSUTrackerGlo::GoToEntranceToLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
556{
557 // go to the entrance of lr in direction dir, w/o applying material corrections.
558 // If check is requested, do this only provided the track did not reach the layer already
559 double xToGo = lr->GetR(-dir);
560 if (check) { // do we need to track till the surface of the current layer ?
561 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
562 if (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // already passed
563 else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // already passed
564 }
565 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
566 // go via layer to its boundary, applying material correction.
567 if (!PropagateSeed(seed,xToGo,fCurrMass, 100, kFALSE)) return kFALSE;
568 return kTRUE;
569 //
570}
571
32d38de2 572//_________________________________________________________________________
c61e50c3 573Bool_t AliITSUTrackerGlo::GetRoadWidth(AliITSUSeed* seed, int ilrA)
32d38de2 574{
575 // calculate road width in terms of phi and z for the track which MUST be on the external radius of the layer
576 // as well as some aux info
577 double bz = GetBz();
578 AliITSURecoLayer* lrA = fITS->GetLayerActive(ilrA);
c61e50c3 579 seed->GetXYZ(&fTrImpData[kTrXIn]); // lab position at the entrance from above
943e1898 580 static AliExternalTrackParam sc; // seed copy for manipalitions
581 sc = *seed;
32d38de2 582 //
c61e50c3 583 fTrImpData[kTrPhiIn] = ATan2(fTrImpData[kTrYIn],fTrImpData[kTrXIn]);
943e1898 584 if (!sc.Rotate(fTrImpData[kTrPhiIn])) return kFALSE; // go to the frame of the entry point into the layer
c61e50c3 585 double dr = lrA->GetDR(); // approximate X dist at the inner radius
943e1898 586 if (!sc.GetXYZAt(sc.GetX()-dr, bz, fTrImpData + kTrXOut)) {
32d38de2 587 // special case: track does not reach inner radius, might be tangential
943e1898 588 double r = sc.GetD(0,0,bz);
32d38de2 589 double x;
943e1898 590 if (!sc.GetXatLabR(r,x,bz,-1)) {
591 sc.Print();
592 AliFatal(Form("This should not happen: r=%f",r));
32d38de2 593 }
943e1898 594 dr = Abs(sc.GetX() - x);
595 if (!sc.GetXYZAt(x, bz, fTrImpData + kTrXOut)) {
596 sc.Print();
597 AliFatal(Form("This should not happen: x=%f",x));
32d38de2 598 }
599 }
600 //
c61e50c3 601 fTrImpData[kTrPhiOut] = ATan2(fTrImpData[kTrYOut],fTrImpData[kTrXOut]);
943e1898 602 double sgy = sc.GetSigmaY2() + dr*dr*sc.GetSigmaSnp2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(ilrA);
603 double sgz = sc.GetSigmaZ2() + dr*dr*sc.GetSigmaTgl2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(ilrA);
c61e50c3 604 sgy = Sqrt(sgy)*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY();
605 sgz = Sqrt(sgz)*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ();
606 fTrImpData[kTrPhi0] = 0.5*(fTrImpData[kTrPhiOut]+fTrImpData[kTrPhiIn]);
173b3073 607 fTrImpData[kTrZ0] = 0.5*(fTrImpData[kTrZOut]+fTrImpData[kTrZIn]);
c61e50c3 608 fTrImpData[kTrDPhi] = 0.5*Abs(fTrImpData[kTrPhiOut]-fTrImpData[kTrPhiIn]) + sgy/lrA->GetR();
173b3073 609 fTrImpData[kTrDZ] = 0.5*Abs(fTrImpData[kTrZOut]-fTrImpData[kTrZIn]) + sgz;
32d38de2 610 //
611 return kTRUE;
612}
613
b8b59e05 614//________________________________________
615void AliITSUTrackerGlo::ResetSeedsPool()
616{
617 // mark all seeds in the pool as unused
618 AliInfo(Form("CurrentSize: %d, BookedUpTo: %d, free: %d",fSeedsPool.GetSize(),fSeedsPool.GetEntriesFast(),fNFreeSeeds));
619 fNFreeSeeds = 0;
620 fSeedsPool.Clear(); // seeds don't allocate memory
621}
622
623
624//________________________________________
625void AliITSUTrackerGlo::MarkSeedFree(AliITSUSeed *sd)
32d38de2 626{
b8b59e05 627 // account that this seed is "deleted"
628 int id = sd->GetPoolID();
629 if (id<0) {
630 AliError(Form("Freeing of seed %p NOT from the pool is requested",sd));
631 return;
632 }
633 // AliInfo(Form("%d %p",id, seed));
634 fSeedsPool.RemoveAt(id);
635 if (fFreeSeedsID.GetSize()<=fNFreeSeeds) fFreeSeedsID.Set( 2*fNFreeSeeds + 100 );
636 fFreeSeedsID.GetArray()[fNFreeSeeds++] = id;
32d38de2 637}
f8832015 638
639//_________________________________________________________________________
640Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
641{
642 // Check if the cluster (in tracking frame!) is matching to track.
643 // The track must be already propagated to sensor tracking frame.
644 // Returns: kStopSearchOnSensor if the search on given sensor should be stopped,
645 // kClusterMatching if the cluster is matching
646 // kClusterMatching otherwise
647 //
f8832015 648 const double kTolerX = 5e-4;
649 AliCluster *cl = fITS->GetLayerActive(lr)->GetCluster(clID);
650 //
c8d1f258 651 Bool_t goodCl = kFALSE;
716ccba7 652 int currLabel = Abs(fCurrESDtrack->GetTPCLabel());
653 //
8b16dbae 654 if (cl->GetLabel(0)>=0) {
655 for (int i=0;i<3;i++) if (cl->GetLabel(i)>=0 && cl->GetLabel(i)==currLabel) {goodCl = kTRUE; break;}
656 }
716ccba7 657 else goodCl = kTRUE;
c8d1f258 658 //
f8832015 659 if (TMath::Abs(cl->GetX())>kTolerX) { // if due to the misalingment X is large, propagate track only
c8d1f258 660 if (!track->PropagateParamOnlyTo(track->GetX()+cl->GetX(),GetBz())) {
3dd9c283 661 if (goodCl) {printf("Loose good cl: Failed propagation. |"); cl->Print();}
c8d1f258 662 return kStopSearchOnSensor; // propagation failed, seedT is intact
663 }
f8832015 664 }
3dd9c283 665 double dy = cl->GetY()-track->GetY();
c8d1f258 666 double dz = cl->GetZ()-track->GetZ();
0091e9f0 667 //
f8832015 668 double dy2 = dy*dy;
669 double tol2 = (track->GetSigmaY2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(lr))*
670 AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY()*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY(); // RS TOOPTIMIZE
671 if (dy2>tol2) { // the clusters are sorted in Z(col) then in Y(row).
3dd9c283 672 if (goodCl) {printf("Loose good cl: dy2=%e > tol2=%e |",dy2,tol2); cl->Print();}
f8832015 673 if (dy>0) return kStopSearchOnSensor; // No chance that other cluster of this sensor will match (all Y's will be even larger)
674 else return kClusterNotMatching; // Other clusters may match
675 }
c8d1f258 676 double dz2 = dz*dz;
f8832015 677 tol2 = (track->GetSigmaZ2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(lr))*
678 AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ()*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ(); // RS TOOPTIMIZE
c8d1f258 679 if (dz2>tol2) {
3dd9c283 680 if (goodCl) {printf("Loose good cl: dz2=%e > tol2=%e |",dz2,tol2); cl->Print();}
c8d1f258 681 return kClusterNotMatching; // Other clusters may match
682 }
f8832015 683 //
684 // check chi2
685 Double_t p[2]={cl->GetY(), cl->GetZ()};
686 Double_t cov[3]={cl->GetSigmaY2(), cl->GetSigmaYZ(), cl->GetSigmaZ2()};
687 double chi2 = track->GetPredictedChi2(p,cov);
c8d1f258 688 if (chi2>AliITSUReconstructor::GetRecoParam()->GetMaxTr2ClChi2(lr)) {
3dd9c283 689 if (goodCl) {
716ccba7 690 printf("Loose good cl: Chi2=%e > Chi2Max=%e |dy: %+.3e dz: %+.3e\n",
691 chi2,AliITSUReconstructor::GetRecoParam()->GetMaxTr2ClChi2(lr),dy,dz);
3dd9c283 692 track->Print("etp");
693 cl->Print("");
694 }
c8d1f258 695 return kClusterNotMatching;
696 }
f8832015 697 //
698 track = NewSeedFromPool(track); // input track will be reused, use its clone for updates
943e1898 699 if (!track->Update()) {
3dd9c283 700 if (goodCl) {printf("Loose good cl: Failed update |"); cl->Print();}
b8b59e05 701 MarkSeedFree(track);
c8d1f258 702 return kClusterNotMatching;
703 }
f8832015 704 track->SetChi2Cl(chi2);
705 track->SetLrClusterID(lr,clID);
706 cl->IncreaseClusterUsage();
707 //
716ccba7 708 track->SetFake(!goodCl);
709 //
710 AliInfo(Form("AddCl(%d) Cl%d lr:%d: dY:%+8.4f dZ:%+8.4f (MC: %5d %5d %5d) |Chi2=%f(%c)",
711 goodCl,clID,lr,dy,dz2,cl->GetLabel(0),cl->GetLabel(1),cl->GetLabel(2), chi2, track->IsFake() ? '-':'+'));
c8d1f258 712 //
f8832015 713 AddProlongationHypothesis(track,lr);
714 //
715 return kClusterMatching;
716}
c8d1f258 717
718//_________________________________________________________________________
719Bool_t AliITSUTrackerGlo::NeedToKill(AliITSUSeed *seed, Int_t flag)
720{
721 // check if the seed should not be discarded
722 const UShort_t kMask = 0xffff;
723 if (flag==kMissingCluster) {
724 int lastChecked = seed->GetLayerID();
725 UShort_t patt = seed->GetHitsPattern();
726 if (lastChecked) patt |= ~(kMask<<lastChecked); // not all layers were checked, complete unchecked once by potential hits
42c3d4bd 727 Bool_t seedOK = fCurrTrackCond->CheckPattern(patt);
c8d1f258 728 return !seedOK;
729 }
730 return kTRUE;
731}
44785f3e 732
733//______________________________________________________________________________
734Bool_t AliITSUTrackerGlo::PropagateSeed(AliITSUSeed *seed, Double_t xToGo, Double_t mass, Double_t maxStep, Bool_t matCorr)
735{
736 // propagate seed to given x applying material correction if requested
737 const Double_t kEpsilon = 1e-5;
738 Double_t xpos = seed->GetX();
739 Int_t dir = (xpos<xToGo) ? 1:-1;
740 Double_t xyz0[3],xyz1[3],param[7];
741 //
8b16dbae 742 Bool_t updTime = dir>0 && seed->IsStartedTimeIntegral();
f497470c 743 if (matCorr || updTime) seed->GetXYZ(xyz1); //starting global position
44785f3e 744 while ( (xToGo-xpos)*dir > kEpsilon){
745 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
746 Double_t x = xpos+step;
747 Double_t bz=GetBz(); // getting the local Bz
748 if (!seed->PropagateToX(x,bz)) return kFALSE;
8b16dbae 749 double ds = 0;
750 if (matCorr || updTime) {
44785f3e 751 xyz0[0]=xyz1[0]; // global pos at the beginning of step
752 xyz0[1]=xyz1[1];
753 xyz0[2]=xyz1[2];
754 seed->GetXYZ(xyz1); // // global pos at the end of step
8b16dbae 755 if (matCorr) {
756 MeanMaterialBudget(xyz0,xyz1,param);
757 Double_t xrho=param[0]*param[4], xx0=param[1];
758 if (dir>0) xrho = -xrho; // outward should be negative
759 if (!seed->ApplyMaterialCorrection(xx0,xrho,mass,kFALSE)) return kFALSE;
760 ds = param[4];
761 }
762 else { // matCorr is not requested but time integral is
763 double d0 = xyz1[0]-xyz0[0];
764 double d1 = xyz1[1]-xyz0[1];
765 double d2 = xyz1[2]-xyz0[2];
766 ds = TMath::Sqrt(d0*d0+d1*d1+d2*d2);
767 }
44785f3e 768 }
8b16dbae 769 if (updTime) seed->AddTimeStep(ds);
44785f3e 770 xpos = seed->GetX();
771 }
772 return kTRUE;
773}
716ccba7 774
3e4e3c23 775//______________________________________________________________________________
776Bool_t AliITSUTrackerGlo::PropagateSeed(AliExternalTrackParam *seed, Double_t xToGo, Double_t mass, Double_t maxStep, Bool_t matCorr)
777{
778 // propagate seed to given x applying material correction if requested
779 const Double_t kEpsilon = 1e-5;
780 Double_t xpos = seed->GetX();
781 Int_t dir = (xpos<xToGo) ? 1:-1;
782 Double_t xyz0[3],xyz1[3],param[7];
783 //
784 Bool_t updTime = dir>0 && seed->IsStartedTimeIntegral();
785 if (matCorr || updTime) seed->GetXYZ(xyz1); //starting global position
786 while ( (xToGo-xpos)*dir > kEpsilon){
787 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
788 Double_t x = xpos+step;
789 Double_t bz=GetBz(); // getting the local Bz
790 if (!seed->PropagateTo(x,bz)) return kFALSE;
791 double ds = 0;
792 if (matCorr || updTime) {
793 xyz0[0]=xyz1[0]; // global pos at the beginning of step
794 xyz0[1]=xyz1[1];
795 xyz0[2]=xyz1[2];
796 seed->GetXYZ(xyz1); // // global pos at the end of step
797 //
798 if (matCorr) {
799 MeanMaterialBudget(xyz0,xyz1,param);
800 Double_t xrho=param[0]*param[4], xx0=param[1];
801 if (dir>0) xrho = -xrho; // outward should be negative
802 if (!seed->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
803 ds = param[4];
804 }
805 else { // matCorr is not requested but time integral is
806 double d0 = xyz1[0]-xyz0[0];
807 double d1 = xyz1[1]-xyz0[1];
808 double d2 = xyz1[2]-xyz0[2];
809 ds = TMath::Sqrt(d0*d0+d1*d1+d2*d2);
810 }
811 }
812 if (updTime) seed->AddTimeStep(ds);
813 //
814 xpos = seed->GetX();
815 }
816 return kTRUE;
817}
818
716ccba7 819//______________________________________________________________________________
820void AliITSUTrackerGlo::SaveCurrentTrackHypotheses()
821{
822 // RS: shall we clean up killed seeds?
823 fCurrHyp = 0;
824 // TODO
825
826}
3e4e3c23 827
828//______________________________________________________________________________
829void AliITSUTrackerGlo::FinalizeHypotheses()
830{
831 // select winner for each hypothesis, remove cl. sharing conflicts
832 AliInfo("TODO");
833 //
834 int nh = fHypStore.GetEntriesFast();
835 for (int ih=0;ih<nh;ih++) {
836 AliITSUTrackHyp* hyp = (AliITSUTrackHyp*) fHypStore.UncheckedAt(ih);
69e0f089 837 if (!hyp || !hyp->DefineWinner()) continue; // TODO
68a0f687 838 CookMCLabel(hyp);
839 UpdateESDTrack(hyp,AliESDtrack::kITSin);
3e4e3c23 840 }
841
842}
c51c3124 843
844//______________________________________________________________________________
68a0f687 845void AliITSUTrackerGlo::UpdateESDTrack(AliITSUTrackHyp* hyp,Int_t flag)
c51c3124 846{
847 // update ESD track with current best hypothesis
848 AliESDtrack* esdTr = hyp->GetESDTrack();
849 if (!esdTr) return;
850 AliITSUSeed* win = hyp->GetWinner();
851 if (!win) return;
68a0f687 852 switch (flag) {
853 case AliESDtrack::kITSin:
854 esdTr->UpdateTrackParams(hyp,flag); // update kinematics
855 // TODO: set cluster info
856 break;
857 //
858 case AliESDtrack::kITSout:
859 esdTr->UpdateTrackParams(hyp,flag); // update kinematics
860 // TODO: avoid setting friend
861 break;
862 //
863 case AliESDtrack::kITSrefit:
864 esdTr->UpdateTrackParams(hyp,flag); // update kinematics
865 // TODO: avoid setting cluster info
866 break;
867 default:
868 AliFatal(Form("Unknown flag %d",flag));
869 }
c51c3124 870 //
871 // transfer module indices
872 // TODO
873}
874
875//______________________________________________________________________________
68a0f687 876Bool_t AliITSUTrackerGlo::RefitTrack(AliITSUTrackHyp* trc, Double_t rDest, Bool_t stopAtLastCl)
c51c3124 877{
878 // refit track till radius rDest
8b16dbae 879 AliITSUTrackHyp tmpTr;
880 //
c51c3124 881 double rCurr = Sqrt(trc->GetX()*trc->GetX() + trc->GetY()*trc->GetY());
882 int dir,lrStart,lrStop;
883 //
8b16dbae 884 dir = rCurr<rDest ? 1 : -1;
885 lrStart = fITS->FindFirstLayerID(rCurr,dir);
886 lrStop = fITS->FindLastLayerID(rDest,dir);
e2d2481c 887 printf("Refit %d: Lr:%d (%f) -> Lr:%d (%f)\n",dir,lrStart,rCurr, lrStop,rDest);
888 printf("Before refit: "); trc->AliExternalTrackParam::Print();
8b16dbae 889 if (lrStop<0 || lrStart<0) AliFatal(Form("Failed to find start(%d) or last(%d) layers. Track from %.3f to %.3f",lrStart,lrStop,rCurr,rDest));
890 //
68a0f687 891 int ncl = trc->FetchClusterInfo(fClInfo);
8b16dbae 892 fCurrMass = trc->GetMass();
893 tmpTr.AliKalmanTrack::operator=(*trc);
894 tmpTr.SetChi2(0);
68a0f687 895 int iclLr[2],nclLr,clCount=0;
c51c3124 896 //
897 for (int ilr=lrStart;ilr!=lrStop;ilr+=dir) {
898 AliITSURecoLayer* lr = fITS->GetLayer(ilr);
899 if ( dir*(rCurr-lr->GetR(dir))>0) continue; // this layer is already passed
8b16dbae 900 int ilrA2,ilrA = lr->GetActiveID();
901 // passive layer or active w/o hits will be traversed on the way to next cluster
902 if (!lr->IsActive() || fClInfo[ilrA2=(ilrA<<1)]<0) continue;
903 //
e2d2481c 904 if (ilr!=lrStart && !TransportToLayer(&tmpTr,lrStart,ilr)) {
e7d83d38 905 AliInfo(Form("Failed to transport %d -> %d\n",lrStart,ilr));
e2d2481c 906 return kFALSE; // go to the entrance to the layer
907 }
8b16dbae 908 lrStart = ilr;
909 //
910 // select the order in which possible 2 clusters (in case of the overlap) will be traversed and fitted
911 nclLr=0;
912 if (dir>0) { // clusters are stored in increasing radius order
913 iclLr[nclLr++]=fClInfo[ilrA2++];
914 if (fClInfo[ilrA2]>=0) iclLr[nclLr++]=fClInfo[ilrA2];
915 }
916 else {
917 if ( fClInfo[ilrA2+1]>=0 ) iclLr[nclLr++]=fClInfo[ilrA2+1];
918 iclLr[nclLr++]=fClInfo[ilrA2];
919 }
920 //
921 for (int icl=0;icl<nclLr;icl++) {
922 AliITSUClusterPix* clus = (AliITSUClusterPix*)lr->GetCluster(iclLr[icl]);
923 AliITSURecoSens* sens = lr->GetSensorFromID(clus->GetVolumeId());
e7d83d38 924 if (!tmpTr.Rotate(sens->GetPhiTF())) {
925 AliInfo(Form("Failed on rotate to %f",sens->GetPhiTF()));
926 return kFALSE;
927 }
928 //printf("Refit cl:%d on lr %d Need to go %.4f -> %.4f\n",icl,ilrA,tmpTr.GetX(),sens->GetXTF()+clus->GetX());
929 if (!PropagateSeed(&tmpTr,sens->GetXTF()+clus->GetX(),fCurrMass)) {
930 AliInfo(Form("Failed on propagate to %f",sens->GetXTF()+clus->GetX()));
931 return kFALSE;
932 }
933 if (!tmpTr.Update(clus)) {
934 AliInfo(Form("Failed on Update"));
935 return kFALSE;
936 }
937 //printf("AfterRefit: "); tmpTr.AliExternalTrackParam::Print();
68a0f687 938 if (stopAtLastCl && ++clCount==ncl) return kTRUE; // it was requested to not propagate after last update
8b16dbae 939 }
c51c3124 940 //
941 }
8b16dbae 942 // All clusters were succesfully fitted. Even if the track does not reach rDest, this is enough to validate it.
943 // Still, try to go as close as possible to rDest.
944 //
945 if (lrStart!=lrStop) {
e7d83d38 946 //printf("Going to last layer %d -> %d\n",lrStart,lrStop);
947 if (!TransportToLayer(&tmpTr,lrStart,lrStop)) {
948 AliInfo(Form("Failed on TransportToLayer %d->%d",lrStart,lrStop));
949 return kTRUE;
950 }
951 if (!GoToExitFromLayer(&tmpTr,fITS->GetLayer(lrStop),dir)) {
952 AliFatal(Form("Failed on GoToExitFromLayer %d",lrStop));
953 return kTRUE; // go till the exit from layer
954 }
e2d2481c 955 //
e7d83d38 956 //printf("On exit from last layer\n");
e2d2481c 957 tmpTr.AliExternalTrackParam::Print();
958 // go to the destination radius
959 if (!tmpTr.GetXatLabR(rDest,rDest,GetBz(),dir)) return kTRUE;
960 if (!PropagateSeed(&tmpTr,rDest,fCurrMass, 100, kFALSE)) return kTRUE;
8b16dbae 961 }
962 trc->AliKalmanTrack::operator=(tmpTr);
e2d2481c 963 printf("After refit (now at lr %d): ",lrStart); trc->AliExternalTrackParam::Print();
8b16dbae 964 return kTRUE;
c51c3124 965}
dd2117a2 966
967//__________________________________________________________________
968void AliITSUTrackerGlo::CookMCLabel(AliITSUTrackHyp* hyp)
969{
970 // build MC label
971 //
972 const int kMaxLbPerCl = 3;
973 int lbID[kMaxLayers*6],lbStat[kMaxLayers*6];
974 Int_t lr,nLab=0,nCl=0;
975 AliITSUSeed *seed = hyp->GetWinner();
976 while(seed) {
977 int clID = seed->GetLrCluster(lr);
978 if (clID>=0) {
979 AliCluster *cl = fITS->GetLayerActive(lr)->GetCluster(clID);
980 nCl++;
981 for (int imc=0;imc<kMaxLbPerCl;imc++) { // labels within single cluster
982 int trLb = cl->GetLabel(imc);
704d9398 983 if (trLb<0) break;
dd2117a2 984 // search this mc track in already accounted ones
985 int iLab;
986 for (iLab=0;iLab<nLab;iLab++) if (lbID[iLab]==trLb) break;
987 if (iLab<nLab) lbStat[iLab]++;
988 else {
989 lbID[nLab] = trLb;
990 lbStat[nLab++] = 1;
991 }
992 } // loop over given cluster's labels
993 }
994 seed = (AliITSUSeed*)seed->GetParent();
995 } // loop over clusters
996 //
41343470 997 if (nCl && nLab) {
dd2117a2 998 int maxLab=0,nTPCok=0;
999 AliESDtrack* esdTr = hyp->GetESDTrack();
1000 int tpcLab = esdTr ? Abs(esdTr->GetTPCLabel()) : -kDummyLabel;
1001 for (int ilb=nLab;ilb--;) {
1002 int st = lbStat[ilb];
1003 if (lbStat[maxLab]<st) maxLab=ilb;
1004 if (tpcLab==lbID[ilb]) nTPCok += st;
1005 }
1006 hyp->SetFakeRatio(1.-float(nTPCok)/nCl);
1007 hyp->SetLabel( nTPCok==nCl ? tpcLab : -tpcLab);
1008 hyp->SetITSLabel( lbStat[maxLab]==nCl ? lbStat[maxLab] : -lbStat[maxLab]); // winner label
1009 return;
1010 }
1011 //
1012 hyp->SetFakeRatio(-1.);
1013 hyp->SetLabel( kDummyLabel );
1014 hyp->SetITSLabel( kDummyLabel );
1015}