ROOT logo
#ifndef ALIITSUCLUSTERPIX_H
#define ALIITSUCLUSTERPIX_H

#include "AliCluster.h"
#include <TMath.h>

// uncomment this to have cluster topology in stored

//#define _ClusterTopology_  

#define CLUSTER_VERSION 2 

class TGeoHMatrix;
class AliITSUGeomTGeo;



class AliITSUClusterPix : public AliCluster
{
 public:
  enum { // frame in which the track is currently defined
    kFrameLoc  = BIT(16)
    ,kFrameTrk = BIT(17)
    ,kFrameGlo = BIT(18)
    ,kFrameBits = kFrameLoc|kFrameTrk|kFrameGlo
    ,kSplit    = BIT(19)
  };
  //
  enum SortMode_t { // various modes
    kSortIdLocXZ  = BIT(0)    // sort according to ID, then X,Z of local frame
    ,kSortIdTrkYZ = BIT(1)    // sort according to ID, then Y,Z of tracking frame
    ,kSortBits = kSortIdLocXZ|kSortIdTrkYZ
  };
  enum {kOffsNZ=0,kMaskNZ=0xff,kOffsNX=8,kMaskNX=0xff,kOffsNPix=16,kMaskNPix=0x1ff,kOffsClUse=25,kMaskClUse=0x7f};
  //
#ifdef _ClusterTopology_
  enum {kMaxPatternBits=32*16, kMaxPatternBytes=kMaxPatternBits/8,
	kSpanMask=0x7fff,kTruncateMask=0x8000};
#endif
 public:
  AliITSUClusterPix();
  AliITSUClusterPix(const AliITSUClusterPix& cluster);
  AliITSUClusterPix &operator=(const AliITSUClusterPix& cluster);
  virtual ~AliITSUClusterPix();
  //
  Bool_t  IsFrameLoc()         const {return TestBit(kFrameLoc);}
  Bool_t  IsFrameGlo()         const {return TestBit(kFrameGlo);}
  Bool_t  IsFrameTrk()         const {return TestBit(kFrameTrk);}
  //
  Bool_t  IsSplit()            const {return TestBit(kSplit);}
  //
  void    SetFrameLoc()              {ResetBit(kFrameBits); SetBit(kFrameLoc);}
  void    SetFrameGlo()              {ResetBit(kFrameBits); SetBit(kFrameGlo);}
  void    SetFrameTrk()              {ResetBit(kFrameTrk);  SetBit(kFrameTrk);}
  //
  void    SetSplit(Bool_t v=kTRUE)   {SetBit(kSplit,v);}
  //
  void    GoToFrameGlo();
  void    GoToFrameLoc();
  void    GoToFrameTrk();
  void    GetLocalXYZ(Float_t xyz[3])                       const;
  void    GetTrackingXYZ(Float_t xyz[3])                    const; 
  //
  void    SetNxNzN(UChar_t nx,UChar_t nz,UShort_t n)              {fNxNzN = ((n&kMaskNPix)<<kOffsNPix) + ((nx&kMaskNX)<<kOffsNX) + ((nz&kMaskNZ)<<kOffsNZ);}
  void    SetClUsage(Int_t n);
  void    ModClUsage(Bool_t used=kTRUE)                           {used ? IncClUsage() : DecClUsage();}
  void    IncClUsage()                                            {SetClUsage(GetClUsage()+1); IncreaseClusterUsage();}
  void    DecClUsage();
  Int_t   GetNx()                                           const {return (fNxNzN>>kOffsNX)&kMaskNX;}
  Int_t   GetNz()                                           const {return (fNxNzN>>kOffsNZ)&kMaskNZ;}
  Int_t   GetNPix()                                         const {return (fNxNzN>>kOffsNPix)&kMaskNPix;}
  Int_t   GetClUsage()                                      const {return (fNxNzN>>kOffsClUse)&kMaskClUse;}
  //
  void    SetQ(UShort_t q)                                        {fCharge = q;}
  Int_t   GetQ()                                            const {return fCharge;}
  //
  virtual void                 Print(Option_t* option = "") const;
  virtual const TGeoHMatrix*   GetTracking2LocalMatrix()           const;
  virtual TGeoHMatrix*         GetMatrix(Bool_t original = kFALSE) const;
  virtual Bool_t               GetGlobalXYZ(Float_t xyz[3]) const;
  virtual Bool_t               GetGlobalXYZ(Double_t xyz[3]) const;
  virtual Bool_t               GetGlobalCov(Float_t cov[6]) const;
  virtual Bool_t               GetXRefPlane(Float_t &xref)  const;
  //
  virtual Bool_t               IsSortable()                 const {return kTRUE;}
  virtual Bool_t               IsEqual(const TObject* obj)  const;
  virtual Int_t	               Compare(const TObject* obj)  const;
  //
  UShort_t                     GetRecoInfo()                const {return fRecoInfo;}
  void                         SetRecoInfo(UShort_t v)            {fRecoInfo = v; ModClUsage(v>0);}
  //
  Bool_t  HasCommonTrack(const AliCluster* cl)          const;
  //
  static  void                 SetGeom(AliITSUGeomTGeo* gm) {fgGeom = gm;}
  static  void                 SetSortMode(SortMode_t md)   {fgMode &= ~kSortBits; fgMode |= md;}
  static  UInt_t               GetSortMode()                {return fgMode&kSortBits;}
  static  UInt_t               GetMode()                    {return fgMode;}
  static  SortMode_t           SortModeIdTrkYZ()            {return kSortIdTrkYZ;}
  static  SortMode_t           SortModeIdLocXZ()            {return kSortIdLocXZ;}
  //
#ifdef _ClusterTopology_
  Int_t    GetPatternRowSpan()                       const  {return fPatternNRows&kSpanMask;}
  Int_t    GetPatternColSpan()                       const  {return fPatternNCols&kSpanMask;}
  Bool_t   IsPatternRowsTruncated()                  const  {return fPatternNRows&kTruncateMask;}
  Bool_t   IsPatternColsTruncated()                  const  {return fPatternNRows&kTruncateMask;}
  Bool_t   IsPatternTruncated()                      const  {return IsPatternRowsTruncated()||IsPatternColsTruncated();}
  void     SetPatternRowSpan(UShort_t nr, Bool_t truncated);
  void     SetPatternColSpan(UShort_t nc, Bool_t truncated);
  void     SetPatternMinRow(UShort_t row)            {fPatternMinRow = row;}
  void     SetPatternMinCol(UShort_t col)            {fPatternMinCol = col;}
  void     ResetPattern();
  Bool_t   TestPixel(UShort_t row,UShort_t col)      const;
  void     SetPixel(UShort_t row,UShort_t col, Bool_t fired=kTRUE);
  void     GetPattern(UChar_t patt[kMaxPatternBytes]) {for(Int_t i=0; i<kMaxPatternBytes; i++) patt[i]=fPattern[i];}
  Int_t    GetPatternMinRow()                        const {return fPatternMinRow;}
  Int_t    GetPatternMinCol()                        const {return fPatternMinCol;}

#endif
  //
 protected:
  //
  UShort_t                fCharge;        //  charge (for MC studies only)
  UShort_t                fRecoInfo;      //! space reserved for reco time manipulations
  Int_t                   fNxNzN;         //  effective cluster size in X (1st byte) and Z (2nd byte) directions 
                                          //  and total Npix(next 9 bits). last 7 bits are used for clusters usage counter
  static UInt_t           fgMode;         //! general mode (sorting mode etc)
  static AliITSUGeomTGeo* fgGeom;         //! pointer on the geometry data

#ifdef  _ClusterTopology_
  UShort_t fPatternNRows;                 // pattern span in rows
  UShort_t fPatternNCols;                 // pattern span in columns
  UShort_t fPatternMinRow;                // pattern start row
  UShort_t fPatternMinCol;                // pattern start column
  UChar_t  fPattern[kMaxPatternBytes];    // cluster topology
  //
  ClassDef(AliITSUClusterPix,CLUSTER_VERSION+1)
#else
  ClassDef(AliITSUClusterPix,CLUSTER_VERSION)
#endif
};

//______________________________________________________
inline void AliITSUClusterPix::DecClUsage() {
  // decrease cluster usage counter
  int n=GetClUsage(); 
  if (n) SetClUsage(--n);
  //
}

//______________________________________________________
inline void AliITSUClusterPix::SetClUsage(Int_t n) {
  // set cluster usage counter
  fNxNzN &= ~(kMaskClUse<<kOffsClUse);
  fNxNzN |= (n&kMaskClUse)<<kOffsClUse;
  if (n<2) SetBit(kShared,kFALSE);
  if (!n)  SetBit(kUsed,kFALSE);
}

#endif
 AliITSUClusterPix.h:1
 AliITSUClusterPix.h:2
 AliITSUClusterPix.h:3
 AliITSUClusterPix.h:4
 AliITSUClusterPix.h:5
 AliITSUClusterPix.h:6
 AliITSUClusterPix.h:7
 AliITSUClusterPix.h:8
 AliITSUClusterPix.h:9
 AliITSUClusterPix.h:10
 AliITSUClusterPix.h:11
 AliITSUClusterPix.h:12
 AliITSUClusterPix.h:13
 AliITSUClusterPix.h:14
 AliITSUClusterPix.h:15
 AliITSUClusterPix.h:16
 AliITSUClusterPix.h:17
 AliITSUClusterPix.h:18
 AliITSUClusterPix.h:19
 AliITSUClusterPix.h:20
 AliITSUClusterPix.h:21
 AliITSUClusterPix.h:22
 AliITSUClusterPix.h:23
 AliITSUClusterPix.h:24
 AliITSUClusterPix.h:25
 AliITSUClusterPix.h:26
 AliITSUClusterPix.h:27
 AliITSUClusterPix.h:28
 AliITSUClusterPix.h:29
 AliITSUClusterPix.h:30
 AliITSUClusterPix.h:31
 AliITSUClusterPix.h:32
 AliITSUClusterPix.h:33
 AliITSUClusterPix.h:34
 AliITSUClusterPix.h:35
 AliITSUClusterPix.h:36
 AliITSUClusterPix.h:37
 AliITSUClusterPix.h:38
 AliITSUClusterPix.h:39
 AliITSUClusterPix.h:40
 AliITSUClusterPix.h:41
 AliITSUClusterPix.h:42
 AliITSUClusterPix.h:43
 AliITSUClusterPix.h:44
 AliITSUClusterPix.h:45
 AliITSUClusterPix.h:46
 AliITSUClusterPix.h:47
 AliITSUClusterPix.h:48
 AliITSUClusterPix.h:49
 AliITSUClusterPix.h:50
 AliITSUClusterPix.h:51
 AliITSUClusterPix.h:52
 AliITSUClusterPix.h:53
 AliITSUClusterPix.h:54
 AliITSUClusterPix.h:55
 AliITSUClusterPix.h:56
 AliITSUClusterPix.h:57
 AliITSUClusterPix.h:58
 AliITSUClusterPix.h:59
 AliITSUClusterPix.h:60
 AliITSUClusterPix.h:61
 AliITSUClusterPix.h:62
 AliITSUClusterPix.h:63
 AliITSUClusterPix.h:64
 AliITSUClusterPix.h:65
 AliITSUClusterPix.h:66
 AliITSUClusterPix.h:67
 AliITSUClusterPix.h:68
 AliITSUClusterPix.h:69
 AliITSUClusterPix.h:70
 AliITSUClusterPix.h:71
 AliITSUClusterPix.h:72
 AliITSUClusterPix.h:73
 AliITSUClusterPix.h:74
 AliITSUClusterPix.h:75
 AliITSUClusterPix.h:76
 AliITSUClusterPix.h:77
 AliITSUClusterPix.h:78
 AliITSUClusterPix.h:79
 AliITSUClusterPix.h:80
 AliITSUClusterPix.h:81
 AliITSUClusterPix.h:82
 AliITSUClusterPix.h:83
 AliITSUClusterPix.h:84
 AliITSUClusterPix.h:85
 AliITSUClusterPix.h:86
 AliITSUClusterPix.h:87
 AliITSUClusterPix.h:88
 AliITSUClusterPix.h:89
 AliITSUClusterPix.h:90
 AliITSUClusterPix.h:91
 AliITSUClusterPix.h:92
 AliITSUClusterPix.h:93
 AliITSUClusterPix.h:94
 AliITSUClusterPix.h:95
 AliITSUClusterPix.h:96
 AliITSUClusterPix.h:97
 AliITSUClusterPix.h:98
 AliITSUClusterPix.h:99
 AliITSUClusterPix.h:100
 AliITSUClusterPix.h:101
 AliITSUClusterPix.h:102
 AliITSUClusterPix.h:103
 AliITSUClusterPix.h:104
 AliITSUClusterPix.h:105
 AliITSUClusterPix.h:106
 AliITSUClusterPix.h:107
 AliITSUClusterPix.h:108
 AliITSUClusterPix.h:109
 AliITSUClusterPix.h:110
 AliITSUClusterPix.h:111
 AliITSUClusterPix.h:112
 AliITSUClusterPix.h:113
 AliITSUClusterPix.h:114
 AliITSUClusterPix.h:115
 AliITSUClusterPix.h:116
 AliITSUClusterPix.h:117
 AliITSUClusterPix.h:118
 AliITSUClusterPix.h:119
 AliITSUClusterPix.h:120
 AliITSUClusterPix.h:121
 AliITSUClusterPix.h:122
 AliITSUClusterPix.h:123
 AliITSUClusterPix.h:124
 AliITSUClusterPix.h:125
 AliITSUClusterPix.h:126
 AliITSUClusterPix.h:127
 AliITSUClusterPix.h:128
 AliITSUClusterPix.h:129
 AliITSUClusterPix.h:130
 AliITSUClusterPix.h:131
 AliITSUClusterPix.h:132
 AliITSUClusterPix.h:133
 AliITSUClusterPix.h:134
 AliITSUClusterPix.h:135
 AliITSUClusterPix.h:136
 AliITSUClusterPix.h:137
 AliITSUClusterPix.h:138
 AliITSUClusterPix.h:139
 AliITSUClusterPix.h:140
 AliITSUClusterPix.h:141
 AliITSUClusterPix.h:142
 AliITSUClusterPix.h:143
 AliITSUClusterPix.h:144
 AliITSUClusterPix.h:145
 AliITSUClusterPix.h:146
 AliITSUClusterPix.h:147
 AliITSUClusterPix.h:148
 AliITSUClusterPix.h:149
 AliITSUClusterPix.h:150
 AliITSUClusterPix.h:151
 AliITSUClusterPix.h:152
 AliITSUClusterPix.h:153
 AliITSUClusterPix.h:154
 AliITSUClusterPix.h:155
 AliITSUClusterPix.h:156
 AliITSUClusterPix.h:157
 AliITSUClusterPix.h:158
 AliITSUClusterPix.h:159