]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUClusterizer.h
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUClusterizer.h
1 #ifndef ALIITSUCLUSTERIZER_H
2 #define ALIITSUCLUSTERIZER_H
3
4 #include <TBits.h>
5 #include <TClonesArray.h>
6 #include "AliITSUClusterPix.h"
7
8 class TTree;
9 class TObjAray;
10 class AliITSUSegmentationPix;
11 class AliITSdigit;
12 class AliCluster;
13 class AliITSURecoParam;
14
15
16 class AliITSUClusterizer : public TObject 
17 {
18   //
19  public:
20   enum {kDigitChunkSize=1024, kMaxLabels=20,kMaxLabInCluster=3};
21   //
22   AliITSUClusterizer(Int_t nrowInit=0);
23   virtual ~AliITSUClusterizer();
24   void SetRawData(Bool_t v=kTRUE)                      {fRawData = v;}
25   void Clusterize();
26   void SetSegmentation(const AliITSUSegmentationPix *segm);
27   void SetRecoParam(const AliITSURecoParam* param)     {fRecoParam = param;}
28   void SetLayerID(Int_t id)                            {fLayerID = id;}
29   void SetVolID(Int_t id)                              {fVolID = id;}
30   void SetNRow(Int_t nrow);
31   void SetAllowDiagonalClusterization(Bool_t v)        {fAllowDiagonalClusterization = v;}
32   void PrepareLorentzAngleCorrection(Double_t bz);
33   //
34   // interface methods
35   void MakeRecPointBranch(TTree */*treeR*/)            {};
36   void SetRecPointTreeAddress(TTree */*treeR*/)        {};
37   void DigitsToRecPoints(const TObjArray */*digList*/) {};
38   
39   void SetDigits(const TClonesArray *digits)       {fInputDigits=digits;fInputDigitsReadIndex=0;}
40   void SetClusters(TClonesArray *clusters)         {fOutputClusters=clusters;}
41   //
42   // labeling methods
43   void AddLabel(int label);
44   void CheckLabels();
45   //
46  protected: // transient data types
47   struct AliITSUClusterizerClusterDigit {
48     AliITSUClusterizerClusterDigit *fNext;
49     AliITSdigit *fDigit;
50   };
51   
52   struct AliITSUClusterizerClusterCand;
53   struct AliITSUClusterizerClusterPart {
54     AliITSUClusterizerClusterPart *fNextInRow;
55     AliITSUClusterizerClusterPart *fPrevInCluster;
56     AliITSUClusterizerClusterPart *fNextInCluster;
57     AliITSUClusterizerClusterCand *fParent;
58     Int_t fUBegin;
59     Int_t fUEnd;
60   };
61   
62   struct AliITSUClusterizerClusterCand {
63     AliITSUClusterizerClusterCand  *fNext; // only used for memory management
64     AliITSUClusterizerClusterPart  *fFirstPart;
65     AliITSUClusterizerClusterDigit *fFirstDigit;
66     AliITSUClusterizerClusterDigit *fLastDigit ;
67   };
68
69  protected:
70   //
71   // allocation and deallocation
72   AliITSUClusterizerClusterDigit* AllocDigitFreelist();
73   AliITSUClusterizerClusterCand*  AllocCand();
74   void                            DeallocCand(AliITSUClusterizerClusterCand *cand);
75   AliITSUClusterizerClusterPart*  AllocPart();
76   void                            DeallocPart(AliITSUClusterizerClusterPart *part) {DeallocParts(part,part); }
77   void                            DeallocParts(AliITSUClusterizerClusterPart *first,AliITSUClusterizerClusterPart *last);
78   AliITSUClusterizerClusterDigit* AllocDigit();
79   void                            DeallocDigit(AliITSUClusterizerClusterDigit *digit) {DeallocDigits(digit,digit);}
80   void                            DeallocDigits(AliITSUClusterizerClusterDigit *first,AliITSUClusterizerClusterDigit *last);
81
82   // input "iterator"
83   AliITSUClusterizerClusterDigit* NextDigit();
84   // output "iterator"
85   AliCluster*                     NextCluster() {return (AliCluster*)fOutputClusters->New(fOutputClusters->GetEntriesFast());}
86   
87   // modifiers
88   void SetAllowDiagonalClusterization();
89
90   void AttachDigitToCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterDigit *digit);
91   void AttachPartToCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterPart *part);
92   void DetachPartFromCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterPart *part);
93   void MergeCands(AliITSUClusterizerClusterCand *a,AliITSUClusterizerClusterCand *b);
94   void Transform(AliITSUClusterPix *cluster, AliITSUClusterizerClusterCand *cand);
95   void CloseCand(AliITSUClusterizerClusterCand *cand);
96   void ClosePart(AliITSUClusterizerClusterPart *part);
97
98   void CloseRemainingParts(AliITSUClusterizerClusterPart *part);
99   //
100  protected:
101   //
102   Int_t fVolID;                             // Volume id (chip index)
103   Bool_t fAllowDiagonalClusterization;      // allow clusters with pixels having common corners only
104   const AliITSUSegmentationPix* fSegm;      // Segmentation or local coord calc.
105   const AliITSURecoParam*       fRecoParam; // reco params
106   //
107   // Digit Input
108   const TClonesArray *fInputDigits;         // supplied digits
109   Int_t         fInputDigitsReadIndex;      // digits counter
110   Int_t         fLayerID;                   // current layer id
111   //
112   Int_t         fCurrLabels[kMaxLabels];    // labels collected for current cluster
113   Int_t         fNLabels;                   // number of collected labels
114   Bool_t        fRawData;                   // is raw data processed?
115   //
116   Double_t      fLorAngCorrection;          // Lorentz Angle correction for current layer
117   // Cluster Output
118   TClonesArray *fOutputClusters;            // external container to store clusters
119   //
120   // temporary variables
121   AliITSUClusterizerClusterDigit *fDigitFreelist    ; //! pool of local digits
122   AliITSUClusterizerClusterPart  *fPartFreelist     ; //! pool of unfinished clusters
123   AliITSUClusterizerClusterCand  *fCandFreelist     ; //! pool of clusters
124   AliITSUClusterizerClusterDigit *fDigitFreelistBptrFirst; //! pointer in the pool
125   AliITSUClusterizerClusterDigit *fDigitFreelistBptrLast ; //! pointer in the pool
126   AliITSUClusterizerClusterPart  *fPartFreelistBptr ; //! pointer in the pool
127   AliITSUClusterizerClusterCand  *fCandFreelistBptr ; //!pointer in the pool
128   //
129 #ifdef _ClusterTopology_
130   TBits  fTopology;       // container for the clusters topology pattern
131   UShort_t fMinCol;       // min col number
132   UShort_t fMinRow;       // min row number
133   void   FillClusterTopology(const AliITSUClusterizerClusterCand *cand, AliITSUClusterPix* cl) const;
134 #endif //_ClusterTopology_
135  private:
136   AliITSUClusterizer(const AliITSUClusterizer&); //Not implemented
137   AliITSUClusterizer& operator=(const AliITSUClusterizer&); //Not implemented
138   //
139   ClassDef(AliITSUClusterizer,0)
140 };
141
142
143 //_______________________________________________________________________________
144 inline void AliITSUClusterizer::DeallocCand(AliITSUClusterizerClusterCand *cand)
145 {
146   // free candidate
147   cand->fNext=fCandFreelist;
148   fCandFreelist=cand;
149 }
150
151 //_______________________________________________________________________________
152 inline void AliITSUClusterizer::DeallocParts(AliITSUClusterizerClusterPart *first,AliITSUClusterizerClusterPart *last)
153 {
154   // free cluster part
155   last->fNextInRow=fPartFreelist;
156   fPartFreelist=first;
157 }
158
159 //_______________________________________________________________________________
160 inline AliITSUClusterizer::AliITSUClusterizerClusterDigit* AliITSUClusterizer::AllocDigit()
161 {
162   // allocate digits
163   if (!fDigitFreelist) fDigitFreelist = AllocDigitFreelist();
164   AliITSUClusterizerClusterDigit *digit = fDigitFreelist;
165   fDigitFreelist = fDigitFreelist->fNext;
166   return digit;
167 }
168
169 //_______________________________________________________________________________
170 inline AliITSUClusterizer::AliITSUClusterizerClusterPart* AliITSUClusterizer::AllocPart()
171 {
172   // allocate cluster part
173   AliITSUClusterizerClusterPart *part=fPartFreelist;
174   fPartFreelist=fPartFreelist->fNextInRow;
175   return part;
176 }
177
178 //_______________________________________________________________________________
179 inline AliITSUClusterizer::AliITSUClusterizerClusterCand* AliITSUClusterizer::AllocCand()
180 {
181   // allocate cluster 
182   AliITSUClusterizerClusterCand *cand=fCandFreelist;
183   fCandFreelist=fCandFreelist->fNext;
184   return cand;
185 }
186
187 //_______________________________________________________________________________
188 inline void AliITSUClusterizer::DeallocDigits(AliITSUClusterizerClusterDigit *first, AliITSUClusterizerClusterDigit *last) 
189 {
190   // free digit
191   last->fNext = fDigitFreelist;
192   fDigitFreelist = first;
193 }
194
195 //_______________________________________________________________________________
196 inline void AliITSUClusterizer::AttachDigitToCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterDigit *digit) 
197 {
198   // attach digit
199   digit->fNext = cand->fFirstDigit;
200   cand->fFirstDigit = digit;
201 }
202
203 //_______________________________________________________________________________
204 inline void AliITSUClusterizer::DetachPartFromCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterPart *part) 
205 {
206   // remove cluster part 
207   if (part->fPrevInCluster)    part->fPrevInCluster->fNextInCluster=part->fNextInCluster;
208   else                         cand->fFirstPart=part->fNextInCluster;
209   if (part->fNextInCluster)    part->fNextInCluster->fPrevInCluster=part->fPrevInCluster;
210 }
211
212 //______________________________________________________________________________
213 inline void AliITSUClusterizer::AddLabel(int label)
214 {
215   // add new label
216   if (fNLabels==kMaxLabels) return;
217   for (int i=fNLabels;i--;) if (fCurrLabels[i]==label) return;
218   fCurrLabels[fNLabels++] = label;
219 }
220
221
222 #endif
223