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