ROOT logo
#ifndef ALIITSTRACKERU_H
#define ALIITSTRACKERU_H
/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 * See cxx source for full Copyright notice                               */

//-------------------------------------------------------------------------
//                ITS upgrade tracker base class
//-------------------------------------------------------------------------
#include "AliTracker.h"
#include "AliESDEvent.h"
#include "AliITSUSeed.h"
#include "AliITSUTrackCond.h"
#include "AliITSUTrackHyp.h"
#include "AliITSUAux.h"
#include "AliITSUMatLUT.h"
#include <TArrayI.h>

class AliITSUReconstructor;
class AliITSURecoDet;
class AliITSUClusterPix;
class AliESDtrack;
class AliITSURecoLayer;
class TTree;

//-------------------------------------------------------------------------
class AliITSUTrackerGlo : public AliTracker {

  public:
  enum {kClus2Tracks,kPropBack,kRefitInw,kNTrackingPhases};   // tracking phases
  enum { // info from track extrapolation to layer for cluster check
    kTrXIn ,kTrYIn ,kTrZIn ,kTrPhiIn , // entrance (outer) point on the layer from above 
    kTrXOut,kTrYOut,kTrZOut,kTrPhiOut, // exit (inner) point on the layer
    kTrPhi0, kTrDPhi, kTrZ0, kTrDZ,     // mean phi,dPhi, mean z, dZ (don't change this order)
    kNTrImpData};
  //
  enum {kMissingCluster=0  // no cluster found on this layer
	,kTransportFailed=1  // seed did not reach target layer
	,kRWCheckFailed =2  // failed to rotate the seed to frame of the layer impact point
  };
  enum {kStopSearchOnSensor,kClusterNotMatching,kClusterMatching}; // flags for track-to-cluster checks
  //
  enum {kDummyLabel=-3141593};
  //
  AliITSUTrackerGlo(AliITSUReconstructor* rec);
  virtual ~AliITSUTrackerGlo();

  virtual Int_t          Clusters2Tracks(AliESDEvent *event);
  virtual Int_t          PropagateBack(AliESDEvent *event);
  virtual Int_t          RefitInward(AliESDEvent *event);
  virtual Int_t          LoadClusters(TTree * treeRP=0);
  virtual void           UnloadClusters();
  virtual AliCluster*    GetCluster(Int_t index) const;
  void                   PrintSeedClusters(const AliITSUSeed* seed, Option_t* option="");
  //
  Int_t                  GetCountPronlongationTrials() const {return fCountProlongationTrials;}
  Int_t                  GetCountITSin()               const {return fCountITSin;}
  Int_t                  GetCountITSout()              const {return fCountITSout;}
  Int_t                  GetCountITSrefit()            const {return fCountITSrefit;}

  //------------------------------------
  AliITSURecoDet*        GetITSInterface()       const {return fITS;}
  //
  //------------------------------------
  Bool_t                 NeedToProlong(AliESDtrack* estTr, Int_t esdID);
  void                   Init(AliITSUReconstructor* rec);
  void                   FindTrack(AliESDtrack* esdTr, Int_t esdID);
  void                   CreateDefaultTrackCond();
  AliITSUTrackHyp*       InitHypothesis(AliESDtrack *esdTr, Int_t esdID);
  Bool_t                 TransportToLayer(AliITSUSeed* seed, Int_t lFrom, Int_t lTo, Double_t rLim=-1);
  Bool_t                 TransportToLayer(AliExternalTrackParam* seed, Int_t lFrom, Int_t lTo, Double_t rLim=-1);
  Bool_t                 TransportToLayerX(AliExternalTrackParam* seed, Int_t lFrom, Int_t lTo, Double_t xStop);  
  Bool_t                 GoToExitFromLayer(AliITSUSeed* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check=kTRUE);
  Bool_t                 GoToExitFromLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check=kTRUE);
  Bool_t                 GoToEntranceToLayer(AliITSUSeed* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check=kFALSE);
  Bool_t                 GoToEntranceToLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check=kFALSE);
  Bool_t                 PropagateSeed(AliITSUSeed *seed, Double_t xToGo, Double_t mass, Double_t maxStep=1.0, Bool_t matCorr=kTRUE);
  Bool_t                 PropagateSeed(AliExternalTrackParam *seed, Double_t xToGo, Double_t mass, Double_t maxStep=1.0, Bool_t matCorr=kTRUE);
  Double_t               RefitTrack(AliITSUTrackHyp* trc, Double_t r, Int_t& nclFit, Int_t stopCond=0);
  Double_t               GetMaterialBudget(const double* pnt0, const double* pnt1, double& x2x0, double& rhol) const;

  Int_t                  GetTrackingPhase()                 const {return fTrackPhaseID;}

  //
  void                   KillSeed(AliITSUSeed* seed, Bool_t branch=kFALSE);
  Bool_t                 NeedToKill(AliITSUSeed* seed, Int_t flag);
  Bool_t                 GetRoadWidth(AliITSUSeed* seed, int ilrA);
  Bool_t                 CheckBackwardMatching(AliITSUSeed* seed);
  Int_t                  CheckCluster(AliITSUSeed* seed, Int_t lr, Int_t clID);
  void                   AddProlongationHypothesis(AliITSUSeed* seed, Int_t lr);
  Bool_t                 AddSeedBranch(AliITSUSeed* seed);
  void                   ValidateAllowedBranches(Int_t accMax);
  void                   ValidateAllowedCandidates(Int_t ilr, Int_t accMax);
  void                   FlagSeedClusters(const AliITSUSeed* seed, Bool_t flg, UShort_t hypRef);
  //
  AliITSUSeed*           NewSeedFromPool(const AliITSUSeed* src=0);
  void                   ResetSeedsPool();
  void                   MarkSeedFree(AliITSUSeed* seed );

  AliITSUTrackHyp*       GetTrackHyp(Int_t id)               const  {return (AliITSUTrackHyp*)fHypStore.UncheckedAt(id);}
  void                   SetTrackHyp(AliITSUTrackHyp* hyp,Int_t id) {fHypStore.AddAtAndExpand(hyp,id);}
  void                   DeleteLastSeedFromPool()                   {fSeedsPool.RemoveLast();}
  void                   CheckClusterSharingConflicts(AliITSUTrackHyp* hyp);
  void                   SaveReducedHypothesesTree(AliITSUTrackHyp* dest);
  void                   CleanHypothesis(AliITSUTrackHyp* hyp);
  void                   FinalizeHypotheses();
  Bool_t                 FinalizeHypothesis(AliITSUTrackHyp* hyp);
  void                   UpdateESDTrack(AliITSUTrackHyp* hyp,Int_t flag);
  void                   CookMCLabel(AliITSUTrackHyp* hyp);
  void                   SetTrackingPhase(Int_t p)        {fTrackPhaseID = p;}
  //
  // monitoring stuff
  void                   FlagSplitClusters();
  Bool_t                 ContainsSplitCluster(const AliITSUSeed* seed, Int_t maxSize=99999);
  void                   CheckClusterUsage();
  //
 protected:
  TObject*&              NextFreeSeed();
  //
 private:
  //
  AliITSUTrackerGlo(const AliITSUTrackerGlo&);
  AliITSUTrackerGlo &operator=(const AliITSUTrackerGlo &tr);
  //
 protected:
  AliITSUReconstructor*           fReconstructor;  // ITS global reconstructor 
  AliITSURecoDet*                 fITS;            // interface to ITS, borrowed from reconstructor
  AliITSUMatLUT*                  fMatLUT;         // material lookup table
  AliESDtrack*                    fCurrESDtrack;   // current esd track in processing
  Int_t                           fCurrESDtrMClb;  // its eventual mc label
  Double_t                        fCurrMass;       // current track mass
  Double_t                        fTrImpData[kNTrImpData];  // data on track impact on the layer
  //
  Int_t                           fCountProlongationTrials;   // number of TPC seeds
  Int_t                           fCountITSin;     // number of successful ITSin 
  Int_t                           fCountITSout;    // number of successful ITSout
  Int_t                           fCountITSrefit;  // number of successful ITSrefit 
  Int_t                           fNTracksESD;     // number of esd tracks
  //
  // the seeds management to be optimized
  TObjArray                       fHypStore;       // storage for tracks hypotheses
  Int_t                           fLayerMaxCandidates; //! size of tmp candidates array 
  AliITSUSeed**                   fLayerCandidates;//! array for branches of current track prolongation
  Int_t                           fNBranchesAdded; // number of branches created for current seed in prolongation
  Int_t                           fNCandidatesAdded; // number of candidates added for current seed in prolongation
  AliITSUTrackHyp*                fCurrHyp;        //! hypotheses container for current track
  AliITSUTrackHyp*                fWorkHyp;        //! temporary hypothesis for track finding
  TClonesArray                    fSeedsPool;      //! pool for seeds
  TArrayI                         fFreeSeedsID;    //! array of ID's of freed seeds
  TArrayI                         fESDIndex;       //! array of ID's of freed seeds
  Int_t                           fNFreeSeeds;     //! number of seeds freed in the pool
  Int_t                           fLastSeedID;     //! id of the pool seed on which is returned by the NextFreeSeed method
  Int_t                           fNLrActive;      //! number of active layers
  //
  TObjArray                       fDefTrackConds;  //! default tracking conditions
  AliITSUTrackCond*               fCurrTrackCond;  //! current tracking condition
  Int_t                           fCurrActLrID;    //! current active layer ID being processed (set only when needed, not guaranteed)
  AliITSURecoLayer*               fCurrLayer;      //! current layer being processed  (set only when needed, not guaranteed)
  Int_t                           fTrackPhaseID;   //! tracking phase (clusters2tracks, backward, inward)
  Int_t                           fCurrPassID;     //! tracking pass (different tracking conditions)
  Bool_t                          fUseMatLUT;      //! use material lookup table rather than TGeo
  //
  static const Double_t           fgkToler;        // tracking tolerance
  //
#ifdef  _ITSU_TUNING_MODE_
  // this code is only for special histos needed to extract some control parameters
  Int_t GetHistoID(Int_t lr, Int_t hid, Int_t pass=0, Int_t phase=0);
  TObjArray* BookControlHistos(const char* pref);
  TObjArray* fCHistoArrCorr; // set of histos for each tracking pass/phase: correct
  TObjArray* fCHistoArrFake; // set of histos for each tracking pass/phase: fakse
  enum {kHResY,kHResYP,kHResZ,kHResZP,kHChi2Cl,kHChi2Nrm,kHBestInBranch,kHBestInCand,kMaxHID=10};
  enum {kHChiMatch,kHChiITSSA}; // custom histos 
  enum {kHistosPhase=kMaxHID*(AliITSUAux::kMaxLayers+1),kHistosPass=kNTrackingPhases*kHistosPhase};
  //
#endif
  //
  ClassDef(AliITSUTrackerGlo,1)   //ITS upgrade tracker
    
};

//________________________________________
inline TObject *&AliITSUTrackerGlo::NextFreeSeed()
{
  // return next free slot where the seed can be created
  fLastSeedID = fNFreeSeeds ? fFreeSeedsID.GetArray()[--fNFreeSeeds] : fSeedsPool.GetEntriesFast();
  //  AliInfo(Form("%d",fLastSeedID));
  return fSeedsPool[ fLastSeedID ];
  //
}

//_________________________________________________________________________
inline AliITSUSeed* AliITSUTrackerGlo::NewSeedFromPool(const AliITSUSeed* src)
{
  // create new seed, optionally copying from the source
  AliITSUSeed* sd =  src ? new( NextFreeSeed() ) AliITSUSeed(*src) : new( NextFreeSeed() ) AliITSUSeed();
  sd->SetPoolID(fLastSeedID);
  return sd;
}

//_________________________________________________________________________
inline void AliITSUTrackerGlo::KillSeed(AliITSUSeed* seed, Bool_t branch)
{
  // flag seed as killed, if requested, kill recursively its parents whose sole child is the seed being killed
  seed->Kill();
  seed = (AliITSUSeed*)seed->GetParent();
  if (seed && !seed->DecChildren() && branch) KillSeed(seed,branch);
}

//_________________________________________________________________________
inline void AliITSUTrackerGlo::AddProlongationHypothesis(AliITSUSeed* seed, Int_t lr)
{
  // add new seed prolongation hypothesis 
#ifdef  _ITSU_TUNING_MODE_
  seed->SetOrdCand(fCurrHyp->GetNSeeds(lr));
#endif
  fCurrHyp->AddSeed(seed,lr);  
}

//_________________________________________________________________________
inline Double_t AliITSUTrackerGlo::GetMaterialBudget(const double* pnt0,const double* pnt1, double& x2x0, double& rhol) const
{
  double par[7];
  if (fUseMatLUT && fMatLUT) {
    double d = fMatLUT->GetMatBudget(pnt0,pnt1,par);
    x2x0 = par[AliITSUMatLUT::kParX2X0];
    rhol = par[AliITSUMatLUT::kParRhoL];    
    return d;
  }
  else {
    MeanMaterialBudget(pnt0,pnt1,par);
    x2x0 = par[1];
    rhol = par[0]*par[4];    
    return par[4];
  }
}

#endif

 AliITSUTrackerGlo.h:1
 AliITSUTrackerGlo.h:2
 AliITSUTrackerGlo.h:3
 AliITSUTrackerGlo.h:4
 AliITSUTrackerGlo.h:5
 AliITSUTrackerGlo.h:6
 AliITSUTrackerGlo.h:7
 AliITSUTrackerGlo.h:8
 AliITSUTrackerGlo.h:9
 AliITSUTrackerGlo.h:10
 AliITSUTrackerGlo.h:11
 AliITSUTrackerGlo.h:12
 AliITSUTrackerGlo.h:13
 AliITSUTrackerGlo.h:14
 AliITSUTrackerGlo.h:15
 AliITSUTrackerGlo.h:16
 AliITSUTrackerGlo.h:17
 AliITSUTrackerGlo.h:18
 AliITSUTrackerGlo.h:19
 AliITSUTrackerGlo.h:20
 AliITSUTrackerGlo.h:21
 AliITSUTrackerGlo.h:22
 AliITSUTrackerGlo.h:23
 AliITSUTrackerGlo.h:24
 AliITSUTrackerGlo.h:25
 AliITSUTrackerGlo.h:26
 AliITSUTrackerGlo.h:27
 AliITSUTrackerGlo.h:28
 AliITSUTrackerGlo.h:29
 AliITSUTrackerGlo.h:30
 AliITSUTrackerGlo.h:31
 AliITSUTrackerGlo.h:32
 AliITSUTrackerGlo.h:33
 AliITSUTrackerGlo.h:34
 AliITSUTrackerGlo.h:35
 AliITSUTrackerGlo.h:36
 AliITSUTrackerGlo.h:37
 AliITSUTrackerGlo.h:38
 AliITSUTrackerGlo.h:39
 AliITSUTrackerGlo.h:40
 AliITSUTrackerGlo.h:41
 AliITSUTrackerGlo.h:42
 AliITSUTrackerGlo.h:43
 AliITSUTrackerGlo.h:44
 AliITSUTrackerGlo.h:45
 AliITSUTrackerGlo.h:46
 AliITSUTrackerGlo.h:47
 AliITSUTrackerGlo.h:48
 AliITSUTrackerGlo.h:49
 AliITSUTrackerGlo.h:50
 AliITSUTrackerGlo.h:51
 AliITSUTrackerGlo.h:52
 AliITSUTrackerGlo.h:53
 AliITSUTrackerGlo.h:54
 AliITSUTrackerGlo.h:55
 AliITSUTrackerGlo.h:56
 AliITSUTrackerGlo.h:57
 AliITSUTrackerGlo.h:58
 AliITSUTrackerGlo.h:59
 AliITSUTrackerGlo.h:60
 AliITSUTrackerGlo.h:61
 AliITSUTrackerGlo.h:62
 AliITSUTrackerGlo.h:63
 AliITSUTrackerGlo.h:64
 AliITSUTrackerGlo.h:65
 AliITSUTrackerGlo.h:66
 AliITSUTrackerGlo.h:67
 AliITSUTrackerGlo.h:68
 AliITSUTrackerGlo.h:69
 AliITSUTrackerGlo.h:70
 AliITSUTrackerGlo.h:71
 AliITSUTrackerGlo.h:72
 AliITSUTrackerGlo.h:73
 AliITSUTrackerGlo.h:74
 AliITSUTrackerGlo.h:75
 AliITSUTrackerGlo.h:76
 AliITSUTrackerGlo.h:77
 AliITSUTrackerGlo.h:78
 AliITSUTrackerGlo.h:79
 AliITSUTrackerGlo.h:80
 AliITSUTrackerGlo.h:81
 AliITSUTrackerGlo.h:82
 AliITSUTrackerGlo.h:83
 AliITSUTrackerGlo.h:84
 AliITSUTrackerGlo.h:85
 AliITSUTrackerGlo.h:86
 AliITSUTrackerGlo.h:87
 AliITSUTrackerGlo.h:88
 AliITSUTrackerGlo.h:89
 AliITSUTrackerGlo.h:90
 AliITSUTrackerGlo.h:91
 AliITSUTrackerGlo.h:92
 AliITSUTrackerGlo.h:93
 AliITSUTrackerGlo.h:94
 AliITSUTrackerGlo.h:95
 AliITSUTrackerGlo.h:96
 AliITSUTrackerGlo.h:97
 AliITSUTrackerGlo.h:98
 AliITSUTrackerGlo.h:99
 AliITSUTrackerGlo.h:100
 AliITSUTrackerGlo.h:101
 AliITSUTrackerGlo.h:102
 AliITSUTrackerGlo.h:103
 AliITSUTrackerGlo.h:104
 AliITSUTrackerGlo.h:105
 AliITSUTrackerGlo.h:106
 AliITSUTrackerGlo.h:107
 AliITSUTrackerGlo.h:108
 AliITSUTrackerGlo.h:109
 AliITSUTrackerGlo.h:110
 AliITSUTrackerGlo.h:111
 AliITSUTrackerGlo.h:112
 AliITSUTrackerGlo.h:113
 AliITSUTrackerGlo.h:114
 AliITSUTrackerGlo.h:115
 AliITSUTrackerGlo.h:116
 AliITSUTrackerGlo.h:117
 AliITSUTrackerGlo.h:118
 AliITSUTrackerGlo.h:119
 AliITSUTrackerGlo.h:120
 AliITSUTrackerGlo.h:121
 AliITSUTrackerGlo.h:122
 AliITSUTrackerGlo.h:123
 AliITSUTrackerGlo.h:124
 AliITSUTrackerGlo.h:125
 AliITSUTrackerGlo.h:126
 AliITSUTrackerGlo.h:127
 AliITSUTrackerGlo.h:128
 AliITSUTrackerGlo.h:129
 AliITSUTrackerGlo.h:130
 AliITSUTrackerGlo.h:131
 AliITSUTrackerGlo.h:132
 AliITSUTrackerGlo.h:133
 AliITSUTrackerGlo.h:134
 AliITSUTrackerGlo.h:135
 AliITSUTrackerGlo.h:136
 AliITSUTrackerGlo.h:137
 AliITSUTrackerGlo.h:138
 AliITSUTrackerGlo.h:139
 AliITSUTrackerGlo.h:140
 AliITSUTrackerGlo.h:141
 AliITSUTrackerGlo.h:142
 AliITSUTrackerGlo.h:143
 AliITSUTrackerGlo.h:144
 AliITSUTrackerGlo.h:145
 AliITSUTrackerGlo.h:146
 AliITSUTrackerGlo.h:147
 AliITSUTrackerGlo.h:148
 AliITSUTrackerGlo.h:149
 AliITSUTrackerGlo.h:150
 AliITSUTrackerGlo.h:151
 AliITSUTrackerGlo.h:152
 AliITSUTrackerGlo.h:153
 AliITSUTrackerGlo.h:154
 AliITSUTrackerGlo.h:155
 AliITSUTrackerGlo.h:156
 AliITSUTrackerGlo.h:157
 AliITSUTrackerGlo.h:158
 AliITSUTrackerGlo.h:159
 AliITSUTrackerGlo.h:160
 AliITSUTrackerGlo.h:161
 AliITSUTrackerGlo.h:162
 AliITSUTrackerGlo.h:163
 AliITSUTrackerGlo.h:164
 AliITSUTrackerGlo.h:165
 AliITSUTrackerGlo.h:166
 AliITSUTrackerGlo.h:167
 AliITSUTrackerGlo.h:168
 AliITSUTrackerGlo.h:169
 AliITSUTrackerGlo.h:170
 AliITSUTrackerGlo.h:171
 AliITSUTrackerGlo.h:172
 AliITSUTrackerGlo.h:173
 AliITSUTrackerGlo.h:174
 AliITSUTrackerGlo.h:175
 AliITSUTrackerGlo.h:176
 AliITSUTrackerGlo.h:177
 AliITSUTrackerGlo.h:178
 AliITSUTrackerGlo.h:179
 AliITSUTrackerGlo.h:180
 AliITSUTrackerGlo.h:181
 AliITSUTrackerGlo.h:182
 AliITSUTrackerGlo.h:183
 AliITSUTrackerGlo.h:184
 AliITSUTrackerGlo.h:185
 AliITSUTrackerGlo.h:186
 AliITSUTrackerGlo.h:187
 AliITSUTrackerGlo.h:188
 AliITSUTrackerGlo.h:189
 AliITSUTrackerGlo.h:190
 AliITSUTrackerGlo.h:191
 AliITSUTrackerGlo.h:192
 AliITSUTrackerGlo.h:193
 AliITSUTrackerGlo.h:194
 AliITSUTrackerGlo.h:195
 AliITSUTrackerGlo.h:196
 AliITSUTrackerGlo.h:197
 AliITSUTrackerGlo.h:198
 AliITSUTrackerGlo.h:199
 AliITSUTrackerGlo.h:200
 AliITSUTrackerGlo.h:201
 AliITSUTrackerGlo.h:202
 AliITSUTrackerGlo.h:203
 AliITSUTrackerGlo.h:204
 AliITSUTrackerGlo.h:205
 AliITSUTrackerGlo.h:206
 AliITSUTrackerGlo.h:207
 AliITSUTrackerGlo.h:208
 AliITSUTrackerGlo.h:209
 AliITSUTrackerGlo.h:210
 AliITSUTrackerGlo.h:211
 AliITSUTrackerGlo.h:212
 AliITSUTrackerGlo.h:213
 AliITSUTrackerGlo.h:214
 AliITSUTrackerGlo.h:215
 AliITSUTrackerGlo.h:216
 AliITSUTrackerGlo.h:217
 AliITSUTrackerGlo.h:218
 AliITSUTrackerGlo.h:219
 AliITSUTrackerGlo.h:220
 AliITSUTrackerGlo.h:221
 AliITSUTrackerGlo.h:222
 AliITSUTrackerGlo.h:223
 AliITSUTrackerGlo.h:224
 AliITSUTrackerGlo.h:225
 AliITSUTrackerGlo.h:226
 AliITSUTrackerGlo.h:227
 AliITSUTrackerGlo.h:228
 AliITSUTrackerGlo.h:229
 AliITSUTrackerGlo.h:230
 AliITSUTrackerGlo.h:231
 AliITSUTrackerGlo.h:232
 AliITSUTrackerGlo.h:233
 AliITSUTrackerGlo.h:234
 AliITSUTrackerGlo.h:235
 AliITSUTrackerGlo.h:236
 AliITSUTrackerGlo.h:237