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