writing in T0.RecPoints calibrated time
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterFinder.h
CommitLineData
a38a7850 1// @(#) $Id$
4aa41877 2// Original: AliHLTClustFinderNew.h,v 1.13 2004/06/18 10:55:26 loizides
a38a7850 3
01f43166 4#ifndef AliHLTTPC_CLUSTERFINDER
5#define AliHLTTPC_CLUSTERFINDER
297174de 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 *
a38a7850 9
01f43166 10/** @file AliHLTTPCClusterFinder.h
297174de 11 @author Anders Vestbo, Constantin Loizides
01f43166 12 Kenneth Aamodt kenneth.aamodt@student.uib.no
01f43166 13 @brief Cluster Finder for the TPC
14*/
15
01f43166 16#include "AliHLTLogging.h"
297174de 17#include <vector>
6b15c309 18#include "AliHLTTPCTransform.h"
deba5d85 19#include "AliHLTTPCDigitData.h"
20#include "AliHLTTPCDigitReader.h"
f14729cb 21#include "AliTPCRecoParam.h"
297174de 22
23class AliHLTTPCPad;
a38a7850 24class AliHLTTPCSpacePointData;
297174de 25class AliHLTTPCClusters;
5ee8e602 26class AliTPCTransform;
a38a7850 27
297174de 28/**
29 * @class AliHLTTPCClusterFinder
30 *
31 * The current cluster finder for HLT
32 * (Based on STAR L3)
33 *
34 * Basically we have two versions for the cluster finder now.
35 * The default version, reads the data pad by pad, and find the
36 * clusters as it reads the data. The other version has now been
37 * developed to cope with unsorted data. New methods for the unsorted
38 * version can be found at the end of the default one i the source file.
39 * Currently the new version is only build to manage zero-suppressed data.
40 * More functionality will be added later.
41 *
42 * The cluster finder is initialized with the Init function,
43 * providing the slice and patch information to work on.
44 *
45 * The input is a provided by the AliHLTTPCDigitReader class,
46 * using the init() funktion, and the next() funktion in order
47 * to get the next bin. Either packed or unpacked data can be
48 * processed, dependent if one uses AliHLTTPCDigitReaderPacked
49 * class or AliHLTTPCDigitReaderUnpacked class in the
50 * Clusterfinder Component.
51 * The resulting space points will be in the
52 * array given by the SetOutputArray function.
53 *
54 * There are several setters which control the behaviour:
55 *
56 * - SetXYError(Float_t): set fixed error in XY direction
57 * - SetZError(Float_t): set fixed error in Z direction
58 * (used if errors are not calculated)
59 * - SetDeconv(Bool_t): switch on/off deconvolution
60 * - SetThreshold(UInt_t): set charge threshold for cluster
61 * - SetMatchWidth(UInt_t): set the match distance in
62 * time for sequences to be merged
63 * - SetSTDOutput(Bool_t): switch on/off output about found clusters
64 * - SetCalcErr(Bool_t): switch on/off calculation of
65 * space point errors (or widths in raw system)
66 * - SetRawSP(Bool_t): switch on/off convertion to raw system
67 *
68 *
69 * Example Usage:
70 *
71 * <pre>
72 * AliHLTTPCFileHandler *file = new AliHLTTPCFileHandler();
73 * file->SetAliInput(digitfile); //give some input file
74 * for(int slice=0; slice<=35; slice++){
75 * for(int patch=0; pat<6; pat++){
76 * file->Init(slice,patch);
77 * UInt_t ndigits=0;
78 * UInt_t maxclusters=100000;
79 * UInt_t pointsize = maxclusters*sizeof(AliHLTTPCSpacePointData);
80 * AliHLTTPCSpacePointData *points = (AliHLTTPCSpacePointData*)memory->Allocate(pointsize);
81 * AliHLTTPCDigitRowData *digits = (AliHLTTPCDigitRowData*)file->AliAltroDigits2Memory(ndigits,event);
82 * AliHLTTPCClusterFinder *cf = new AliHLTTPCClusterFinder();
83 * cf->SetMatchWidth(2);
84 * cf->InitSlice( slice, patch, row[0], row[1], maxPoints );
85 * cf->SetSTDOutput(kTRUE); //Some output to standard IO
86 * cf->SetRawSP(kFALSE); //Convert space points to local system
87 * cf->SetThreshold(5); //Threshold of cluster charge
88 * cf->SetDeconv(kTRUE); //Deconv in pad and time direction
89 * cf->SetCalcErr(kTRUE); //Calculate the errors of the spacepoints
90 * cf->SetOutputArray(points); //Move the spacepoints to the array
91 * cf->Read(iter->fPtr, iter->fSize ); //give the data to the cf
92 * cf->ProcessDigits(); //process the rows given by init
93 * Int_t npoints = cf->GetNumberOfClusters();
94 * AliHLTTPCMemHandler *out= new AliHLTTPCMemHandler();
95 * out->SetBinaryOutput(fname);
96 * out->Memory2Binary(npoints,points); //store the spacepoints
97 * out->CloseBinaryOutput();
98 * delete out;
99 * file->free();
100 * delete cf;
101 * }
102 * }
103 * </pre>
104 * @ingroup alihlt_tpc
105 */
46b33a24 106class AliHLTTPCClusterFinder : public AliHLTLogging {
a38a7850 107
108 public:
109 struct AliClusterData
110 {
111 UInt_t fTotalCharge; //tot charge of cluster
112 UInt_t fPad; //pad value
113 UInt_t fTime; //time value
114 ULong64_t fPad2; //for error in XY direction
115 ULong64_t fTime2; //for error in Z direction
116 UInt_t fMean; //mean in time
117 UInt_t fFlags; //different flags
118 UInt_t fChargeFalling; //for deconvolution
119 UInt_t fLastCharge; //for deconvolution
120 UInt_t fLastMergedPad; //dont merge twice per pad
d8b2f74a 121 Int_t fRow; //row value
6b15c309 122 UInt_t fQMax; //qmax
a38a7850 123 };
124 typedef struct AliClusterData AliClusterData; //!
125
deba5d85 126 struct MCWeight{
127 Int_t fMCID;
128 Float_t fWeight;
129 static Bool_t CompareWeights( const MCWeight &mc1, const MCWeight &mc2 ){ return mc1.fWeight > mc2.fWeight; }
130 };
131 typedef struct MCWeight MCWeight;
132
133 struct ClusterMCInfo{
134 MCWeight fClusterID[3];
135 };
136 typedef struct ClusterMCInfo ClusterMCInfo;
137
138
8f8bf0af 139 /** standard constructor */
140 AliHLTTPCClusterFinder();
a912b63b 141
8f8bf0af 142 /** destructor */
143 virtual ~AliHLTTPCClusterFinder();
144
a912b63b 145 /** Initialize the slice */
8f8bf0af 146 void InitSlice(Int_t slice,Int_t patch,Int_t maxpoints);
8f8bf0af 147
a912b63b 148 /** Initializes the pad array (vector)*/
149 void InitializePadArray();
150
151 /** Deinitialize the pad array (vector)*/
152 Int_t DeInitializePadArray();
153
154 /** Read the data in unsorted format, storing the clustercandidates */
155 void ReadDataUnsorted(void* ptr,unsigned long size);
156
157 /** Read the data in unsorted format, and deconvolute the signals for each pad in time direction */
158 void ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned long size);
159
160 /** Loops over all rows finding the clusters */
161 void FindClusters();
162
163 /** Compare two neighbouring pads for matching clustercandidates */
164 Bool_t ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCClusters* candidate,Int_t nextPadToRead);
165
166 /** Fills the hw address list */
167 Int_t FillHWAddressList(AliHLTUInt16_t *hwaddlist, Int_t maxHWAddress);
168
deba5d85 169 /** Fills the mc info */
170 Int_t FillOutputMCInfo(AliHLTTPCClusterFinder::ClusterMCInfo * outputMCInfo, Int_t maxNumberOfClusterMCInfo);
171
a912b63b 172 /** Set the pointer to the outputbuffer */
8f8bf0af 173 void SetOutputArray(AliHLTTPCSpacePointData *pt);
a912b63b 174
175 /** Returns the number of clusters */
176 Int_t GetNumberOfClusters() const {return fNClusters;}
177
3f0fd8f1 178 /** Returns the Ocuppancy limit */
179 Float_t GetOccupancyLimit() {return fOccupancyLimit;}
180
a912b63b 181 // setters
182 void SetDeconv(Bool_t f) {fDeconvPad=f; fDeconvTime=f;}
183 void SetDeconvPad(Bool_t f) {fDeconvPad=f;}
184 void SetDeconvTime(Bool_t f) {fDeconvTime=f;}
185 void SetUnsorted(Int_t unsorted){fUnsorted=unsorted;}
186 void SetPatch(Int_t patch){fCurrentPatch=patch;}
187 void SetDoPadSelection(Bool_t input){fDoPadSelection=input;}
188 void SetLastTimeBin(Int_t ltb){fLastTimeBin=ltb;}
189 void SetFirstTimeBin(Int_t ftb){fFirstTimeBin=ftb;}
db76ab35 190 void SetReleaseMemory( Bool_t v ){ fReleaseMemory = v;}
a912b63b 191 void UpdateLastTimeBin(){fLastTimeBin=AliHLTTPCTransform::GetNTimeBins();}
192
193//---------------------------------- Under this line the old sorted clusterfinder functions can be found --------------------------------
194 void Read(void* ptr,unsigned long size);
195 void ProcessDigits();
8f8bf0af 196 void WriteClusters(Int_t n_clusters,AliClusterData *list);
a912b63b 197 void WriteClusters(Int_t nclusters,AliHLTTPCClusters *list);
8252a538 198 void PrintClusters();
8f8bf0af 199 void SetXYError(Float_t f) {fXYErr=f;}
200 void SetZError(Float_t f) {fZErr=f;}
8f8bf0af 201 void SetThreshold(UInt_t i) {fThreshold=i;}
202 void SetOccupancyLimit(Float_t f) {fOccupancyLimit=f;}
8f8bf0af 203 void SetMatchWidth(UInt_t i) {fMatch=i;}
204 void SetSTDOutput(Bool_t f=kFALSE) {fStdout=f;}
205 void SetCalcErr(Bool_t f=kTRUE) {fCalcerr=f;}
206 void SetRawSP(Bool_t f=kFALSE) {fRawSP=f;}
207 void SetReader(AliHLTTPCDigitReader* f){fDigitReader = f;}
deba5d85 208
209 void Set32BitFormat(Bool_t flag){f32BitFormat = flag;}
210
211 void SetDoMC(Bool_t flag){fDoMC = flag;}
2fdb1ae7 212
213 vector<AliHLTUInt16_t> fClustersHWAddressVector; //! transient
214
215 typedef vector<AliHLTTPCPad*> AliHLTTPCPadVector;
216
217 vector<AliHLTTPCPadVector> fRowPadVector; //! transient
deba5d85 218
219 void FillMCClusterVector(vector<AliHLTTPCDigitData> digitData);
220
221 vector<AliHLTTPCClusterFinder::MCWeight> GetClusterMCInfo(){return fClusterMCVector;}
222
4f43db26 223 Bool_t UpdateCalibDB();
224
98034d0d 225 protected:
8f8bf0af 226 /** copy constructor prohibited */
227 AliHLTTPCClusterFinder(const AliHLTTPCClusterFinder&);
228 /** assignment operator prohibited */
229 AliHLTTPCClusterFinder& operator=(const AliHLTTPCClusterFinder&);
230
2a083ac4 231 AliHLTTPCSpacePointData *fSpacePointData; //! array of space points
232 AliHLTTPCDigitReader *fDigitReader; //! reader instance
a38a7850 233
a912b63b 234 UChar_t* fPtr; //! pointer to packed block
235 unsigned long fSize; //! packed block size
236 Bool_t fDeconvTime; //! deconv in time direction
237 Bool_t fDeconvPad; //! deconv in pad direction
238 Bool_t fStdout; //! have print out in write clusters
239 Bool_t fCalcerr; //! calculate centroid sigmas
240 Bool_t fRawSP; //! store centroids in raw system
241
242
243 Int_t fFirstRow; //! first row
244 Int_t fLastRow; //! last row
245 Int_t fCurrentRow; //! current active row
246 Int_t fCurrentSlice; //! current slice
247 Int_t fCurrentPatch; //! current patch
248 Int_t fMatch; //! size of match
249 UInt_t fThreshold; //! threshold for clusters
250 Int_t fNClusters; //! number of found clusters
251 Int_t fMaxNClusters; //! max. number of clusters
252 Float_t fXYErr; //! fixed error in XY
253 Float_t fZErr; //! fixed error in Z
5235c3e9 254
a912b63b 255 Float_t fOccupancyLimit; //! Occupancy Limit
8252a538 256
a912b63b 257 Int_t fUnsorted; //! enable for processing of unsorted digit data
258 Bool_t fVectorInitialized; //! flag to check if pad vector is initialized
259
8252a538 260 vector<AliHLTTPCClusters> fClusters; //! transient
deba5d85 261
262 vector<ClusterMCInfo> fClustersMCInfo; //! transient
263
264 vector<AliHLTTPCDigitData> fMCDigits; //! transient
8252a538 265
266 UInt_t* fNumberOfPadsInRow; //! transient
267
268 UInt_t fNumberOfRows; //! transient
269
2fdb1ae7 270 UInt_t fRowOfFirstCandidate; //! transient
271
272 Bool_t fDoPadSelection; //! transient
a38a7850 273
6b15c309 274 Int_t fFirstTimeBin; //! transient
275
276 Int_t fLastTimeBin; //! transient
277
278 UInt_t fTotalChargeOfPreviousClusterCandidate; //! transient
279
280 Bool_t fChargeOfCandidatesFalling; //! transient
281
deba5d85 282 Bool_t f32BitFormat; //! transient
283
284 Bool_t fDoMC; //! transient
285
286 vector<MCWeight> fClusterMCVector; //! transient
64defa03 287
6a5788b9 288 AliTPCTransform * fOfflineTransform; //! transient
289
f14729cb 290 AliTPCRecoParam fOfflineTPCRecoParam; //! transient
291
6a5788b9 292 Float_t fTimeMeanDiff; //! transient
5ee8e602 293
db76ab35 294 Bool_t fReleaseMemory; //! flag to release the memory after each event
295
a38a7850 296#ifdef do_mc
297 void GetTrackID(Int_t pad,Int_t time,Int_t *trackID);
298#endif
299
db76ab35 300 ClassDef(AliHLTTPCClusterFinder,11) //Fast cluster finder
a38a7850 301};
302#endif