1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
22 //-------------------------------------------------------------------------
23 // Implementation of the ITS Upgrade tracker mother class.
24 //-------------------------------------------------------------------------
26 #include <Riostream.h>
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"
38 #include "AliITSUClusterPix.h"
39 using namespace AliITSUAux;
40 using namespace TMath;
44 //----------------- tmp stuff -----------------
46 ClassImp(AliITSUTrackerGlo)
48 const Double_t AliITSUTrackerGlo::fgkToler = 1e-6;// tolerance for layer on-surface check
51 //_________________________________________________________________________
52 AliITSUTrackerGlo::AliITSUTrackerGlo(AliITSUReconstructor* rec)
59 ,fSeedsPool("AliITSUSeed",0)
67 // Default constructor
71 //_________________________________________________________________________
72 AliITSUTrackerGlo::~AliITSUTrackerGlo()
81 //_________________________________________________________________________
82 void AliITSUTrackerGlo::Init(AliITSUReconstructor* rec)
84 // init with external reconstructor
86 fITS = new AliITSURecoDet(rec->GetGeom(),"ITSURecoInterface");
87 int nLr = fITS->GetNLayersActive();
88 fClInfo = new Int_t[nLr<<1];
89 for (int ilr=nLr;ilr--;) {
90 fITS->GetLayerActive(ilr)->SetClusters(rec->GetClusters(ilr));
93 fSeedsPool.ExpandCreateFast(1000); // RS TOCHECK
94 fFreeSeedsID.Set(1000);
96 fTrCond.SetNLayers(fITS->GetNLayersActive());
97 fTrCond.AddNewCondition(5);
98 fTrCond.AddGroupPattern( (0x1<<0)|(0x1<<1) );
99 fTrCond.AddGroupPattern( (0x1<<3)|(0x1<<4) );
100 fTrCond.AddGroupPattern( (0x1<<5)|(0x1<<6) );
102 fTrCond.AddNewCondition(5);
103 fTrCond.AddGroupPattern( (0x1<<0)|(0x1<<2) );
104 fTrCond.AddGroupPattern( (0x1<<3)|(0x1<<4) );
105 fTrCond.AddGroupPattern( (0x1<<5)|(0x1<<6) );
107 fTrCond.AddNewCondition(5);
108 fTrCond.AddGroupPattern( (0x1<<1)|(0x1<<2) );
109 fTrCond.AddGroupPattern( (0x1<<3)|(0x1<<4) );
110 fTrCond.AddGroupPattern( (0x1<<5)|(0x1<<6) );
112 printf("Tracking Conditions: ");
116 //_________________________________________________________________________
117 Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
121 SetTrackingPhase(kClus2Tracks);
123 int nTrESD = esdEv->GetNumberOfTracks();
124 AliInfo(Form("Will try to find prolongations for %d tracks",nTrESD));
125 AliITSUReconstructor::GetRecoParam()->Print();
127 if (fHypStore.GetSize()<nTrESD) fHypStore.Expand(nTrESD+100);
129 fITS->ProcessClusters();
130 // select ESD tracks to propagate
131 for (int itr=0;itr<nTrESD;itr++) {
132 AliESDtrack *esdTr = esdEv->GetTrack(itr);
133 AliInfo(Form("Processing track %d | MCLabel: %d",itr,esdTr->GetTPCLabel()));
134 if (!NeedToProlong(esdTr)) continue; // are we interested in this track?
135 FindTrack(esdTr, itr);
138 AliInfo(Form("SeedsPool: %d, BookedUpTo: %d, free: %d",fSeedsPool.GetSize(),fSeedsPool.GetEntriesFast(),fNFreeSeeds));
140 FinalizeHypotheses();
145 //_________________________________________________________________________
146 Int_t AliITSUTrackerGlo::PropagateBack(AliESDEvent *esdEv)
149 // Do outward fits in ITS
151 SetTrackingPhase(kPropBack);
152 int nTrESD = esdEv->GetNumberOfTracks();
153 AliInfo(Form("Will propagate back %d tracks",nTrESD));
155 double bz0 = GetBz();
156 Double_t xyzTrk[3],xyzVtx[3]={GetX(),GetY(),GetZ()};
157 AliITSUTrackHyp dummyTr,*currTr=0;
158 const double kWatchStep=10.; // for larger steps watch arc vs segment difference
159 Double_t times[AliPID::kSPECIES];
162 for (int itr=0;itr<nTrESD;itr++) {
163 AliESDtrack *esdTr = esdEv->GetTrack(itr);
164 // Start time integral and add distance from current position to vertex
165 if (esdTr->IsOn(AliESDtrack::kITSout)) continue; // already done
167 esdTr->GetXYZ(xyzTrk);
168 Double_t dst = 0.; // set initial track lenght, tof
170 double dxs = xyzTrk[0] - xyzVtx[0];
171 double dys = xyzTrk[1] - xyzVtx[1];
172 double dzs = xyzTrk[2] - xyzVtx[2];
173 // RS: for large segment steps d use approximation of cicrular arc s by
174 // s = 2R*asin(d/2R) = d/p asin(p) \approx d/p (p + 1/6 p^3) = d (1+1/6 p^2)
175 // where R is the track radius, p = d/2R = 2C*d (C is the abs curvature)
176 // Hence s^2/d^2 = (1+1/6 p^2)^2
177 dst = dxs*dxs + dys*dys;
178 if (dst > kWatchStep*kWatchStep) { // correct circular part for arc/segment factor
179 double crv = Abs(esdTr->GetC(bz0));
180 double fcarc = 1.+crv*crv*dst/6.;
187 esdTr->SetStatus(AliESDtrack::kTIME);
189 if (!esdTr->IsOn(AliESDtrack::kITSin)) { // case of tracks w/o ITS prolongation: just set the time integration
190 dummyTr.AliExternalTrackParam::operator=(*esdTr);
191 dummyTr.StartTimeIntegral();
192 dummyTr.AddTimeStep(dst);
193 dummyTr.GetIntegratedTimes(times);
194 esdTr->SetIntegratedTimes(times);
195 esdTr->SetIntegratedLength(dummyTr.GetIntegratedLength());
199 currTr = GetTrackHyp(itr);
200 currTr->StartTimeIntegral();
201 currTr->AddTimeStep(dst);
202 printf("Before resetCov: "); currTr->AliExternalTrackParam::Print();
203 currTr->ResetCovariance(10000);
204 if (RefitTrack(currTr,fITS->GetRMax())) { // propagate to exit from the ITS/TPC screen
205 UpdateESDTrack(currTr,AliESDtrack::kITSout);
208 AliInfo(Form("Refit Failed for track %d",itr));
216 //_________________________________________________________________________
217 Int_t AliITSUTrackerGlo::RefitInward(AliESDEvent *esdEv)
220 // refit the tracks inward, using current cov.matrix
222 SetTrackingPhase(kRefitInw);
223 Int_t nTrESD = esdEv->GetNumberOfTracks();
224 AliInfo(Form("Will refit inward %d tracks",nTrESD));
225 AliITSUTrackHyp *currTr=0;
227 for (int itr=0;itr<nTrESD;itr++) {
228 AliESDtrack *esdTr = esdEv->GetTrack(itr);
229 // Start time integral and add distance from current position to vertex
230 UInt_t trStat = esdTr->GetStatus();
231 if ( !(trStat & AliESDtrack::kITSout) ) continue;
232 if ( trStat & AliESDtrack::kITSrefit ) continue; // already done
233 if ( (trStat & AliESDtrack::kTPCout) && !(trStat & AliESDtrack::kTPCrefit) ) continue;
235 currTr = GetTrackHyp(itr);
236 currTr->AliExternalTrackParam::operator=(*esdTr); // fetch current ESDtrack kinematics
237 if (RefitTrack(currTr,fITS->GetRMin())) { // propagate up to inside radius of the beam pipe
238 UpdateESDTrack(currTr,AliESDtrack::kITSrefit);
241 AliInfo(Form("Refit Failed for track %d",itr));
248 //_________________________________________________________________________
249 Int_t AliITSUTrackerGlo::LoadClusters(TTree * treeRP)
251 // read from tree (if pointer provided) or directly from the ITS reco interface
253 return fReconstructor->LoadClusters(treeRP);
256 //_________________________________________________________________________
257 void AliITSUTrackerGlo::UnloadClusters()
263 Info("UnloadClusters","To be implemented");
265 //_________________________________________________________________________
266 AliCluster * AliITSUTrackerGlo::GetCluster(Int_t /*index*/) const
272 Info("GetCluster","To be implemented");
276 //_________________________________________________________________________
277 Bool_t AliITSUTrackerGlo::NeedToProlong(AliESDtrack* esdTr)
279 // do we need to match this track to ITS?
281 static double bz = GetBz();
282 if (!esdTr->IsOn(AliESDtrack::kTPCin) ||
283 esdTr->IsOn(AliESDtrack::kTPCout) ||
284 esdTr->IsOn(AliESDtrack::kITSin) ||
285 esdTr->GetKinkIndex(0)>0) return kFALSE;
287 if (esdTr->Pt()<AliITSUReconstructor::GetRecoParam()->GetMinPtForProlongation()) return kFALSE;
290 esdTr->GetDZ(GetX(),GetY(),GetZ(),bz,dtz);
291 // if track is not V0 candidata but has large offset wrt IP, reject it. RS TOCHECK
292 if ( !(esdTr->GetV0Index(0)>0 && dtz[0]>AliITSUReconstructor::GetRecoParam()->GetMaxDforV0dghtrForProlongation())
293 && (Abs(dtz[0])>AliITSUReconstructor::GetRecoParam()->GetMaxDForProlongation() ||
294 Abs(dtz[1])>AliITSUReconstructor::GetRecoParam()->GetMaxDZForProlongation())) return kFALSE;
299 //_________________________________________________________________________
300 void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr, Int_t esdID)
302 // find prolongaion candidates finding for single seed
304 AliITSUSeed seedUC; // copy of the seed from the upper layer
305 AliITSUSeed seedT; // transient seed between the seedUC and new prolongation hypothesis
307 if (!InitHypothesis(esdTr,esdID)) return; // initialize prolongations hypotheses tree
309 AliITSURecoSens *hitSens[AliITSURecoSens::kNNeighbors+1];
311 TObjArray clArr; // container for transfer of clusters matching to seed
313 int nLrActive = fITS->GetNLayersActive();
314 for (int ila=nLrActive;ila--;) {
315 int ilaUp = ila+1; // prolong seeds from layer above
317 // for the outermost layer the seed is created from the ESD track
318 int nSeedsUp = (ilaUp==nLrActive) ? 1 : fCurrHyp->GetNSeeds(ilaUp);
320 for (int isd=0;isd<nSeedsUp;isd++) {
322 if (ilaUp==nLrActive) {
324 seedUC.InitFromESDTrack(esdTr);
327 seedU = fCurrHyp->GetSeed(ilaUp,isd); // seed on prev.active layer to prolong
328 seedUC = *seedU; // its copy will be prolonged
329 seedUC.SetParent(seedU);
331 seedUC.ResetFMatrix(); // reset the matrix for propagation to next layer
332 // go till next active layer
333 AliInfo(Form("working on Lr:%d Seed:%d of %d",ila,isd,nSeedsUp));
334 if (!TransportToLayer(&seedUC, fITS->GetLrIDActive(ilaUp), fITS->GetLrIDActive(ila)) ) {
336 AliInfo("Transport failed");
337 // Check if the seed satisfies to track definition
338 if (NeedToKill(&seedUC,kTransportFailed) && seedU) KillSeed(seedU,kTRUE);
339 continue; // RS TODO: decide what to do with tracks stopped on higher layers w/o killing
341 AliITSURecoLayer* lrA = fITS->GetLayerActive(ila);
342 if (!GetRoadWidth(&seedUC, ila)) { // failed to find road width on the layer
343 if (NeedToKill(&seedUC,kRWCheckFailed) && seedU) KillSeed(seedU,kTRUE);
346 int nsens = lrA->FindSensors(&fTrImpData[kTrPhi0], hitSens); // find detectors which may be hit by the track
347 AliInfo(Form("Will check %d sensors on lr:%d ",nsens,ila));
350 for (int isn=nsens;isn--;) {
352 AliITSURecoSens* sens = hitSens[isn];
354 // We need to propagate the seed to sensor on lrA staying the frame of the sensor from prev.layer,
355 // since the transport matrix should be defined in this frame.
356 double xs; // X in the TF of current seed, corresponding to intersection with sensor plane
357 if (!seedT.GetTrackingXAtXAlpha(sens->GetXTF(),sens->GetPhiTF(),bz, xs)) continue;
358 if (!PropagateSeed(&seedT,xs,fCurrMass)) continue;
359 // if (!seedT.PropagateToX(xs,bz)) continue;
360 // if (!seedT.Rotate(sens->GetPhiTF())) continue;
361 if (!seedT.RotateToAlpha(sens->GetPhiTF())) continue;
363 int clID0 = sens->GetFirstClusterId();
364 for (int icl=sens->GetNClusters();icl--;) {
365 int res = CheckCluster(&seedT,ila,clID0+icl);
367 if (res==kStopSearchOnSensor) break; // stop looking on this sensor
368 if (res==kClusterNotMatching) continue; // cluster does not match
369 // cluster is matching and it was added to the hypotheses tree
372 // cluster search is done. Do we need ta have a version of this seed skipping current layer
374 if (!NeedToKill(&seedT,kMissingCluster)) {
375 AliITSUSeed* seedSkp = NewSeedFromPool(&seedT);
376 double penalty = -AliITSUReconstructor::GetRecoParam()->GetMissPenalty(ila);
377 // to do: make penalty to account for probability to miss the cluster for good reason
378 seedSkp->SetChi2Cl(penalty);
379 AddProlongationHypothesis(seedSkp,ila);
382 ((TObjArray*)fCurrHyp->GetLayerSeeds(ila))->Sort();
383 printf(">>> All hypotheses on lr %d: \n",ila);
384 for (int ih=0;ih<fCurrHyp->GetNSeeds(ila);ih++) {
385 printf(" #%3d ",ih); fCurrHyp->GetSeed(ila,ih)->Print();
388 if (ila!=0) continue;
389 double vecL[5] = {0};
390 double matL[15] = {0};
391 AliITSUSeed* sp = fCurrHyp->GetSeed(ila,ih);
392 while(sp->GetParent()) {
393 sp->Smooth(vecL,matL);
394 if (sp->GetLayerID()>=fITS->GetNLayersActive()-1) break;
395 sp = (AliITSUSeed*)sp->GetParent();
401 SaveCurrentTrackHypotheses();
405 //_________________________________________________________________________
406 Bool_t AliITSUTrackerGlo::InitHypothesis(AliESDtrack *esdTr, Int_t esdID)
408 // init prolongaion candidates finding for single seed
409 fCurrHyp = GetTrackHyp(esdID);
410 if (fCurrHyp) return kTRUE;
412 fCurrMass = esdTr->GetMass();
413 fCurrESDtrack = esdTr;
414 if (fCurrMass<kPionMass*0.9) fCurrMass = kPionMass; // don't trust to mu, e identification from TPCin
416 fCurrHyp = new AliITSUTrackHyp(fITS->GetNLayersActive());
417 fCurrHyp->SetESDTrack(esdTr);
418 fCurrHyp->SetUniqueID(esdID);
419 fCurrHyp->SetMass(fCurrMass);
420 SetTrackHyp(fCurrHyp,esdID);
426 //_________________________________________________________________________
427 Bool_t AliITSUTrackerGlo::TransportToLayer(AliITSUSeed* seed, Int_t lFrom, Int_t lTo)
429 // transport seed from layerFrom to the entrance of layerTo
432 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
434 int dir = lTo > lFrom ? 1:-1;
435 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
436 Bool_t checkFirst = kTRUE;
439 if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
442 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
443 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
445 // go the entrance of the layer, assuming no materials in between
446 double xToGo = lrTo->GetR(-dir);
447 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
448 if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) return kFALSE;
455 //_________________________________________________________________________
456 Bool_t AliITSUTrackerGlo::TransportToLayer(AliExternalTrackParam* seed, Int_t lFrom, Int_t lTo)
458 // transport track from layerFrom to the entrance of layerTo
460 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
462 int dir = lTo > lFrom ? 1:-1;
463 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
464 Bool_t checkFirst = kTRUE;
467 if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
470 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
471 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
473 if (!GoToExitFromLayer(seed,lrTo,dir)) return kFALSE; // go the entrance of the layer, assuming no materials in between
480 //_________________________________________________________________________
481 Bool_t AliITSUTrackerGlo::GoToExitFromLayer(AliITSUSeed* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
483 // go to the exit from lr in direction dir, applying material corrections in steps specific for this layer
484 // If check is requested, do this only provided the track has not exited the layer already
485 double xToGo = lr->GetR(dir);
486 if (check) { // do we need to track till the surface of the current layer ?
487 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
488 // AliInfo(Form(" dir:%d Cur: %e Tgt: %e",dir,Sqrt(curR2),xToGo));
489 if (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // on the surface or outside of the layer
490 else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // on the surface or outside of the layer
492 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
493 // go via layer to its boundary, applying material correction.
494 if (!PropagateSeed(seed,xToGo,fCurrMass, lr->GetMaxStep())) return kFALSE;
500 //_________________________________________________________________________
501 Bool_t AliITSUTrackerGlo::GoToExitFromLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
503 // go to the exit from lr in direction dir, applying material corrections in steps specific for this layer
504 // If check is requested, do this only provided the track has not exited the layer already
505 double xToGo = lr->GetR(dir);
506 if (check) { // do we need to track till the surface of the current layer ?
507 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
508 if (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // on the surface or outside of the layer
509 else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // on the surface or outside of the layer
511 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
512 // go via layer to its boundary, applying material correction.
513 if (!PropagateSeed(seed,xToGo,fCurrMass, lr->GetMaxStep())) return kFALSE;
520 //_________________________________________________________________________
521 Bool_t AliITSUTrackerGlo::GoToEntranceToLayer(AliITSUSeed* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
523 // go to the entrance of lr in direction dir, w/o applying material corrections.
524 // If check is requested, do this only provided the track did not reach the layer already
525 double xToGo = lr->GetR(-dir);
526 if (check) { // do we need to track till the surface of the current layer ?
527 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
528 if (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // already passed
529 else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // already passed
531 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
532 // go via layer to its boundary, applying material correction.
533 if (!PropagateSeed(seed,xToGo,fCurrMass, 100, kFALSE)) return kFALSE;
538 //_________________________________________________________________________
539 Bool_t AliITSUTrackerGlo::GoToEntranceToLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
541 // go to the entrance of lr in direction dir, w/o applying material corrections.
542 // If check is requested, do this only provided the track did not reach the layer already
543 double xToGo = lr->GetR(-dir);
544 if (check) { // do we need to track till the surface of the current layer ?
545 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
546 if (dir>0) { if (curR2-xToGo*xToGo>fgkToler) return kTRUE; } // already passed
547 else if (dir<0) { if (xToGo*xToGo-curR2>fgkToler) return kTRUE; } // already passed
549 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
550 // go via layer to its boundary, applying material correction.
551 if (!PropagateSeed(seed,xToGo,fCurrMass, 100, kFALSE)) return kFALSE;
556 //_________________________________________________________________________
557 Bool_t AliITSUTrackerGlo::GetRoadWidth(AliITSUSeed* seed, int ilrA)
559 // calculate road width in terms of phi and z for the track which MUST be on the external radius of the layer
560 // as well as some aux info
562 AliITSURecoLayer* lrA = fITS->GetLayerActive(ilrA);
563 seed->GetXYZ(&fTrImpData[kTrXIn]); // lab position at the entrance from above
564 static AliExternalTrackParam sc; // seed copy for manipalitions
567 fTrImpData[kTrPhiIn] = ATan2(fTrImpData[kTrYIn],fTrImpData[kTrXIn]);
568 if (!sc.Rotate(fTrImpData[kTrPhiIn])) return kFALSE; // go to the frame of the entry point into the layer
569 double dr = lrA->GetDR(); // approximate X dist at the inner radius
570 if (!sc.GetXYZAt(sc.GetX()-dr, bz, fTrImpData + kTrXOut)) {
571 // special case: track does not reach inner radius, might be tangential
572 double r = sc.GetD(0,0,bz);
574 if (!sc.GetXatLabR(r,x,bz,-1)) {
576 AliFatal(Form("This should not happen: r=%f",r));
578 dr = Abs(sc.GetX() - x);
579 if (!sc.GetXYZAt(x, bz, fTrImpData + kTrXOut)) {
581 AliFatal(Form("This should not happen: x=%f",x));
585 fTrImpData[kTrPhiOut] = ATan2(fTrImpData[kTrYOut],fTrImpData[kTrXOut]);
586 double sgy = sc.GetSigmaY2() + dr*dr*sc.GetSigmaSnp2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(ilrA);
587 double sgz = sc.GetSigmaZ2() + dr*dr*sc.GetSigmaTgl2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(ilrA);
588 sgy = Sqrt(sgy)*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY();
589 sgz = Sqrt(sgz)*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ();
590 fTrImpData[kTrPhi0] = 0.5*(fTrImpData[kTrPhiOut]+fTrImpData[kTrPhiIn]);
591 fTrImpData[kTrZ0] = 0.5*(fTrImpData[kTrZOut]+fTrImpData[kTrZIn]);
592 fTrImpData[kTrDPhi] = 0.5*Abs(fTrImpData[kTrPhiOut]-fTrImpData[kTrPhiIn]) + sgy/lrA->GetR();
593 fTrImpData[kTrDZ] = 0.5*Abs(fTrImpData[kTrZOut]-fTrImpData[kTrZIn]) + sgz;
598 //________________________________________
599 void AliITSUTrackerGlo::ResetSeedsPool()
601 // mark all seeds in the pool as unused
602 AliInfo(Form("CurrentSize: %d, BookedUpTo: %d, free: %d",fSeedsPool.GetSize(),fSeedsPool.GetEntriesFast(),fNFreeSeeds));
604 fSeedsPool.Clear(); // seeds don't allocate memory
608 //________________________________________
609 void AliITSUTrackerGlo::MarkSeedFree(AliITSUSeed *sd)
611 // account that this seed is "deleted"
612 int id = sd->GetPoolID();
614 AliError(Form("Freeing of seed %p NOT from the pool is requested",sd));
617 // AliInfo(Form("%d %p",id, seed));
618 fSeedsPool.RemoveAt(id);
619 if (fFreeSeedsID.GetSize()<=fNFreeSeeds) fFreeSeedsID.Set( 2*fNFreeSeeds + 100 );
620 fFreeSeedsID.GetArray()[fNFreeSeeds++] = id;
623 //_________________________________________________________________________
624 Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
626 // Check if the cluster (in tracking frame!) is matching to track.
627 // The track must be already propagated to sensor tracking frame.
628 // Returns: kStopSearchOnSensor if the search on given sensor should be stopped,
629 // kClusterMatching if the cluster is matching
630 // kClusterMatching otherwise
632 const double kTolerX = 5e-4;
633 AliCluster *cl = fITS->GetLayerActive(lr)->GetCluster(clID);
635 Bool_t goodCl = kFALSE;
636 int currLabel = Abs(fCurrESDtrack->GetTPCLabel());
638 if (cl->GetLabel(0)>=0) {
639 for (int i=0;i<3;i++) if (cl->GetLabel(i)>=0 && cl->GetLabel(i)==currLabel) {goodCl = kTRUE; break;}
643 if (TMath::Abs(cl->GetX())>kTolerX) { // if due to the misalingment X is large, propagate track only
644 if (!track->PropagateParamOnlyTo(track->GetX()+cl->GetX(),GetBz())) {
645 if (goodCl) {printf("Loose good cl: Failed propagation. |"); cl->Print();}
646 return kStopSearchOnSensor; // propagation failed, seedT is intact
649 double dy = cl->GetY()-track->GetY();
650 double dz = cl->GetZ()-track->GetZ();
653 double tol2 = (track->GetSigmaY2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(lr))*
654 AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY()*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY(); // RS TOOPTIMIZE
655 if (dy2>tol2) { // the clusters are sorted in Z(col) then in Y(row).
656 if (goodCl) {printf("Loose good cl: dy2=%e > tol2=%e |",dy2,tol2); cl->Print();}
657 if (dy>0) return kStopSearchOnSensor; // No chance that other cluster of this sensor will match (all Y's will be even larger)
658 else return kClusterNotMatching; // Other clusters may match
661 tol2 = (track->GetSigmaZ2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(lr))*
662 AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ()*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ(); // RS TOOPTIMIZE
664 if (goodCl) {printf("Loose good cl: dz2=%e > tol2=%e |",dz2,tol2); cl->Print();}
665 return kClusterNotMatching; // Other clusters may match
669 Double_t p[2]={cl->GetY(), cl->GetZ()};
670 Double_t cov[3]={cl->GetSigmaY2(), cl->GetSigmaYZ(), cl->GetSigmaZ2()};
671 double chi2 = track->GetPredictedChi2(p,cov);
672 if (chi2>AliITSUReconstructor::GetRecoParam()->GetMaxTr2ClChi2(lr)) {
674 printf("Loose good cl: Chi2=%e > Chi2Max=%e |dy: %+.3e dz: %+.3e\n",
675 chi2,AliITSUReconstructor::GetRecoParam()->GetMaxTr2ClChi2(lr),dy,dz);
679 return kClusterNotMatching;
682 track = NewSeedFromPool(track); // input track will be reused, use its clone for updates
683 if (!track->Update()) {
684 if (goodCl) {printf("Loose good cl: Failed update |"); cl->Print();}
686 return kClusterNotMatching;
688 track->SetChi2Cl(chi2);
689 track->SetLrClusterID(lr,clID);
690 cl->IncreaseClusterUsage();
692 track->SetFake(!goodCl);
694 AliInfo(Form("AddCl(%d) Cl%d lr:%d: dY:%+8.4f dZ:%+8.4f (MC: %5d %5d %5d) |Chi2=%f(%c)",
695 goodCl,clID,lr,dy,dz2,cl->GetLabel(0),cl->GetLabel(1),cl->GetLabel(2), chi2, track->IsFake() ? '-':'+'));
697 AddProlongationHypothesis(track,lr);
699 return kClusterMatching;
702 //_________________________________________________________________________
703 Bool_t AliITSUTrackerGlo::NeedToKill(AliITSUSeed *seed, Int_t flag)
705 // check if the seed should not be discarded
706 const UShort_t kMask = 0xffff;
707 if (flag==kMissingCluster) {
708 int lastChecked = seed->GetLayerID();
709 UShort_t patt = seed->GetHitsPattern();
710 if (lastChecked) patt |= ~(kMask<<lastChecked); // not all layers were checked, complete unchecked once by potential hits
711 Bool_t seedOK = fTrCond.CheckPattern(patt);
717 //______________________________________________________________________________
718 Bool_t AliITSUTrackerGlo::PropagateSeed(AliITSUSeed *seed, Double_t xToGo, Double_t mass, Double_t maxStep, Bool_t matCorr)
720 // propagate seed to given x applying material correction if requested
721 const Double_t kEpsilon = 1e-5;
722 Double_t xpos = seed->GetX();
723 Int_t dir = (xpos<xToGo) ? 1:-1;
724 Double_t xyz0[3],xyz1[3],param[7];
726 Bool_t updTime = dir>0 && seed->IsStartedTimeIntegral();
727 if (matCorr || updTime) seed->GetXYZ(xyz1); //starting global position
728 while ( (xToGo-xpos)*dir > kEpsilon){
729 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
730 Double_t x = xpos+step;
731 Double_t bz=GetBz(); // getting the local Bz
732 if (!seed->PropagateToX(x,bz)) return kFALSE;
734 if (matCorr || updTime) {
735 xyz0[0]=xyz1[0]; // global pos at the beginning of step
738 seed->GetXYZ(xyz1); // // global pos at the end of step
740 MeanMaterialBudget(xyz0,xyz1,param);
741 Double_t xrho=param[0]*param[4], xx0=param[1];
742 if (dir>0) xrho = -xrho; // outward should be negative
743 if (!seed->ApplyMaterialCorrection(xx0,xrho,mass,kFALSE)) return kFALSE;
746 else { // matCorr is not requested but time integral is
747 double d0 = xyz1[0]-xyz0[0];
748 double d1 = xyz1[1]-xyz0[1];
749 double d2 = xyz1[2]-xyz0[2];
750 ds = TMath::Sqrt(d0*d0+d1*d1+d2*d2);
753 if (updTime) seed->AddTimeStep(ds);
759 //______________________________________________________________________________
760 Bool_t AliITSUTrackerGlo::PropagateSeed(AliExternalTrackParam *seed, Double_t xToGo, Double_t mass, Double_t maxStep, Bool_t matCorr)
762 // propagate seed to given x applying material correction if requested
763 const Double_t kEpsilon = 1e-5;
764 Double_t xpos = seed->GetX();
765 Int_t dir = (xpos<xToGo) ? 1:-1;
766 Double_t xyz0[3],xyz1[3],param[7];
768 Bool_t updTime = dir>0 && seed->IsStartedTimeIntegral();
769 if (matCorr || updTime) seed->GetXYZ(xyz1); //starting global position
770 while ( (xToGo-xpos)*dir > kEpsilon){
771 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
772 Double_t x = xpos+step;
773 Double_t bz=GetBz(); // getting the local Bz
774 if (!seed->PropagateTo(x,bz)) return kFALSE;
776 if (matCorr || updTime) {
777 xyz0[0]=xyz1[0]; // global pos at the beginning of step
780 seed->GetXYZ(xyz1); // // global pos at the end of step
783 MeanMaterialBudget(xyz0,xyz1,param);
784 Double_t xrho=param[0]*param[4], xx0=param[1];
785 if (dir>0) xrho = -xrho; // outward should be negative
786 if (!seed->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
789 else { // matCorr is not requested but time integral is
790 double d0 = xyz1[0]-xyz0[0];
791 double d1 = xyz1[1]-xyz0[1];
792 double d2 = xyz1[2]-xyz0[2];
793 ds = TMath::Sqrt(d0*d0+d1*d1+d2*d2);
796 if (updTime) seed->AddTimeStep(ds);
803 //______________________________________________________________________________
804 void AliITSUTrackerGlo::SaveCurrentTrackHypotheses()
806 // RS: shall we clean up killed seeds?
812 //______________________________________________________________________________
813 void AliITSUTrackerGlo::FinalizeHypotheses()
815 // select winner for each hypothesis, remove cl. sharing conflicts
818 int nh = fHypStore.GetEntriesFast();
819 for (int ih=0;ih<nh;ih++) {
820 AliITSUTrackHyp* hyp = (AliITSUTrackHyp*) fHypStore.UncheckedAt(ih);
821 if (!hyp || !hyp->DefineWinner()) continue; // TODO
823 UpdateESDTrack(hyp,AliESDtrack::kITSin);
828 //______________________________________________________________________________
829 void AliITSUTrackerGlo::UpdateESDTrack(AliITSUTrackHyp* hyp,Int_t flag)
831 // update ESD track with current best hypothesis
832 AliESDtrack* esdTr = hyp->GetESDTrack();
834 AliITSUSeed* win = hyp->GetWinner();
837 case AliESDtrack::kITSin:
838 esdTr->UpdateTrackParams(hyp,flag); // update kinematics
839 // TODO: set cluster info
842 case AliESDtrack::kITSout:
843 esdTr->UpdateTrackParams(hyp,flag); // update kinematics
844 // TODO: avoid setting friend
847 case AliESDtrack::kITSrefit:
848 esdTr->UpdateTrackParams(hyp,flag); // update kinematics
849 // TODO: avoid setting cluster info
852 AliFatal(Form("Unknown flag %d",flag));
855 // transfer module indices
859 //______________________________________________________________________________
860 Bool_t AliITSUTrackerGlo::RefitTrack(AliITSUTrackHyp* trc, Double_t rDest, Bool_t stopAtLastCl)
862 // refit track till radius rDest
863 AliITSUTrackHyp tmpTr;
865 double rCurr = Sqrt(trc->GetX()*trc->GetX() + trc->GetY()*trc->GetY());
866 int dir,lrStart,lrStop;
868 dir = rCurr<rDest ? 1 : -1;
869 lrStart = fITS->FindFirstLayerID(rCurr,dir);
870 lrStop = fITS->FindLastLayerID(rDest,dir);
871 printf("Refit %d: Lr:%d (%f) -> Lr:%d (%f)\n",dir,lrStart,rCurr, lrStop,rDest);
872 printf("Before refit: "); trc->AliExternalTrackParam::Print();
873 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));
875 int ncl = trc->FetchClusterInfo(fClInfo);
876 fCurrMass = trc->GetMass();
877 tmpTr.AliKalmanTrack::operator=(*trc);
879 int iclLr[2],nclLr,clCount=0;
881 for (int ilr=lrStart;ilr!=lrStop;ilr+=dir) {
882 AliITSURecoLayer* lr = fITS->GetLayer(ilr);
883 if ( dir*(rCurr-lr->GetR(dir))>0) continue; // this layer is already passed
884 int ilrA2,ilrA = lr->GetActiveID();
885 // passive layer or active w/o hits will be traversed on the way to next cluster
886 if (!lr->IsActive() || fClInfo[ilrA2=(ilrA<<1)]<0) continue;
888 if (ilr!=lrStart && !TransportToLayer(&tmpTr,lrStart,ilr)) {
889 AliInfo(Form("Failed to transport %d -> %d\n",lrStart,ilr));
890 return kFALSE; // go to the entrance to the layer
894 // select the order in which possible 2 clusters (in case of the overlap) will be traversed and fitted
896 if (dir>0) { // clusters are stored in increasing radius order
897 iclLr[nclLr++]=fClInfo[ilrA2++];
898 if (fClInfo[ilrA2]>=0) iclLr[nclLr++]=fClInfo[ilrA2];
901 if ( fClInfo[ilrA2+1]>=0 ) iclLr[nclLr++]=fClInfo[ilrA2+1];
902 iclLr[nclLr++]=fClInfo[ilrA2];
905 for (int icl=0;icl<nclLr;icl++) {
906 AliITSUClusterPix* clus = (AliITSUClusterPix*)lr->GetCluster(iclLr[icl]);
907 AliITSURecoSens* sens = lr->GetSensorFromID(clus->GetVolumeId());
908 if (!tmpTr.Rotate(sens->GetPhiTF())) {
909 AliInfo(Form("Failed on rotate to %f",sens->GetPhiTF()));
912 //printf("Refit cl:%d on lr %d Need to go %.4f -> %.4f\n",icl,ilrA,tmpTr.GetX(),sens->GetXTF()+clus->GetX());
913 if (!PropagateSeed(&tmpTr,sens->GetXTF()+clus->GetX(),fCurrMass)) {
914 AliInfo(Form("Failed on propagate to %f",sens->GetXTF()+clus->GetX()));
917 if (!tmpTr.Update(clus)) {
918 AliInfo(Form("Failed on Update"));
921 //printf("AfterRefit: "); tmpTr.AliExternalTrackParam::Print();
922 if (stopAtLastCl && ++clCount==ncl) return kTRUE; // it was requested to not propagate after last update
926 // All clusters were succesfully fitted. Even if the track does not reach rDest, this is enough to validate it.
927 // Still, try to go as close as possible to rDest.
929 if (lrStart!=lrStop) {
930 //printf("Going to last layer %d -> %d\n",lrStart,lrStop);
931 if (!TransportToLayer(&tmpTr,lrStart,lrStop)) {
932 AliInfo(Form("Failed on TransportToLayer %d->%d",lrStart,lrStop));
935 if (!GoToExitFromLayer(&tmpTr,fITS->GetLayer(lrStop),dir)) {
936 AliFatal(Form("Failed on GoToExitFromLayer %d",lrStop));
937 return kTRUE; // go till the exit from layer
940 //printf("On exit from last layer\n");
941 tmpTr.AliExternalTrackParam::Print();
942 // go to the destination radius
943 if (!tmpTr.GetXatLabR(rDest,rDest,GetBz(),dir)) return kTRUE;
944 if (!PropagateSeed(&tmpTr,rDest,fCurrMass, 100, kFALSE)) return kTRUE;
946 trc->AliKalmanTrack::operator=(tmpTr);
947 printf("After refit (now at lr %d): ",lrStart); trc->AliExternalTrackParam::Print();
951 //__________________________________________________________________
952 void AliITSUTrackerGlo::CookMCLabel(AliITSUTrackHyp* hyp)
956 const int kMaxLbPerCl = 3;
957 int lbID[kMaxLayers*6],lbStat[kMaxLayers*6];
958 Int_t lr,nLab=0,nCl=0;
959 AliITSUSeed *seed = hyp->GetWinner();
961 int clID = seed->GetLrCluster(lr);
963 AliCluster *cl = fITS->GetLayerActive(lr)->GetCluster(clID);
965 for (int imc=0;imc<kMaxLbPerCl;imc++) { // labels within single cluster
966 int trLb = cl->GetLabel(imc);
968 // search this mc track in already accounted ones
970 for (iLab=0;iLab<nLab;iLab++) if (lbID[iLab]==trLb) break;
971 if (iLab<nLab) lbStat[iLab]++;
976 } // loop over given cluster's labels
978 seed = (AliITSUSeed*)seed->GetParent();
979 } // loop over clusters
982 int maxLab=0,nTPCok=0;
983 AliESDtrack* esdTr = hyp->GetESDTrack();
984 int tpcLab = esdTr ? Abs(esdTr->GetTPCLabel()) : -kDummyLabel;
985 for (int ilb=nLab;ilb--;) {
986 int st = lbStat[ilb];
987 if (lbStat[maxLab]<st) maxLab=ilb;
988 if (tpcLab==lbID[ilb]) nTPCok += st;
990 hyp->SetFakeRatio(1.-float(nTPCok)/nCl);
991 hyp->SetLabel( nTPCok==nCl ? tpcLab : -tpcLab);
992 hyp->SetITSLabel( lbStat[maxLab]==nCl ? lbStat[maxLab] : -lbStat[maxLab]); // winner label
996 hyp->SetFakeRatio(-1.);
997 hyp->SetLabel( kDummyLabel );
998 hyp->SetITSLabel( kDummyLabel );