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