1 #ifndef ALIITSUCLUSTERIZER_H
2 #define ALIITSUCLUSTERIZER_H
5 #include <TClonesArray.h>
6 #include "AliITSUClusterPix.h"
10 class AliITSUSegmentationPix;
13 class AliITSURecoParam;
16 class AliITSUClusterizer : public TObject
20 enum {kDigitChunkSize=1024, kMaxLabels=20,kMaxLabInCluster=3};
21 enum {kMaskNZ=0xff,kMaskNX=0xff,kMaskNPix=0x1ff,kMaskClUse=0x7f};
23 AliITSUClusterizer(Int_t nrowInit=0);
24 virtual ~AliITSUClusterizer();
25 void SetRawData(Bool_t v=kTRUE) {fRawData = v;}
27 void SetSegmentation(const AliITSUSegmentationPix *segm);
28 void SetRecoParam(const AliITSURecoParam* param) {fRecoParam = param;}
29 void SetLayerID(Int_t id) {fLayerID = id;}
30 void SetVolID(Int_t id) {fVolID = id;}
31 void SetNRow(Int_t nrow);
32 void SetAllowDiagonalClusterization(Bool_t v) {fAllowDiagonalClusterization = v;}
33 void PrepareLorentzAngleCorrection(Double_t bz);
36 void MakeRecPointBranch(TTree */*treeR*/) {};
37 void SetRecPointTreeAddress(TTree */*treeR*/) {};
38 void DigitsToRecPoints(const TObjArray */*digList*/) {};
40 void SetDigits(const TClonesArray *digits) {fInputDigits=digits;fInputDigitsReadIndex=0;}
41 void SetClusters(TClonesArray *clusters) {fOutputClusters=clusters;}
44 void AddLabel(int label);
47 protected: // transient data types
48 struct AliITSUClusterizerClusterDigit {
49 AliITSUClusterizerClusterDigit *fNext;
53 struct AliITSUClusterizerClusterCand;
54 struct AliITSUClusterizerClusterPart {
55 AliITSUClusterizerClusterPart *fNextInRow;
56 AliITSUClusterizerClusterPart *fPrevInCluster;
57 AliITSUClusterizerClusterPart *fNextInCluster;
58 AliITSUClusterizerClusterCand *fParent;
63 struct AliITSUClusterizerClusterCand {
64 AliITSUClusterizerClusterCand *fNext; // only used for memory management
65 AliITSUClusterizerClusterPart *fFirstPart;
66 AliITSUClusterizerClusterDigit *fFirstDigit;
67 AliITSUClusterizerClusterDigit *fLastDigit ;
72 // allocation and deallocation
73 AliITSUClusterizerClusterDigit* AllocDigitFreelist();
74 AliITSUClusterizerClusterCand* AllocCand();
75 void DeallocCand(AliITSUClusterizerClusterCand *cand);
76 AliITSUClusterizerClusterPart* AllocPart();
77 void DeallocPart(AliITSUClusterizerClusterPart *part) {DeallocParts(part,part); }
78 void DeallocParts(AliITSUClusterizerClusterPart *first,AliITSUClusterizerClusterPart *last);
79 AliITSUClusterizerClusterDigit* AllocDigit();
80 void DeallocDigit(AliITSUClusterizerClusterDigit *digit) {DeallocDigits(digit,digit);}
81 void DeallocDigits(AliITSUClusterizerClusterDigit *first,AliITSUClusterizerClusterDigit *last);
84 AliITSUClusterizerClusterDigit* NextDigit();
86 AliCluster* NextCluster() {return (AliCluster*)fOutputClusters->New(fOutputClusters->GetEntriesFast());}
89 void SetAllowDiagonalClusterization();
91 void AttachDigitToCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterDigit *digit);
92 void AttachPartToCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterPart *part);
93 void DetachPartFromCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterPart *part);
94 void MergeCands(AliITSUClusterizerClusterCand *a,AliITSUClusterizerClusterCand *b);
95 void Transform(AliITSUClusterPix *cluster, AliITSUClusterizerClusterCand *cand);
96 void CloseCand(AliITSUClusterizerClusterCand *cand);
97 void ClosePart(AliITSUClusterizerClusterPart *part);
99 void CloseRemainingParts(AliITSUClusterizerClusterPart *part);
103 Int_t fVolID; // Volume id (chip index)
104 Bool_t fAllowDiagonalClusterization; // allow clusters with pixels having common corners only
105 const AliITSUSegmentationPix* fSegm; // Segmentation or local coord calc.
106 const AliITSURecoParam* fRecoParam; // reco params
109 const TClonesArray *fInputDigits; // supplied digits
110 Int_t fInputDigitsReadIndex; // digits counter
111 Int_t fLayerID; // current layer id
113 Int_t fCurrLabels[kMaxLabels]; // labels collected for current cluster
114 Int_t fNLabels; // number of collected labels
115 Bool_t fRawData; // is raw data processed?
117 Double_t fLorAngCorrection; // Lorentz Angle correction for current layer
119 TClonesArray *fOutputClusters; // external container to store clusters
121 // temporary variables
122 AliITSUClusterizerClusterDigit *fDigitFreelist ; //! pool of local digits
123 AliITSUClusterizerClusterPart *fPartFreelist ; //! pool of unfinished clusters
124 AliITSUClusterizerClusterCand *fCandFreelist ; //! pool of clusters
125 AliITSUClusterizerClusterDigit *fDigitFreelistBptrFirst; //! pointer in the pool
126 AliITSUClusterizerClusterDigit *fDigitFreelistBptrLast ; //! pointer in the pool
127 AliITSUClusterizerClusterPart *fPartFreelistBptr ; //! pointer in the pool
128 AliITSUClusterizerClusterCand *fCandFreelistBptr ; //!pointer in the pool
130 #ifdef _ClusterTopology_
131 TBits fTopology; // container for the clusters topology pattern
132 UShort_t fMinCol; // min col number
133 UShort_t fMinRow; // min row number
134 void FillClusterTopology(const AliITSUClusterizerClusterCand *cand, AliITSUClusterPix* cl) const;
135 #endif //_ClusterTopology_
137 AliITSUClusterizer(const AliITSUClusterizer&); //Not implemented
138 AliITSUClusterizer& operator=(const AliITSUClusterizer&); //Not implemented
140 ClassDef(AliITSUClusterizer,0)
144 //_______________________________________________________________________________
145 inline void AliITSUClusterizer::DeallocCand(AliITSUClusterizerClusterCand *cand)
148 cand->fNext=fCandFreelist;
152 //_______________________________________________________________________________
153 inline void AliITSUClusterizer::DeallocParts(AliITSUClusterizerClusterPart *first,AliITSUClusterizerClusterPart *last)
156 last->fNextInRow=fPartFreelist;
160 //_______________________________________________________________________________
161 inline AliITSUClusterizer::AliITSUClusterizerClusterDigit* AliITSUClusterizer::AllocDigit()
164 if (!fDigitFreelist) fDigitFreelist = AllocDigitFreelist();
165 AliITSUClusterizerClusterDigit *digit = fDigitFreelist;
166 fDigitFreelist = fDigitFreelist->fNext;
170 //_______________________________________________________________________________
171 inline AliITSUClusterizer::AliITSUClusterizerClusterPart* AliITSUClusterizer::AllocPart()
173 // allocate cluster part
174 AliITSUClusterizerClusterPart *part=fPartFreelist;
175 fPartFreelist=fPartFreelist->fNextInRow;
179 //_______________________________________________________________________________
180 inline AliITSUClusterizer::AliITSUClusterizerClusterCand* AliITSUClusterizer::AllocCand()
183 AliITSUClusterizerClusterCand *cand=fCandFreelist;
184 fCandFreelist=fCandFreelist->fNext;
188 //_______________________________________________________________________________
189 inline void AliITSUClusterizer::DeallocDigits(AliITSUClusterizerClusterDigit *first, AliITSUClusterizerClusterDigit *last)
192 last->fNext = fDigitFreelist;
193 fDigitFreelist = first;
196 //_______________________________________________________________________________
197 inline void AliITSUClusterizer::AttachDigitToCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterDigit *digit)
200 digit->fNext = cand->fFirstDigit;
201 cand->fFirstDigit = digit;
204 //_______________________________________________________________________________
205 inline void AliITSUClusterizer::DetachPartFromCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterPart *part)
207 // remove cluster part
208 if (part->fPrevInCluster) part->fPrevInCluster->fNextInCluster=part->fNextInCluster;
209 else cand->fFirstPart=part->fNextInCluster;
210 if (part->fNextInCluster) part->fNextInCluster->fPrevInCluster=part->fPrevInCluster;
213 //______________________________________________________________________________
214 inline void AliITSUClusterizer::AddLabel(int label)
217 if (fNLabels==kMaxLabels) return;
218 for (int i=fNLabels;i--;) if (fCurrLabels[i]==label) return;
219 fCurrLabels[fNLabels++] = label;