]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/ITS/trackingSAP/AliITSSAPLayer.h
58199a7943a0616282da5d877a4f9c2ea1ff05b1
[u/mrichter/AliRoot.git] / HLT / ITS / trackingSAP / AliITSSAPLayer.h
1 #ifndef ALIITSSAPLAYER_H
2 #define ALIITSSAPLAYER_H
3
4 #include <algorithm>
5 #include <vector>
6 #include <TObject.h>
7 #include <TObjArray.h>
8 #include "AliITSRecPoint.h"
9 class AliVertex;
10 class AliITSSAPLayer 
11 {
12
13  public:
14   struct ClsInfo   // cluster info, optionally XY origin at vertex
15   { 
16     float x,y,z,phi,r;    // lab params
17     int   zphibin; // bins is z,phi
18     int   index;          // index in RecPoints array
19     int   detid;          // detector index //RS ??? Do we need it?
20     bool operator<(const ClsInfo &rhs) const {return zphibin<rhs.zphibin;}
21     //
22   };
23   typedef struct ClsInfo ClsInfo_t;
24   //
25   struct ClBinInfo  // info on bin clusters start, number of clusters
26   {
27     unsigned short ncl;    // number of clusters
28     unsigned short first;  // entry of 1st cluster in sorted vector of ClsInfo
29     int            index;  // index in the vector containing cells with non-0 occupancy
30   };
31   typedef struct ClBinInfo ClBinInfo_t;
32   //
33   struct ITSDetInfo  // info on sensor
34   {
35     int index; // sensor vid
36     float xTF,xTFmisal,phiTF,sinTF,cosTF; //tracking frame parameters of the detector
37   };
38   typedef struct ITSDetInfo ITSDetInfo_t;
39
40
41   AliITSSAPLayer();
42   AliITSSAPLayer(int id, float zspan,int nzbins,int nphibins, int buffer=100);
43   virtual ~AliITSSAPLayer();
44   //
45   int     GetVIDOffset()                const {return fVIDOffset;}
46   int     GetNClusters()                const {return fNClusters;}
47   int     GetNZBins()                   const {return fNZBins;}
48   int     GetNPhiBins()                 const {return fNPhiBins;}
49   float   GetZMin()                     const {return fZMin;}
50   float   GetZMax()                     const {return fZMax;}
51   //
52   void    SetNZBins(int v)                    {fNZBins = v;}
53   void    SetNPhiBins(int v)                  {fNPhiBins = v;}
54   void    SetZMin(float v)                    {fZMin = v;}
55   void    SetZMax(float v)                    {fZMax = v;}
56   //
57   void Init(int buffer=100);
58   //
59   void AddCluster(AliITSRecPoint *cl)         {fClusters->AddAtAndExpand(cl,fNClusters++);}
60   //
61   void SortClusters(const AliVertex* vtx=0);
62   int  GetPhiBin(float phi)             const {return phi*fDPhiInv;}
63   int  GetZBin  (float z)               const {return (z-fZMin)*fDZInv;}
64   int  GetBinIndex(int iz, int iphi)    const {return iphi*fNZBins + iz;}
65   int  GetBinZ(int ipz)                 const {return ipz%fNZBins;}
66   int  GetBinPhi(int ipz)               const {return ipz/fNZBins;}
67   void GetBinZPhi(int ipz,int &iz,int &iphi) const {iz = GetBinZ(ipz); iphi=GetBinPhi(ipz);}
68   //
69   int  SelectClusters(float zmin,float zmax,float phimin,float phimax);
70   int  GetNFoundBins()                  const {return fFoundBins.size();}
71   int  GetFoundBin(int i)               const {return fFoundBins[i];}
72   int  GetFoundBinClusters(int i, int &first)  const;
73   void ResetFoundIterator();
74   AliITSSAPLayer::ClsInfo_t* GetClusterInfo(int i) const {return (AliITSSAPLayer::ClsInfo_t*)&fSortedClInfo[i];}
75   AliITSSAPLayer::ClsInfo_t* GetNextClusterInfo();
76   int                     GetNextClusterInfoID();
77   AliITSRecPoint*         GetNextCluster();
78   AliITSRecPoint*         GetClusterSorted(int i)   const {return (AliITSRecPoint*)fClusters->UncheckedAt(fSortedClInfo[i].index);}
79   AliITSRecPoint*         GetClusterUnSorted(int i) const {return (AliITSRecPoint*)fClusters->UncheckedAt(i);}
80   //
81   AliITSSAPLayer::ITSDetInfo_t& GetDetInfo(int id)     const {return (ITSDetInfo_t&)fDetectors[id];}
82   Int_t                   GetNDetectors()           const {return fDetectors.size();}
83
84   void         ClearSortedInfo();
85   virtual void Clear(Option_t *opt="");
86   virtual void Print(Option_t *opt="")  const;
87
88  protected:
89   TObjArray* fClusters;       // externally supplied clusters
90   int   fLrID;                // layer id
91   int   fVIDOffset;           // offset of VID for detectors of this layer
92   int   fNClusters;           // N clusters
93   //
94   float fZMin;                // Zmin
95   float fZMax;                // Zmax
96   float fDZInv;               // inverse size of Z bin
97   float fDPhiInv;             // inverse size of Phi bin
98   int   fNZBins;             // N cells in Z
99   int   fNPhiBins;           // N cells in Phi
100   //
101   int   fQueryZBmin;         // min bin in Z of the query
102   int   fQueryZBmax;         // max bin in Z of the query
103   int   fQueryPhiBmin;       // min bin in phi of the query
104   int   fQueryPhiBmax;       // max bin in phi of the query
105   ClBinInfo_t* fBins;           // 2D (z,phi) grid of clusters binned in z,phi
106   int* fOccBins;              // id's of bins with non-0 occupancy
107   int  fNOccBins;             // number of occupied bins
108   int  fNFoundClusters;       // number of found clusters in the query zone
109   int  fFoundClusterIterator; // at which cluster within the bin we are?
110   int  fFoundBinIterator;     // at which foune bin we are?
111   std::vector<int>     fFoundBins;    // occupied bins satisfying to query
112   std::vector<ClsInfo_t> fSortedClInfo; // processed cluster info
113   std::vector<ITSDetInfo_t> fDetectors; // detector params
114   //
115 };
116
117 //_____________________________________________________ 
118 inline int AliITSSAPLayer::GetFoundBinClusters(int i, int &first)  const {
119   // set the entry of the first cl.info in the fSortedClInfo 
120   // and return n clusters in the bin
121   ClBinInfo_t& bin=fBins[GetFoundBin(i)];
122   first = bin.first;
123   return bin.ncl;
124 }
125
126 //_____________________________________________________ 
127 inline AliITSRecPoint* AliITSSAPLayer::GetNextCluster() {
128   // return next cluster
129   ClsInfo_t* cli=GetNextClusterInfo(); 
130   return cli ? (AliITSRecPoint*)fClusters->UncheckedAt(cli->index) : 0;
131 }
132
133 //_____________________________________________________________
134 inline AliITSSAPLayer::ClsInfo_t* AliITSSAPLayer::GetNextClusterInfo()
135 {
136   // return cluster info for next matching cluster
137   int id = GetNextClusterInfoID();
138   return id<0 ? 0 : (AliITSSAPLayer::ClsInfo_t*)&fSortedClInfo[id];
139 }
140
141 #endif