4 #ifndef ALIHLTTPCHWCLUSTERMERGER_H
5 #define ALIHLTTPCHWCLUSTERMERGER_H
6 //* This file is property of and copyright by the ALICE HLT Project *
7 //* ALICE Experiment at CERN, All rights reserved. *
8 //* See cxx source for full Copyright notice *
10 // @file AliHLTTPCHWClusterMerger.h
11 // @author Matthias Richter, Sergey Gorbunov
13 // @brief Merger class for HLT TPC Hardware clusters
14 // Handles merging of branch border clusters
16 #include "AliHLTTPCRawCluster.h"
17 #include "AliHLTTPCClusterMCData.h"
18 #include "AliHLTLogging.h"
23 * @class AliHLTTPCHWClusterMerger
25 * @ingroup alihlt_base
27 class AliHLTTPCHWClusterMerger : public AliHLTLogging
30 /// standard constructor
31 AliHLTTPCHWClusterMerger();
33 ~AliHLTTPCHWClusterMerger();
37 //////////////////////////////////////////////////////////////////////////////////////////////////////////
38 //////////////////////////////////////////////////////////////////////////////////////////////////////////
40 /// check if a cluster is a candidate for merging
42 bool CheckCandidate(int slice, int partition, const T& c) {
43 return CheckCandidate(slice, partition, c.GetPadRow(), c.GetPad(), c.GetTime(), c.GetSigmaY2() );
46 /// check if a cluster is a candidate for merging
47 bool CheckCandidate(int slice,
49 int partitionrow, // local row in partition
54 /// cache cluster for later merging
56 int AddCandidate(int slice,
60 return AddCandidate(slice,
73 // cache cluster for later merging
75 int AddCandidate(int slice,
79 const AliHLTTPCClusterMCLabel *mc) {
80 return AddCandidate(slice,
94 /// cache cluster for later merging
95 int AddCandidate(int slice,
97 short partitionrow, // local row in the partition
102 unsigned short charge,
104 AliHLTUInt32_t id=~AliHLTUInt32_t(0),
105 const AliHLTTPCClusterMCLabel *mc=NULL
114 //////////////////////////////////////////////////////////////////////////////////////////////////////////
115 //////////////////////////////////////////////////////////////////////////////////////////////////////////
117 /// helper class to store relevant data for a cluster at border
118 struct AliBorderRecord {
119 AliHLTInt64_t fClusterRecordID;
120 AliHLTUInt32_t fTimeBin;
124 /// helper class to store relevant data for a cluster candidate
125 class AliClusterRecord {
128 : fSlice(-1), fPartition(-1), fBorder(-1), fMergedFlag(-1), fId(~AliHLTUInt32_t(0)), fCluster(), fMC() {}
129 AliClusterRecord(int slice, int partition, int border,int merged, AliHLTUInt32_t id, const AliHLTTPCRawCluster &cluster)
130 : fSlice(slice), fPartition(partition), fBorder(border), fMergedFlag(merged), fId(id), fCluster(cluster), fMC() {}
131 AliClusterRecord(int slice, int partition, int border,int merged, AliHLTUInt32_t id, const AliHLTTPCRawCluster &cluster, const AliHLTTPCClusterMCLabel &mc)
132 : fSlice(slice), fPartition(partition), fBorder(border), fMergedFlag(merged), fId(id), fCluster(cluster), fMC(mc) {}
134 AliClusterRecord(const AliClusterRecord& other)
135 : fSlice(other.fSlice), fPartition(other.fPartition), fBorder(other.fBorder), fMergedFlag(other.fMergedFlag), fId(other.fId), fCluster(other.fCluster), fMC(other.fMC) {}
136 AliClusterRecord& operator=(const AliClusterRecord& other) {
137 if (this==&other) return *this;
138 this->~AliClusterRecord();
139 new (this) AliClusterRecord(other);
143 ~AliClusterRecord() {}
145 AliClusterRecord& operator=(const AliHLTTPCRawCluster& c) {
150 int IsMergedTo() const { return fMergedFlag; }
151 int GetSlice() const {return fSlice;}
152 int GetBorder() const {return fBorder;}
153 int GetPartition() const {return fPartition;}
154 AliHLTUInt32_t GetId() const {return fId;}
155 operator AliHLTTPCRawCluster() const {return fCluster;}
156 const AliHLTTPCRawCluster& GetCluster() const {return fCluster;}
157 const AliHLTTPCClusterMCLabel& GetMCLabel() const {return fMC;}
158 void SetMergedTo( int ind ){ fMergedFlag = ind;}
159 AliHLTTPCRawCluster &Cluster(){ return fCluster; }
160 AliHLTTPCClusterMCLabel& MCLabel(){ return fMC; }
166 AliHLTUInt32_t fId; //!
167 AliHLTTPCRawCluster fCluster; //!
168 AliHLTTPCClusterMCLabel fMC; //!
171 //////////////////////////////////////////////////////////////////////////////////////////////////////////
172 //////////////////////////////////////////////////////////////////////////////////////////////////////////
174 /// iterator class to access merged and remaining clusters
177 iterator() : fArray(NULL), fIter() {}
178 iterator(vector<AliClusterRecord>* pArray) : fArray(pArray), fIter() {if (fArray) fIter=fArray->begin();}
179 iterator(const iterator& other) : fArray(other.fArray), fIter(other.fIter) {}
180 iterator& operator=(const iterator& other) {
181 if (this==&other) return *this;
182 fArray=other.fArray; fIter=other.fIter; return *this;
186 AliClusterRecord operator*() {return *fIter;}
189 iterator& operator++() {
190 if (!fArray || fIter==fArray->end()) return *this;
191 while ((++fIter)!=fArray->end()) {
192 if ( fIter->IsMergedTo()<0 ) break;
196 iterator& operator--() {
197 if (!fArray) return *this;
198 while (fIter!=fArray->begin()) {
200 if ( fIter->IsMergedTo()<0 ) break;
206 iterator operator++(int) {iterator i(*this); this->operator++(); return i;}
207 iterator operator--(int) {iterator i(*this); this->operator--(); return i;}
209 iterator& operator+=(int step) {
210 if (!fArray) return *this;
211 while ((fIter)!=fArray->end() && step-->0) {++fIter;}
215 bool operator==(const iterator& other) {
216 return (other.fArray!=NULL && fArray!=NULL && other.fIter==fIter);
219 bool operator!=(const iterator& other) {
220 return (other.fArray!=NULL && fArray!=NULL && other.fIter!=fIter);
225 vector<AliClusterRecord>* fArray; //!
226 vector<AliClusterRecord>::iterator fIter; //!
229 //////////////////////////////////////////////////////////////////////////////////////////////////////////
230 //////////////////////////////////////////////////////////////////////////////////////////////////////////
232 /// iterator function, start iteration
235 new (&fIter) iterator(&fClusters);
236 fEnd=fIter; fEnd+=fClusters.size();
237 // skip empty (merged) clusters
238 while (fIter!=fEnd && ( (*fIter).IsMergedTo()>=0) ) {
244 /// iterator function, end marker
249 const vector<AliHLTTPCHWClusterMerger::AliClusterRecord> &GetRecords(){ return fClusters; }
250 static int GetNSlices(){ return fkNSlices; }
251 int GetNBorders() const { return fNBorders; }
252 int GetBorderNClusters( int ib ) const { return fBorderNClusters[ib]; }
253 int GetBorderFirstCluster( int ib ) const { return fBorderFirstCluster[ib]; }
254 const AliHLTTPCHWClusterMerger::AliBorderRecord *GetBorderClusters() const { return fBorderClusters;}
256 //////////////////////////////////////////////////////////////////////////////////////////////////////////
257 //////////////////////////////////////////////////////////////////////////////////////////////////////////
263 AliHLTTPCHWClusterMerger(const AliHLTTPCHWClusterMerger&);
264 /// assignment operator
265 AliHLTTPCHWClusterMerger& operator=(const AliHLTTPCHWClusterMerger&);
268 static bool CompareTime( const AliBorderRecord &b1, const AliBorderRecord &b2){
269 return b1.fTimeBin > b2.fTimeBin;
272 static bool CompareMCWeights(const AliHLTTPCClusterMCWeight &a, const AliHLTTPCClusterMCWeight &b){
273 return a.fWeight > b.fWeight;
275 static bool CompareMCLabels(const AliHLTTPCClusterMCWeight &a, const AliHLTTPCClusterMCWeight &b){
276 return a.fMCID < b.fMCID;
279 AliHLTInt16_t *fMapping;//!
283 AliHLTFloat32_t *fBorders; //!
284 int *fBorderNClusters; //!
285 int *fBorderFirstCluster; //!
286 AliBorderRecord *fBorderClusters;
287 int fBorderNClustersTotal; //!
289 vector<AliClusterRecord> fClusters; //! array of candidates
290 vector<AliHLTUInt32_t> fRemovedClusterIds; //! array of removed clusters by id
293 static const int fkMergeWidth = 3;
294 static const int fkNSlices = 36;
295 static const int fkMergeTimeWindow = 3;
296 ClassDef(AliHLTTPCHWClusterMerger, 0)
299 #endif //ALIHLTTPCHWCLUSTERMERGER_H