2 // Original: AliHLTClustFinderNew.h,v 1.13 2004/06/18 10:55:26 loizides
4 #ifndef AliHLTTPC_CLUSTERFINDER
5 #define AliHLTTPC_CLUSTERFINDER
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 AliHLTTPCClusterFinder.h
11 @author Anders Vestbo, Constantin Loizides
12 Kenneth Aamodt kenneth.aamodt@student.uib.no
13 @brief Cluster Finder for the TPC
16 #include "AliHLTLogging.h"
18 #include "AliHLTTPCTransform.h"
19 #include "AliHLTTPCDigitData.h"
20 #include "AliHLTTPCDigitReader.h"
23 class AliHLTTPCSpacePointData;
24 class AliHLTTPCClusters;
25 class AliTPCTransform;
28 * @class AliHLTTPCClusterFinder
30 * The current cluster finder for HLT
33 * Basically we have two versions for the cluster finder now.
34 * The default version, reads the data pad by pad, and find the
35 * clusters as it reads the data. The other version has now been
36 * developed to cope with unsorted data. New methods for the unsorted
37 * version can be found at the end of the default one i the source file.
38 * Currently the new version is only build to manage zero-suppressed data.
39 * More functionality will be added later.
41 * The cluster finder is initialized with the Init function,
42 * providing the slice and patch information to work on.
44 * The input is a provided by the AliHLTTPCDigitReader class,
45 * using the init() funktion, and the next() funktion in order
46 * to get the next bin. Either packed or unpacked data can be
47 * processed, dependent if one uses AliHLTTPCDigitReaderPacked
48 * class or AliHLTTPCDigitReaderUnpacked class in the
49 * Clusterfinder Component.
50 * The resulting space points will be in the
51 * array given by the SetOutputArray function.
53 * There are several setters which control the behaviour:
55 * - SetXYError(Float_t): set fixed error in XY direction
56 * - SetZError(Float_t): set fixed error in Z direction
57 * (used if errors are not calculated)
58 * - SetDeconv(Bool_t): switch on/off deconvolution
59 * - SetThreshold(UInt_t): set charge threshold for cluster
60 * - SetMatchWidth(UInt_t): set the match distance in
61 * time for sequences to be merged
62 * - SetSTDOutput(Bool_t): switch on/off output about found clusters
63 * - SetCalcErr(Bool_t): switch on/off calculation of
64 * space point errors (or widths in raw system)
65 * - SetRawSP(Bool_t): switch on/off convertion to raw system
71 * AliHLTTPCFileHandler *file = new AliHLTTPCFileHandler();
72 * file->SetAliInput(digitfile); //give some input file
73 * for(int slice=0; slice<=35; slice++){
74 * for(int patch=0; pat<6; pat++){
75 * file->Init(slice,patch);
77 * UInt_t maxclusters=100000;
78 * UInt_t pointsize = maxclusters*sizeof(AliHLTTPCSpacePointData);
79 * AliHLTTPCSpacePointData *points = (AliHLTTPCSpacePointData*)memory->Allocate(pointsize);
80 * AliHLTTPCDigitRowData *digits = (AliHLTTPCDigitRowData*)file->AliAltroDigits2Memory(ndigits,event);
81 * AliHLTTPCClusterFinder *cf = new AliHLTTPCClusterFinder();
82 * cf->SetMatchWidth(2);
83 * cf->InitSlice( slice, patch, row[0], row[1], maxPoints );
84 * cf->SetSTDOutput(kTRUE); //Some output to standard IO
85 * cf->SetRawSP(kFALSE); //Convert space points to local system
86 * cf->SetThreshold(5); //Threshold of cluster charge
87 * cf->SetDeconv(kTRUE); //Deconv in pad and time direction
88 * cf->SetCalcErr(kTRUE); //Calculate the errors of the spacepoints
89 * cf->SetOutputArray(points); //Move the spacepoints to the array
90 * cf->Read(iter->fPtr, iter->fSize ); //give the data to the cf
91 * cf->ProcessDigits(); //process the rows given by init
92 * Int_t npoints = cf->GetNumberOfClusters();
93 * AliHLTTPCMemHandler *out= new AliHLTTPCMemHandler();
94 * out->SetBinaryOutput(fname);
95 * out->Memory2Binary(npoints,points); //store the spacepoints
96 * out->CloseBinaryOutput();
103 * @ingroup alihlt_tpc
105 class AliHLTTPCClusterFinder : public AliHLTLogging {
108 struct AliClusterData
110 UInt_t fTotalCharge; //tot charge of cluster
111 UInt_t fPad; //pad value
112 UInt_t fTime; //time value
113 ULong64_t fPad2; //for error in XY direction
114 ULong64_t fTime2; //for error in Z direction
115 UInt_t fMean; //mean in time
116 UInt_t fFlags; //different flags
117 UInt_t fChargeFalling; //for deconvolution
118 UInt_t fLastCharge; //for deconvolution
119 UInt_t fLastMergedPad; //dont merge twice per pad
120 Int_t fRow; //row value
123 typedef struct AliClusterData AliClusterData; //!
128 static Bool_t CompareWeights( const MCWeight &mc1, const MCWeight &mc2 ){ return mc1.fWeight > mc2.fWeight; }
130 typedef struct MCWeight MCWeight;
132 struct ClusterMCInfo{
133 MCWeight fClusterID[3];
135 typedef struct ClusterMCInfo ClusterMCInfo;
138 /** standard constructor */
139 AliHLTTPCClusterFinder();
142 virtual ~AliHLTTPCClusterFinder();
144 /** Initialize the slice */
145 void InitSlice(Int_t slice,Int_t patch,Int_t maxpoints);
147 /** Initializes the pad array (vector)*/
148 void InitializePadArray();
150 /** Deinitialize the pad array (vector)*/
151 Int_t DeInitializePadArray();
153 /** Read the data in unsorted format, storing the clustercandidates */
154 void ReadDataUnsorted(void* ptr,unsigned long size);
156 /** Read the data in unsorted format, and deconvolute the signals for each pad in time direction */
157 void ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned long size);
159 /** Loops over all rows finding the clusters */
162 /** Compare two neighbouring pads for matching clustercandidates */
163 Bool_t ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCClusters* candidate,Int_t nextPadToRead);
165 /** Fills the hw address list */
166 Int_t FillHWAddressList(AliHLTUInt16_t *hwaddlist, Int_t maxHWAddress);
168 /** Fills the mc info */
169 Int_t FillOutputMCInfo(AliHLTTPCClusterFinder::ClusterMCInfo * outputMCInfo, Int_t maxNumberOfClusterMCInfo);
171 /** Set the pointer to the outputbuffer */
172 void SetOutputArray(AliHLTTPCSpacePointData *pt);
174 /** Returns the number of clusters */
175 Int_t GetNumberOfClusters() const {return fNClusters;}
177 /** Returns the Ocuppancy limit */
178 Float_t GetOccupancyLimit() {return fOccupancyLimit;}
181 void SetDeconv(Bool_t f) {fDeconvPad=f; fDeconvTime=f;}
182 void SetDeconvPad(Bool_t f) {fDeconvPad=f;}
183 void SetDeconvTime(Bool_t f) {fDeconvTime=f;}
184 void SetUnsorted(Int_t unsorted){fUnsorted=unsorted;}
185 void SetPatch(Int_t patch){fCurrentPatch=patch;}
186 void SetDoPadSelection(Bool_t input){fDoPadSelection=input;}
187 void SetLastTimeBin(Int_t ltb){fLastTimeBin=ltb;}
188 void SetFirstTimeBin(Int_t ftb){fFirstTimeBin=ftb;}
189 void UpdateLastTimeBin(){fLastTimeBin=AliHLTTPCTransform::GetNTimeBins();}
191 //---------------------------------- Under this line the old sorted clusterfinder functions can be found --------------------------------
192 void Read(void* ptr,unsigned long size);
193 void ProcessDigits();
194 void WriteClusters(Int_t n_clusters,AliClusterData *list);
195 void WriteClusters(Int_t nclusters,AliHLTTPCClusters *list);
196 void PrintClusters();
197 void SetXYError(Float_t f) {fXYErr=f;}
198 void SetZError(Float_t f) {fZErr=f;}
199 void SetThreshold(UInt_t i) {fThreshold=i;}
200 void SetOccupancyLimit(Float_t f) {fOccupancyLimit=f;}
201 void SetMatchWidth(UInt_t i) {fMatch=i;}
202 void SetSTDOutput(Bool_t f=kFALSE) {fStdout=f;}
203 void SetCalcErr(Bool_t f=kTRUE) {fCalcerr=f;}
204 void SetRawSP(Bool_t f=kFALSE) {fRawSP=f;}
205 void SetReader(AliHLTTPCDigitReader* f){fDigitReader = f;}
207 void Set32BitFormat(Bool_t flag){f32BitFormat = flag;}
209 void SetDoMC(Bool_t flag){fDoMC = flag;}
211 vector<AliHLTUInt16_t> fClustersHWAddressVector; //! transient
213 typedef vector<AliHLTTPCPad*> AliHLTTPCPadVector;
215 vector<AliHLTTPCPadVector> fRowPadVector; //! transient
217 void FillMCClusterVector(vector<AliHLTTPCDigitData> digitData);
219 vector<AliHLTTPCClusterFinder::MCWeight> GetClusterMCInfo(){return fClusterMCVector;}
222 /** copy constructor prohibited */
223 AliHLTTPCClusterFinder(const AliHLTTPCClusterFinder&);
224 /** assignment operator prohibited */
225 AliHLTTPCClusterFinder& operator=(const AliHLTTPCClusterFinder&);
227 AliHLTTPCSpacePointData *fSpacePointData; //! array of space points
228 AliHLTTPCDigitReader *fDigitReader; //! reader instance
230 UChar_t* fPtr; //! pointer to packed block
231 unsigned long fSize; //! packed block size
232 Bool_t fDeconvTime; //! deconv in time direction
233 Bool_t fDeconvPad; //! deconv in pad direction
234 Bool_t fStdout; //! have print out in write clusters
235 Bool_t fCalcerr; //! calculate centroid sigmas
236 Bool_t fRawSP; //! store centroids in raw system
239 Int_t fFirstRow; //! first row
240 Int_t fLastRow; //! last row
241 Int_t fCurrentRow; //! current active row
242 Int_t fCurrentSlice; //! current slice
243 Int_t fCurrentPatch; //! current patch
244 Int_t fMatch; //! size of match
245 UInt_t fThreshold; //! threshold for clusters
246 Int_t fNClusters; //! number of found clusters
247 Int_t fMaxNClusters; //! max. number of clusters
248 Float_t fXYErr; //! fixed error in XY
249 Float_t fZErr; //! fixed error in Z
251 Float_t fOccupancyLimit; //! Occupancy Limit
253 Int_t fUnsorted; //! enable for processing of unsorted digit data
254 Bool_t fVectorInitialized; //! flag to check if pad vector is initialized
256 vector<AliHLTTPCClusters> fClusters; //! transient
258 vector<ClusterMCInfo> fClustersMCInfo; //! transient
260 vector<AliHLTTPCDigitData> fMCDigits; //! transient
262 UInt_t* fNumberOfPadsInRow; //! transient
264 UInt_t fNumberOfRows; //! transient
266 UInt_t fRowOfFirstCandidate; //! transient
268 Bool_t fDoPadSelection; //! transient
270 Int_t fFirstTimeBin; //! transient
272 Int_t fLastTimeBin; //! transient
274 UInt_t fTotalChargeOfPreviousClusterCandidate; //! transient
276 Bool_t fChargeOfCandidatesFalling; //! transient
278 Bool_t f32BitFormat; //! transient
280 Bool_t fDoMC; //! transient
282 vector<MCWeight> fClusterMCVector; //! transient
284 AliTPCTransform * fOfflineTransform; //! transient
286 Float_t fTimeMeanDiff; //! transient
289 void GetTrackID(Int_t pad,Int_t time,Int_t *trackID);
292 ClassDef(AliHLTTPCClusterFinder,9) //Fast cluster finder