1 //-------------------------------------------------------------------------
2 // Implementation of the ITS tracker class
3 // It reads AliITSUClusterPix clusters and and fills the ESD with tracks
4 //-------------------------------------------------------------------------
17 //#include "AliITSUTrackerSAauxVc.h" // Structs and other stuff using Vc library
19 #include "AliESDEvent.h"
20 #include "AliITSUClusterPix.h"
21 #include "AliITSUTrackerSA.h"
22 #include "AliITSUReconstructor.h"
23 #include "AliITSURecoDet.h"
24 #include "AliESDtrack.h"
26 #include <Riostream.h>
32 //#include "AliITSUtrackSA.h" // Some dedicated SA track class ?
34 ClassImp(AliITSUTrackerSA)
36 const Double_t AliITSUTrackerSA::fgkToler = 1e-6;// tolerance for layer on-surface check
38 //________________________________________________________________________________
39 AliITSUTrackerSA::AliITSUTrackerSA(AliITSUReconstructor* rec) :
56 //--------------------------------------------------------------------
57 // This default constructor needs to be provided
58 //--------------------------------------------------------------------
59 for(Int_t i=0;i<7;++i) {
60 fClusters[i].reserve(5000);
65 //________________________________________________________________________________
66 AliITSUTrackerSA::AliITSUTrackerSA(const AliITSUTrackerSA &t):
68 fReconstructor(t.fReconstructor),
71 fUseMatLUT(t.fUseMatLUT),
72 fCurrMass(t.fCurrMass),
83 //--------------------------------------------------------------------
84 // The copy constructor is protected
85 //--------------------------------------------------------------------
88 //________________________________________________________________________________
89 AliITSUTrackerSA::~AliITSUTrackerSA()
96 //_________________________________________________________________________
97 void AliITSUTrackerSA::Init(AliITSUReconstructor* rec)
99 // init with external reconstructor
101 fITS = rec->GetITSInterface();
103 // create material lookup table
104 const int kNTest = 1000;
105 const double kStepsPerCM=5;
106 fMatLUT = new AliITSUMatLUT(fITS->GetRMin(),fITS->GetRMax(),Nint(kStepsPerCM*(fITS->GetRMax()-fITS->GetRMin())));
108 for (int ilr=fITS->GetNLayers();ilr--;) {
109 AliITSURecoLayer* lr = fITS->GetLayer(ilr);
110 if (zmn>Abs(lr->GetZMin())) zmn = Abs(lr->GetZMin());
111 if (zmn>Abs(lr->GetZMax())) zmn = Abs(lr->GetZMax());
113 fMatLUT->FillData(kNTest,-zmn,zmn);
117 //________________________________________________________________________________
118 Int_t AliITSUTrackerSA::Clusters2Tracks(AliESDEvent *event) {
119 //--------------------------------------------------------------------
120 // This is the main tracking function
121 // The clusters must already be loaded
122 //--------------------------------------------------------------------
124 // Possibly, create the track "seeds" (combinatorial)
126 // Possibly, increment the seeds with additional clusters (Kalman)
128 // Possibly, (re)fit the found tracks
131 // - High momentum first;
132 // - Low momentum with vertex constraint;
133 // - Everything else.
135 MakeDoublets(); // To be implemented
136 //MakeTriplets(); // Are triplets really necessary? MFT does not use them.
138 //GlobalFit(); // To be implemented
139 //ChiSquareSelection(); // To be implemented
144 //________________________________________________________________________________
145 Int_t AliITSUTrackerSA::PropagateBack(AliESDEvent */*event*/) {
146 //--------------------------------------------------------------------
147 // Here, we implement the Kalman smoother ?
148 // The clusters must be already loaded
149 //--------------------------------------------------------------------
154 //________________________________________________________________________________
155 Int_t AliITSUTrackerSA::RefitInward(AliESDEvent */*event*/) {
156 //--------------------------------------------------------------------
157 // Some final refit, after the outliers get removed by the smoother ?
158 // The clusters must be loaded
159 //--------------------------------------------------------------------
164 Int_t AliITSUTrackerSA::LoadClusters(TTree *cluTree) {
165 //--------------------------------------------------------------------
166 // This function reads the ITSU clusters from the tree,
167 // sort them, distribute over the internal tracker arrays, etc
168 //--------------------------------------------------------------------
169 fITS->LoadClusters(cluTree);
170 fITS->ProcessClusters();
172 for(int iL=0; iL<7; ++iL) {
173 fClustersTC[iL]=*fITS->GetLayerActive(iL)->GetClustersAddress();
174 TClonesArray *clCont=fClustersTC[iL];
175 fNClusters[iL]=clCont->GetEntriesFast();
176 Float_t phi[fNClusters[iL]];
177 fIndex[iL] = new Int_t[fNClusters[iL]];
178 for(int iC=0;iC<fNClusters[iL];++iC) {
179 const AliITSUClusterPix *cl = (AliITSUClusterPix*)clCont->At(iC);
181 cl->GetGlobalXYZ(pos);
182 phi[iC] = pos[0]==0.f ? TMath::PiOver2() : TMath::ATan2(pos[1]-GetY(),pos[0]-GetX());
183 float angle=0.f; // TO BE UNDERSTOOD: DO I STILL NEED THE STATION ANGLE IF I USE THE GLOBAL COVARIANCE MATRIX?
184 fClusters[iL].push_back(itsCluster(pos[0],pos[1],pos[2],cl->GetSigmaY2(),cl->GetSigmaZ2(),cl->GetSigmaYZ(),phi[iC],angle));
186 TMath::Sort(fNClusters[iL],phi,fIndex[iL],kFALSE);
189 // PrintInfo("clusters");
194 //________________________________________________________________________________
195 void AliITSUTrackerSA::UnloadClusters() {
196 //--------------------------------------------------------------------
197 // This function unloads ITSU clusters from the RAM
198 //--------------------------------------------------------------------
199 for(int i=0;i<7;++i) {
200 fClusters[i].clear();
204 for(int i=0;i<6;++i) fDoublets[i].clear();
207 //________________________________________________________________________________
208 AliCluster *AliITSUTrackerSA::GetCluster(Int_t /*index*/) const {
209 //--------------------------------------------------------------------
210 // Return pointer to a given cluster
211 //--------------------------------------------------------------------
212 return 0; // replace with an actual pointer
215 //________________________________________________________________________________
216 void AliITSUTrackerSA::CASelection(AliESDEvent *event) {
217 // Here it's implemented the Cellular Automaton routine
218 // Firstly the level of each doublet is set according to the level of
219 // the neighbour doublets.
220 // Doublet are considered to be neighbour if they share one point and the
221 // phi and theta direction difference of the two is below a cut value.
223 cout << "Begin of the CA selection" << endl;
224 for( int iL = 1; iL < 6; ++iL ) {
226 const itsCluster* clusters1 = &fClusters[iL-1][0];
227 const itsCluster* clusters2 = &fClusters[iL][0];
228 const itsCluster* clusters3 = &fClusters[iL+1][0];
230 const nPlets* doublets1 = &fDoublets[iL-1][0];
231 nPlets* doublets2 = &fDoublets[iL][0];
233 for ( int iD2 = 0; iD2 < fNDoublets[iL]; ++iD2 ) {
234 for ( int iD1 = 0; iD1 < fNDoublets[iL-1]; ++iD1 ) {
235 const int id1 = doublets1[iD1].id0;
236 const int id2 = doublets2[iD2].id0;
238 if ( doublets2[iD2].level <= ( doublets1[iD1].level + 1 ) ) {
239 const int id3 = doublets2[iD2].id1;
240 const float r3 = Sqrt( clusters3[id3].x * clusters3[id3].x + clusters3[id3].y * clusters3[id3].y );
241 const float r2 = Sqrt( clusters2[id2].x * clusters2[id2].x + clusters2[id2].y * clusters2[id2].y );
242 const float extrZ3 = doublets1[iD1].tanLambda * ( r3 - r2 ) + clusters2[id2].z ;
243 //cout << extrZ3 << " " << clusters3[id3].z << " " << Abs ( extrZ3 - clusters3[id3].z ) << endl;
244 if ( Abs ( extrZ3 - clusters3[id3].z ) < fZCut ) {
245 //cout << "OK Z doublets: "<< iL-1 << "," << iD1 << "\t" << iL << "," <<iD2 << endl;
246 const float det = (clusters1[id1].x - GetX())*(clusters2[id2].y - GetY()) - (clusters2[id2].x-GetX() )*(clusters1[id1].y - GetY()); // (GetX() - clusters2[id2].x)*(clusters1[id1].y - clusters2[id2].y) - (GetY() - clusters2[id2].y)*(clusters1[id1].x - clusters2[id2].x);
247 //cout << det << endl;
248 if ( Abs(det) <= 1e-12 ) {
249 // linear extrapolation to next layer
250 const float dsq = ( doublets1[iD1].tanPhi * (clusters3[id3].x + clusters2[id2].x) + clusters3[id3].y - clusters2[id2].y ) *
251 ( doublets1[iD1].tanPhi * (clusters3[id3].x + clusters2[id2].x) + clusters3[id3].y - clusters2[id2].y ) / (1 + doublets1[iD1].tanPhi * doublets1[iD1].tanPhi );
252 if ( dsq < fRPhiCut*fRPhiCut ) {
253 doublets2[iD2].level += doublets1[iD1].level;
254 doublets2[iD2].neighbours.push_back(iD1);
257 const float r1sq = clusters1[id1].x * clusters1[id1].x + clusters1[id1].y * clusters1[id1].y ;
258 const float rvsq = GetX() * GetX() + GetY() * GetY();
259 const float deta = (rvsq - r1sq) * (clusters2[id2].y - GetY()) - (rvsq - r2*r2) * (clusters1[id1].y - GetY());
260 const float detb = - (rvsq - r1sq) * (clusters2[id2].x - GetX()) + (rvsq - r2*r2) * (clusters1[id1].x - GetX()) ;
261 const float a = deta/det ;
262 const float b = detb/det ;
263 const float c = -rvsq - a * GetX() - b * GetY();
264 const float rc = Sqrt( a*a/4.f + b*b/4.f - c );
265 const float d = Sqrt( (a/2.f + clusters3[id3].x) * (a/2.f + clusters3[id3].x) + (b/2.f + clusters3[id3].y) * (b/2.f + clusters3[id3].y) );
266 //cout << d << " " << rc << " " << d - rc << endl;
267 if ( Abs( d - rc ) < fRPhiCut ) {
268 doublets2[iD2].level += doublets1[iD1].level;
269 doublets2[iD2].neighbours.push_back(iD1);
280 PrintInfo("doublets");
283 // Hic sunt leones: the following code could be optimised to be iterative. But now I don't have time.
284 for ( int level = 6; level >= 2 ; --level ) {
285 vector<trackC> candidates;
287 const int limit = level > 5 ? 5 : level;
288 for ( int doubl = 5; doubl >= limit; --doubl ) {
289 for ( int iD = 0; iD < fNDoublets[doubl]; ++iD ) {
290 if ( fDoublets[doubl][iD].level == level ) {
291 cout << "Pushing new candidate" << endl;
292 candidates.push_back(trackC());
293 candidates[nCand].fPoints[doubl*2+2] = fDoublets[doubl][iD].id1;
294 candidates[nCand].fPoints[doubl*2] = fDoublets[doubl][iD].id0;
295 CandidatesTreeTraversal(candidates, iD, doubl, nCand);
300 nCand = candidates.size();
301 Double_t rDest = fITS->GetRMax();
302 cout << "Number of candidates at level " << level << ": " << candidates.size() << endl;
304 for( int i = 0; i < nCand; ++i ) index[i] = i;
305 for ( int cand = 0; cand < nCand; ++cand ) {
307 for ( int j = 0; j < 14; ++j ) {
308 if( candidates[cand].fPoints[j] > -1 ) ++count;
310 cout << "Candidates " << cand << ", number of points: " << count << endl;
311 // candidates[cand].ResetCovariance(50.);
312 InitTrackParams(candidates[cand]);
313 cout << "Fit cnd: " << cand << " " << candidates[cand] << endl;
314 candidates[cand].fChi2 = RefitTrack( (AliExternalTrackParam*)&candidates[cand], candidates[cand].fPoints, rDest ,-1);
316 CompDesc comp(&candidates);
317 sort(index,index+nCand,comp);
318 for ( int cand = 0; cand < nCand; ++cand ) {
319 const int ii = index[cand];
321 //cout << ii << " " << candidates[ii] << endl;
323 if ( candidates[ii].fChi2 < 0. ) break;
324 bool goodTrack = true;
325 for ( unsigned int point = 0; point < 14; ++point ) {
326 if ( candidates[ii].fPoints[point] != -1 ) {
327 if( !(fClusters[ point/2 ][ candidates[ii].fPoints[point] ].isUsed ) ) {
328 fClusters[ point/2 ][ candidates[ii].fPoints[point] ].isUsed = true;
335 AliESDtrack outTrack;
336 outTrack.SetOuterParam((AliExternalTrackParam*)&candidates[ii],AliESDtrack::kITSpureSA);
337 event->AddTrack(&outTrack);
344 // for ( int level = 6; level >=3 ; --level ) {
345 // vector<int> points[7];
346 // for ( int doubl = 5; doubl >= 2; --doubl ) {
347 // if( ( doubl + 1 - level ) < 0 ) break;
348 // for ( int iD = 0; iD < fNDoublets[doubl]; ++iD ) {
349 // if ( fDoublets[doubl][iD].level == level ) {
350 // points[doubl+1].push_back( fDoublets[doubl][iD].id1 );
351 // points[doubl].push_back( fDoublets[doubl][iD].id0 );
353 // vector<int> currentVector = (fDoublets[doubl][iD].neighbours);
354 // for( int iL = 1; iL <= doubl; ++iL ) {
355 // const nPlets * doublets = &fDoublets[doubl-iL][0];
357 // for ( unsigned int iV = 0 ; iV < currentVector.size() ; ++iV ) {
358 // points[doubl-iL].push_back( doublets[ currentVector[ iV ] ].id0 ) ;
359 // for ( unsigned int iN = 0 ; iN < doublets[ currentVector[ iV ] ].neighbours.size(); ++iN ) {
360 // tmp.push_back( doublets[ currentVector[ iV ] ].neighbours[ iN ] );
363 // currentVector.swap( tmp );
371 //________________________________________________________________________________
372 void AliITSUTrackerSA::MakeDoublets() {
373 // Make associations between two points on adjacent layers within an azimuthal window.
374 // Under consideration:
375 // - track parameter estimation using the primary vertex position
379 cout << "Vertex of used by the tracker: " << GetX() << " " << GetY() << " " << GetZ() << endl;
381 for( int iL = 0 ; iL < 6 ; ++iL ) {
383 const itsCluster* clusters1 = &fClusters[iL][0];
384 const itsCluster* clusters2 = &fClusters[iL+1][0];
386 // 0 - 2Pi junction treatment (part I)
387 for ( int iCC1 = 0 ; iCC1 < fNClusters[iL] ; ++iCC1 ) {
389 const int iC1 = fIndex[iL][iCC1];
390 for ( int iCC2 = fNClusters[iL+1]-1; iCC2 > -1 ; --iCC2 ) {
391 const int iC2 = fIndex[iL+1][iCC2];
392 if( (TMath::TwoPi() - (clusters2[iC2].phi-clusters1[iC1].phi) ) < fPhiCut ) {
393 fDoublets[iL].push_back(nPlets(iC1,iC2));
394 fDoublets[iL][fNDoublets[iL]].tanPhi = (clusters1[iC1].y-clusters2[iC2].y)/(clusters1[iC1].x-clusters2[iC2].x);
395 float r1 = Sqrt(clusters1[iC1].x * clusters1[iC1].x + clusters1[iC1].y * clusters1[iC1].y);
396 cout << clusters2[iC2].x * clusters2[iC2].x + clusters2[iC2].y * clusters2[iC2].y << flush << endl;
397 float r2 = Sqrt(clusters2[iC2].x * clusters2[iC2].x + clusters2[iC2].y * clusters2[iC2].y);
398 fDoublets[iL][fNDoublets[iL]].tanLambda = (clusters1[iC1].z-clusters2[iC2].z)/(r1-r2);
409 for ( int iCC1 = 0 ; iCC1 < fNClusters[iL] ; ++iCC1 ) {
410 const int iC1 = fIndex[iL][iCC1];
411 for ( int iCC2 = 0; iCC2 < fNClusters[iL+1] ; ++iCC2 ) {
412 const int iC2 = fIndex[iL+1][iCC2];
413 if( Abs( clusters1[iC1].phi - clusters2[iC2].phi ) < fPhiCut ) {
414 fDoublets[iL].push_back(nPlets(iC1,iC2));
415 fDoublets[iL][fNDoublets[iL]].tanPhi = (clusters1[iC1].y-clusters2[iC2].y)/(clusters1[iC1].x-clusters2[iC2].x);
416 float r1 = Sqrt(clusters1[iC1].x * clusters1[iC1].x + clusters1[iC1].y * clusters1[iC1].y);
417 float r2 = Sqrt(clusters2[iC2].x * clusters2[iC2].x + clusters2[iC2].y * clusters2[iC2].y);
418 fDoublets[iL][fNDoublets[iL]].tanLambda = (clusters1[iC1].z-clusters2[iC2].z)/(r1-r2);
420 } else if( clusters2[iC2].phi - clusters1[iC1].phi > fPhiCut ) break;
426 // 0 - 2Pi junction treatment (part II)
427 for ( int iCC1 = fNClusters[iL]-1; iCC1 > -1 ; --iCC1 ) {
429 const int iC1 = fIndex[iL][iCC1];
430 for ( int iCC2 = 0; iCC2 < fNClusters[iL+1] ; ++iCC2 ) {
431 const int iC2 = fIndex[iL+1][iCC2];
432 if( (TMath::TwoPi() - (clusters1[iC1].phi-clusters2[iC2].phi) ) < fPhiCut ) {
433 fDoublets[iL].push_back(nPlets(iC1,iC2));
434 fDoublets[iL][fNDoublets[iL]].tanPhi = (clusters1[iC1].y-clusters2[iC2].y)/(clusters1[iC1].x-clusters2[iC2].x);
435 float r1 = Sqrt(clusters1[iC1].x * clusters1[iC1].x + clusters1[iC1].y * clusters1[iC1].y);
436 float r2 = Sqrt(clusters2[iC2].x * clusters2[iC2].x + clusters2[iC2].y * clusters2[iC2].y);
437 fDoublets[iL][fNDoublets[iL]].tanLambda = (clusters1[iC1].z-clusters2[iC2].z)/(r1-r2);
449 // PrintInfo("doublets");
452 //______________________________________________________________________________
453 Bool_t AliITSUTrackerSA::InitTrackParams(trackC &track)
455 // Set the initial guess on track kinematics for propagation.
456 // Assume at least 3 points available
457 int lrOcc[AliITSUAux::kMaxLayers], nCl=0;
459 // we will need endpoints and middle layer
460 for (int i=fITS->GetNLayersActive();i--;) if (track.fPoints[i<<0x1]>-1) lrOcc[nCl++] = i;
462 AliError(Form("Cannot estimate momentum of tracks with %d clusters",nCl));
463 cout << track << endl;
468 int lr1 = lrOcc[nCl/2];
469 int lr2 = lrOcc[nCl-1];
471 const itsCluster& cl0 = fClusters[lr0][ track.fPoints[lr0<<0x1] ];
472 const itsCluster& cl1 = fClusters[lr1][ track.fPoints[lr1<<0x1] ];
473 const itsCluster& cl2 = fClusters[lr2][ track.fPoints[lr2<<0x1] ];
474 double cv = Curvature(cl0.x,cl0.y, cl1.x,cl1.y, cl2.x,cl2.y);
475 double tgl = (cl2.z-cl0.z)/TMath::Sqrt((cl2.x-cl0.x)*(cl2.x-cl0.x)+(cl2.y-cl0.y)*(cl2.y-cl0.y));
476 // double phi = TMath::ATan2((cl2.y-cl1.y),(cl2.x-cl1.x));
478 AliITSUClusterPix* clus = (AliITSUClusterPix*)fClustersTC[ lr0 ]->At( track.fPoints[lr0<<0x1] );
479 AliITSURecoLayer* lr = fITS->GetLayerActive(lr0);
480 AliITSURecoSens* sens = lr->GetSensorFromID(clus->GetVolumeId());
481 double x = sens->GetXTF() + clus->GetX();
482 double alp = sens->GetPhiTF();
483 // printf("Alp: %f phi: %f\n",alp,phi);
484 double par[5] = {clus->GetY(),clus->GetZ(),0,tgl,cv};
492 track.Set(x,alp,par,cov);
496 //______________________________________________________________________________
497 void AliITSUTrackerSA::CandidatesTreeTraversal(vector<trackC> &track, int &iD, int &doubl, int &nCand) {
501 cout << "ERROR IN CandidatesTreeTraversal" << endl;
507 track[nCand].fPoints[ 2 * currD ] = fDoublets[ currD ] [ fDoublets[ doubl ][ iD ].neighbours[0] ].id0;
510 if ( fDoublets[ currD ] [ fDoublets[ doubl ][ iD ].neighbours[0] ].level == 1 ) {
512 cout << "Setting track " << nCand << " information using its first cluster: " << endl;
513 cout << "Layer " << currD << ", id " << track[nCand].fPoints[ 2 * currD ] <<endl;
514 AliITSUClusterPix* clus = (AliITSUClusterPix*)fClustersTC[ currD ]->At( track[nCand].fPoints[ 2 * currD ] ); // assign your 1st cluster (from which the fit is starting)
515 AliITSURecoLayer* lr = fITS->GetLayerActive(currD) ; // assign the layer which the cluster belongs to
517 AliITSURecoSens* sens = lr->GetSensorFromID(clus->GetVolumeId());
518 double x = sens->GetXTF() + clus->GetX();
519 double alp = sens->GetPhiTF();
520 double par[5] = {clus->GetY(),clus->GetZ(),0,0,0.01};
528 track[nCand].Set(x,alp,par,cov);
529 // cout << "after set " << track[nCand] << endl;
532 CandidatesTreeTraversal(track,fDoublets[doubl][iD].neighbours[0],currD,nCand);
535 for( unsigned int iD2 = 1 ; iD2 < fDoublets[ doubl ][ iD ].neighbours.size() ; ++iD2 ) {
536 track.push_back(track[nCand++]);
537 track[nCand].fPoints[ 2 * currD ] = fDoublets[ currD ] [ fDoublets[ doubl ][ iD ].neighbours[ iD2 ] ].id0;
538 if ( fDoublets[ currD ] [ fDoublets[ doubl ][ iD ].neighbours[iD2] ].level == 1 ) {
539 AliITSUClusterPix* clus = (AliITSUClusterPix*)fClustersTC[ currD ]->At( track[nCand].fPoints[ 2 * currD ] ); // assign your 1st cluster (from which the fit is starting)
540 AliITSURecoLayer* lr = fITS->GetLayerActive(currD) ; // assign the layer which the cluster belongs to
542 AliITSURecoSens* sens = lr->GetSensorFromID(clus->GetVolumeId());
543 double x = sens->GetXTF() + clus->GetX();
544 double alp = sens->GetPhiTF();
545 double par[5] = {clus->GetY(),clus->GetZ(),0,0,0};
553 track[nCand].Set(x,alp,par,cov);
556 CandidatesTreeTraversal(track,fDoublets[doubl][iD].neighbours[iD2],currD,nCand);
561 //______________________________________________________________________________
562 Double_t AliITSUTrackerSA::RefitTrack(AliExternalTrackParam* trc,
563 Int_t clInfo[2*AliITSUAux::kMaxLayers],
564 Double_t rDest, Int_t stopCond)
566 // refit track till radius rDest.
567 // if stopCond<0 : propagate till last cluster then stop
568 // if stopCond==0: propagate till last cluster then try to go till limiting rDest, don't mind if fail
569 // if stopCond>0 : rDest must be reached
571 // The clList should provide the indices of clusters at corresponding layer (as stored in the layer
572 // TClonesArray, with convention (allowing for up to 2 clusters per layer due to the overlaps):
573 // if there is a cluster on given layer I, then it should be stored at clInfo[2*I-1]
574 // if there is an additional cluster on this layer, it goes to clInfo[2*I]
575 // -1 means no cluster
577 double rCurr = Sqrt(trc->GetX()*trc->GetX() + trc->GetY()*trc->GetY());
578 int dir,lrStart,lrStop;
580 dir = rCurr<rDest ? 1 : -1;
581 lrStart = fITS->FindFirstLayerID(rCurr,dir);
582 lrStop = fITS->FindLastLayerID(rDest,dir); // lr id before which we have to stop
583 cout << "Start/End layers and direction " << lrStart << " " << lrStop << " " << dir << endl;
585 if (lrStop<0 || lrStart<0) AliFatal(Form("Failed to find start(%d) or last(%d) layers. "
586 "Track from %.3f to %.3f",lrStart,lrStop,rCurr,rDest));
589 for (int i=2*fITS->GetNLayersActive();i--;) {if (clInfo[i]<0) continue; nCl++;}
591 AliExternalTrackParam tmpTr(*trc);
596 int lrStop1 = lrStop+dir;
597 for (int ilr=lrStart;ilr!=lrStop1;ilr+=dir) {
598 AliITSURecoLayer* lr = fITS->GetLayer(ilr);
599 if ( dir*(rCurr-lr->GetR(dir))>0) {
600 cout << ilr << " passed!" << endl;
602 } // this layer is already passed
603 int ilrA2,ilrA = lr->GetActiveID();
604 // passive layer or active w/o hits will be traversed on the way to next cluster
605 if (!lr->IsActive() || clInfo[ilrA2=(ilrA<<1)]<0) {
606 cout << ilr << " is inactive or without cluster for current candidates" << endl;
609 cout << "OK layer " << ilr << endl;
611 // select the order in which possible 2 clusters (in case of the overlap) will be traversed and fitted
613 if (dir>0) { // clusters are stored in increasing radius order
614 iclLr[nclLr++]=clInfo[ilrA2++];
615 if (clInfo[ilrA2]>=0) iclLr[nclLr++]=clInfo[ilrA2];
618 if ( clInfo[ilrA2+1]>=0 ) iclLr[nclLr++]=clInfo[ilrA2+1];
619 iclLr[nclLr++]=clInfo[ilrA2];
622 Bool_t transportedToLayer = kFALSE;
623 for (int icl=0;icl<nclLr;icl++) {
624 AliITSUClusterPix* clus = (AliITSUClusterPix*)lr->GetCluster(iclLr[icl]);
625 AliITSURecoSens* sens = lr->GetSensorFromID(clus->GetVolumeId());
626 if (!tmpTr.Rotate(sens->GetPhiTF())) { cout << "failed rotation" << endl; return -1; }
628 double xClus = sens->GetXTF()+clus->GetX();
629 if (!transportedToLayer) {
630 if (ilr!=lrStart && !TransportToLayerX(&tmpTr,lrStart,ilr,xClus)) {
631 cout << "failed transport to the entrance" << endl; return -1; } // go to the entrance to the layer
633 transportedToLayer = kTRUE;
636 if (!PropagateSeed(&tmpTr,xClus,fCurrMass)) { cout << "failed propagation of the seed X:" << xClus << endl; tmpTr.Print(); return -1; }
638 Double_t p[2]={clus->GetY(), clus->GetZ()};
639 Double_t cov[3]={clus->GetSigmaY2(), clus->GetSigmaYZ(), clus->GetSigmaZ2()};
640 double chi2cl = tmpTr.GetPredictedChi2(p,cov);
643 if ( !tmpTr.Update(p,cov) ) { cout << "failed update of the covariance" << endl; return -1; }
644 if (++nclFit==nCl && stopCond<0) {
646 // printf("Fit chi2: %f for %d clusters\n",chi2,nclFit);
647 return chi2; // it was requested to not propagate after last update
652 // All clusters were succesfully fitted. Even if the track does not reach rDest, this is enough to validate it.
653 // Still, try to go as close as possible to rDest.
655 // printf("Fit chi2: %f for %d clusters\n",chi2,nclFit);
657 if (lrStart!=lrStop) {
658 if (!TransportToLayer(&tmpTr,lrStart,lrStop)) return (stopCond>0) ? -chi2 : chi2; // rDest was obligatory
659 if (!GoToExitFromLayer(&tmpTr,fITS->GetLayer(lrStop),dir)) return (stopCond>0) ? -chi2 : chi2; // rDest was obligatory
661 // go to the destination radius. Note that here we don't select direction to avoid precision problems
662 if (!tmpTr.GetXatLabR(rDest,rDest,GetBz(),0) || !PropagateSeed(&tmpTr,rDest,fCurrMass, 100, kFALSE)) {
663 return (stopCond>0) ? -chi2 : chi2; // rDest was obligatory
670 //______________________________________________________________________________
671 Bool_t AliITSUTrackerSA::PropagateSeed(AliExternalTrackParam *seed, Double_t xToGo, Double_t mass, Double_t maxStep, Bool_t matCorr)
673 // propagate seed to given x applying material correction if requested
674 const Double_t kEpsilon = 1e-5;
675 Double_t xpos = seed->GetX();
676 Int_t dir = (xpos<xToGo) ? 1:-1;
677 Double_t xyz0[3],xyz1[3];
679 Bool_t updTime = dir>0 && seed->IsStartedTimeIntegral();
680 if (matCorr || updTime) seed->GetXYZ(xyz1); //starting global position
681 while ( (xToGo-xpos)*dir > kEpsilon){
682 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
683 Double_t x = xpos+step;
684 Double_t bz=GetBz(); // getting the local Bz
685 if (!seed->PropagateTo(x,bz)) return kFALSE;
687 if (matCorr || updTime) {
688 xyz0[0]=xyz1[0]; // global pos at the beginning of step
691 seed->GetXYZ(xyz1); // // global pos at the end of step
695 ds = GetMaterialBudget(xyz0,xyz1,xx0,xrho);
696 if (dir>0) xrho = -xrho; // outward should be negative
697 if (!seed->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
699 else { // matCorr is not requested but time integral is
700 double d0 = xyz1[0]-xyz0[0];
701 double d1 = xyz1[1]-xyz0[1];
702 double d2 = xyz1[2]-xyz0[2];
703 ds = TMath::Sqrt(d0*d0+d1*d1+d2*d2);
706 if (updTime) seed->AddTimeStep(ds);
713 //_________________________________________________________________________
714 Bool_t AliITSUTrackerSA::TransportToLayer(AliExternalTrackParam* seed, Int_t lFrom, Int_t lTo, Double_t rLim)
716 // transport track from layerFrom to the entrance of layerTo or to rLim (if>0), wathever is closer
718 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
720 int dir = lTo > lFrom ? 1:-1;
721 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
722 Bool_t checkFirst = kTRUE;
723 Bool_t limReached = kFALSE;
726 if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
729 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
730 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
732 // go the entrance of the layer, assuming no materials in between
733 double xToGo = lrTo->GetR(-dir);
736 if (rLim<xToGo) {xToGo = rLim; limReached = kTRUE;}
739 if (rLim>xToGo) {xToGo = rLim; limReached = kTRUE;}
742 // double xts = xToGo;
743 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) {
744 // printf("FailHere1: %f %f %d\n",xts,xToGo,dir);
745 // seed->Print("etp");
748 if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) {
749 //printf("FailHere2: %f %f %d\n",xts,xToGo,dir);
750 //seed->Print("etp");
754 if (limReached) break;
760 //_________________________________________________________________________
761 Bool_t AliITSUTrackerSA::TransportToLayerX(AliExternalTrackParam* seed, Int_t lFrom, Int_t lTo, Double_t xStop)
763 // transport track from layerFrom to the entrance of layerTo but do not pass control parameter X
765 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
767 int dir = lTo > lFrom ? 1:-1;
768 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
769 Bool_t checkFirst = kTRUE;
772 if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
775 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
776 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
778 // go the entrance of the layer, assuming no materials in between
779 double xToGo = lrTo->GetR(-dir); // R of the entrance to layer
781 // double xts = xToGo;
782 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) {
783 // printf("FailHere1: %f %f %d\n",xts,xToGo,dir);
784 // seed->Print("etp");
787 if ( (dir>0&&xToGo>xStop) || (dir<0&&xToGo<xStop) ) xToGo = xStop;
790 AliDebug(2,Form("go in dir=%d to R=%.4f(X:%.4f)",dir,lrTo->GetR(-dir), xToGo));
792 if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) {
793 //printf("FailHere2: %f %f %d\n",xts,xToGo,dir);
794 //seed->Print("etp");
803 //_________________________________________________________________________
804 Bool_t AliITSUTrackerSA::GoToExitFromLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
806 // go to the exit from lr in direction dir, applying material corrections in steps specific for this layer
807 // If check is requested, do this only provided the track has not exited the layer already
808 double xToGo = lr->GetR(dir);
809 if (check) { // do we need to track till the surface of the current layer ?
810 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
811 if (dir>0) { if (curR2-xToGo*xToGo>-fgkToler) return kTRUE; } // on the surface or outside of the layer
812 else if (dir<0) { if (xToGo*xToGo-curR2>-fgkToler) return kTRUE; } // on the surface or outside of the layer
814 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
815 // go via layer to its boundary, applying material correction.
816 if (!PropagateSeed(seed,xToGo,fCurrMass, lr->GetMaxStep())) return kFALSE;
822 //_________________________________________________________________________
823 Bool_t AliITSUTrackerSA::GoToEntranceToLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
825 // go to the entrance of lr in direction dir, w/o applying material corrections.
826 // If check is requested, do this only provided the track did not reach the layer already
827 double xToGo = lr->GetR(-dir);
828 if (check) { // do we need to track till the surface of the current layer ?
829 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
830 if (dir>0) { if (curR2-xToGo*xToGo>-fgkToler) return kTRUE; } // already passed
831 else if (dir<0) { if (xToGo*xToGo-curR2>-fgkToler) return kTRUE; } // already passed
833 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
834 // go via layer to its boundary, applying material correction.
835 if (!PropagateSeed(seed,xToGo,fCurrMass, 100, kFALSE)) return kFALSE;
840 //____________________________________________________
841 Double_t AliITSUTrackerSA::GetMaterialBudget(const double* pnt0,const double* pnt1, double& x2x0, double& rhol) const
844 if (fUseMatLUT && fMatLUT) {
845 double d = fMatLUT->GetMatBudget(pnt0,pnt1,par);
846 x2x0 = par[AliITSUMatLUT::kParX2X0];
847 rhol = par[AliITSUMatLUT::kParRhoL];
851 MeanMaterialBudget(pnt0,pnt1,par);
853 rhol = par[0]*par[4];
858 //____________________________________________________________________
859 Double_t AliITSUTrackerSA::Curvature(Double_t x1,Double_t y1,Double_t
860 x2,Double_t y2,Double_t x3,Double_t y3)
863 //calculates the curvature of track
864 Double_t den = (x3-x1)*(y2-y1)-(x2-x1)*(y3-y1);
866 Double_t a = ((y3-y1)*(x2*x2+y2*y2-x1*x1-y1*y1)-(y2-y1)*(x3*x3+y3*y3-x1*x1-y1*y1))/den;
867 Double_t b = -(x2*x2-x1*x1+y2*y2-y1*y1+a*(x2-x1))/(y2-y1);
868 Double_t c = -x1*x1-y1*y1-a*x1-b*y1;
871 if((a*a+b*b-4*c)<0) return 0;
872 Double_t rad = TMath::Sqrt(a*a+b*b-4*c)/2.;
875 if((x1>0 && y1>0 && x1<xc)) rad*=-1;
876 if((x1<0 && y1>0 && x1<xc)) rad*=-1;
877 // if((x1<0 && y1<0 && x1<xc)) rad*=-1;
878 // if((x1>0 && y1<0 && x1<xc)) rad*=-1;
885 //____________________________________________________
886 void AliITSUTrackerSA::PrintInfo(TString what) {
888 if( what.Contains("clusters") ) {
889 cout << "Dumping clusters info" << endl;
890 for ( int i = 0; i < 7; ++i ) {
891 cout << "**** Layer " << i << " ****" << endl;
892 for ( int c = 0; c < fNClusters[i]; ++c ) {
893 cout << "*** Cluster " << c << " ***" <<endl;
894 cout << fClusters[i][c] << endl;
899 if( what.Contains("doublets") ) {
900 cout << "Dumping doublets info" << endl;
901 for ( int i = 0; i < 6; ++i ) {
902 cout << "**** Doublets array " << i << " ****" << endl;
903 for ( int c = 0; c < fNDoublets[i]; ++c ) {
904 cout << "*** Doublet " << c << " ***" <<endl;
905 cout << fDoublets[i][c] << endl;