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 ClassImp(AliITSUTrackerGlo)
44 //_________________________________________________________________________
45 AliITSUTrackerGlo::AliITSUTrackerGlo(AliITSUReconstructor* rec)
50 ,fSeedsPool("AliITSUSeed",0)
52 // Default constructor
56 //_________________________________________________________________________
57 AliITSUTrackerGlo::~AliITSUTrackerGlo()
66 //_________________________________________________________________________
67 void AliITSUTrackerGlo::Init(AliITSUReconstructor* rec)
69 // init with external reconstructor
71 fITS = new AliITSURecoDet(rec->GetGeom(),"ITSURecoInterface");
72 for (int ilr=fITS->GetNLayersActive();ilr--;) {
73 fITS->GetLayerActive(ilr)->SetClusters(rec->GetClusters(ilr));
76 fSeedsPool.ExpandCreateFast(1000); // RS TOCHECK
77 int n = fITS->GetNLayersActive()+1;
78 fSeedsLr = new TObjArray[n];
83 //_________________________________________________________________________
84 Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
88 AliITSUReconstructor::GetRecoParam()->Print();
90 fITS->ProcessClusters();
91 // select ESD tracks to propagate
92 int nTrESD = esdEv->GetNumberOfTracks();
93 for (int itr=0;itr<nTrESD;itr++) {
94 printf("Processing track %d\n",itr);
95 AliESDtrack *esdTr = esdEv->GetTrack(itr);
102 //_________________________________________________________________________
103 Int_t AliITSUTrackerGlo::PropagateBack(AliESDEvent * /*event*/)
109 Info("PropagateBack","To be implemented");
113 //_________________________________________________________________________
114 Int_t AliITSUTrackerGlo::RefitInward(AliESDEvent * /*event*/)
120 Info("RefitInward","To be implemented");
124 //_________________________________________________________________________
125 Int_t AliITSUTrackerGlo::LoadClusters(TTree * treeRP)
127 // read from tree (if pointer provided) or directly from the ITS reco interface
129 return fReconstructor->LoadClusters(treeRP);
132 //_________________________________________________________________________
133 void AliITSUTrackerGlo::UnloadClusters()
139 Info("UnloadClusters","To be implemented");
141 //_________________________________________________________________________
142 AliCluster * AliITSUTrackerGlo::GetCluster(Int_t /*index*/) const
148 Info("GetCluster","To be implemented");
152 //_________________________________________________________________________
153 Bool_t AliITSUTrackerGlo::NeedToProlong(AliESDtrack* esdTr)
155 // do we need to match this track to ITS?
157 static double bz = GetBz();
158 if (!esdTr->IsOn(AliESDtrack::kTPCin) ||
159 esdTr->IsOn(AliESDtrack::kTPCout) ||
160 esdTr->IsOn(AliESDtrack::kITSin) ||
161 esdTr->GetKinkIndex(0)>0) return kFALSE;
163 if (esdTr->Pt()<AliITSUReconstructor::GetRecoParam()->GetMinPtForProlongation()) return kFALSE;
166 esdTr->GetDZ(GetX(),GetY(),GetZ(),bz,dtz);
167 // if track is not V0 candidata but has large offset wrt IP, reject it. RS TOCHECK
168 if ( !(esdTr->GetV0Index(0)>0 && dtz[0]>AliITSUReconstructor::GetRecoParam()->GetMaxDforV0dghtrForProlongation())
169 && (Abs(dtz[0])>AliITSUReconstructor::GetRecoParam()->GetMaxDForProlongation() ||
170 Abs(dtz[1])>AliITSUReconstructor::GetRecoParam()->GetMaxDZForProlongation())) return kFALSE;
175 //_________________________________________________________________________
176 void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr)
178 // find prolongaion candidates finding for single seed
180 if (!NeedToProlong(esdTr)) return; // are we interested in this track?
181 if (!InitSeed(esdTr)) return; // initialize prolongations hypotheses tree
183 AliITSURecoSens *hitSens[AliITSURecoSens::kNNeighbors+1];
184 AliITSUSeed seedUC; // copy of the seed from the upper layer
185 AliITSUSeed seedT; // transient seed between the seedUC and new prolongation hypothesis
187 TObjArray clArr; // container for transfer of clusters matching to seed
189 for (int ila=fITS->GetNLayersActive();ila--;) {
190 int ilaUp = ila+1; // prolong seeds from layer above
191 int nSeedsUp = GetNSeeds(ilaUp);
192 printf("NSeeds %d\n",nSeedsUp);
193 for (int isd=0;isd<nSeedsUp;isd++) {
194 AliITSUSeed* seedU = GetSeed(ilaUp,isd); // seed on prev.active layer to prolong
196 seedUC.SetParent(seedU);
197 // go till next active layer
198 printf("Lr:%d Seed:%d\n",ila,isd);
199 if (!TransportToLayer(&seedUC, fITS->GetLrIDActive(ilaUp), fITS->GetLrIDActive(ila)) ) {
201 printf("Tr failed\n");
202 // Check if the seed satisfies to track definition
203 if (NeedToKill(&seedUC,kTransportFailed)) KillSeed(ilaUp,isd);
204 continue; // RS TODO: decide what to do with tracks stopped on higher layers w/o killing
206 AliITSURecoLayer* lrA = fITS->GetLayerActive(ila);
207 if (!GetRoadWidth(&seedUC, ila)) { // failed to find road width on the layer
208 if (NeedToKill(&seedUC,kRWCheckFailed)) KillSeed(ilaUp,isd);
211 int nsens = lrA->FindSensors(&fTrImpData[kTrPhi0], hitSens); // find detectors which may be hit by the track
212 printf("Lr:%d Ns:%d\n",ila, nsens);
214 for (int isn=nsens;isn--;) {
216 AliITSURecoSens* sens = hitSens[isn];
218 if (!seedT.Propagate(sens->GetPhiTF(),sens->GetXTF(),GetBz())) continue; // propagation failed, seedT is intact
219 int clID0 = sens->GetFirstClusterId();
220 printf("Sn:%d Ncl:%d\n",isn,sens->GetNClusters());
221 for (int icl=sens->GetNClusters();icl--;) {
222 int res = CheckCluster(&seedT,ila,clID0+icl);
224 if (res==kStopSearchOnSensor) break; // stop looking on this sensor
225 if (res==kClusterNotMatching) continue; // cluster does not match
226 // cluster is matching and it was added to the hypotheses tree
229 // cluster search is done. Do we need ta have a version of this seed skipping current layer
231 if (!NeedToKill(&seedT,kMissingCluster)) AddProlongationHypothesis(NewSeedFromPool(&seedT) ,ila);
238 //_________________________________________________________________________
239 Bool_t AliITSUTrackerGlo::InitSeed(AliESDtrack *esdTr)
241 // init prolongaion candidates finding for single seed
242 fCurrMass = esdTr->GetMass();
243 if (fCurrMass<kPionMass*0.9) fCurrMass = kPionMass; // don't trust to mu, e identification from TPCin
245 AliITSUSeed* seed = NewSeedFromPool();
246 seed->SetLr(fITS->GetNLayersActive()); // fake layer
247 seed->AliExternalTrackParam::operator=(*esdTr);
248 seed->SetParent(esdTr);
249 AddProlongationHypothesis(seed,fITS->GetNLayersActive());
254 //_________________________________________________________________________
255 void AliITSUTrackerGlo::ResetSeedTree()
257 // reset current hypotheses tree
258 for (int i=fITS->GetNLayersActive()+1;i--;) fSeedsLr[fITS->GetNLayersActive()].Clear();
261 //_________________________________________________________________________
262 Bool_t AliITSUTrackerGlo::TransportToLayer(AliITSUSeed* seed, Int_t lFrom, Int_t lTo)
264 // transport seed from layerFrom to the entrance of layerTo
266 const double kToler = 1e-6; // tolerance for layer on-surface check
268 int dir = lTo > lFrom ? 1:-1;
269 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
270 Bool_t checkFirst = kTRUE;
272 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
274 Bool_t doLayer = kTRUE;
275 double xToGo = dir>0 ? lrFr->GetRMax() : lrFr->GetRMin();
276 if (checkFirst) { // do we need to track till the surface of the current layer ?
278 if (dir>0) { if (curR2-xToGo*xToGo>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
279 else if (dir<0) { if (xToGo*xToGo-curR2>kToler) doLayer = kFALSE; } // on the surface or outside of the layer
282 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
283 // go via layer to its boundary, applying material correction.
284 if (!PropagateTrackTo(seed,xToGo,fCurrMass, lrFr->GetMaxStep(), kFALSE, -1, 0, kTRUE)) return kFALSE;
287 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
288 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
290 // go the entrance of the layer, assuming no materials in between
291 double xToGo = dir>0 ? lrTo->GetRMin() : lrTo->GetRMax();
292 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
293 if (!seed->PropagateTo(xToGo, GetBz())) return kFALSE; // RS: do we need BxByBz?
300 //_________________________________________________________________________
301 Bool_t AliITSUTrackerGlo::GetRoadWidth(AliITSUSeed* seed, int ilrA)
303 // calculate road width in terms of phi and z for the track which MUST be on the external radius of the layer
304 // as well as some aux info
306 AliITSURecoLayer* lrA = fITS->GetLayerActive(ilrA);
307 seed->GetXYZ(&fTrImpData[kTrXIn]); // lab position at the entrance from above
309 fTrImpData[kTrPhiIn] = ATan2(fTrImpData[kTrYIn],fTrImpData[kTrXIn]);
310 if (!seed->Rotate(fTrImpData[kTrPhiIn])) return kFALSE; // go to the frame of the entry point into the layer
311 double dr = lrA->GetDR(); // approximate X dist at the inner radius
312 if (!seed->GetXYZAt(seed->GetX()-dr, bz, fTrImpData + kTrXOut)) {
313 // special case: track does not reach inner radius, might be tangential
314 double r = seed->GetD(0,0,bz);
316 if (!seed->GetXatLabR(r,x,bz,-1)) {
317 AliError(Form("This should not happen: r=%f",r));
321 dr = Abs(seed->GetX() - x);
322 if (!seed->GetXYZAt(x, bz, fTrImpData + kTrXOut)) {
323 AliError(Form("This should not happen: x=%f",x));
329 fTrImpData[kTrPhiOut] = ATan2(fTrImpData[kTrYOut],fTrImpData[kTrXOut]);
330 double sgy = seed->GetSigmaY2() + dr*dr*seed->GetSigmaSnp2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(ilrA);
331 double sgz = seed->GetSigmaZ2() + dr*dr*seed->GetSigmaTgl2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(ilrA);
332 sgy = Sqrt(sgy)*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY();
333 sgz = Sqrt(sgz)*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ();
334 fTrImpData[kTrPhi0] = 0.5*(fTrImpData[kTrPhiOut]+fTrImpData[kTrPhiIn]);
335 fTrImpData[kTrZ0] = 0.5*(fTrImpData[kTrZOut]+fTrImpData[kTrZIn]);
336 fTrImpData[kTrDPhi] = 0.5*Abs(fTrImpData[kTrPhiOut]-fTrImpData[kTrPhiIn]) + sgy/lrA->GetR();
337 fTrImpData[kTrDZ] = 0.5*Abs(fTrImpData[kTrZOut]-fTrImpData[kTrZIn]) + sgz;
342 //_________________________________________________________________________
343 AliITSUSeed* AliITSUTrackerGlo::NewSeedFromPool(const AliITSUSeed* src)
345 // create new seed, optionally copying from the source
347 new(fSeedsPool[fSeedsPool.GetEntriesFast()]) AliITSUSeed(*src) :
348 new(fSeedsPool[fSeedsPool.GetEntriesFast()]) AliITSUSeed();
351 //_________________________________________________________________________
352 Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
354 // Check if the cluster (in tracking frame!) is matching to track.
355 // The track must be already propagated to sensor tracking frame.
356 // Returns: kStopSearchOnSensor if the search on given sensor should be stopped,
357 // kClusterMatching if the cluster is matching
358 // kClusterMatching otherwise
360 // The seed is already propagated to cluster
361 const double kTolerX = 5e-4;
362 AliCluster *cl = fITS->GetLayerActive(lr)->GetCluster(clID);
364 if (TMath::Abs(cl->GetX())>kTolerX) { // if due to the misalingment X is large, propagate track only
365 if (!track->PropagateParamOnlyTo(track->GetX()+cl->GetX(),GetBz())) return kStopSearchOnSensor; // propagation failed, seedT is intact
367 double dy = cl->GetY() - track->GetY();
369 double tol2 = (track->GetSigmaY2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(lr))*
370 AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY()*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadY(); // RS TOOPTIMIZE
371 if (dy2>tol2) { // the clusters are sorted in Z(col) then in Y(row).
372 if (dy>0) return kStopSearchOnSensor; // No chance that other cluster of this sensor will match (all Y's will be even larger)
373 else return kClusterNotMatching; // Other clusters may match
375 double dz2 = cl->GetZ()-track->GetZ();
377 tol2 = (track->GetSigmaZ2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(lr))*
378 AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ()*AliITSUReconstructor::GetRecoParam()->GetNSigmaRoadZ(); // RS TOOPTIMIZE
379 if (dz2>tol2) return kClusterNotMatching; // Other clusters may match
382 Double_t p[2]={cl->GetY(), cl->GetZ()};
383 Double_t cov[3]={cl->GetSigmaY2(), cl->GetSigmaYZ(), cl->GetSigmaZ2()};
384 double chi2 = track->GetPredictedChi2(p,cov);
385 if (chi2>AliITSUReconstructor::GetRecoParam()->GetMaxTr2ClChi2(lr)) return kClusterNotMatching;
387 track = NewSeedFromPool(track); // input track will be reused, use its clone for updates
388 if (!track->Update(p,cov)) return kClusterNotMatching;
389 track->SetChi2Cl(chi2);
390 track->SetLrClusterID(lr,clID);
391 cl->IncreaseClusterUsage();
393 AddProlongationHypothesis(track,lr);
395 return kClusterMatching;