LCOV - code coverage report
Current view: top level - ITS/ITSbase - AliITStrackerV2.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 24 678 3.5 %
Date: 2016-06-14 17:26:59 Functions: 8 37 21.6 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, 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             : /* $Id$ */
      16             : //-------------------------------------------------------------------------
      17             : //               Implementation of the ITS tracker class
      18             : //    It reads AliITSRecPoint clusters and creates AliITStrackV2 tracks
      19             : //                   and fills with them the ESD
      20             : //          Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
      21             : //     dEdx analysis by: Boris Batyunya, JINR, Boris.Batiounia@cern.ch
      22             : //-------------------------------------------------------------------------
      23             : 
      24             : #include <new>
      25             : 
      26             : #include <TError.h>
      27             : #include <TFile.h>
      28             : #include <TTree.h>
      29             : #include <TRandom.h>
      30             : #include <TGeoMatrix.h>
      31             : 
      32             : #include "AliITSgeomTGeo.h"
      33             : #include "AliAlignObj.h"
      34             : #include "AliITSRecPoint.h"
      35             : #include "AliESDEvent.h"
      36             : #include "AliESDtrack.h"
      37             : #include "AliITSRecPoint.h"
      38             : #include "AliITSReconstructor.h"
      39             : #include "AliITStrackerV2.h"
      40             : 
      41         118 : ClassImp(AliITStrackerV2)
      42             : 
      43        1416 : AliITStrackerV2::AliITSlayer AliITStrackerV2::fgLayers[AliITSgeomTGeo::kNLayers]; //ITS layers
      44             : 
      45           0 : AliITStrackerV2::AliITStrackerV2(): 
      46           0 :   AliTracker(), 
      47           0 :   fI(AliITSgeomTGeo::GetNLayers()),
      48           0 :   fBestTrack(),
      49           0 :   fTrackToFollow(),
      50           0 :   fPass(0),
      51           0 :   fLastLayerToTrackTo(AliITSRecoParam::GetLastLayerToTrackTo())
      52           0 : {
      53             :   //--------------------------------------------------------------------
      54             :   //This is the AliITStrackerV2 default constructor
      55             :   //--------------------------------------------------------------------
      56             : 
      57           0 :   for (Int_t i=1; i<AliITSgeomTGeo::GetNLayers()+1; i++) new(fgLayers+i-1) AliITSlayer();
      58             : 
      59           0 :   fConstraint[0]=1; fConstraint[1]=0;
      60             : 
      61           0 :   Double_t xyz[]={AliITSReconstructor::GetRecoParam()->GetXVdef(),
      62           0 :                   AliITSReconstructor::GetRecoParam()->GetYVdef(),
      63           0 :                   AliITSReconstructor::GetRecoParam()->GetZVdef()}; 
      64           0 :   Double_t ers[]={AliITSReconstructor::GetRecoParam()->GetSigmaXVdef(),
      65           0 :                   AliITSReconstructor::GetRecoParam()->GetSigmaYVdef(),
      66           0 :                   AliITSReconstructor::GetRecoParam()->GetSigmaZVdef()}; 
      67           0 :   SetVertex(xyz,ers);
      68             : 
      69           0 :   for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) fLayersNotToSkip[i]=AliITSRecoParam::GetLayersNotToSkip(i);
      70             : 
      71           0 : }
      72             : 
      73           0 : AliITStrackerV2::AliITStrackerV2(const AliITStrackerV2 &t): 
      74           0 :   AliTracker(t), 
      75           0 :   fI(t.fI),
      76           0 :   fBestTrack(t.fBestTrack),
      77           0 :   fTrackToFollow(t.fTrackToFollow),
      78           0 :   fPass(t.fPass),
      79           0 :   fLastLayerToTrackTo(t.fLastLayerToTrackTo)
      80           0 : {
      81             :   //--------------------------------------------------------------------
      82             :   //This is the AliITStrackerV2 copy constructor
      83             :   //--------------------------------------------------------------------
      84             : 
      85             :   //for (Int_t i=1; i<AliITSgeomTGeo::GetNLayers()+1; i++) new(fgLayers+i-1) AliITSlayer();
      86             : 
      87           0 :   fConstraint[0]=t.fConstraint[0]; fConstraint[1]=t.fConstraint[1];
      88             : 
      89           0 :   Double_t xyz[]={AliITSReconstructor::GetRecoParam()->GetXVdef(),
      90           0 :                   AliITSReconstructor::GetRecoParam()->GetYVdef(),
      91           0 :                   AliITSReconstructor::GetRecoParam()->GetZVdef()}; 
      92           0 :   Double_t ers[]={AliITSReconstructor::GetRecoParam()->GetSigmaXVdef(),
      93           0 :                   AliITSReconstructor::GetRecoParam()->GetSigmaYVdef(),
      94           0 :                   AliITSReconstructor::GetRecoParam()->GetSigmaZVdef()}; 
      95           0 :   xyz[0]=t.GetX(); xyz[1]=t.GetY(); xyz[2]=t.GetZ(); 
      96           0 :   ers[0]=t.GetSigmaX(); ers[1]=t.GetSigmaY(); ers[2]=t.GetSigmaZ(); 
      97           0 :   SetVertex(xyz,ers);
      98             : 
      99           0 :   for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) fLayersNotToSkip[i]=t.fLayersNotToSkip[i];
     100             : 
     101           0 : }
     102             : 
     103           0 : AliITStrackerV2::AliITStrackerV2(const Char_t *geom) : 
     104           0 :   AliTracker(), 
     105           0 :   fI(AliITSgeomTGeo::GetNLayers()),
     106           0 :   fBestTrack(),
     107           0 :   fTrackToFollow(),
     108           0 :   fPass(0),
     109           0 :   fLastLayerToTrackTo(AliITSRecoParam::GetLastLayerToTrackTo())
     110           0 : {
     111             :   //--------------------------------------------------------------------
     112             :   //This is the AliITStrackerV2 constructor
     113             :   //--------------------------------------------------------------------
     114           0 :   if (geom) {
     115           0 :     AliWarning("\"geom\" is actually a dummy argument !");
     116             :   }
     117             : 
     118           0 :   for (Int_t i=1; i<AliITSgeomTGeo::GetNLayers()+1; i++) {
     119           0 :     Int_t nlad=AliITSgeomTGeo::GetNLadders(i);
     120           0 :     Int_t ndet=AliITSgeomTGeo::GetNDetectors(i);
     121             : 
     122           0 :     Double_t xyz[3], &x=xyz[0], &y=xyz[1], &z=xyz[2];
     123           0 :     AliITSgeomTGeo::GetOrigTranslation(i,1,1,xyz); 
     124           0 :     Double_t poff=TMath::ATan2(y,x);
     125           0 :     Double_t zoff=z;
     126           0 :     Double_t r=TMath::Sqrt(x*x + y*y);
     127             : 
     128           0 :     AliITSgeomTGeo::GetOrigTranslation(i,1,2,xyz);
     129           0 :     r += TMath::Sqrt(x*x + y*y);
     130           0 :     AliITSgeomTGeo::GetOrigTranslation(i,2,1,xyz);
     131           0 :     r += TMath::Sqrt(x*x + y*y);
     132           0 :     AliITSgeomTGeo::GetOrigTranslation(i,2,2,xyz);
     133           0 :     r += TMath::Sqrt(x*x + y*y);
     134           0 :     r*=0.25;
     135             : 
     136           0 :     new (fgLayers+i-1) AliITSlayer(r,poff,zoff,nlad,ndet);
     137             : 
     138           0 :     for (Int_t j=1; j<nlad+1; j++) {
     139           0 :       for (Int_t k=1; k<ndet+1; k++) { //Fill this layer with detectors
     140           0 :         TGeoHMatrix m; AliITSgeomTGeo::GetOrigMatrix(i,j,k,m);
     141           0 :         const TGeoHMatrix *tm=AliITSgeomTGeo::GetTracking2LocalMatrix(i,j,k);
     142           0 :         m.Multiply(tm);
     143           0 :         Double_t txyz[3]={0.}; 
     144           0 :         xyz[0]=0.; xyz[1]=0.; xyz[2]=0.;
     145           0 :         m.LocalToMaster(txyz,xyz);
     146           0 :         r=TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
     147           0 :         Double_t phi=TMath::ATan2(xyz[1],xyz[0]);
     148             : 
     149           0 :         if (phi<0) phi+=TMath::TwoPi();
     150           0 :         else if (phi>=TMath::TwoPi()) phi-=TMath::TwoPi();
     151             : 
     152           0 :         AliITSdetector &det=fgLayers[i-1].GetDetector((j-1)*ndet + k-1); 
     153           0 :         new(&det) AliITSdetector(r,phi); 
     154           0 :       } 
     155             :     }  
     156             : 
     157           0 :   }
     158             : 
     159           0 :   fConstraint[0]=1; fConstraint[1]=0;
     160             : 
     161           0 :   Double_t xyz[]={AliITSReconstructor::GetRecoParam()->GetXVdef(),
     162           0 :                   AliITSReconstructor::GetRecoParam()->GetYVdef(),
     163           0 :                   AliITSReconstructor::GetRecoParam()->GetZVdef()}; 
     164           0 :   Double_t ers[]={AliITSReconstructor::GetRecoParam()->GetSigmaXVdef(),
     165           0 :                   AliITSReconstructor::GetRecoParam()->GetSigmaYVdef(),
     166           0 :                   AliITSReconstructor::GetRecoParam()->GetSigmaZVdef()}; 
     167           0 :   SetVertex(xyz,ers);
     168             : 
     169           0 :   for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) fLayersNotToSkip[i]=AliITSRecoParam::GetLayersNotToSkip(i);
     170             : 
     171           0 : }
     172             : 
     173             : void AliITStrackerV2::SetLayersNotToSkip(Int_t *l) {
     174             :   //--------------------------------------------------------------------
     175             :   //This function set masks of the layers which must be not skipped
     176             :   //--------------------------------------------------------------------
     177           0 :   for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) fLayersNotToSkip[i]=l[i];
     178           0 : }
     179             : 
     180             : Int_t AliITStrackerV2::LoadClusters(TTree *cTree) {
     181             :   //--------------------------------------------------------------------
     182             :   //This function loads ITS clusters
     183             :   //--------------------------------------------------------------------
     184           0 :   TBranch *branch=cTree->GetBranch("ITSRecPoints");
     185           0 :   if (!branch) { 
     186           0 :     Error("LoadClusters"," can't get the branch !\n");
     187           0 :     return 1;
     188             :   }
     189             : 
     190           0 :   TClonesArray dummy("AliITSRecPoint",10000), *clusters=&dummy;
     191           0 :   branch->SetAddress(&clusters);
     192             : 
     193             :   Int_t j=0;
     194           0 :   for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) {
     195           0 :     Int_t ndet=fgLayers[i].GetNdetectors();
     196           0 :     Int_t jmax = j + fgLayers[i].GetNladders()*ndet;
     197             : 
     198           0 :     Double_t r=fgLayers[i].GetR();
     199           0 :     Double_t circ=TMath::TwoPi()*r;
     200             : 
     201           0 :     for (; j<jmax; j++) {           
     202           0 :       if (!cTree->GetEvent(j)) continue;
     203           0 :       Int_t ncl=clusters->GetEntriesFast();
     204             :  
     205           0 :       while (ncl--) {
     206           0 :         AliITSRecPoint *c=(AliITSRecPoint*)clusters->UncheckedAt(ncl);
     207             : 
     208           0 :         if (!c->Misalign()) AliWarning("Can't misalign this cluster !");
     209             : 
     210           0 :         Int_t idx=c->GetDetectorIndex();
     211           0 :         AliITSdetector &det=fgLayers[i].GetDetector(idx);
     212             :    
     213           0 :         Double_t y=r*det.GetPhi()+c->GetY();
     214           0 :         if (y>circ) y-=circ; else if (y<0) y+=circ;
     215           0 :         c->SetPhiR(y);
     216             : 
     217           0 :         fgLayers[i].InsertCluster(new AliITSRecPoint(*c));
     218             :       }
     219           0 :       clusters->Delete();
     220           0 :     }
     221           0 :     fgLayers[i].ResetRoad(); //road defined by the cluster density
     222             :   }
     223             : 
     224             :   return 0;
     225           0 : }
     226             : 
     227             : void AliITStrackerV2::UnloadClusters() {
     228             :   //--------------------------------------------------------------------
     229             :   //This function unloads ITS clusters
     230             :   //--------------------------------------------------------------------
     231           0 :   for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) fgLayers[i].ResetClusters();
     232           0 : }
     233             : 
     234             : static Int_t CorrectForDeadZoneMaterial(AliITStrackV2 *t) {
     235             :   //--------------------------------------------------------------------
     236             :   // Correction for the material between the TPC and the ITS
     237             :   // (should it belong to the TPC code ?)
     238             :   //--------------------------------------------------------------------
     239             :   Double_t riw=80., diw=0.0053, x0iw=30; // TPC inner wall ? 
     240             :   Double_t rcd=61., dcd=0.0053, x0cd=30; // TPC "central drum" ?
     241             :   Double_t yr=12.8, dr=0.03; // rods ?
     242             :   Double_t zm=0.2, dm=0.40;  // membrane
     243             :   //Double_t rr=52., dr=0.19, x0r=24., yyr=7.77; //rails
     244             :   Double_t rs=50., ds=0.001; // something belonging to the ITS (screen ?)
     245             : 
     246           0 :   if (t->GetX() > riw) {
     247           0 :      if (!t->PropagateTo(riw,diw,x0iw)) return 1;
     248           0 :      if (TMath::Abs(t->GetY())>yr) t->CorrectForMaterial(dr);
     249           0 :      if (TMath::Abs(t->GetZ())<zm) t->CorrectForMaterial(dm);
     250           0 :      if (!t->PropagateTo(rcd,dcd,x0cd)) return 1;
     251             :      //Double_t x,y,z; t->GetGlobalXYZat(rr,x,y,z);
     252             :      //if (TMath::Abs(y)<yyr) t->PropagateTo(rr,dr,x0r); 
     253           0 :      if (!t->PropagateTo(rs,ds)) return 1;
     254           0 :   } else if (t->GetX() < rs) {
     255           0 :      if (!t->PropagateTo(rs,-ds)) return 1;
     256             :      //Double_t x,y,z; t->GetGlobalXYZat(rr,x,y,z);
     257             :      //if (TMath::Abs(y)<yyr) t->PropagateTo(rr,-dr,x0r); 
     258           0 :      if (!t->PropagateTo(rcd,-dcd,x0cd)) return 1;
     259           0 :      if (!t->PropagateTo(riw+0.001,-diw,x0iw)) return 1;
     260             :   } else {
     261           0 :   ::Error("CorrectForDeadZoneMaterial","track is already in the dead zone !");
     262           0 :     return 1;
     263             :   }
     264             :   
     265           0 :   return 0;
     266           0 : }
     267             : 
     268             : Int_t AliITStrackerV2::Clusters2Tracks(AliESDEvent *event) {
     269             :   //--------------------------------------------------------------------
     270             :   // This functions reconstructs ITS tracks
     271             :   // The clusters must be already loaded !
     272             :   //--------------------------------------------------------------------
     273           0 :   TObjArray itsTracks(15000);
     274             : 
     275             :   {/* Read ESD tracks */
     276           0 :     Int_t nentr=event->GetNumberOfTracks();
     277           0 :     Info("Clusters2Tracks", "Number of ESD tracks: %d\n", nentr);
     278           0 :     while (nentr--) {
     279           0 :       AliESDtrack *esd=event->GetTrack(nentr);
     280             : 
     281           0 :       if ((esd->GetStatus()&AliESDtrack::kTPCin)==0) continue;
     282           0 :       if (esd->GetStatus()&AliESDtrack::kTPCout) continue;
     283           0 :       if (esd->GetStatus()&AliESDtrack::kITSin) continue;
     284             : 
     285           0 :       AliITStrackV2 *t = new AliITStrackV2(*esd);
     286             : 
     287           0 :       if (TMath::Abs(t->GetD(GetX(),GetY()))>4) {
     288           0 :         delete t;
     289           0 :         continue;
     290             :       }
     291             : 
     292           0 :       if (CorrectForDeadZoneMaterial(t)!=0) {
     293           0 :          Warning("Clusters2Tracks",
     294             :                  "failed to correct for the material in the dead zone !\n");
     295           0 :          delete t;
     296           0 :          continue;
     297             :       }
     298           0 :       itsTracks.AddLast(t);
     299           0 :     }
     300             :   } /* End Read ESD tracks */
     301             : 
     302           0 :   itsTracks.Sort();
     303           0 :   Int_t nentr=itsTracks.GetEntriesFast();
     304             : 
     305             :   Int_t ntrk=0;
     306           0 :   for (fPass=0; fPass<2; fPass++) {
     307           0 :      Int_t &constraint=fConstraint[fPass]; if (constraint<0) continue;
     308           0 :      for (Int_t i=0; i<nentr; i++) {
     309           0 :        AliITStrackV2 *t=(AliITStrackV2*)itsTracks.UncheckedAt(i);
     310           0 :        if (t==0) continue;           //this track has been already tracked
     311           0 :        Int_t tpcLabel=t->GetLabel(); //save the TPC track label
     312             : 
     313           0 :        ResetTrackToFollow(*t);
     314           0 :        ResetBestTrack();
     315             : 
     316           0 :        for (FollowProlongation(); fI<AliITSgeomTGeo::GetNLayers(); fI++) {
     317           0 :           while (TakeNextProlongation()) FollowProlongation();
     318             :        }
     319             : 
     320           0 :        if (fBestTrack.GetNumberOfClusters() == 0) continue;
     321             : 
     322           0 :        if (fConstraint[fPass]) {
     323           0 :           ResetTrackToFollow(*t);
     324           0 :           if (!RefitAt(3.7, &fTrackToFollow, &fBestTrack)) continue;
     325           0 :           ResetBestTrack();
     326             :        }
     327             : 
     328           0 :        fBestTrack.SetLabel(tpcLabel);
     329           0 :        fBestTrack.CookdEdx();
     330           0 :        CookLabel(&fBestTrack,0.); //For comparison only
     331           0 :        fBestTrack.UpdateESDtrack(AliESDtrack::kITSin);
     332           0 :        UseClusters(&fBestTrack);
     333           0 :        delete itsTracks.RemoveAt(i);
     334           0 :        ntrk++;
     335           0 :      }
     336           0 :   }
     337             : 
     338           0 :   itsTracks.Delete();
     339             : 
     340           0 :   Info("Clusters2Tracks","Number of prolonged tracks: %d\n",ntrk);
     341             : 
     342             :   return 0;
     343           0 : }
     344             : 
     345             : Int_t AliITStrackerV2::PropagateBack(AliESDEvent *event) {
     346             :   //--------------------------------------------------------------------
     347             :   // This functions propagates reconstructed ITS tracks back
     348             :   // The clusters must be loaded !
     349             :   //--------------------------------------------------------------------
     350           0 :   Int_t nentr=event->GetNumberOfTracks();
     351           0 :   Info("PropagateBack", "Number of ESD tracks: %d\n", nentr);
     352             : 
     353             :   Int_t ntrk=0;
     354           0 :   for (Int_t i=0; i<nentr; i++) {
     355           0 :      AliESDtrack *esd=event->GetTrack(i);
     356             : 
     357           0 :      if ((esd->GetStatus()&AliESDtrack::kITSin)==0) continue;
     358           0 :      if (esd->GetStatus()&AliESDtrack::kITSout) continue;
     359             : 
     360           0 :      AliITStrackV2 *t = new AliITStrackV2(*esd);
     361             : 
     362           0 :      ResetTrackToFollow(*t);
     363             : 
     364             :      // propagete to vertex [SR, GSI 17.02.2003]
     365             :      // Start Time measurement [SR, GSI 17.02.2003], corrected by I.Belikov
     366           0 :      if (fTrackToFollow.PropagateTo(3.,0.0028,65.19)) {
     367           0 :        if (fTrackToFollow.PropagateToVertex(event->GetVertex())) {
     368           0 :           fTrackToFollow.StartTimeIntegral();
     369           0 :        }
     370           0 :        Bool_t okProp=fTrackToFollow.PropagateTo(3.,-0.0028,65.19);
     371           0 :        if(!okProp){
     372           0 :          AliWarning("Propagation to beam pipe radius failed");
     373           0 :        }
     374           0 :      }
     375             : 
     376           0 :      fTrackToFollow.ResetCovariance(10.); fTrackToFollow.ResetClusters();
     377           0 :      if (RefitAt(49.,&fTrackToFollow,t)) {
     378           0 :         if (CorrectForDeadZoneMaterial(&fTrackToFollow)!=0) {
     379           0 :           Warning("PropagateBack",
     380             :                   "failed to correct for the material in the dead zone !\n");
     381           0 :           delete t;
     382           0 :           continue;
     383             :         }
     384           0 :         fTrackToFollow.SetLabel(t->GetLabel());
     385             :         //fTrackToFollow.CookdEdx();
     386           0 :         CookLabel(&fTrackToFollow,0.); //For comparison only
     387           0 :         fTrackToFollow.UpdateESDtrack(AliESDtrack::kITSout);
     388           0 :         UseClusters(&fTrackToFollow);
     389           0 :         ntrk++;
     390           0 :      }
     391           0 :      delete t;
     392           0 :   }
     393             : 
     394           0 :   Info("PropagateBack","Number of back propagated ITS tracks: %d\n",ntrk);
     395             : 
     396           0 :   return 0;
     397           0 : }
     398             : 
     399             : Int_t AliITStrackerV2::RefitInward(AliESDEvent *event) {
     400             :   //--------------------------------------------------------------------
     401             :   // This functions refits ITS tracks using the 
     402             :   // "inward propagated" TPC tracks
     403             :   // The clusters must be loaded !
     404             :   //--------------------------------------------------------------------
     405           0 :   Int_t nentr=event->GetNumberOfTracks();
     406           0 :   Info("RefitInward", "Number of ESD tracks: %d\n", nentr);
     407             : 
     408             :   Int_t ntrk=0;
     409           0 :   for (Int_t i=0; i<nentr; i++) {
     410           0 :     AliESDtrack *esd=event->GetTrack(i);
     411             : 
     412           0 :     if ((esd->GetStatus()&AliESDtrack::kITSout) == 0) continue;
     413           0 :     if (esd->GetStatus()&AliESDtrack::kITSrefit) continue;
     414           0 :     if (esd->GetStatus()&AliESDtrack::kTPCout)
     415           0 :     if ((esd->GetStatus()&AliESDtrack::kTPCrefit)==0) continue;
     416             : 
     417           0 :     AliITStrackV2 *t = new AliITStrackV2(*esd);
     418             : 
     419           0 :     if (CorrectForDeadZoneMaterial(t)!=0) {
     420           0 :        Warning("RefitInward",
     421             :                "failed to correct for the material in the dead zone !\n");
     422           0 :        delete t;
     423           0 :        continue;
     424             :     }
     425             : 
     426           0 :     ResetTrackToFollow(*t);
     427           0 :     fTrackToFollow.ResetClusters();
     428             : 
     429             :     //Refitting...
     430           0 :     if (RefitAt(3.7, &fTrackToFollow, t, kTRUE)) {
     431           0 :        fTrackToFollow.SetLabel(t->GetLabel());
     432           0 :        fTrackToFollow.CookdEdx();
     433           0 :        CookLabel(&fTrackToFollow,0.); //For comparison only
     434             : 
     435           0 :        if (fTrackToFollow.PropagateTo(3.,0.0028,65.19)) {//The beam pipe 
     436           0 :          fTrackToFollow.UpdateESDtrack(AliESDtrack::kITSrefit);
     437           0 :          AliESDtrack  *esdTrack =fTrackToFollow.GetESDtrack();
     438           0 :          Double_t r[3]={0.,0.,0.};
     439             :          Double_t maxD=3.;
     440           0 :          esdTrack->RelateToVertex(event->GetVertex(),GetBz(r),maxD);
     441           0 :          ntrk++;
     442           0 :        }
     443             :     }
     444           0 :     delete t;
     445           0 :   }
     446             : 
     447           0 :   Info("RefitInward","Number of refitted tracks: %d\n",ntrk);
     448             : 
     449           0 :   return 0;
     450           0 : }
     451             : 
     452             : AliCluster *AliITStrackerV2::GetCluster(Int_t index) const {
     453             :   //--------------------------------------------------------------------
     454             :   //       Return pointer to a given cluster
     455             :   //--------------------------------------------------------------------
     456           0 :   Int_t l=(index & 0xf0000000) >> 28;
     457           0 :   Int_t c=(index & 0x0fffffff) >> 00;
     458           0 :   return fgLayers[l].GetCluster(c);
     459             : }
     460             : 
     461             : 
     462             : void AliITStrackerV2::FollowProlongation() {
     463             :   //--------------------------------------------------------------------
     464             :   //This function finds a track prolongation 
     465             :   //--------------------------------------------------------------------
     466           0 :   while (fI>fLastLayerToTrackTo) {
     467           0 :     Int_t i=fI-1;
     468             : 
     469           0 :     AliITSlayer &layer=fgLayers[i];
     470           0 :     AliITStrackV2 &track=fTracks[i];
     471             : 
     472           0 :     Double_t r=layer.GetR();
     473             : 
     474           0 :     if (i==3 || i==1) {
     475           0 :        Double_t rs=0.5*(fgLayers[i+1].GetR() + r);
     476             :        Double_t d=0.0034, x0=38.6;
     477           0 :        if (i==1) {rs=9.; d=0.0097; x0=42;}
     478           0 :        if (!fTrackToFollow.PropagateTo(rs,d,x0)) {
     479             :          //Warning("FollowProlongation","propagation failed !\n");
     480           0 :          return;
     481             :        }
     482           0 :     }
     483             : 
     484             :     //find intersection
     485           0 :     Double_t phi,z;  
     486           0 :     if (!fTrackToFollow.GetPhiZat(r,phi,z)) {
     487             :       //Warning("FollowProlongation","failed to estimate track !\n");
     488           0 :       return;
     489             :     }
     490             : 
     491           0 :     Int_t idet=layer.FindDetectorIndex(phi,z);
     492           0 :     if (idet<0) {
     493             :       //Warning("FollowProlongation","failed to find a detector !\n");
     494           0 :       return;
     495             :     }
     496             : 
     497             :     //propagate to the intersection
     498           0 :     const AliITSdetector &det=layer.GetDetector(idet);
     499           0 :     phi=det.GetPhi();
     500           0 :     if (!fTrackToFollow.Propagate(phi,det.GetR())) {
     501             :       //Warning("FollowProlongation","propagation failed !\n");
     502           0 :       return;
     503             :     }
     504           0 :     fTrackToFollow.SetDetectorIndex(idet);
     505             : 
     506             :     //Select possible prolongations and store the current track estimation
     507           0 :     track.~AliITStrackV2(); new(&track) AliITStrackV2(fTrackToFollow);
     508           0 :     Double_t dz=7*TMath::Sqrt(track.GetSigmaZ2() + AliITSReconstructor::GetRecoParam()->GetSigmaZ2(i));
     509           0 :     Double_t dy=7*TMath::Sqrt(track.GetSigmaY2() + AliITSReconstructor::GetRecoParam()->GetSigmaY2(i));
     510           0 :     Double_t road=layer.GetRoad();
     511           0 :     if (dz*dy>road*road) {
     512           0 :        Double_t dd=TMath::Sqrt(dz*dy), scz=dz/dd, scy=dy/dd;
     513           0 :        dz=road*scz; dy=road*scy;
     514           0 :     } 
     515             : 
     516             :     //Double_t dz=4*TMath::Sqrt(track.GetSigmaZ2() + AliITSReconstructor::GetRecoParam()->GetSigmaZ2(i));
     517           0 :     if (dz < 0.5*TMath::Abs(track.GetTgl())) dz=0.5*TMath::Abs(track.GetTgl());
     518           0 :     if (dz > AliITSReconstructor::GetRecoParam()->GetMaxRoad()) {
     519             :       //Warning("FollowProlongation","too broad road in Z !\n");
     520           0 :       return;
     521             :     }
     522             : 
     523           0 :     if (TMath::Abs(fTrackToFollow.GetZ()-GetZ()) > r+dz) return;
     524             : 
     525             :     //Double_t dy=4*TMath::Sqrt(track.GetSigmaY2() + AliITSReconstructor::GetRecoParam()->GetSigmaY2(i));
     526           0 :     if (dy < 0.5*TMath::Abs(track.GetSnp())) dy=0.5*TMath::Abs(track.GetSnp());
     527           0 :     if (dy > AliITSReconstructor::GetRecoParam()->GetMaxRoad()) {
     528             :       //Warning("FollowProlongation","too broad road in Y !\n");
     529           0 :       return;
     530             :     }
     531             : 
     532           0 :     fI--;
     533             : 
     534           0 :     Double_t zmin=track.GetZ() - dz; 
     535           0 :     Double_t zmax=track.GetZ() + dz;
     536           0 :     Double_t ymin=track.GetY() + r*phi - dy;
     537           0 :     Double_t ymax=track.GetY() + r*phi + dy;
     538           0 :     if (layer.SelectClusters(zmin,zmax,ymin,ymax)==0) 
     539           0 :        if (fLayersNotToSkip[fI]) return;  
     540             : 
     541           0 :     if (!TakeNextProlongation()) 
     542           0 :        if (fLayersNotToSkip[fI]) return;
     543             : 
     544           0 :   } 
     545             : 
     546             :   //deal with the best track
     547           0 :   Int_t ncl=fTrackToFollow.GetNumberOfClusters();
     548           0 :   Int_t nclb=fBestTrack.GetNumberOfClusters();
     549           0 :   if (ncl)
     550           0 :   if (ncl >= nclb) {
     551           0 :      Double_t chi2=fTrackToFollow.GetChi2();
     552           0 :      if (chi2/ncl < AliITSReconstructor::GetRecoParam()->GetChi2PerCluster()) {        
     553           0 :         if (ncl > nclb || chi2 < fBestTrack.GetChi2()) {
     554           0 :            ResetBestTrack();
     555           0 :         }
     556             :      }
     557           0 :   }
     558             : 
     559           0 : }
     560             : 
     561             : Int_t AliITStrackerV2::TakeNextProlongation() {
     562             :   //--------------------------------------------------------------------
     563             :   // This function takes another track prolongation 
     564             :   //
     565             :   //  dEdx analysis by: Boris Batyunya, JINR, Boris.Batiounia@cern.ch 
     566             :   //--------------------------------------------------------------------
     567           0 :   AliITSlayer &layer=fgLayers[fI];
     568           0 :   ResetTrackToFollow(fTracks[fI]);
     569             : 
     570           0 :   Double_t dz=7*TMath::Sqrt(fTrackToFollow.GetSigmaZ2() + AliITSReconstructor::GetRecoParam()->GetSigmaZ2(fI));
     571           0 :   Double_t dy=7*TMath::Sqrt(fTrackToFollow.GetSigmaY2() + AliITSReconstructor::GetRecoParam()->GetSigmaY2(fI));
     572           0 :   Double_t road=layer.GetRoad();
     573           0 :   if (dz*dy>road*road) {
     574           0 :      Double_t dd=TMath::Sqrt(dz*dy), scz=dz/dd, scy=dy/dd;
     575           0 :      dz=road*scz; dy=road*scy;
     576           0 :   } 
     577             : 
     578           0 :   const AliITSRecPoint *c=0; Int_t ci=-1;
     579             :   const AliITSRecPoint *cc=0; Int_t cci=-1;
     580           0 :   Double_t chi2=AliITSReconstructor::GetRecoParam()->GetMaxChi2();
     581           0 :   while ((c=layer.GetNextCluster(ci))!=0) {
     582           0 :     Int_t idet=c->GetDetectorIndex();
     583             : 
     584           0 :     if (fTrackToFollow.GetDetectorIndex()!=idet) {
     585           0 :        const AliITSdetector &det=layer.GetDetector(idet);
     586           0 :        ResetTrackToFollow(fTracks[fI]);
     587           0 :        if (!fTrackToFollow.Propagate(det.GetPhi(),det.GetR())) {
     588             :          //Warning("TakeNextProlongation","propagation failed !\n");
     589           0 :          continue;
     590             :        }
     591           0 :        fTrackToFollow.SetDetectorIndex(idet);
     592           0 :        if (TMath::Abs(fTrackToFollow.GetZ()-GetZ())>layer.GetR()+dz) continue;
     593           0 :     }
     594             : 
     595           0 :     if (TMath::Abs(fTrackToFollow.GetZ() - c->GetZ()) > dz) continue;
     596           0 :     if (TMath::Abs(fTrackToFollow.GetY() - c->GetY()) > dy) continue;
     597             : 
     598           0 :     Double_t ch2=fTrackToFollow.GetPredictedChi2(c); 
     599           0 :     if (ch2 > chi2) continue;
     600             :     chi2=ch2;
     601           0 :     cc=c; cci=ci;
     602           0 :     break;
     603             :   }
     604             : 
     605           0 :   if (!cc) return 0;
     606             : 
     607             :   {// Take into account the mis-alignment
     608           0 :     Double_t x = fTrackToFollow.GetX() + cc->GetX();
     609           0 :     if (!fTrackToFollow.PropagateTo(x,0.,0.)) return 0;
     610           0 :   }
     611           0 :   if (!fTrackToFollow.Update(cc,chi2,(fI<<28)+cci)) {
     612             :      //Warning("TakeNextProlongation","filtering failed !\n");
     613           0 :      return 0;
     614             :   }
     615             : 
     616           0 :   if (fTrackToFollow.GetNumberOfClusters()>1)
     617           0 :     if (TMath::Abs(fTrackToFollow.GetD(GetX(),GetY()))>4) return 0;
     618             : 
     619           0 :   fTrackToFollow.
     620           0 :     SetSampledEdx(cc->GetQ(),fI-2); //b.b.
     621             : 
     622             :   {
     623           0 :   Double_t x0;
     624           0 :  Double_t d=layer.GetThickness(fTrackToFollow.GetY(),fTrackToFollow.GetZ(),x0);
     625           0 :   fTrackToFollow.CorrectForMaterial(d,x0);
     626           0 :   }
     627             : 
     628           0 :   if (fConstraint[fPass]) {
     629           0 :     Double_t d=GetEffectiveThickness(0,0); //Think of this !!!!
     630           0 :     Double_t xyz[]={GetX(),GetY(),GetZ()};
     631           0 :     Double_t ers[]={GetSigmaX(),GetSigmaY(),GetSigmaZ()};
     632           0 :     fTrackToFollow.Improve(d,xyz,ers);
     633           0 :   }
     634             : 
     635           0 :   return 1;
     636           0 : }
     637             : 
     638             : 
     639             : AliITStrackerV2::AliITSlayer::AliITSlayer():
     640         708 :   fR(0.),
     641         354 :   fPhiOffset(0.),
     642         354 :   fNladders(0),
     643         354 :   fZOffset(0.),
     644         354 :   fNdetectors(0),
     645         354 :   fDetectors(0),
     646         354 :   fNsel(0),
     647         354 :   fRoad(2*fR*TMath::Sqrt(3.14/1.)) //assuming that there's only one cluster
     648         708 : {
     649             :   //--------------------------------------------------------------------
     650             :   //default AliITSlayer constructor
     651             :   //--------------------------------------------------------------------
     652             :   
     653        4248 :   for (Int_t i=0; i<kNsector; i++) fN[i]=0;
     654    22656708 :   for (Int_t i=0; i<AliITSRecoParam::kMaxClusterPerLayer; i++){
     655    11328000 :     fClusters[i]=0;
     656    11328000 :     fIndex[i]=0;
     657             :   }
     658         708 : }
     659             : 
     660             : AliITStrackerV2::AliITSlayer::
     661             : AliITSlayer(Double_t r,Double_t p,Double_t z,Int_t nl,Int_t nd): 
     662           0 :   fR(r), 
     663           0 :   fPhiOffset(p), 
     664           0 :   fNladders(nl),
     665           0 :   fZOffset(z),
     666           0 :   fNdetectors(nd),
     667           0 :   fDetectors(new AliITSdetector[nl*nd]),
     668           0 :   fNsel(0),
     669           0 :   fRoad(2*r*TMath::Sqrt(3.14/1.)) //assuming that there's only one cluster
     670           0 : {
     671             :   //--------------------------------------------------------------------
     672             :   //main AliITSlayer constructor
     673             :   //--------------------------------------------------------------------
     674             : 
     675           0 :   for (Int_t i=0; i<kNsector; i++) fN[i]=0;
     676             : 
     677           0 :   for (Int_t i=0; i<AliITSRecoParam::kMaxClusterPerLayer; i++){
     678           0 :     fClusters[i]=0;
     679           0 :     fIndex[i]=0;
     680             :   }
     681           0 : }
     682             : 
     683         708 : AliITStrackerV2::AliITSlayer::~AliITSlayer() {
     684             :   //--------------------------------------------------------------------
     685             :   // AliITSlayer destructor
     686             :   //--------------------------------------------------------------------
     687         708 :   delete[] fDetectors;
     688         354 :   ResetClusters();
     689         708 : }
     690             : 
     691             : void AliITStrackerV2::AliITSlayer::ResetClusters() {
     692             :   //--------------------------------------------------------------------
     693             :   // This function removes loaded clusters
     694             :   //--------------------------------------------------------------------
     695        4602 :    for (Int_t s=0; s<kNsector; s++) {
     696        1770 :        Int_t &n=fN[s];
     697        3540 :        while (n) {
     698           0 :           n--;
     699           0 :           delete fClusters[s*kMaxClusterPerSector+n];
     700             :        }
     701             :    }
     702         354 : }
     703             : 
     704             : void AliITStrackerV2::AliITSlayer::ResetRoad() {
     705             :   //--------------------------------------------------------------------
     706             :   // This function calculates the road defined by the cluster density
     707             :   //--------------------------------------------------------------------
     708             :   Int_t n=0;
     709           0 :   for (Int_t s=0; s<kNsector; s++) {
     710           0 :     Int_t i=fN[s];
     711           0 :     while (i--) 
     712           0 :        if (TMath::Abs(fClusters[s*kMaxClusterPerSector+i]->GetZ())<fR) n++;
     713             :   }
     714           0 :   if (n>1) fRoad=2*fR*TMath::Sqrt(3.14/n);
     715           0 : }
     716             : 
     717             : Int_t AliITStrackerV2::AliITSlayer::InsertCluster(AliITSRecPoint *c) {
     718             :   //--------------------------------------------------------------------
     719             :   // This function inserts a cluster to this layer in increasing
     720             :   // order of the cluster's fZ
     721             :   //--------------------------------------------------------------------
     722           0 :   Float_t circ=TMath::TwoPi()*fR;
     723           0 :   Int_t sec=Int_t(kNsector*c->GetPhiR()/circ);
     724           0 :   if (sec>=kNsector) {
     725           0 :      ::Error("InsertCluster","Wrong sector !\n");
     726           0 :      return 1;
     727             :   }
     728           0 :   Int_t &n=fN[sec];
     729           0 :   if (n>=kMaxClusterPerSector) {
     730           0 :      ::Error("InsertCluster","Too many clusters !\n");
     731           0 :      return 1;
     732             :   }
     733           0 :   if (n==0) fClusters[sec*kMaxClusterPerSector]=c;
     734             :   else {
     735           0 :      Int_t i=FindClusterIndex(c->GetZ(),sec);
     736           0 :      Int_t k=n-i+sec*kMaxClusterPerSector;
     737           0 :      memmove(fClusters+i+1 ,fClusters+i,k*sizeof(AliITSRecPoint*));
     738           0 :      fClusters[i]=c;
     739             :   }
     740           0 :   n++;
     741           0 :   return 0;
     742           0 : }
     743             : 
     744             : Int_t 
     745             : AliITStrackerV2::AliITSlayer::FindClusterIndex(Float_t z,Int_t s) const {
     746             :   //--------------------------------------------------------------------
     747             :   // For the sector "s", this function returns the index of the first 
     748             :   // with its fZ >= "z". 
     749             :   //--------------------------------------------------------------------
     750           0 :   Int_t nc=fN[s];
     751           0 :   if (nc==0) return kMaxClusterPerSector*s;
     752             : 
     753           0 :   Int_t b=kMaxClusterPerSector*s;
     754           0 :   if (z <= fClusters[b]->GetZ()) return b;
     755             : 
     756           0 :   Int_t e=b+nc-1;
     757           0 :   if (z > fClusters[e]->GetZ()) return e+1;
     758             : 
     759           0 :   Int_t m=(b+e)/2;
     760           0 :   for (; b<e; m=(b+e)/2) {
     761           0 :     if (z > fClusters[m]->GetZ()) b=m+1;
     762             :     else e=m; 
     763             :   }
     764             :   return m;
     765           0 : }
     766             : 
     767             : Int_t AliITStrackerV2::AliITSlayer::
     768             : SelectClusters(Float_t zmin,Float_t zmax,Float_t ymin, Float_t ymax) {
     769             :   //--------------------------------------------------------------------
     770             :   // This function selects clusters within the "window"
     771             :   //--------------------------------------------------------------------
     772           0 :     Float_t circ=fR*TMath::TwoPi();
     773             : 
     774           0 :     if (ymin>circ) ymin-=circ; else if (ymin<0) ymin+=circ;
     775           0 :     if (ymax>circ) ymax-=circ; else if (ymax<0) ymax+=circ;
     776             : 
     777           0 :     Int_t i1=Int_t(kNsector*ymin/circ); if (i1==kNsector) i1--;
     778           0 :     if (fN[i1]!=0) {
     779           0 :        Float_t ym = (ymax<ymin) ? ymax+circ : ymax;
     780           0 :        Int_t i=FindClusterIndex(zmin,i1), imax=i1*kMaxClusterPerSector+fN[i1];
     781           0 :        for (; i<imax; i++) {
     782           0 :            AliITSRecPoint *c=fClusters[i];
     783           0 :            if (c->IsUsed()) continue;
     784           0 :            if (c->GetZ()>zmax) break;
     785           0 :            if (c->GetPhiR()<=ymin) continue;
     786           0 :            if (c->GetPhiR()>ym) continue;
     787           0 :            fIndex[fNsel++]=i;
     788           0 :        }
     789           0 :     }
     790             : 
     791           0 :     Int_t i2=Int_t(kNsector*ymax/circ); if (i2==kNsector) i2--;
     792           0 :     if (i2==i1) return fNsel;
     793             : 
     794           0 :     if (fN[i2]!=0) {
     795           0 :        Float_t ym = (ymin>ymax) ? ymin-circ : ymin;
     796           0 :        Int_t i=FindClusterIndex(zmin,i2), imax=i2*kMaxClusterPerSector+fN[i2];
     797           0 :        for (; i<imax; i++) {
     798           0 :            AliITSRecPoint *c=fClusters[i];
     799           0 :            if (c->IsUsed()) continue;
     800           0 :            if (c->GetZ()>zmax) break;
     801           0 :            if (c->GetPhiR()<=ym) continue;
     802           0 :            if (c->GetPhiR()>ymax) continue;
     803           0 :            fIndex[fNsel++]=i;
     804           0 :        }
     805           0 :     }
     806             : 
     807           0 :     return fNsel;
     808           0 : }
     809             : 
     810             : const AliITSRecPoint *AliITStrackerV2::AliITSlayer::GetNextCluster(Int_t &ci){
     811             :   //--------------------------------------------------------------------
     812             :   // This function returns clusters within the "window" 
     813             :   //--------------------------------------------------------------------
     814             :   AliITSRecPoint *c=0;
     815           0 :   ci=-1;
     816           0 :   if (fNsel) {
     817           0 :      fNsel--;
     818           0 :      ci=fIndex[fNsel]; 
     819           0 :      c=fClusters[ci];
     820           0 :   }
     821           0 :   return c; 
     822             : }
     823             : 
     824             : Int_t AliITStrackerV2::AliITSlayer::GetNumberOfClusters() const {
     825             :   Int_t n=0;
     826           0 :   for (Int_t s=0; s<kNsector; s++) n+=fN[s];
     827           0 :   return n; 
     828             : }
     829             : 
     830             : Int_t 
     831             : AliITStrackerV2::AliITSlayer::FindDetectorIndex(Double_t phi,Double_t z)const {
     832             :   //--------------------------------------------------------------------
     833             :   //This function finds the detector crossed by the track
     834             :   //--------------------------------------------------------------------
     835             :   Double_t dphi;
     836           0 :   if (fZOffset<0)            // old geometry
     837           0 :     dphi = -(phi-fPhiOffset);
     838             :   else                       // new geometry
     839             :     dphi = phi-fPhiOffset;
     840             : 
     841           0 :   if      (dphi <  0) dphi += 2*TMath::Pi();
     842           0 :   else if (dphi >= 2*TMath::Pi()) dphi -= 2*TMath::Pi();
     843           0 :   Int_t np=Int_t(dphi*fNladders*0.5/TMath::Pi()+0.5);
     844           0 :   if (np>=fNladders) np-=fNladders;
     845           0 :   if (np<0)          np+=fNladders;
     846             : 
     847           0 :   Double_t dz=fZOffset-z;
     848           0 :   Int_t nz=Int_t(dz*(fNdetectors-1)*0.5/fZOffset+0.5);
     849           0 :   if (nz>=fNdetectors) return -1;
     850           0 :   if (nz<0)            return -1;
     851             : 
     852           0 :   return np*fNdetectors + nz;
     853           0 : }
     854             : 
     855             : Double_t 
     856             : AliITStrackerV2::AliITSlayer::GetThickness(Double_t y,Double_t z,Double_t &x0)
     857             : const {
     858             :   //--------------------------------------------------------------------
     859             :   //This function returns the layer thickness at this point (units X0)
     860             :   //--------------------------------------------------------------------
     861             :   Double_t d=0.0085;
     862           0 :   x0=21.82;
     863             : 
     864           0 :   if (43<fR&&fR<45) { //SSD2
     865             :      Double_t dd=0.0034;
     866             :      d=dd;
     867           0 :      if (TMath::Abs(y-0.00)>3.40) d+=dd;
     868           0 :      if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
     869           0 :      if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
     870           0 :      for (Int_t i=0; i<12; i++) {
     871           0 :        if (TMath::Abs(z-3.9*(i+0.5))<0.15) {
     872           0 :           if (TMath::Abs(y-0.00)>3.40) d+=dd;
     873           0 :           d+=0.0034; 
     874           0 :           break;
     875             :        }
     876           0 :        if (TMath::Abs(z+3.9*(i+0.5))<0.15) {
     877           0 :           if (TMath::Abs(y-0.00)>3.40) d+=dd;
     878           0 :           d+=0.0034; 
     879           0 :           break;
     880             :        }         
     881           0 :        if (TMath::Abs(z-3.4-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
     882           0 :        if (TMath::Abs(z+0.5+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
     883             :      }
     884           0 :   } else 
     885           0 :   if (37<fR&&fR<41) { //SSD1
     886             :      Double_t dd=0.0034;
     887             :      d=dd;
     888           0 :      if (TMath::Abs(y-0.00)>3.40) d+=dd;
     889           0 :      if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
     890           0 :      if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
     891           0 :      for (Int_t i=0; i<11; i++) {
     892           0 :        if (TMath::Abs(z-3.9*i)<0.15) {
     893           0 :           if (TMath::Abs(y-0.00)>3.40) d+=dd;
     894           0 :           d+=dd; 
     895           0 :           break;
     896             :        }
     897           0 :        if (TMath::Abs(z+3.9*i)<0.15) {
     898           0 :           if (TMath::Abs(y-0.00)>3.40) d+=dd;
     899           0 :           d+=dd; 
     900           0 :           break;
     901             :        }         
     902           0 :        if (TMath::Abs(z-1.85-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
     903           0 :        if (TMath::Abs(z+2.05+3.9*i)<0.50) {d+=(0.016-0.0034); break;}         
     904             :      }
     905           0 :   } else
     906           0 :   if (13<fR&&fR<26) { //SDD
     907             :      Double_t dd=0.0033;
     908             :      d=dd;
     909           0 :      if (TMath::Abs(y-0.00)>3.30) d+=dd;
     910             : 
     911           0 :      if (TMath::Abs(y-1.80)<0.55) {
     912           0 :         d+=0.016;
     913           0 :         for (Int_t j=0; j<20; j++) {
     914           0 :           if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
     915           0 :           if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
     916             :         } 
     917           0 :      }
     918           0 :      if (TMath::Abs(y+1.80)<0.55) {
     919           0 :         d+=0.016;
     920           0 :         for (Int_t j=0; j<20; j++) {
     921           0 :           if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
     922           0 :           if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
     923             :         } 
     924           0 :      }
     925             : 
     926           0 :      for (Int_t i=0; i<4; i++) {
     927           0 :        if (TMath::Abs(z-7.3*i)<0.60) {
     928           0 :           d+=dd;
     929           0 :           if (TMath::Abs(y-0.00)>3.30) d+=dd; 
     930           0 :           break;
     931             :        }
     932           0 :        if (TMath::Abs(z+7.3*i)<0.60) {
     933           0 :           d+=dd; 
     934           0 :           if (TMath::Abs(y-0.00)>3.30) d+=dd; 
     935           0 :           break;
     936             :        }
     937             :      }
     938           0 :   } else
     939           0 :   if (6<fR&&fR<8) {   //SPD2
     940           0 :      Double_t dd=0.0063; x0=21.5;
     941             :      d=dd;
     942           0 :      if (TMath::Abs(y-3.08)>0.5) d+=dd;
     943             :      //if (TMath::Abs(y-3.08)>0.45) d+=dd;
     944           0 :      if (TMath::Abs(y-3.03)<0.10) {d+=0.014;}
     945           0 :   } else
     946           0 :   if (3<fR&&fR<5) {   //SPD1
     947           0 :      Double_t dd=0.0063; x0=21.5;
     948             :      d=dd;
     949           0 :      if (TMath::Abs(y+0.21)>0.6) d+=dd;
     950             :      //if (TMath::Abs(y+0.21)>0.45) d+=dd;
     951           0 :      if (TMath::Abs(y+0.10)<0.10) {d+=0.014;}
     952           0 :   }
     953             : 
     954           0 :   return d;
     955             : }
     956             : 
     957             : Double_t AliITStrackerV2::GetEffectiveThickness(Double_t y,Double_t z) const
     958             : {
     959             :   //--------------------------------------------------------------------
     960             :   //Returns the thickness between the current layer and the vertex (units X0)
     961             :   //--------------------------------------------------------------------
     962             :   Double_t d=0.0028*3*3; //beam pipe
     963           0 :   Double_t x0=0;
     964             : 
     965           0 :   Double_t xn=fgLayers[fI].GetR();
     966           0 :   for (Int_t i=0; i<fI; i++) {
     967           0 :     Double_t xi=fgLayers[i].GetR();
     968           0 :     d+=fgLayers[i].GetThickness(y,z,x0)*xi*xi;
     969             :   }
     970             : 
     971           0 :   if (fI>1) {
     972             :     Double_t xi=9.;
     973           0 :     d+=0.0097*xi*xi;
     974           0 :   }
     975             : 
     976           0 :   if (fI>3) {
     977           0 :     Double_t xi=0.5*(fgLayers[3].GetR()+fgLayers[4].GetR());
     978           0 :     d+=0.0034*xi*xi;
     979           0 :   }
     980             : 
     981           0 :   return d/(xn*xn);
     982           0 : }
     983             : 
     984             : Bool_t AliITStrackerV2::RefitAt(Double_t xx,AliITStrackV2 *t,
     985             :                                 const AliITStrackV2 *c, Bool_t extra) {
     986             :   //--------------------------------------------------------------------
     987             :   // This function refits the track "t" at the position "x" using
     988             :   // the clusters from "c"
     989             :   // If "extra"==kTRUE, 
     990             :   //    the clusters from overlapped modules get attached to "t" 
     991             :   //--------------------------------------------------------------------
     992           0 :   Int_t index[AliITSgeomTGeo::kNLayers];
     993             :   Int_t k;
     994           0 :   for (k=0; k<AliITSgeomTGeo::GetNLayers(); k++) index[k]=-1;
     995           0 :   Int_t nc=c->GetNumberOfClusters();
     996           0 :   for (k=0; k<nc; k++) { 
     997           0 :     Int_t idx=c->GetClusterIndex(k),nl=(idx&0xf0000000)>>28;
     998           0 :     index[nl]=idx; 
     999             :   }
    1000             : 
    1001             :   Int_t from, to, step;
    1002           0 :   if (xx > t->GetX()) {
    1003           0 :       from=0; to=AliITSgeomTGeo::GetNLayers();
    1004             :       step=+1;
    1005           0 :   } else {
    1006           0 :       from=AliITSgeomTGeo::GetNLayers()-1; to=-1;
    1007             :       step=-1;
    1008             :   }
    1009             : 
    1010           0 :   for (Int_t i=from; i != to; i += step) {
    1011           0 :      AliITSlayer &layer=fgLayers[i];
    1012           0 :      Double_t r=layer.GetR();
    1013             :  
    1014             :      {
    1015           0 :      Double_t hI=i-0.5*step; 
    1016           0 :      if (TMath::Abs(hI-1.5)<0.01 || TMath::Abs(hI-3.5)<0.01) {  
    1017           0 :        Int_t iLay = i-step;
    1018             :        Double_t rs = 0.;
    1019           0 :        if(iLay<0 || iLay>= AliITSgeomTGeo::kNLayers){
    1020           0 :          AliError(Form("Invalid layer %d ",iLay));
    1021           0 :          return kFALSE;
    1022             :        }
    1023             :        else{
    1024           0 :          rs=0.5*(fgLayers[i-step].GetR() + r);
    1025             :        }
    1026             :        Double_t d=0.0034, x0=38.6; 
    1027           0 :        if (TMath::Abs(hI-1.5)<0.01) {rs=9.; d=0.0097; x0=42;}
    1028           0 :        if (!t->PropagateTo(rs,-step*d,x0)) {
    1029           0 :          return kFALSE;
    1030             :        }
    1031           0 :      }
    1032           0 :      }
    1033             : 
    1034             :      // remember old position [SR, GSI 18.02.2003]
    1035           0 :      Double_t oldX=0., oldY=0., oldZ=0.;
    1036           0 :      if (t->IsStartedTimeIntegral() && step==1) {
    1037           0 :         t->GetGlobalXYZat(t->GetX(),oldX,oldY,oldZ);
    1038           0 :      }
    1039             :      //
    1040             : 
    1041           0 :      Double_t phi,z;
    1042           0 :      if (!t->GetPhiZat(r,phi,z)) { 
    1043           0 :        return kFALSE;
    1044             :      }
    1045             : 
    1046           0 :      Int_t idet=layer.FindDetectorIndex(phi,z);
    1047           0 :      if (idet<0) { 
    1048           0 :        return kFALSE;
    1049             :      }
    1050           0 :      const AliITSdetector &det=layer.GetDetector(idet);
    1051           0 :      phi=det.GetPhi();
    1052           0 :      if (!t->Propagate(phi,det.GetR())) {
    1053           0 :        return kFALSE;
    1054             :      }
    1055           0 :      t->SetDetectorIndex(idet);
    1056             : 
    1057             :      const AliITSRecPoint *cl=0;
    1058           0 :      Double_t maxchi2=AliITSReconstructor::GetRecoParam()->GetMaxChi2();
    1059             : 
    1060           0 :      Int_t idx=index[i];
    1061           0 :      if (idx>=0) {
    1062           0 :         const AliITSRecPoint *ccc=(AliITSRecPoint *)GetCluster(idx); 
    1063           0 :         if (idet != ccc->GetDetectorIndex()) {
    1064           0 :            idet=ccc->GetDetectorIndex();
    1065           0 :            const AliITSdetector &det2=layer.GetDetector(idet);
    1066           0 :            if (!t->Propagate(det2.GetPhi(),det2.GetR())) {
    1067           0 :              return kFALSE;
    1068             :            }
    1069           0 :            t->SetDetectorIndex(idet);
    1070           0 :         }
    1071           0 :         Double_t chi2=t->GetPredictedChi2(ccc);
    1072           0 :         if (chi2<maxchi2) { 
    1073             :           cl=ccc; 
    1074             :           maxchi2=chi2; 
    1075             :         } else {
    1076           0 :           return kFALSE;
    1077             :         }
    1078           0 :      }
    1079             :  
    1080           0 :      if (cl) {
    1081             :        // Take into account the mis-alignment
    1082           0 :        Double_t x=t->GetX()+cl->GetX();
    1083           0 :        if (!t->PropagateTo(x,0.,0.)) return kFALSE;
    1084           0 :        if (!t->Update(cl,maxchi2,idx)) {
    1085           0 :           return kFALSE;
    1086             :        }
    1087           0 :        t->SetSampledEdx(cl->GetQ(),i-2);
    1088           0 :      }
    1089             : 
    1090             :      {
    1091           0 :      Double_t x0;
    1092           0 :      Double_t d=layer.GetThickness(t->GetY(),t->GetZ(),x0);
    1093           0 :      t->CorrectForMaterial(-step*d,x0);
    1094           0 :      }
    1095             :                  
    1096           0 :      if (extra) { //search for extra clusters
    1097           0 :         AliITStrackV2 tmp(*t);
    1098           0 :         Double_t dz=4*TMath::Sqrt(tmp.GetSigmaZ2()+AliITSReconstructor::GetRecoParam()->GetSigmaZ2(i));
    1099           0 :         if (dz < 0.5*TMath::Abs(tmp.GetTgl())) dz=0.5*TMath::Abs(tmp.GetTgl());
    1100           0 :         Double_t dy=4*TMath::Sqrt(t->GetSigmaY2()+AliITSReconstructor::GetRecoParam()->GetSigmaY2(i));
    1101           0 :         if (dy < 0.5*TMath::Abs(tmp.GetSnp())) dy=0.5*TMath::Abs(tmp.GetSnp());
    1102           0 :         Double_t zmin=t->GetZ() - dz;
    1103           0 :         Double_t zmax=t->GetZ() + dz;
    1104           0 :         Double_t ymin=t->GetY() + phi*r - dy;
    1105           0 :         Double_t ymax=t->GetY() + phi*r + dy;
    1106           0 :         layer.SelectClusters(zmin,zmax,ymin,ymax);
    1107             : 
    1108           0 :         const AliITSRecPoint *cx=0; Int_t ci=-1,cci=-1;
    1109           0 :         maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2();
    1110             :         Double_t tolerance=0.1;
    1111           0 :         while ((cx=layer.GetNextCluster(ci))!=0) {
    1112           0 :            if (idet == cx->GetDetectorIndex()) continue;
    1113             : 
    1114           0 :            const AliITSdetector &detx=layer.GetDetector(cx->GetDetectorIndex());
    1115             : 
    1116           0 :            if (!tmp.Propagate(detx.GetPhi(),detx.GetR())) continue;
    1117             :            
    1118           0 :            if (TMath::Abs(tmp.GetZ() - cx->GetZ()) > tolerance) continue;
    1119           0 :            if (TMath::Abs(tmp.GetY() - cx->GetY()) > tolerance) continue;
    1120             : 
    1121           0 :            Double_t chi2=tmp.GetPredictedChi2(cx);
    1122           0 :            if (chi2<maxchi2) { maxchi2=chi2; cci=ci; }
    1123           0 :         }
    1124           0 :         if (cci>=0) t->SetExtraCluster(i,(i<<28)+cci);
    1125           0 :      }
    1126             : 
    1127             :      // track time update [SR, GSI 17.02.2003]
    1128           0 :      if (t->IsStartedTimeIntegral() && step==1) {
    1129           0 :         Double_t newX, newY, newZ;
    1130           0 :         t->GetGlobalXYZat(t->GetX(),newX,newY,newZ);
    1131           0 :         Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) + 
    1132           0 :                        (oldZ-newZ)*(oldZ-newZ);
    1133           0 :         t->AddTimeStep(TMath::Sqrt(dL2));
    1134           0 :      }
    1135             :      //
    1136             : 
    1137           0 :   }
    1138             : 
    1139           0 :   if (!t->PropagateTo(xx,0.,0.)) return kFALSE;
    1140           0 :   return kTRUE;
    1141           0 : }
    1142             : 
    1143             : void AliITStrackerV2::UseClusters(const AliKalmanTrack *t, Int_t from) const {
    1144             :   //--------------------------------------------------------------------
    1145             :   // This function marks clusters assigned to the track
    1146             :   //--------------------------------------------------------------------
    1147           0 :   AliTracker::UseClusters(t,from);
    1148             : 
    1149           0 :   Int_t clusterIndex = t->GetClusterIndex(0);
    1150             :   AliITSRecPoint *c= 0x0;
    1151             : 
    1152           0 :   if (clusterIndex>-1)
    1153           0 :     c = (AliITSRecPoint *)GetCluster(clusterIndex);
    1154           0 :   if (c && c->GetSigmaZ2()>0.1) c->UnUse();
    1155             : 
    1156             :   c = 0x0;
    1157           0 :   clusterIndex = t->GetClusterIndex(1);
    1158           0 :   if (clusterIndex>-1)
    1159           0 :     c=(AliITSRecPoint *)GetCluster(clusterIndex);
    1160           0 :   if (c && c->GetSigmaZ2()>0.1) c->UnUse();
    1161             : 
    1162           0 : }

Generated by: LCOV version 1.11