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;
43 //----------------- tmp stuff -----------------
45 ClassImp(AliITSUTrackerGlo)
46 //_________________________________________________________________________
47 AliITSUTrackerGlo::AliITSUTrackerGlo(AliITSUReconstructor* rec)
54 ,fSeedsPool("AliITSUSeed",0)
59 // Default constructor
63 //_________________________________________________________________________
64 AliITSUTrackerGlo::~AliITSUTrackerGlo()
73 //_________________________________________________________________________
74 void AliITSUTrackerGlo::Init(AliITSUReconstructor* rec)
76 // init with external reconstructor
78 fITS = new AliITSURecoDet(rec->GetGeom(),"ITSURecoInterface");
79 int nLr = fITS->GetNLayersActive();
80 fClInfo = new Int_t[nLr<<1];
81 for (int ilr=nLr;ilr--;) {
82 fITS->GetLayerActive(ilr)->SetClusters(rec->GetClusters(ilr));
85 fSeedsPool.ExpandCreateFast(1000); // RS TOCHECK
87 fTrCond.SetNLayers(fITS->GetNLayersActive());
88 fTrCond.AddNewCondition(5);
89 fTrCond.AddGroupPattern( (0x1<<0)|(0x1<<1) );
90 fTrCond.AddGroupPattern( (0x1<<3)|(0x1<<4) );
91 fTrCond.AddGroupPattern( (0x1<<5)|(0x1<<6) );
93 fTrCond.AddNewCondition(5);
94 fTrCond.AddGroupPattern( (0x1<<0)|(0x1<<2) );
95 fTrCond.AddGroupPattern( (0x1<<3)|(0x1<<4) );
96 fTrCond.AddGroupPattern( (0x1<<5)|(0x1<<6) );
98 fTrCond.AddNewCondition(5);
99 fTrCond.AddGroupPattern( (0x1<<1)|(0x1<<2) );
100 fTrCond.AddGroupPattern( (0x1<<3)|(0x1<<4) );
101 fTrCond.AddGroupPattern( (0x1<<5)|(0x1<<6) );
103 printf("Tracking Conditions: ");
107 //_________________________________________________________________________
108 Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
112 fTrackPhase = kClus2Tracks;
113 int nTrESD = esdEv->GetNumberOfTracks();
114 AliInfo(Form("Will try to find prolongations for %d tracks",nTrESD));
115 AliITSUReconstructor::GetRecoParam()->Print();
117 if (fHypStore.GetSize()<nTrESD) fHypStore.Expand(nTrESD+100);
119 fITS->ProcessClusters();
120 // select ESD tracks to propagate
121 for (int itr=0;itr<nTrESD;itr++) {
122 AliESDtrack *esdTr = esdEv->GetTrack(itr);
123 AliInfo(Form("Processing track %d | MCLabel: %d",itr,esdTr->GetTPCLabel()));
124 if (!NeedToProlong(esdTr)) continue; // are we interested in this track?
125 FindTrack(esdTr, itr);
128 printf("Hypotheses for current event (N seeds in pool: %d, size: %d)\n",fSeedsPool.GetEntriesFast(),fSeedsPool.GetSize());
130 FinalizeHypotheses();
135 //_________________________________________________________________________
136 Int_t AliITSUTrackerGlo::PropagateBack(AliESDEvent *esdEv)
139 // Do outward fits in ITS
141 fTrackPhase = kPropBack;
142 int nTrESD = esdEv->GetNumberOfTracks();
143 AliInfo(Form("Will fit %d tracks",nTrESD));
145 double bz0 = GetBz();
146 Double_t xyzTrk[3],xyzVtx[3]={GetX(),GetY(),GetZ()};
147 AliITSUTrackHyp dummyTr,*currTr=0;
148 const double kWatchStep=10.; // for larger steps watch arc vs segment difference
149 Double_t times[AliPID::kSPECIES];
152 for (int itr=0;itr<nTrESD;itr++) {
153 AliESDtrack *esdTr = esdEv->GetTrack(itr);
154 // Start time integral and add distance from current position to vertex
155 if (esdTr->IsOn(AliESDtrack::kITSout)) continue; // already done
157 esdTr->GetXYZ(xyzTrk);
158 Double_t dst = 0.; // set initial track lenght, tof
160 double dxs = xyzTrk[0] - xyzVtx[0];
161 double dys = xyzTrk[1] - xyzVtx[1];
162 double dzs = xyzTrk[2] - xyzVtx[2];
163 // RS: for large segment steps d use approximation of cicrular arc s by
164 // s = 2R*asin(d/2R) = d/p asin(p) \approx d/p (p + 1/6 p^3) = d (1+1/6 p^2)
165 // where R is the track radius, p = d/2R = 2C*d (C is the abs curvature)
166 // Hence s^2/d^2 = (1+1/6 p^2)^2
167 dst = dxs*dxs + dys*dys;
168 if (dst > kWatchStep*kWatchStep) { // correct circular part for arc/segment factor
169 double crv = Abs(esdTr->GetC(bz0));
170 double fcarc = 1.+crv*crv*dst/6.;
177 esdTr->SetStatus(AliESDtrack::kTIME);
179 if (!esdTr->IsOn(AliESDtrack::kITSin)) { // case of tracks w/o ITS prolongation: just set the time integration
180 dummyTr.StartTimeIntegral();
181 dummyTr.AddTimeStep(TMath::Sqrt(dst));
182 dummyTr.GetIntegratedTimes(times);
183 esdTr->SetIntegratedTimes(times);
184 esdTr->SetIntegratedLength(dummyTr.GetIntegratedLength());
188 currTr = GetTrackHyp(itr);
189 currTr->StartTimeIntegral();
190 currTr->AddTimeStep(dst);
191 currTr->ResetCovariance(10.);
192 RefitTrack(currTr,fITS->GetRMax()); // propagate to exit from the ITS/TPC screen
199 //_________________________________________________________________________
200 Int_t AliITSUTrackerGlo::RefitInward(AliESDEvent * /*event*/)
206 Info("RefitInward","To be implemented");
210 //_________________________________________________________________________
211 Int_t AliITSUTrackerGlo::LoadClusters(TTree * treeRP)
213 // read from tree (if pointer provided) or directly from the ITS reco interface
215 return fReconstructor->LoadClusters(treeRP);
218 //_________________________________________________________________________
219 void AliITSUTrackerGlo::UnloadClusters()
225 Info("UnloadClusters","To be implemented");
227 //_________________________________________________________________________
228 AliCluster * AliITSUTrackerGlo::GetCluster(Int_t /*index*/) const
234 Info("GetCluster","To be implemented");
238 //_________________________________________________________________________
239 Bool_t AliITSUTrackerGlo::NeedToProlong(AliESDtrack* esdTr)
241 // do we need to match this track to ITS?
243 static double bz = GetBz();
244 if (!esdTr->IsOn(AliESDtrack::kTPCin) ||
245 esdTr->IsOn(AliESDtrack::kTPCout) ||
246 esdTr->IsOn(AliESDtrack::kITSin) ||
247 esdTr->GetKinkIndex(0)>0) return kFALSE;
249 if (esdTr->Pt()<AliITSUReconstructor::GetRecoParam()->GetMinPtForProlongation()) return kFALSE;
252 esdTr->GetDZ(GetX(),GetY(),GetZ(),bz,dtz);
253 // if track is not V0 candidata but has large offset wrt IP, reject it. RS TOCHECK
254 if ( !(esdTr->GetV0Index(0)>0 && dtz[0]>AliITSUReconstructor::GetRecoParam()->GetMaxDforV0dghtrForProlongation())
255 && (Abs(dtz[0])>AliITSUReconstructor::GetRecoParam()->GetMaxDForProlongation() ||
256 Abs(dtz[1])>AliITSUReconstructor::GetRecoParam()->GetMaxDZForProlongation())) return kFALSE;
261 //_________________________________________________________________________
262 void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr, Int_t esdID)
264 // find prolongaion candidates finding for single seed
266 AliITSUSeed seedUC; // copy of the seed from the upper layer
267 AliITSUSeed seedT; // transient seed between the seedUC and new prolongation hypothesis
269 if (!InitHypothesis(esdTr,esdID)) return; // initialize prolongations hypotheses tree
271 AliITSURecoSens *hitSens[AliITSURecoSens::kNNeighbors+1];
273 TObjArray clArr; // container for transfer of clusters matching to seed
275 int nLrActive = fITS->GetNLayersActive();
276 for (int ila=nLrActive;ila--;) {
277 int ilaUp = ila+1; // prolong seeds from layer above
279 // for the outermost layer the seed is created from the ESD track
280 int nSeedsUp = (ilaUp==nLrActive) ? 1 : fCurrHyp->GetNSeeds(ilaUp);
282 for (int isd=0;isd<nSeedsUp;isd++) {
284 if (ilaUp==nLrActive) {
286 seedUC.InitFromESDTrack(esdTr);
289 seedU = fCurrHyp->GetSeed(ilaUp,isd); // seed on prev.active layer to prolong
290 seedUC = *seedU; // its copy will be prolonged
291 seedUC.SetParent(seedU);
293 seedUC.ResetFMatrix(); // reset the matrix for propagation to next layer
294 // go till next active layer
295 AliInfo(Form("working on Lr:%d Seed:%d of %d",ila,isd,nSeedsUp));
296 if (!TransportToLayer(&seedUC, fITS->GetLrIDActive(ilaUp), fITS->GetLrIDActive(ila)) ) {
298 AliInfo("Transport failed");
299 // Check if the seed satisfies to track definition
300 if (NeedToKill(&seedUC,kTransportFailed) && seedU) seedU->Kill();
301 continue; // RS TODO: decide what to do with tracks stopped on higher layers w/o killing
303 AliITSURecoLayer* lrA = fITS->GetLayerActive(ila);
304 if (!GetRoadWidth(&seedUC, ila)) { // failed to find road width on the layer
305 if (NeedToKill(&seedUC,kRWCheckFailed) && seedU) seedU->Kill();
308 int nsens = lrA->FindSensors(&fTrImpData[kTrPhi0], hitSens); // find detectors which may be hit by the track
309 AliInfo(Form("Will check %d sensors on lr:%d ",nsens,ila));
312 for (int isn=nsens;isn--;) {
314 AliITSURecoSens* sens = hitSens[isn];
316 // We need to propagate the seed to sensor on lrA staying the frame of the sensor from prev.layer,
317 // since the transport matrix should be defined in this frame.
318 double xs; // X in the TF of current seed, corresponding to intersection with sensor plane
319 if (!seedT.GetTrackingXAtXAlpha(sens->GetXTF(),sens->GetPhiTF(),bz, xs)) continue;
320 if (!PropagateSeed(&seedT,xs,fCurrMass)) continue;
321 // if (!seedT.PropagateToX(xs,bz)) continue;
322 // if (!seedT.Rotate(sens->GetPhiTF())) continue;
323 if (!seedT.RotateToAlpha(sens->GetPhiTF())) continue;
325 int clID0 = sens->GetFirstClusterId();
326 for (int icl=sens->GetNClusters();icl--;) {
327 int res = CheckCluster(&seedT,ila,clID0+icl);
329 if (res==kStopSearchOnSensor) break; // stop looking on this sensor
330 if (res==kClusterNotMatching) continue; // cluster does not match
331 // cluster is matching and it was added to the hypotheses tree
334 // cluster search is done. Do we need ta have a version of this seed skipping current layer
336 if (!NeedToKill(&seedT,kMissingCluster)) {
337 AliITSUSeed* seedSkp = NewSeedFromPool(&seedT);
338 double penalty = -AliITSUReconstructor::GetRecoParam()->GetMissPenalty(ila);
339 // to do: make penalty to account for probability to miss the cluster for good reason
340 seedSkp->SetChi2Cl(penalty);
341 AddProlongationHypothesis(seedSkp,ila);
344 ((TObjArray*)fCurrHyp->GetLayerSeeds(ila))->Sort();
345 printf(">>> All hypotheses on lr %d: \n",ila);
346 for (int ih=0;ih<fCurrHyp->GetNSeeds(ila);ih++) {
347 printf(" #%3d ",ih); fCurrHyp->GetSeed(ila,ih)->Print();
350 if (ila!=0) continue;
351 double vecL[5] = {0};
352 double matL[15] = {0};
353 AliITSUSeed* sp = fCurrHyp->GetSeed(ila,ih);
354 while(sp->GetParent()) {
355 sp->Smooth(vecL,matL);
356 if (sp->GetLayerID()>=fITS->GetNLayersActive()-1) break;
357 sp = (AliITSUSeed*)sp->GetParent();
363 SaveCurrentTrackHypotheses();
367 //_________________________________________________________________________
368 Bool_t AliITSUTrackerGlo::InitHypothesis(AliESDtrack *esdTr, Int_t esdID)
370 // init prolongaion candidates finding for single seed
371 fCurrHyp = GetTrackHyp(esdID);
372 if (fCurrHyp) return kTRUE;
374 fCurrMass = esdTr->GetMass();
375 fCurrESDtrack = esdTr;
376 if (fCurrMass<kPionMass*0.9) fCurrMass = kPionMass; // don't trust to mu, e identification from TPCin
378 fCurrHyp = new AliITSUTrackHyp(fITS->GetNLayersActive());
379 fCurrHyp->SetESDTrack(esdTr);
380 fCurrHyp->SetUniqueID(esdID);
381 fCurrHyp->SetMass(fCurrMass);
382 SetTrackHyp(fCurrHyp,esdID);
388 //_________________________________________________________________________
389 Bool_t AliITSUTrackerGlo::TransportToLayer(AliITSUSeed* seed, Int_t lFrom, Int_t lTo)
391 // transport seed from layerFrom to the entrance of layerTo
393 const double kToler = 1e-6; // tolerance for layer on-surface check
396 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
398 int dir = lTo > lFrom ? 1:-1;
399 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
400 Bool_t checkFirst = kTRUE;
402 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
404 Bool_t doLayer = kTRUE;
405 double xToGo = lrFr->GetR(dir);
406 if (checkFirst) { // do we need to track till the surface of the current layer ?
408 if (dir>0) { if (curR2-xToGo*xToGo>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
409 else if (dir<0) { if (xToGo*xToGo-curR2>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
412 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
413 // go via layer to its boundary, applying material correction.
414 if (!PropagateSeed(seed,xToGo,fCurrMass, lrFr->GetMaxStep())) return kFALSE;
417 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
418 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
420 // go the entrance of the layer, assuming no materials in between
421 double xToGo = lrTo->GetR(-dir);
422 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
423 if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) return kFALSE;
430 //_________________________________________________________________________
431 Bool_t AliITSUTrackerGlo::TransportToLayer(AliExternalTrackParam* seed, Int_t lFrom, Int_t lTo)
433 // transport track from layerFrom to the entrance of layerTo
435 const double kToler = 1e-6; // tolerance for layer on-surface check
437 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
439 int dir = lTo > lFrom ? 1:-1;
440 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
441 Bool_t checkFirst = kTRUE;
443 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
445 Bool_t doLayer = kTRUE;
446 double xToGo = lrFr->GetR(dir);
447 if (checkFirst) { // do we need to track till the surface of the current layer ?
449 if (dir>0) { if (curR2-xToGo*xToGo>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
450 else if (dir<0) { if (xToGo*xToGo-curR2>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
453 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
454 // go via layer to its boundary, applying material correction.
455 if (!PropagateSeed(seed,xToGo,fCurrMass, lrFr->GetMaxStep())) return kFALSE;
458 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
459 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
461 // go the entrance of the layer, assuming no materials in between
462 double xToGo = lrTo->GetR(-dir);
463 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
464 if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) return kFALSE;
471 //_________________________________________________________________________
472 Bool_t AliITSUTrackerGlo::GetRoadWidth(AliITSUSeed* seed, int ilrA)
474 // calculate road width in terms of phi and z for the track which MUST be on the external radius of the layer
475 // as well as some aux info
477 AliITSURecoLayer* lrA = fITS->GetLayerActive(ilrA);
478 seed->GetXYZ(&fTrImpData[kTrXIn]); // lab position at the entrance from above
479 static AliExternalTrackParam sc; // seed copy for manipalitions
482 fTrImpData[kTrPhiIn] = ATan2(fTrImpData[kTrYIn],fTrImpData[kTrXIn]);
483 if (!sc.Rotate(fTrImpData[kTrPhiIn])) return kFALSE; // go to the frame of the entry point into the layer
484 double dr = lrA->GetDR(); // approximate X dist at the inner radius
485 if (!sc.GetXYZAt(sc.GetX()-dr, bz, fTrImpData + kTrXOut)) {
486 // special case: track does not reach inner radius, might be tangential
487 double r = sc.GetD(0,0,bz);
489 if (!sc.GetXatLabR(r,x,bz,-1)) {
491 AliFatal(Form("This should not happen: r=%f",r));
493 dr = Abs(sc.GetX() - x);
494 if (!sc.GetXYZAt(x, bz, fTrImpData + kTrXOut)) {
496 AliFatal(Form("This should not happen: x=%f",x));
500 fTrImpData[kTrPhiOut] = ATan2(fTrImpData[kTrYOut],fTrImpData[kTrXOut]);
501 double sgy = sc.GetSigmaY2() + dr*dr*sc.GetSigmaSnp2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(ilrA);
502 double sgz = sc.GetSigmaZ2() + dr*dr*sc.GetSigmaTgl2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(ilrA);
503 sgy = Sqrt(sgy)*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY();
504 sgz = Sqrt(sgz)*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ();
505 fTrImpData[kTrPhi0] = 0.5*(fTrImpData[kTrPhiOut]+fTrImpData[kTrPhiIn]);
506 fTrImpData[kTrZ0] = 0.5*(fTrImpData[kTrZOut]+fTrImpData[kTrZIn]);
507 fTrImpData[kTrDPhi] = 0.5*Abs(fTrImpData[kTrPhiOut]-fTrImpData[kTrPhiIn]) + sgy/lrA->GetR();
508 fTrImpData[kTrDZ] = 0.5*Abs(fTrImpData[kTrZOut]-fTrImpData[kTrZIn]) + sgz;
513 //_________________________________________________________________________
514 AliITSUSeed* AliITSUTrackerGlo::NewSeedFromPool(const AliITSUSeed* src)
516 // create new seed, optionally copying from the source
518 new(fSeedsPool[fSeedsPool.GetEntriesFast()]) AliITSUSeed(*src) :
519 new(fSeedsPool[fSeedsPool.GetEntriesFast()]) AliITSUSeed();
522 //_________________________________________________________________________
523 Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
525 // Check if the cluster (in tracking frame!) is matching to track.
526 // The track must be already propagated to sensor tracking frame.
527 // Returns: kStopSearchOnSensor if the search on given sensor should be stopped,
528 // kClusterMatching if the cluster is matching
529 // kClusterMatching otherwise
531 const double kTolerX = 5e-4;
532 AliCluster *cl = fITS->GetLayerActive(lr)->GetCluster(clID);
534 Bool_t goodCl = kFALSE;
535 int currLabel = Abs(fCurrESDtrack->GetTPCLabel());
537 if (cl->GetLabel(0)>=0) {
538 for (int i=0;i<3;i++) if (cl->GetLabel(i)>=0 && cl->GetLabel(i)==currLabel) {goodCl = kTRUE; break;}
542 if (TMath::Abs(cl->GetX())>kTolerX) { // if due to the misalingment X is large, propagate track only
543 if (!track->PropagateParamOnlyTo(track->GetX()+cl->GetX(),GetBz())) {
544 if (goodCl) {printf("Loose good cl: Failed propagation. |"); cl->Print();}
545 return kStopSearchOnSensor; // propagation failed, seedT is intact
548 double dy = cl->GetY()-track->GetY();
549 double dz = cl->GetZ()-track->GetZ();
552 double tol2 = (track->GetSigmaY2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(lr))*
553 AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY()*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY(); // RS TOOPTIMIZE
554 if (dy2>tol2) { // the clusters are sorted in Z(col) then in Y(row).
555 if (goodCl) {printf("Loose good cl: dy2=%e > tol2=%e |",dy2,tol2); cl->Print();}
556 if (dy>0) return kStopSearchOnSensor; // No chance that other cluster of this sensor will match (all Y's will be even larger)
557 else return kClusterNotMatching; // Other clusters may match
560 tol2 = (track->GetSigmaZ2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(lr))*
561 AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ()*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ(); // RS TOOPTIMIZE
563 if (goodCl) {printf("Loose good cl: dz2=%e > tol2=%e |",dz2,tol2); cl->Print();}
564 return kClusterNotMatching; // Other clusters may match
568 Double_t p[2]={cl->GetY(), cl->GetZ()};
569 Double_t cov[3]={cl->GetSigmaY2(), cl->GetSigmaYZ(), cl->GetSigmaZ2()};
570 double chi2 = track->GetPredictedChi2(p,cov);
571 if (chi2>AliITSUReconstructor::GetRecoParam()->GetMaxTr2ClChi2(lr)) {
573 printf("Loose good cl: Chi2=%e > Chi2Max=%e |dy: %+.3e dz: %+.3e\n",
574 chi2,AliITSUReconstructor::GetRecoParam()->GetMaxTr2ClChi2(lr),dy,dz);
578 return kClusterNotMatching;
581 track = NewSeedFromPool(track); // input track will be reused, use its clone for updates
582 if (!track->Update()) {
583 if (goodCl) {printf("Loose good cl: Failed update |"); cl->Print();}
584 return kClusterNotMatching;
586 track->SetChi2Cl(chi2);
587 track->SetLrClusterID(lr,clID);
588 cl->IncreaseClusterUsage();
590 track->SetFake(!goodCl);
592 AliInfo(Form("AddCl(%d) Cl%d lr:%d: dY:%+8.4f dZ:%+8.4f (MC: %5d %5d %5d) |Chi2=%f(%c)",
593 goodCl,clID,lr,dy,dz2,cl->GetLabel(0),cl->GetLabel(1),cl->GetLabel(2), chi2, track->IsFake() ? '-':'+'));
595 AddProlongationHypothesis(track,lr);
597 return kClusterMatching;
600 //_________________________________________________________________________
601 Bool_t AliITSUTrackerGlo::NeedToKill(AliITSUSeed *seed, Int_t flag)
603 // check if the seed should not be discarded
604 const UShort_t kMask = 0xffff;
605 if (flag==kMissingCluster) {
606 int lastChecked = seed->GetLayerID();
607 UShort_t patt = seed->GetHitsPattern();
608 if (lastChecked) patt |= ~(kMask<<lastChecked); // not all layers were checked, complete unchecked once by potential hits
609 Bool_t seedOK = fTrCond.CheckPattern(patt);
615 //______________________________________________________________________________
616 Bool_t AliITSUTrackerGlo::PropagateSeed(AliITSUSeed *seed, Double_t xToGo, Double_t mass, Double_t maxStep, Bool_t matCorr)
618 // propagate seed to given x applying material correction if requested
619 const Double_t kEpsilon = 1e-5;
620 Double_t xpos = seed->GetX();
621 Int_t dir = (xpos<xToGo) ? 1:-1;
622 Double_t xyz0[3],xyz1[3],param[7];
624 Bool_t updTime = dir>0 && seed->IsStartedTimeIntegral();
625 if (matCorr) seed->GetXYZ(xyz1); //starting global position
626 while ( (xToGo-xpos)*dir > kEpsilon){
627 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
628 Double_t x = xpos+step;
629 Double_t bz=GetBz(); // getting the local Bz
630 if (!seed->PropagateToX(x,bz)) return kFALSE;
632 if (matCorr || updTime) {
633 xyz0[0]=xyz1[0]; // global pos at the beginning of step
636 seed->GetXYZ(xyz1); // // global pos at the end of step
638 MeanMaterialBudget(xyz0,xyz1,param);
639 Double_t xrho=param[0]*param[4], xx0=param[1];
640 if (dir>0) xrho = -xrho; // outward should be negative
641 if (!seed->ApplyMaterialCorrection(xx0,xrho,mass,kFALSE)) return kFALSE;
644 else { // matCorr is not requested but time integral is
645 double d0 = xyz1[0]-xyz0[0];
646 double d1 = xyz1[1]-xyz0[1];
647 double d2 = xyz1[2]-xyz0[2];
648 ds = TMath::Sqrt(d0*d0+d1*d1+d2*d2);
651 if (updTime) seed->AddTimeStep(ds);
657 //______________________________________________________________________________
658 Bool_t AliITSUTrackerGlo::PropagateSeed(AliExternalTrackParam *seed, Double_t xToGo, Double_t mass, Double_t maxStep, Bool_t matCorr)
660 // propagate seed to given x applying material correction if requested
661 const Double_t kEpsilon = 1e-5;
662 Double_t xpos = seed->GetX();
663 Int_t dir = (xpos<xToGo) ? 1:-1;
664 Double_t xyz0[3],xyz1[3],param[7];
666 Bool_t updTime = dir>0 && seed->IsStartedTimeIntegral();
667 if (matCorr || updTime) seed->GetXYZ(xyz1); //starting global position
668 while ( (xToGo-xpos)*dir > kEpsilon){
669 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
670 Double_t x = xpos+step;
671 Double_t bz=GetBz(); // getting the local Bz
672 if (!seed->PropagateTo(x,bz)) return kFALSE;
674 if (matCorr || updTime) {
675 xyz0[0]=xyz1[0]; // global pos at the beginning of step
678 seed->GetXYZ(xyz1); // // global pos at the end of step
681 MeanMaterialBudget(xyz0,xyz1,param);
682 Double_t xrho=param[0]*param[4], xx0=param[1];
683 if (dir>0) xrho = -xrho; // outward should be negative
684 if (!seed->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
687 else { // matCorr is not requested but time integral is
688 double d0 = xyz1[0]-xyz0[0];
689 double d1 = xyz1[1]-xyz0[1];
690 double d2 = xyz1[2]-xyz0[2];
691 ds = TMath::Sqrt(d0*d0+d1*d1+d2*d2);
694 if (updTime) seed->AddTimeStep(ds);
701 //______________________________________________________________________________
702 void AliITSUTrackerGlo::SaveCurrentTrackHypotheses()
704 // RS: shall we clean up killed seeds?
710 //______________________________________________________________________________
711 void AliITSUTrackerGlo::FinalizeHypotheses()
713 // select winner for each hypothesis, remove cl. sharing conflicts
716 int nh = fHypStore.GetEntriesFast();
717 for (int ih=0;ih<nh;ih++) {
718 AliITSUTrackHyp* hyp = (AliITSUTrackHyp*) fHypStore.UncheckedAt(ih);
720 hyp->DefineWinner(); // TODO
726 //______________________________________________________________________________
727 void AliITSUTrackerGlo::UpdateESDTrack(AliITSUTrackHyp* hyp)
729 // update ESD track with current best hypothesis
730 AliESDtrack* esdTr = hyp->GetESDTrack();
732 AliITSUSeed* win = hyp->GetWinner();
734 esdTr->UpdateTrackParams(hyp,AliESDtrack::kITSin);
736 // transfer module indices
740 //______________________________________________________________________________
741 Bool_t AliITSUTrackerGlo::RefitTrack(AliITSUTrackHyp* trc, Double_t rDest)
743 // refit track till radius rDest
744 AliITSUTrackHyp tmpTr;
746 double rCurr = Sqrt(trc->GetX()*trc->GetX() + trc->GetY()*trc->GetY());
747 int dir,lrStart,lrStop;
749 dir = rCurr<rDest ? 1 : -1;
750 lrStart = fITS->FindFirstLayerID(rCurr,dir);
751 lrStop = fITS->FindLastLayerID(rDest,dir);
752 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));
754 trc->FetchClusterInfo(fClInfo);
755 fCurrMass = trc->GetMass();
756 tmpTr.AliKalmanTrack::operator=(*trc);
760 for (int ilr=lrStart;ilr!=lrStop;ilr+=dir) {
761 AliITSURecoLayer* lr = fITS->GetLayer(ilr);
762 if ( dir*(rCurr-lr->GetR(dir))>0) continue; // this layer is already passed
763 int ilrA2,ilrA = lr->GetActiveID();
764 // passive layer or active w/o hits will be traversed on the way to next cluster
765 if (!lr->IsActive() || fClInfo[ilrA2=(ilrA<<1)]<0) continue;
767 if (!TransportToLayer(&tmpTr,lrStart,ilr)) return kFALSE;
770 // select the order in which possible 2 clusters (in case of the overlap) will be traversed and fitted
772 if (dir>0) { // clusters are stored in increasing radius order
773 iclLr[nclLr++]=fClInfo[ilrA2++];
774 if (fClInfo[ilrA2]>=0) iclLr[nclLr++]=fClInfo[ilrA2];
777 if ( fClInfo[ilrA2+1]>=0 ) iclLr[nclLr++]=fClInfo[ilrA2+1];
778 iclLr[nclLr++]=fClInfo[ilrA2];
781 for (int icl=0;icl<nclLr;icl++) {
782 AliITSUClusterPix* clus = (AliITSUClusterPix*)lr->GetCluster(iclLr[icl]);
783 AliITSURecoSens* sens = lr->GetSensorFromID(clus->GetVolumeId());
784 if (!tmpTr.Rotate(sens->GetPhiTF())) return kFALSE;
785 if (!PropagateSeed(&tmpTr,sens->GetXTF()+clus->GetX(),fCurrMass)) return kFALSE;
786 if (!tmpTr.Update(clus)) return kFALSE;
790 // All clusters were succesfully fitted. Even if the track does not reach rDest, this is enough to validate it.
791 // Still, try to go as close as possible to rDest.
793 if (lrStart!=lrStop) {
794 if (!TransportToLayer(&tmpTr,lrStart,lrStop)) return kTRUE;
795 // go to the exit from layer
798 trc->AliKalmanTrack::operator=(tmpTr);