LCOV - code coverage report
Current view: top level - ITS/ITSbase - AliITStrackerSA.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 500 640 78.1 %
Date: 2016-06-14 17:26:59 Functions: 26 29 89.7 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : ///////////////////////////////////////////////////////////
      19             : //  Stand alone ITS tracker class                        //
      20             : //  Origin:  Elisabetta Crescio - crescio@to.infn.it     //
      21             : //  Updated: Francesco Prino    - prino@to.infn.it       //
      22             : ///////////////////////////////////////////////////////////
      23             : 
      24             : #include <stdlib.h>
      25             : 
      26             : #include <TArrayI.h>
      27             : #include <TBranch.h>
      28             : #include <TObjArray.h>
      29             : #include <TTree.h>
      30             : #include <TStopwatch.h>
      31             : 
      32             : #include "AliESDEvent.h"
      33             : #include "AliESDVertex.h"
      34             : #include "AliESDtrack.h"
      35             : #include "AliITSVertexer.h"
      36             : #include "AliITSclusterTable.h"
      37             : #include "AliITSRecPoint.h"
      38             : #include "AliITSgeomTGeo.h"
      39             : #include "AliITStrackSA.h"
      40             : #include "AliITStrackerSA.h"
      41             : #include "AliITSReconstructor.h"
      42             : #include "AliLog.h"
      43             : #include "AliRun.h"
      44             : 
      45         118 : ClassImp(AliITStrackerSA)
      46             : 
      47             : //____________________________________________________________________________
      48           0 : AliITStrackerSA::AliITStrackerSA():AliITStrackerMI(),
      49           0 : fPhiEstimate(0),
      50           0 : fITSStandAlone(0),
      51           0 : fLambdac(0),
      52           0 : fPhic(0),
      53           0 : fCoef1(0),
      54           0 : fCoef2(0),
      55           0 : fCoef3(0),
      56           0 : fNloop(0),
      57           0 : fPhiWin(0),
      58           0 : fLambdaWin(0),
      59           0 : fListOfTracks(0),
      60           0 : fListOfSATracks(0),
      61           0 : fITSclusters(0),
      62           0 : fInwardFlag(0),
      63           0 : fOuterStartLayer(0),
      64           0 : fInnerStartLayer(5),
      65           0 : fMinNPoints(0),
      66           0 : fMinQ(0.),
      67           0 : fCluCoord(0){
      68             :   // Default constructor
      69           0 :   Init();
      70             :  
      71           0 : }
      72             : //____________________________________________________________________________
      73           2 : AliITStrackerSA::AliITStrackerSA(const Char_t *geom):AliITStrackerMI(0),
      74           2 : fPhiEstimate(0),
      75           2 : fITSStandAlone(0),
      76           2 : fLambdac(0),
      77           2 : fPhic(0),
      78           2 : fCoef1(0),
      79           2 : fCoef2(0),
      80           2 : fCoef3(0),
      81           2 : fNloop(0),
      82           2 : fPhiWin(0),
      83           2 : fLambdaWin(0),
      84           2 : fListOfTracks(0),
      85           2 : fListOfSATracks(0),
      86           2 : fITSclusters(0),
      87           2 : fInwardFlag(0),
      88           2 : fOuterStartLayer(0),
      89           2 : fInnerStartLayer(5),
      90           2 : fMinNPoints(0),
      91           2 : fMinQ(0.),
      92           2 : fCluCoord(0) 
      93          10 : {
      94             :   // Standard constructor (Vertex is known and passed to this obj.)
      95           2 :   if (geom) {
      96           0 :     AliWarning("\"geom\" is actually a dummy argument !");
      97             :   }
      98             : 
      99           2 :   Init();
     100             :  
     101           4 : }
     102             : 
     103             : //____________________________________________________________________________
     104          12 : AliITStrackerSA::~AliITStrackerSA(){
     105             :   // destructor
     106             :  
     107           6 :   if(fPhiWin)delete []fPhiWin;
     108           6 :   if(fLambdaWin)delete []fLambdaWin;
     109           2 :   fListOfTracks->Delete();
     110           4 :   delete fListOfTracks;
     111           2 :   fListOfSATracks->Delete();
     112           4 :   delete fListOfSATracks;
     113           2 :   if(fCluCoord){
     114          28 :     for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){
     115          12 :       if(fCluCoord[i]){
     116          12 :         fCluCoord[i]->Delete();
     117          24 :         delete fCluCoord[i];
     118             :       }
     119             :     }
     120           4 :     delete [] fCluCoord;
     121             :   }
     122           6 : }
     123             : 
     124             : //____________________________________________________________________________
     125             : Int_t AliITStrackerSA::Clusters2Tracks(AliESDEvent *event){
     126             : // This method is used to find and fit the tracks. By default the corresponding
     127             : // method in the parent class is invoked. In this way a combined tracking
     128             : // TPC+ITS is performed. If the flag fITSStandAlone is true, the tracking
     129             : // is done in the ITS only. In the standard reconstruction chain this option
     130             : // can be set via AliReconstruction::SetOption("ITS","onlyITS")
     131             :   Int_t rc=0;
     132          16 :   TStopwatch sw;
     133           8 :   ConfigureTrackFinding();
     134             : 
     135           8 :   if(!fITSStandAlone){
     136           8 :     sw.Start();
     137           8 :     rc=AliITStrackerMI::Clusters2Tracks(event);
     138           8 :     sw.Stop();
     139          64 :     AliInfoF("timingMI: %e/%e real/cpu",sw.RealTime(),sw.CpuTime());
     140           8 :   }
     141             :   else {
     142           0 :     AliDebug(1,"Stand Alone flag set: doing tracking in ITS alone\n");
     143             :   }
     144           8 :   if(!rc){ 
     145           8 :     if (event->GetNumberOfTPCClusters()) {
     146           8 :       sw.Start();
     147           8 :       rc=FindTracks(event,kFALSE); //RS: do complementary reco if there are TPC clusters
     148           8 :       sw.Stop();
     149          64 :       AliInfoF("timingSAcompl: %e/%e real/cpu",sw.RealTime(),sw.CpuTime());
     150           8 :     }
     151             :     Int_t nSPDcontr=0;
     152           8 :     const AliESDVertex *spdv = event->GetPrimaryVertexSPD();
     153          24 :     if(spdv) nSPDcontr = spdv->GetNContributors();
     154          16 :     if(AliITSReconstructor::GetRecoParam()->GetSAUseAllClusters()==kTRUE && 
     155           0 :        nSPDcontr<=AliITSReconstructor::GetRecoParam()->GetMaxSPDcontrForSAToUseAllClusters()) {
     156           0 :       sw.Start();
     157           0 :       rc=FindTracks(event,kTRUE);
     158           0 :       sw.Stop();
     159           0 :       AliInfoF("timingSApure: %e/%e real/cpu",sw.RealTime(),sw.CpuTime());
     160           0 :     }
     161           8 :   }
     162             :   return rc;
     163           8 : }
     164             : 
     165             : //____________________________________________________________________________
     166             : void AliITStrackerSA::Init(){
     167             :   //  Reset all data members
     168           4 :     fPhiEstimate=0;
     169          12 :     for(Int_t i=0;i<2;i++){fPoint1[i]=0;fPoint2[i]=0;fPoint3[i]=0;}
     170           2 :     fLambdac=0;
     171           2 :     fPhic=0;
     172           2 :     fCoef1=0;
     173           2 :     fCoef2=0;
     174           2 :     fCoef3=0;
     175           2 :     fPointc[0]=0;
     176           2 :     fPointc[1]=0;
     177           2 :     fITSclusters = 0;
     178           2 :     SetOuterStartLayer(1);
     179           2 :     SetSAFlag(kFALSE);
     180           4 :     fListOfTracks=new TClonesArray("AliITStrackMI",100);
     181           4 :     fListOfSATracks=new TClonesArray("AliITStrackSA",100);
     182           2 :     fCluCoord = 0;
     183           2 :     fMinNPoints = 3;
     184           2 :  }
     185             : //_______________________________________________________________________
     186             : void AliITStrackerSA::ResetForFinding(){
     187             :   //  Reset data members used in all loops during track finding
     188        3268 :     fPhiEstimate=0;
     189        9804 :     for(Int_t i=0;i<2;i++){fPoint1[i]=0;fPoint2[i]=0;fPoint3[i]=0;}
     190        1634 :     fLambdac=0;
     191        1634 :     fPhic=0;
     192        1634 :     fCoef1=0;
     193        1634 :     fCoef2=0;
     194        1634 :     fCoef3=0;
     195        1634 :     fPointc[0]=0;
     196        1634 :     fPointc[1]=0;
     197        1634 :     fListOfTracks->Clear();
     198        1634 :     fListOfSATracks->Clear();
     199        1634 : }
     200             : //_______________________________________________________________________
     201             : void AliITStrackerSA::ConfigureTrackFinding(){
     202             :   // set windows for track search based on recoparam parameters
     203             : 
     204          16 :   Int_t nLoops=AliITSReconstructor::GetRecoParam()->GetNLoopsSA();
     205           8 :   if(nLoops==32){
     206           0 :     SetFixedWindowSizes();
     207           0 :   }else{
     208           8 :     Double_t phimin=AliITSReconstructor::GetRecoParam()->GetMinPhiSA();
     209           8 :     Double_t phimax=AliITSReconstructor::GetRecoParam()->GetMaxPhiSA();
     210           8 :     Double_t lambmin=AliITSReconstructor::GetRecoParam()->GetMinLambdaSA();
     211           8 :     Double_t lambmax=AliITSReconstructor::GetRecoParam()->GetMaxLambdaSA();
     212           8 :     SetCalculatedWindowSizes(nLoops,phimin,phimax,lambmin,lambmax);
     213             :   }
     214           8 :   fMinQ=AliITSReconstructor::GetRecoParam()->GetSAMinClusterCharge();
     215             : 
     216           8 : }
     217             :  
     218             : 
     219             : //______________________________________________________________________
     220             : Int_t AliITStrackerSA::FindTracks(AliESDEvent* event, Bool_t useAllClusters){
     221             : 
     222             : // Track finder using the ESD object
     223             : 
     224          24 :   AliDebug(2,Form(" field is %f",event->GetMagneticField()));
     225          24 :   AliDebug(2,Form("SKIPPING %d %d %d %d %d %d",ForceSkippingOfLayer(0),ForceSkippingOfLayer(1),ForceSkippingOfLayer(2),ForceSkippingOfLayer(3),ForceSkippingOfLayer(4),ForceSkippingOfLayer(5)));
     226             : 
     227           8 :   if(!fITSclusters){
     228           0 :     Fatal("FindTracks","ITS cluster tree is not accessed!!!\n Please use method SetClusterTree to pass the pointer to the tree\n");
     229           0 :     return -1;
     230             :   }
     231             :   //Reads event and mark clusters of traks already found, with flag kITSin
     232           8 :   Int_t nentr=event->GetNumberOfTracks();
     233           8 :   if(!useAllClusters) {
     234         280 :     while (nentr--) {
     235         136 :       AliESDtrack *track=event->GetTrack(nentr);
     236         136 :       if ((track->GetStatus()&AliESDtrack::kITSin) == AliESDtrack::kITSin){
     237          82 :         Int_t idx[12];
     238          82 :         Int_t ncl = track->GetITSclusters(idx);
     239        1016 :         for(Int_t k=0;k<ncl;k++){
     240         426 :           AliITSRecPoint* cll = (AliITSRecPoint*)GetCluster(idx[k]);
     241         426 :           cll->SetBit(kSAflag);
     242             :         }
     243          82 :       }
     244             :     }
     245             :   }else{
     246           0 :     while (nentr--) {
     247           0 :       AliESDtrack *track=event->GetTrack(nentr);
     248           0 :       if ((track->GetStatus()&AliESDtrack::kITSin) == AliESDtrack::kITSin){
     249           0 :         Int_t idx[12];
     250           0 :         Int_t ncl = track->GetITSclusters(idx);
     251           0 :         for(Int_t k=0;k<ncl;k++){
     252           0 :           AliITSRecPoint* cll = (AliITSRecPoint*)GetCluster(idx[k]);
     253           0 :           cll->ResetBit(kSAflag);
     254             :         }
     255           0 :       }
     256             :     }
     257             :   }
     258             :   //Get primary vertex
     259           8 :   Double_t primaryVertex[3];
     260           8 :   event->GetVertex()->GetXYZ(primaryVertex);
     261             :   //Creates TClonesArray with clusters for each layer. The clusters already used
     262             :   //by AliITStrackerMI are not considered
     263           8 :   Int_t nclusters[AliITSgeomTGeo::kNLayers]={0,0,0,0,0,0};
     264           8 :   Int_t dmar[AliITSgeomTGeo::kNLayers]={0,0,0,0,0,0};
     265           8 :   if (fCluCoord == 0) {
     266           2 :     fCluCoord = new TClonesArray*[AliITSgeomTGeo::kNLayers];
     267          28 :     for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++) {
     268          12 :       fCluCoord[i]=0;
     269             :     }
     270           2 :   }
     271         112 :   for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){
     272          48 :     AliITSlayer &layer=fgLayers[i];
     273          48 :     if (!ForceSkippingOfLayer(i)) {
     274        1428 :       for(Int_t cli=0;cli<layer.GetNumberOfClusters();cli++){
     275         666 :         AliITSRecPoint* cls = (AliITSRecPoint*)layer.GetCluster(cli);
     276        1084 :         if(cls->TestBit(kSAflag)==kTRUE) continue; //clusters used by TPC prol.
     277         248 :         if(cls->GetQ()==0) continue; //fake clusters dead zones
     278         456 :         if(i>1 && cls->GetQ()<=fMinQ) continue; // cut on SDD and SSD cluster charge
     279         248 :         nclusters[i]++;
     280         248 :       }
     281          48 :     }
     282          48 :     dmar[i]=0;
     283          48 :     if(!fCluCoord[i]){
     284          24 :       fCluCoord[i] = new TClonesArray("AliITSclusterTable",nclusters[i]);
     285          12 :     }else{
     286          36 :       fCluCoord[i]->Clear(); //Delete();
     287             :       //fCluCoord[i]->Expand(nclusters[i]); //RS will autoexpand
     288             :     }
     289             :   }
     290             : 
     291         112 :   for(Int_t ilay=0;ilay<AliITSgeomTGeo::GetNLayers();ilay++){
     292          48 :     TClonesArray &clucoo = *fCluCoord[ilay];
     293          48 :     AliITSlayer &layer=fgLayers[ilay];
     294          48 :     if (!ForceSkippingOfLayer(ilay)) {
     295        1428 :       for(Int_t cli=0;cli<layer.GetNumberOfClusters();cli++){
     296         666 :         AliITSRecPoint* cls = (AliITSRecPoint*)layer.GetCluster(cli);
     297        1084 :         if(cls->TestBit(kSAflag)==kTRUE) continue;
     298         248 :         if(cls->GetQ()==0) continue;
     299         456 :         if(ilay>1 && cls->GetQ()<=fMinQ) continue; 
     300         248 :         Double_t phi=0;Double_t lambda=0;
     301         248 :         Double_t x=0;Double_t y=0;Double_t z=0;
     302         248 :         Double_t sx=0;Double_t sy=0;Double_t sz=0;
     303         248 :         GetCoorAngles(cls,phi,lambda,x,y,z,primaryVertex);
     304         248 :         GetCoorErrors(cls,sx,sy,sz);
     305         248 :         new (clucoo[dmar[ilay]]) AliITSclusterTable(x,y,z,sx,sy,sz,phi,lambda,cli);
     306         248 :         dmar[ilay]++;
     307         248 :       }
     308          48 :     }
     309          48 :     fCluCoord[ilay]->Sort();
     310             :   }
     311             : 
     312             :   // track counter
     313             :   Int_t ntrack=0;
     314             : 
     315             :   static Int_t nClusLay[AliITSgeomTGeo::kNLayers];//counter for clusters on each layer
     316             :   Int_t startLayForSeed=0;
     317           8 :   Int_t lastLayForSeed=fOuterStartLayer;
     318             :   Int_t nSeedSteps=lastLayForSeed-startLayForSeed;
     319             :   Int_t seedStep=1;
     320           8 :   if(fInwardFlag){
     321           0 :     startLayForSeed=AliITSgeomTGeo::GetNLayers()-1;
     322           0 :     lastLayForSeed=fInnerStartLayer;
     323           0 :     nSeedSteps=startLayForSeed-lastLayForSeed;
     324             :     seedStep=-1;
     325           0 :   }
     326             : 
     327             :   // loop on minimum number of points
     328          80 :   for(Int_t iMinNPoints=AliITSgeomTGeo::GetNLayers(); iMinNPoints>=fMinNPoints; iMinNPoints--) {
     329             : 
     330             :     // loop on starting layer for track finding 
     331         256 :     for(Int_t iSeedLay=0; iSeedLay<=nSeedSteps; iSeedLay++) {
     332          96 :       Int_t theLay=startLayForSeed+iSeedLay*seedStep;
     333          96 :       if(ForceSkippingOfLayer(theLay)) continue;
     334          96 :       Int_t minNPoints=iMinNPoints-theLay;
     335          96 :       if(fInwardFlag) minNPoints=iMinNPoints-(AliITSgeomTGeo::GetNLayers()-1-theLay);
     336         960 :       for(Int_t i=theLay+1;i<AliITSgeomTGeo::GetNLayers();i++)
     337         384 :         if(ForceSkippingOfLayer(i)) 
     338           0 :           minNPoints--;
     339         120 :       if(minNPoints<fMinNPoints) continue;
     340             : 
     341             :       // loop on phi and lambda window size
     342        3024 :       for(Int_t nloop=0;nloop<fNloop;nloop++){
     343        1440 :         Int_t nclTheLay=fCluCoord[theLay]->GetEntries();
     344        4506 :         while(nclTheLay--){ 
     345        1626 :           ResetForFinding();
     346        1626 :           Bool_t useRP=SetFirstPoint(theLay,nclTheLay,primaryVertex);
     347        1626 :           if(!useRP) continue;      
     348        1626 :           AliITStrackSA trs;
     349             :             
     350             :           Int_t pflag=0;            
     351             :           Int_t kk;
     352       22764 :           for(kk=0;kk<AliITSgeomTGeo::GetNLayers();kk++) nClusLay[kk] = 0;
     353             :             
     354             :           kk=0;
     355        4878 :           nClusLay[kk] = SearchClusters(theLay,fPhiWin[nloop],fLambdaWin[nloop],
     356        1626 :                                         &trs,primaryVertex[2],pflag);
     357        1626 :           Int_t nextLay=theLay+seedStep;
     358             :           Bool_t goon=kTRUE;
     359        1626 :           if(nextLay<0 || nextLay == 6) goon = kFALSE;
     360        8708 :           while(goon){
     361        7082 :             kk++;
     362       21246 :             nClusLay[kk] = SearchClusters(nextLay,fPhiWin[nloop],fLambdaWin[nloop],
     363        7082 :                                             &trs,primaryVertex[2],pflag);
     364        7082 :             if(nClusLay[kk]!=0){
     365             :               pflag=1;
     366         724 :               if(kk==1) {
     367         246 :                 fPoint3[0]=fPointc[0];
     368         246 :                 fPoint3[1]=fPointc[1];
     369         246 :               } else {
     370         478 :                 UpdatePoints();
     371             :               }
     372             :             }
     373        7082 :             nextLay+=seedStep;
     374        8708 :             if(nextLay<0 || nextLay==6) goon=kFALSE;
     375             :           }
     376             : 
     377             :             
     378             :           Int_t layOK=0;
     379        1626 :           if(!fInwardFlag){
     380       20668 :             for(Int_t nnp=0;nnp<AliITSgeomTGeo::GetNLayers()-theLay;nnp++){
     381       11058 :               if(nClusLay[nnp]!=0) layOK+=1;
     382             :             }
     383        1626 :           }else{
     384           0 :             for(Int_t nnp=theLay; nnp>=0; nnp--){
     385           0 :               if(nClusLay[nnp]!=0) layOK+=1;
     386             :             }
     387             :           }
     388        1626 :           if(layOK>=minNPoints){ 
     389          80 :             AliDebug(2,Form("---NPOINTS: %d; MAP: %d %d %d %d %d %d\n",layOK,nClusLay[0],nClusLay[1],nClusLay[2],nClusLay[3],nClusLay[4],nClusLay[5]));
     390             :             AliITStrackV2* tr2 = 0;
     391          16 :             tr2 = FitTrack(&trs,primaryVertex);
     392          16 :             if(!tr2){ 
     393           0 :               continue;
     394             :             }
     395          80 :             AliDebug(2,Form("---NPOINTS fit: %d\n",tr2->GetNumberOfClusters()));
     396             :               
     397          16 :             StoreTrack(tr2,event,useAllClusters);
     398          16 :             ntrack++;
     399             :               
     400          16 :           }   
     401             :           
     402        3252 :         }//end loop on clusters of theLay
     403             :       } //end loop on window sizes
     404          72 :     } //end loop on theLay
     405             :   }//end loop on min points
     406             : 
     407             :   // search for 1-point tracks in SPD, only for cosmics
     408             :   // (A.Dainese 21.03.08)
     409           8 :   if(AliITSReconstructor::GetRecoParam()->GetSAOnePointTracks() && 
     410           0 :      TMath::Abs(event->GetMagneticField())<0.01) {
     411             :     Int_t outerLayer=1; // only SPD
     412           0 :     for(Int_t innLay=0; innLay<=TMath::Min(1,fOuterStartLayer); innLay++) {
     413             :       //   counter for clusters on each layer  
     414             : 
     415           0 :       for(Int_t nloop=0;nloop<fNloop;nloop++){
     416           0 :         Int_t nclInnLay=fCluCoord[innLay]->GetEntries();
     417           0 :         while(nclInnLay--){ //loop starting from layer innLay
     418           0 :           ResetForFinding();
     419           0 :           Bool_t useRP=SetFirstPoint(innLay,nclInnLay,primaryVertex);
     420           0 :           if(!useRP) continue;
     421           0 :           AliITStrackSA trs;
     422             :             
     423             :           Int_t pflag=0;            
     424             :           Int_t kk;
     425           0 :           for(kk=0;kk<AliITSgeomTGeo::GetNLayers();kk++) nClusLay[kk] = 0;
     426             :           
     427             :           kk=0;
     428           0 :           nClusLay[kk] = SearchClusters(innLay,fPhiWin[nloop],fLambdaWin[nloop],
     429           0 :                                   &trs,primaryVertex[2],pflag);
     430           0 :           for(Int_t nextLay=innLay+1; nextLay<=outerLayer; nextLay++) {
     431           0 :             kk++;
     432           0 :             nClusLay[kk] = SearchClusters(nextLay,fPhiWin[nloop],fLambdaWin[nloop],
     433           0 :                                     &trs,primaryVertex[2],pflag);
     434           0 :             if(nClusLay[kk]!=0){
     435             :               pflag=1;
     436           0 :               if(kk==1) {
     437           0 :                 fPoint3[0]=fPointc[0];
     438           0 :                 fPoint3[1]=fPointc[1];
     439           0 :               } else {
     440           0 :                 UpdatePoints();
     441             :               }
     442             :             }
     443             :           }
     444             :           
     445             :           Int_t layOK=0;
     446           0 :           for(Int_t nnp=0;nnp<AliITSgeomTGeo::GetNLayers()-innLay;nnp++){
     447           0 :             if(nClusLay[nnp]!=0) layOK+=1;
     448             :           }
     449           0 :           if(layOK==1) {
     450           0 :             AliDebug(2,Form("----NPOINTS: %d; MAP: %d %d %d %d %d %d\n",layOK,nClusLay[0],nClusLay[1],nClusLay[2],nClusLay[3],nClusLay[4],nClusLay[5]));
     451             :             AliITStrackV2* tr2 = 0;
     452             :             Bool_t onePoint = kTRUE;
     453           0 :             tr2 = FitTrack(&trs,primaryVertex,onePoint);
     454           0 :             if(!tr2){
     455           0 :               continue;
     456             :             }
     457           0 :             AliDebug(2,Form("----NPOINTS fit: %d\n",tr2->GetNumberOfClusters()));
     458             :             
     459           0 :             StoreTrack(tr2,event,useAllClusters);
     460           0 :             ntrack++;
     461             :             
     462           0 :           }   
     463             :           
     464           0 :         }//end loop on clusters of innLay
     465             :       } //end loop on window sizes
     466             :       
     467             :     } //end loop on innLay
     468           0 :   } // end search 1-point tracks
     469             :   
     470          16 :   if(!useAllClusters) AliInfo(Form("Number of found tracks: %d",event->GetNumberOfTracks()));
     471           8 :   ResetForFinding();
     472             :   return 0;
     473             : 
     474          16 : }
     475             :  
     476             : //________________________________________________________________________
     477             : 
     478             : AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVertex,Bool_t onePoint) {
     479             :   //fit of the found track (most general case, also <6 points, layers missing)
     480             :   // A.Dainese 16.11.07 
     481             : 
     482             :   
     483             :   const Int_t kMaxClu=AliITStrackSA::kMaxNumberOfClusters;
     484             : 
     485             :   static Int_t firstmod[AliITSgeomTGeo::kNLayers];  
     486             :   static Int_t clind[AliITSgeomTGeo::kNLayers][kMaxClu];
     487             :   static Int_t clmark[AliITSgeomTGeo::kNLayers][kMaxClu];
     488             :   static Int_t end[AliITSgeomTGeo::kNLayers];
     489             :   static Int_t indices[AliITSgeomTGeo::kNLayers];
     490             : 
     491             :   static AliITSRecPoint *listlayer[AliITSgeomTGeo::kNLayers][kMaxClu];
     492             : 
     493         224 :   for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++) {
     494          96 :     firstmod[i]=AliITSgeomTGeo::GetModuleIndex(i+1,1,1);
     495          96 :     end[i]=0;
     496        3072 :     for(Int_t j=0;j<kMaxClu; j++){
     497        1440 :       clind[i][j]=0;
     498        1440 :       clmark[i][j]=0;
     499        1440 :       listlayer[i][j]=0;
     500             :    }
     501             :   }
     502             :   
     503             : 
     504          16 :   Int_t nclusters = tr->GetNumberOfClustersSA();
     505         212 :   for(Int_t ncl=0;ncl<nclusters;ncl++){
     506          90 :     Int_t index = tr->GetClusterIndexSA(ncl); 
     507          90 :     AliITSRecPoint* cl = (AliITSRecPoint*)GetCluster(index);
     508          90 :     Int_t lay = (index & 0xf0000000) >> 28;
     509          90 :     Int_t nInLay=end[lay];
     510          90 :     listlayer[lay][nInLay]=cl;
     511          90 :     clind[lay][nInLay]=index;
     512          90 :     end[lay]++;
     513             :   }
     514             : 
     515         224 :   for(Int_t nlay=0;nlay<AliITSgeomTGeo::GetNLayers();nlay++){
     516         372 :     for(Int_t ncl=0;ncl<tr->GetNumberOfMarked(nlay);ncl++){
     517          90 :       Int_t mark = tr->GetClusterMark(nlay,ncl);
     518          90 :       clmark[nlay][ncl]=mark;
     519             :     }
     520             :   }
     521             : 
     522             : 
     523             :   Int_t firstLay=-1,secondLay=-1;
     524         224 :   for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++) {
     525          96 :     if(end[i]==0) {
     526           8 :       end[i]=1;
     527           8 :     }else{
     528          88 :       if(firstLay==-1) {
     529             :         firstLay=i;
     530          88 :       } else if(secondLay==-1) {
     531             :         secondLay=i;
     532          16 :       }
     533             :     }
     534             :   }
     535             : 
     536          32 :   if(firstLay==-1 || (secondLay==-1 && !onePoint)) return 0;
     537          16 :   TClonesArray &arrMI= *fListOfTracks;
     538          16 :   TClonesArray &arrSA= *fListOfSATracks;
     539             :   Int_t nFoundTracks=0;
     540             : 
     541             : 
     542          64 :   for(Int_t l0=0;l0<end[0];l0++){ //loop on layer 1
     543          16 :     indices[0]=l0;
     544          64 :     for(Int_t l1=0;l1<end[1];l1++){ //loop on layer 2
     545          16 :       indices[1]=l1;
     546          64 :       for(Int_t l2=0;l2<end[2];l2++){  //loop on layer 3
     547          16 :         indices[2]=l2;
     548          64 :         for(Int_t l3=0;l3<end[3];l3++){ //loop on layer 4   
     549          16 :           indices[3]=l3;
     550          64 :           for(Int_t l4=0;l4<end[4];l4++){ //loop on layer 5
     551          16 :             indices[4]=l4;
     552          68 :             for(Int_t l5=0;l5<end[5];l5++){ //loop on layer 6  
     553          18 :               indices[5]=l5;
     554             : 
     555             :               // estimate curvature from 2 innermost points (or innermost point + vertex)
     556             : 
     557          18 :               Int_t iFirstLay=indices[firstLay];
     558          18 :               Int_t mrk1=clmark[firstLay][iFirstLay];
     559             : 
     560          18 :               AliITSRecPoint* p1=(AliITSRecPoint*)listlayer[firstLay][iFirstLay];
     561          18 :               Int_t module1 = p1->GetDetectorIndex()+firstmod[firstLay]; 
     562          18 :               Int_t layer,ladder,detector;
     563          18 :               AliITSgeomTGeo::GetModuleId(module1,layer,ladder,detector);
     564          18 :               Double_t yclu1 = p1->GetY();
     565          18 :               Double_t zclu1 = p1->GetZ();
     566             : 
     567             :               Double_t x1,y1,z1;
     568             :               Double_t x2,y2,z2;
     569             :               Double_t cv=0,tgl2=0,phi2=0;
     570          18 :               AliITSclusterTable* arr1 = (AliITSclusterTable*)GetClusterCoord(firstLay,mrk1);
     571          18 :               x1 = arr1->GetX();
     572          18 :               y1 = arr1->GetY();
     573          18 :               z1 = arr1->GetZ();
     574             : 
     575          18 :               if(secondLay>0) {
     576          18 :                 Int_t iSecondLay=indices[secondLay];          
     577          18 :                 Int_t mrk2=clmark[secondLay][iSecondLay];
     578          18 :                 AliITSclusterTable* arr2 = (AliITSclusterTable*)GetClusterCoord(secondLay,mrk2);
     579          18 :                 x2 = arr2->GetX();
     580          18 :                 y2 = arr2->GetY();
     581          18 :                 z2 = arr2->GetZ();
     582          18 :                 cv = Curvature(primaryVertex[0],primaryVertex[1],x1,y1,x2,y2);
     583          18 :                 tgl2 = (z2-z1)/TMath::Sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
     584          18 :                 phi2 = TMath::ATan2((y2-y1),(x2-x1));
     585          18 :               } else { // special case of 1-point tracks, only for cosmics (B=0)
     586           0 :                 x2 = primaryVertex[0];
     587           0 :                 y2 = primaryVertex[1];
     588           0 :                 z2 = primaryVertex[2];
     589             :                 cv = 0;
     590           0 :                 tgl2 = (z1-z2)/TMath::Sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
     591           0 :                 phi2 = TMath::ATan2((y1-y2),(x1-x2));
     592             :               }
     593             : 
     594             :               // create track and attach it the RecPoints
     595          18 :               AliITStrackSA trac(layer,ladder,detector,yclu1,zclu1,phi2,tgl2,cv,1);
     596         252 :               for(Int_t iLay=5; iLay>=0; iLay--){
     597         108 :                 Int_t iInLay=indices[iLay];
     598         108 :                 AliITSRecPoint* cl=(AliITSRecPoint*)listlayer[iLay][iInLay];
     599         108 :                 if(cl!=0){
     600         100 :                   trac.AddClusterV2(iLay,(clind[iLay][iInLay] & 0x0fffffff)>>0);
     601         104 :                   trac.AddClusterMark(iLay,clmark[iLay][iInLay]);
     602             :                 }
     603             :               }
     604             : 
     605             :               //fit with Kalman filter using AliITStrackerMI::RefitAt()
     606          18 :               AliITStrackSA ot(trac);
     607             : 
     608          18 :               ot.ResetCovariance(10.);
     609          18 :               ot.ResetClusters();
     610             :               
     611             :               // Propagate inside the innermost layer with a cluster 
     612          72 :               if(ot.Propagate(ot.GetX()-0.1*ot.GetX())) {
     613             : 
     614          36 :                 if(RefitAt(AliITSRecoParam::GetrInsideITSscreen(),&ot,&trac)){ //fit from layer 1 to layer 6
     615          18 :                   AliITStrackMI otrack2(ot);
     616          18 :                   otrack2.ResetCovariance(10.); 
     617          18 :                   otrack2.ResetClusters();
     618             :                   //fit from layer 6 to layer 1
     619          36 :                   if(RefitAt(AliITSRecoParam::GetrInsideSPD1(),&otrack2,&ot)) {
     620          54 :                     new(arrMI[nFoundTracks]) AliITStrackMI(otrack2);
     621          54 :                     new(arrSA[nFoundTracks]) AliITStrackSA(trac);
     622          18 :                     ++nFoundTracks;
     623          18 :                   }
     624             :                               
     625          18 :                 }       
     626             :               }
     627          18 :             }//end loop layer 6
     628             :           }//end loop layer 5
     629             :         }//end loop layer 4        
     630             :       }//end loop layer 3
     631             :     }//end loop layer 2 
     632             :   }//end loop layer 1
     633             : 
     634             : 
     635             : 
     636             : 
     637          16 :   if(fListOfTracks->GetEntries()==0) return 0;
     638             : 
     639          16 :   Int_t lowchi2 = FindTrackLowChiSquare();
     640          16 :   AliITStrackV2* otrack =(AliITStrackV2*)fListOfTracks->At(lowchi2);
     641          16 :   AliITStrackSA* trsa = (AliITStrackSA*)fListOfSATracks->At(lowchi2);
     642             :  
     643          16 :   if(otrack==0) return 0;
     644             : 
     645          16 :   CookLabel(otrack,0.); //MI change - to see fake ratio
     646          16 :   Int_t label=FindLabel(otrack);
     647          16 :   otrack->SetLabel(label);  
     648             :   Double_t low=0.;
     649             :   Double_t up=0.51;    
     650          16 :   otrack->CookdEdx(low,up);
     651             : 
     652             :   //remove clusters of found track
     653         224 :   for(Int_t nlay=0;nlay<AliITSgeomTGeo::GetNLayers();nlay++){
     654         368 :     for(Int_t cln=0;cln<trsa->GetNumberOfMarked(nlay);cln++){
     655          88 :       Int_t index = trsa->GetClusterMark(nlay,cln);
     656          88 :       RemoveClusterCoord(nlay,index);
     657             :     }    
     658             :   }
     659             : 
     660             :   return otrack;
     661             : 
     662          16 : }
     663             : 
     664             : //_______________________________________________________
     665             : void AliITStrackerSA::StoreTrack(AliITStrackV2 *t,AliESDEvent *event, Bool_t pureSA) const 
     666             : {
     667             :   //
     668             :   // Add new track to the ESD
     669             :   //
     670          16 :   AliESDtrack outtrack;
     671          16 :   outtrack.UpdateTrackParams(t,AliESDtrack::kITSin);
     672          16 :   if(pureSA) outtrack.SetStatus(AliESDtrack::kITSpureSA);
     673         416 :   for(Int_t i=0;i<12;i++) {
     674         192 :     outtrack.SetITSModuleIndex(i,t->GetModuleIndex(i));
     675             :   }
     676          16 :   Double_t sdedx[4]={0.,0.,0.,0.};
     677         160 :   for(Int_t i=0; i<4; i++) sdedx[i]=t->GetSampledEdx(i);
     678          16 :   outtrack.SetITSdEdxSamples(sdedx);
     679             : 
     680             : 
     681          32 :   if(AliITSReconstructor::GetRecoParam()->GetSAUsedEdxInfo()){
     682           0 :     Double_t mom=t->P();
     683           0 :     Double_t ppid[AliPID::kSPECIES];
     684           0 :     for(Int_t isp=0;isp<AliPID::kSPECIES;isp++) ppid[isp]=0.;
     685           0 :     ppid[AliPID::kPion]=1.;
     686           0 :     if(mom<0.7){
     687           0 :       Double_t truncmean=t->GetdEdx();
     688           0 :       Int_t ide=fITSPid->GetParticleIdFromdEdxVsP(mom,truncmean,kTRUE);
     689           0 :       if(ide==AliPID::kProton){
     690           0 :         ppid[AliPID::kProton]=1.;
     691           0 :         ppid[AliPID::kPion]=0.;
     692           0 :       }
     693           0 :       else if(ide==AliPID::kKaon){ 
     694           0 :         ppid[AliPID::kKaon]=1.; 
     695           0 :         ppid[AliPID::kPion]=0.;
     696           0 :       }
     697           0 :     }
     698           0 :     outtrack.SetITSpid(ppid);
     699           0 :     outtrack.SetESDpid(ppid);    
     700           0 :   }
     701          16 :   event->AddTrack(&outtrack);
     702             : 
     703             :   return;
     704          16 : }
     705             : 
     706             : 
     707             : //_______________________________________________________
     708             : Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t lambdawindow, AliITStrackSA* trs,Double_t /*zvertex*/,Int_t pflag){
     709             :   //function used to to find the clusters associated to the track
     710             : 
     711       17416 :   if(ForceSkippingOfLayer(layer)) return 0;
     712             : 
     713             : 
     714             :   Int_t nc=0;
     715        8708 :   AliITSlayer &lay = fgLayers[layer];
     716        8708 :   Double_t r=lay.GetR();
     717        8708 :   if(pflag==1){      
     718         866 :     Double_t cx1,cx2,cy1,cy2;
     719         866 :     FindEquation(fPoint1[0],fPoint1[1],fPoint2[0],fPoint2[1],fPoint3[0],fPoint3[1],fCoef1,fCoef2,fCoef3);
     720         866 :     if (FindIntersection(fCoef1,fCoef2,fCoef3,-r*r,cx1,cy1,cx2,cy2)==0)
     721           0 :        return 0;
     722         866 :     Double_t fi1=TMath::ATan2(cy1-fPoint1[1],cx1-fPoint1[0]);
     723         866 :     Double_t fi2=TMath::ATan2(cy2-fPoint1[1],cx2-fPoint1[0]);
     724         866 :     fPhiEstimate=ChoosePoint(fi1,fi2,fPhic);
     725        1732 :   }
     726             : 
     727             :  
     728        8708 :   Double_t phiExpect=fPhiEstimate;
     729        8708 :   Double_t lamExpect=fLambdac;
     730             : 
     731        8708 :   Int_t ncl = fCluCoord[layer]->GetEntriesFast();
     732        8708 :   Int_t startcl=FindIndex(layer,lamExpect-lambdawindow*1.02);
     733        8708 :   Int_t endcl=FindIndex(layer,lamExpect+lambdawindow*1.02)+1;
     734       15184 :   if(endcl>=ncl) endcl=ncl-1;
     735             : 
     736       50598 :   for (Int_t index=startcl; index<=endcl; index++) {
     737             :     //for (Int_t index=0; index<ncl; index++) {
     738       12237 :     AliITSclusterTable* arr = (AliITSclusterTable*)GetClusterCoord(layer,index);
     739             : 
     740             : 
     741       12237 :     Double_t phi = arr->GetPhi();
     742       12237 :     Double_t deltaPhi = phi-phiExpect;
     743       12997 :     if(deltaPhi>TMath::Pi()) deltaPhi-=2*TMath::Pi();
     744       12219 :     else if(deltaPhi<-TMath::Pi()) deltaPhi+=2*TMath::Pi();
     745       21364 :     if (TMath::Abs(deltaPhi)>phiwindow) continue;
     746             :     
     747        3110 :     Double_t lambda = arr->GetLambda();
     748        3868 :     if (TMath::Abs(lambda-lamExpect)>lambdawindow) continue;
     749             : 
     750        2352 :     if(trs->GetNumberOfClustersSA()==trs->GetMaxNumberOfClusters()) return 0;
     751        2352 :     if(trs->GetNumberOfMarked(layer)==trs->GetMaxNMarkedPerLayer()) return 0;
     752        2352 :     Int_t orind = arr->GetOrInd();
     753        2352 :     trs->AddClusterSA(layer,orind);
     754        2352 :     trs->AddClusterMark(layer,index);
     755        2352 :     nc++;
     756        2352 :     fLambdac=lambda;
     757        2352 :     fPhiEstimate=phi;
     758             :     
     759        2352 :     fPointc[0]=arr->GetX();
     760        2352 :     fPointc[1]=arr->GetY();
     761             :     
     762        2352 :   }
     763        8708 :   return nc;
     764        8708 : }
     765             : 
     766             : //________________________________________________________________
     767             : Bool_t AliITStrackerSA::SetFirstPoint(Int_t lay, Int_t clu, Double_t* primaryVertex){
     768             :   // Sets the first point (seed) for tracking
     769             : 
     770        3252 :   AliITSclusterTable* arr = (AliITSclusterTable*)GetClusterCoord(lay,clu);
     771        1626 :   fPhic = arr->GetPhi();
     772        1626 :   fLambdac = arr->GetLambda();
     773        1626 :   fPhiEstimate = fPhic;
     774        1626 :   fPoint1[0]=primaryVertex[0];
     775        1626 :   fPoint1[1]=primaryVertex[1];
     776        1626 :   fPoint2[0]=arr->GetX();
     777        1626 :   fPoint2[1]=arr->GetY();
     778        1626 :   return kTRUE; 
     779             : }
     780             : 
     781             : //________________________________________________________________
     782             : void AliITStrackerSA::UpdatePoints(){
     783             :   //update of points for the estimation of the curvature  
     784             : 
     785         956 :   fPoint2[0]=fPoint3[0];
     786         478 :   fPoint2[1]=fPoint3[1];
     787         478 :   fPoint3[0]=fPointc[0];
     788         478 :   fPoint3[1]=fPointc[1];
     789             : 
     790             :   
     791         478 : }
     792             : 
     793             : //___________________________________________________________________
     794             : Int_t AliITStrackerSA::FindEquation(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Double_t x3, Double_t y3,Double_t& a, Double_t& b, Double_t& c){
     795             : 
     796             :    //given (x,y) of three recpoints (in global coordinates) 
     797             :    //returns the parameters a,b,c of circonference x*x + y*y +a*x + b*y +c
     798        1732 :    double dx31=x3-x1,dy31=y3-y1,dx21=x2-x1,dy21=y2-y1;
     799         866 :    Double_t den = dx31*dy21-dx21*dy31;
     800         866 :    if(den==0) return 0;
     801         866 :    else den = 1./den;
     802             :    //
     803         866 :    double r31 = -dx31*(x1+x3) - dy31*(y1+y3);
     804         866 :    double r21 = -dx21*(x1+x2) - dy21*(y1+y2);
     805             :    //
     806         866 :    double da = r31*dy21 - r21*dy31;
     807         866 :    double db = r21*dx31 - r31*dx21;
     808         866 :    a = da*den;
     809         866 :    b = db*den;
     810         866 :    c = -x1*x1-y1*y1-a*x1-b*y1;
     811             :    return 1;
     812         866 :  }
     813             : //__________________________________________________________________________
     814             :  Int_t AliITStrackerSA::FindIntersection(Double_t a1, Double_t b1, Double_t c1, Double_t c2,Double_t& x1,Double_t& y1, Double_t& x2, Double_t& y2){
     815             :  
     816             :  //Finds the intersection between the circonference of the track and the circonference centered in (0,0) represented by one layer
     817             :  //c2 is -rlayer*rlayer
     818             : 
     819        1732 :   if(a1==0) return 0;
     820         866 :  Double_t m = c2-c1; 
     821         866 :  Double_t aA = (b1*b1)/(a1*a1)+1;
     822         866 :  Double_t bB = (-2*m*b1/(a1*a1));
     823         866 :  Double_t cC = c2+(m*m)/(a1*a1);
     824         866 :  Double_t dD = bB*bB-4*aA*cC;
     825         866 :  if(dD<0) return 0;
     826             :  
     827         866 :  y1 = (-bB+TMath::Sqrt(dD))/(2*aA); 
     828         866 :  y2 = (-bB-TMath::Sqrt(dD))/(2*aA); 
     829         866 :  x1 = (c2-c1-b1*y1)/a1;
     830         866 :  x2 = (c2-c1-b1*y2)/a1;
     831             : 
     832         866 :  return 1; 
     833         866 : }
     834             : //____________________________________________________________________
     835             : Double_t AliITStrackerSA::Curvature(Double_t x1,Double_t y1,Double_t 
     836             : x2,Double_t y2,Double_t x3,Double_t y3){
     837             : 
     838             :   //calculates the curvature of track  
     839          36 :   double dy21 = y2-y1;
     840          18 :   if(TMath::Abs(dy21)<kAlmost0) return 0;
     841          18 :   Double_t den = (x3-x1)*dy21-(x2-x1)*(y3-y1);
     842          18 :   if(TMath::Abs(den)<kAlmost0) return 0;
     843          18 :   Double_t a = ((y3-y1)*(x2*x2+y2*y2-x1*x1-y1*y1)-(y2-y1)*(x3*x3+y3*y3-x1*x1-y1*y1))/den;
     844          18 :   Double_t b = -(x2*x2-x1*x1+y2*y2-y1*y1+a*(x2-x1))/dy21;
     845          18 :   Double_t c = -x1*x1-y1*y1-a*x1-b*y1;
     846          18 :   Double_t xc=-a/2.;
     847          18 :   double det = a*a+b*b-4*c;
     848          18 :   if(det<0) return 0;
     849          54 :   Double_t rad = det<kAlmost0 ? 0 :TMath::Sqrt(det)/2.;
     850          18 :   if(rad==0) return 0;
     851             :   
     852          18 :   if((x1>0 && y1>0 && x1<xc)) rad*=-1;
     853          36 :   if((x1<0 && y1>0 && x1<xc)) rad*=-1;
     854             :   //  if((x1<0 && y1<0 && x1<xc)) rad*=-1;
     855             :   // if((x1>0 && y1<0 && x1<xc)) rad*=-1;
     856             :   
     857          18 :   return 1/rad;
     858             :  
     859          18 : }
     860             : 
     861             : 
     862             : //____________________________________________________________________
     863             : Double_t AliITStrackerSA::ChoosePoint(Double_t p1, Double_t p2, Double_t pp){
     864             : 
     865             :   //Returns the point closest to pp
     866             : 
     867        1732 :   Double_t diff1 = p1-pp;
     868         866 :   Double_t diff2 = p2-pp;
     869             :   
     870        1598 :   if(TMath::Abs(diff1)<TMath::Abs(diff2)) fPhiEstimate=p1;
     871         134 :   else fPhiEstimate=p2;  
     872         866 :   return fPhiEstimate;
     873             :   
     874             : }
     875             : 
     876             : 
     877             : //_________________________________________________________________
     878             : Int_t AliITStrackerSA::FindTrackLowChiSquare() const {
     879             :   // returns track with lowest chi square  
     880          32 :   Int_t dim=fListOfTracks->GetEntries();
     881          30 :   if(dim<=1) return 0;
     882           2 :   AliITStrackV2* trk = (AliITStrackV2*)fListOfTracks->At(0);
     883           2 :   Double_t minChi2=trk->GetChi2();
     884             :   Int_t index=0;
     885           8 :   for(Int_t i=1;i<dim;i++){
     886           2 :     trk = (AliITStrackV2*)fListOfTracks->At(i);
     887           2 :     Double_t chi2=trk->GetChi2();
     888           2 :     if(chi2<minChi2){
     889             :       minChi2=chi2;
     890             :       index=i;
     891           0 :     }
     892             :   }
     893             :   return index;
     894          16 : }
     895             : 
     896             : //__________________________________________________________
     897             : Int_t AliITStrackerSA::FindLabel(AliITStrackV2* track){
     898             :   // compute the track label starting from cluster labels
     899             :   
     900          32 :   Int_t labl[AliITSgeomTGeo::kNLayers][3];
     901          16 :   Int_t cnts[AliITSgeomTGeo::kNLayers][3];
     902         224 :   for(Int_t j=0;j<AliITSgeomTGeo::GetNLayers();j++){
     903         768 :     for(Int_t k=0;k<3;k++){
     904         288 :       labl[j][k]=-2;
     905         288 :       cnts[j][k]=1;
     906             :     }
     907             :   }
     908             :   Int_t iNotLabel=0;
     909         208 :   for(Int_t i=0;i<track->GetNumberOfClusters(); i++) {
     910          88 :     Int_t indexc = track->GetClusterIndex(i);
     911          88 :     AliITSRecPoint* cl = (AliITSRecPoint*)GetCluster(indexc);
     912          88 :     Int_t iLayer=cl->GetLayer();
     913         704 :     for(Int_t k=0;k<3;k++){
     914         264 :       labl[iLayer][k]=cl->GetLabel(k);
     915         452 :       if(labl[iLayer][k]<0) iNotLabel++;
     916             :     }
     917             :   }
     918          16 :   if(iNotLabel==3*track->GetNumberOfClusters()) return -2;
     919             : 
     920         224 :   for(Int_t j1=0;j1<AliITSgeomTGeo::kNLayers; j1++) {
     921         672 :     for(Int_t j2=0; j2<j1;  j2++){
     922        1920 :       for(Int_t k1=0; k1<3; k1++){
     923        5760 :         for(Int_t k2=0; k2<3; k2++){
     924        2816 :           if(labl[j1][k1]>=0 && labl[j1][k1]==labl[j2][k2] && cnts[j2][k2]>0){
     925          56 :             cnts[j2][k2]++;
     926          56 :             cnts[j1][k1]=0;
     927          56 :           }
     928             :         }
     929             :       }
     930             :     }
     931             :   }
     932             : 
     933             : 
     934             :   Int_t cntMax=0;
     935             :   Int_t label=-1;
     936         224 :   for(Int_t j=0;j<AliITSgeomTGeo::kNLayers;j++){
     937         768 :     for(Int_t k=0;k<3;k++){
     938         360 :       if(cnts[j][k]>cntMax && labl[j][k]>=0){
     939             :         cntMax=cnts[j][k];
     940             :         label=labl[j][k];
     941          18 :       }
     942             :     }
     943             :   }
     944             : 
     945             :   Int_t lflag=0;
     946         224 :   for(Int_t i=0;i<AliITSgeomTGeo::kNLayers;i++)
     947         234 :     if(labl[i][0]==label || labl[i][1]==label || labl[i][2]==label) lflag++;
     948             :   
     949          24 :   if(lflag<track->GetNumberOfClusters()) label = -label;
     950             :   return label;
     951          16 : }
     952             : //_____________________________________________________________________________
     953             : void AliITStrackerSA::SetCalculatedWindowSizes(Int_t n, Double_t phimin, Double_t phimax, Double_t lambdamin, Double_t lambdamax){
     954             :   // Set sizes of the phi and lambda windows used for track finding
     955             : 
     956          16 :   if( n != fNloop){
     957           2 :     if(fPhiWin){
     958           0 :       delete [] fPhiWin;
     959           0 :       fPhiWin=0x0;
     960           0 :     }
     961           2 :     if(fLambdaWin){
     962           0 :       delete [] fLambdaWin;
     963           0 :       fLambdaWin=0x0;
     964           0 :     }
     965             :   }
     966           8 :   fNloop = n;
     967          10 :   if(!fPhiWin) fPhiWin = new Double_t[fNloop];
     968          10 :   if(!fLambdaWin) fLambdaWin = new Double_t[fNloop];
     969             : 
     970           8 :   Double_t stepPhi=(phimax-phimin)/(Double_t)(fNloop-1);
     971           8 :   Double_t stepLambda=(lambdamax-lambdamin)/(Double_t)(fNloop-1);
     972         336 :   for(Int_t k=0;k<fNloop;k++){
     973         160 :     Double_t phi=phimin+k*stepPhi;
     974         160 :     Double_t lam=lambdamin+k*stepLambda;
     975         160 :     fPhiWin[k]=phi;
     976         160 :     fLambdaWin[k]=lam;
     977             :   }
     978           8 : }
     979             : //_____________________________________________________________________________
     980             : void AliITStrackerSA::SetFixedWindowSizes(Int_t n, Double_t *phi, Double_t *lam){
     981             :   // Set sizes of the phi and lambda windows used for track finding
     982           0 :   fNloop = n;
     983           0 :   if(phi){ // user defined values
     984           0 :     fPhiWin = new Double_t[fNloop];
     985           0 :     fLambdaWin = new Double_t[fNloop];
     986           0 :     for(Int_t k=0;k<fNloop;k++){
     987           0 :       fPhiWin[k]=phi[k];
     988           0 :       fLambdaWin[k]=lam[k];
     989             :     }
     990           0 :   }
     991             :   else {  // default values
     992             :             
     993           0 :     Double_t phid[32]   = {0.002,0.003,0.004,0.0045,0.0047,
     994             :                            0.005,0.0053,0.0055,0.006,0.0063,
     995             :                            0.0065,0.007,0.0073,0.0075,0.0077,
     996             :                            0.008,0.0083,0.0085,0.0087,0.009,
     997             :                            0.0095,0.0097,0.01,0.0105,0.011,
     998             :                            0.0115,0.012,0.0125,0.013,0.0135,
     999             :                            0.0140,0.0145};
    1000           0 :     Double_t lambdad[32] = {0.003,0.004,0.005,0.005,0.005,
    1001             :                             0.005,0.005,0.006,0.006,0.006,
    1002             :                             0.006,0.007,0.007,0.007,0.007,
    1003             :                             0.007,0.007,0.007,0.007,0.007,
    1004             :                             0.007,0.007,0.008,0.008,0.008,
    1005             :                             0.008,0.008,0.008,0.008,0.008,
    1006             :                             0.008,0.008};
    1007             :     
    1008           0 :     if(fNloop!=32){
    1009           0 :       fNloop = 32;
    1010           0 :     }
    1011             :     
    1012             :     
    1013           0 :     fPhiWin = new Double_t[fNloop];
    1014           0 :     fLambdaWin = new Double_t[fNloop];
    1015             : 
    1016           0 :     Double_t factor=AliITSReconstructor::GetRecoParam()->GetFactorSAWindowSizes(); // possibility to enlarge windows for cosmics reco with large misalignments (A.Dainese)
    1017             :   
    1018           0 :     for(Int_t k=0;k<fNloop;k++){
    1019           0 :       fPhiWin[k]=phid[k]*factor;
    1020           0 :       fLambdaWin[k]=lambdad[k]*factor;
    1021             :     }
    1022             :   
    1023           0 :   }
    1024             : 
    1025           0 : }
    1026             : //_______________________________________________________________________
    1027             : void AliITStrackerSA::GetCoorAngles(AliITSRecPoint* cl,Double_t &phi,Double_t &lambda, Double_t &x, Double_t &y,Double_t &z, const Double_t* vertex){
    1028             :   //Returns values of phi (azimuthal) and lambda angles for a given cluster
    1029             : /*  
    1030             :   Double_t rot[9];     fGeom->GetRotMatrix(module,rot);
    1031             :   Int_t lay,lad,det; fGeom->GetModuleId(module,lay,lad,det);
    1032             :   Double_t tx,ty,tz;  fGeom->GetTrans(lay,lad,det,tx,ty,tz);     
    1033             : 
    1034             :   Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
    1035             :   Double_t phi1=TMath::Pi()/2+alpha;
    1036             :   if (lay==1) phi1+=TMath::Pi();
    1037             : 
    1038             :   Double_t cp=TMath::Cos(phi1), sp=TMath::Sin(phi1);
    1039             :   Double_t r=tx*cp+ty*sp;
    1040             : 
    1041             :   xyz= r*cp - cl->GetY()*sp;
    1042             :   y= r*sp + cl->GetY()*cp;
    1043             :   z=cl->GetZ();
    1044             : */
    1045         496 :   Float_t xyz[3];
    1046         248 :   cl->GetGlobalXYZ(xyz);
    1047         248 :   x=xyz[0];
    1048         248 :   y=xyz[1];
    1049         248 :   z=xyz[2];
    1050             :  
    1051         248 :   phi=TMath::ATan2(y-vertex[1],x-vertex[0]);
    1052         248 :   lambda=TMath::ATan2(z-vertex[2],TMath::Sqrt((x-vertex[0])*(x-vertex[0])+(y-vertex[1])*(y-vertex[1])));
    1053         248 : }
    1054             : 
    1055             : //________________________________________________________________________
    1056             : void AliITStrackerSA::GetCoorErrors(AliITSRecPoint* cl,Double_t &sx,Double_t &sy, Double_t &sz){
    1057             : 
    1058             :   //returns sigmax, y, z of cluster in global coordinates
    1059             : /*
    1060             :   Double_t rot[9];     fGeom->GetRotMatrix(module,rot);
    1061             :   Int_t lay,lad,det; 
    1062             :   AliITSgeomTGeo::GetModuleId(module,lay,lad,det);
    1063             :  
    1064             :   Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
    1065             :   Double_t phi=TMath::Pi()/2+alpha;
    1066             :   if (lay==1) phi+=TMath::Pi();
    1067             : 
    1068             :   Double_t cp=TMath::Cos(phi), sp=TMath::Sin(phi);
    1069             : */
    1070         496 :   Float_t covm[6];
    1071         248 :   cl->GetGlobalCov(covm);
    1072         248 :   sx=TMath::Sqrt(covm[0]);
    1073         248 :   sy=TMath::Sqrt(covm[3]);
    1074         248 :   sz=TMath::Sqrt(covm[5]);
    1075             : /*
    1076             :   sx = TMath::Sqrt(sp*sp*cl->GetSigmaY2());
    1077             :   sy = TMath::Sqrt(cp*cp*cl->GetSigmaY2());
    1078             :   sz = TMath::Sqrt(cl->GetSigmaZ2());
    1079             : */
    1080         248 : }
    1081             : 
    1082             : //________________________________________________________________________
    1083             : Int_t AliITStrackerSA::FindIndex(Int_t lay, Double_t lamVal) const {
    1084             :   // Find the cluster at limit of lambda window 
    1085             : 
    1086             :   Int_t base = 0;
    1087       34832 :   Int_t last = fCluCoord[lay]->GetEntriesFast()-1;
    1088       19440 :   if(last<0) return 0;
    1089             :   Int_t position;
    1090       15392 :   Double_t lamfirst=((AliITSclusterTable*)fCluCoord[lay]->At(base))->GetLambda();
    1091       17344 :   if(lamfirst>lamVal) return base;
    1092       13440 :   Double_t lamlast=((AliITSclusterTable*)fCluCoord[lay]->At(last))->GetLambda();
    1093       22466 :   if(lamlast<=lamVal) return last;
    1094        9029 :   while (last >= base) {
    1095        9029 :     position = (base+last) / 2;
    1096        9029 :     Double_t a=((AliITSclusterTable*)fCluCoord[lay]->At(position))->GetLambda()-lamVal;
    1097        9029 :     Double_t b=((AliITSclusterTable*)fCluCoord[lay]->At(position+1))->GetLambda()-lamVal;
    1098       13443 :     if(a*b<=0) return position;
    1099        7184 :     if(a>0) last = position;
    1100             :     else  base = position;
    1101        4615 :   }
    1102           0 :   return 0;
    1103       17416 : }
    1104             : 

Generated by: LCOV version 1.11