]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCClusterFinder.h
added new helper components to libAliHLTUtil (EsdCollector and AliHLTOUTPublisher...
[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 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                               *
9
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
14 */
15
16 #include "AliHLTLogging.h"
17 #include <vector>
18
19 class AliHLTTPCPad;
20 class AliHLTTPCSpacePointData;
21 class AliHLTTPCDigitReader;
22 class AliHLTTPCClusters;
23
24 /**
25  * @class AliHLTTPCClusterFinder
26  *
27  * The current cluster finder for HLT
28  * (Based on STAR L3)
29  *
30  * Basically we have two versions for the cluster finder now.
31  * The default version, reads the data pad by pad, and find the
32  * clusters as it reads the data. The other version has now been
33  * developed to cope with unsorted data. New methods for the unsorted
34  * version can  be found at the end of the default one i the source file.
35  * Currently the new version is only build to manage zero-suppressed data.
36  * More functionality will be added later.
37  * 
38  * The cluster finder is initialized with the Init function, 
39  * providing the slice and patch information to work on. 
40  *
41  * The input is a provided by the AliHLTTPCDigitReader class,
42  * using the init() funktion, and the next() funktion in order 
43  * to get the next bin. Either packed or unpacked data can be
44  * processed, dependent if one uses AliHLTTPCDigitReaderPacked 
45  * class or AliHLTTPCDigitReaderUnpacked class in the 
46  * Clusterfinder Component.
47  * The resulting space points will be in the
48  * array given by the SetOutputArray function.
49  * 
50  * There are several setters which control the behaviour:
51  *
52  * - SetXYError(Float_t):   set fixed error in XY direction
53  * - SetZError(Float_t):    set fixed error in Z  direction
54  *                            (used if errors are not calculated) 
55  * - SetDeconv(Bool_t):     switch on/off deconvolution
56  * - SetThreshold(UInt_t):  set charge threshold for cluster
57  * - SetMatchWidth(UInt_t): set the match distance in 
58  *                            time for sequences to be merged 
59  * - SetSTDOutput(Bool_t):  switch on/off output about found clusters   
60  * - SetCalcErr(Bool_t):    switch on/off calculation of 
61  *                          space point errors (or widths in raw system)
62  * - SetRawSP(Bool_t):      switch on/off convertion to raw system
63  *
64  *
65  * Example Usage:
66  *
67  * <pre>
68  * AliHLTTPCFileHandler *file = new AliHLTTPCFileHandler();
69  * file->SetAliInput(digitfile); //give some input file
70  * for(int slice=0; slice<=35; slice++){
71  *   for(int patch=0; pat<6; pat++){
72  *     file->Init(slice,patch);
73  *     UInt_t ndigits=0;
74  *     UInt_t maxclusters=100000;
75  *     UInt_t pointsize = maxclusters*sizeof(AliHLTTPCSpacePointData);
76  *     AliHLTTPCSpacePointData *points = (AliHLTTPCSpacePointData*)memory->Allocate(pointsize);
77  *     AliHLTTPCDigitRowData *digits = (AliHLTTPCDigitRowData*)file->AliAltroDigits2Memory(ndigits,event);
78  *     AliHLTTPCClusterFinder *cf = new AliHLTTPCClusterFinder();
79  *     cf->SetMatchWidth(2);
80  *     cf->InitSlice( slice, patch, row[0], row[1], maxPoints );
81  *     cf->SetSTDOutput(kTRUE);    //Some output to standard IO
82  *     cf->SetRawSP(kFALSE);       //Convert space points to local system
83  *     cf->SetThreshold(5);        //Threshold of cluster charge
84  *     cf->SetDeconv(kTRUE);       //Deconv in pad and time direction
85  *     cf->SetCalcErr(kTRUE);      //Calculate the errors of the spacepoints
86  *     cf->SetOutputArray(points); //Move the spacepoints to the array
87  *     cf->Read(iter->fPtr, iter->fSize ); //give the data to the cf
88  *     cf->ProcessDigits();        //process the rows given by init
89  *     Int_t npoints = cf->GetNumberOfClusters();
90  *     AliHLTTPCMemHandler *out= new AliHLTTPCMemHandler();
91  *     out->SetBinaryOutput(fname);
92  *     out->Memory2Binary(npoints,points); //store the spacepoints
93  *     out->CloseBinaryOutput();
94  *     delete out;
95  *     file->free();
96  *     delete cf;
97  *   }
98  * }
99  * </pre>
100  * @ingroup alihlt_tpc
101  */
102 class AliHLTTPCClusterFinder : public AliHLTLogging {
103
104  public:
105   struct AliClusterData
106   {
107     UInt_t fTotalCharge;   //tot charge of cluster
108     UInt_t fPad;           //pad value
109     UInt_t fTime;          //time value
110     ULong64_t fPad2;       //for error in XY direction
111     ULong64_t fTime2;      //for error in Z  direction
112     UInt_t fMean;          //mean in time
113     UInt_t fFlags;         //different flags
114     UInt_t fChargeFalling; //for deconvolution
115     UInt_t fLastCharge;    //for deconvolution
116     UInt_t fLastMergedPad; //dont merge twice per pad
117     Int_t fRow;             //row value
118   };
119   typedef struct AliClusterData AliClusterData; //!
120
121   /** standard constructor */
122   AliHLTTPCClusterFinder();
123   /** destructor */
124   virtual ~AliHLTTPCClusterFinder();
125
126   void Read(void* ptr,unsigned long size);
127
128   void InitSlice(Int_t slice,Int_t patch,Int_t firstrow, Int_t lastrow,Int_t maxpoints);
129   void InitSlice(Int_t slice,Int_t patch,Int_t maxpoints);
130   void ProcessDigits();
131
132   void SetOutputArray(AliHLTTPCSpacePointData *pt);
133   void WriteClusters(Int_t n_clusters,AliClusterData *list);
134   void PrintClusters();
135   void SetXYError(Float_t f) {fXYErr=f;}
136   void SetZError(Float_t f) {fZErr=f;}
137   void SetDeconv(Bool_t f) {fDeconvPad=f; fDeconvTime=f;}
138   void SetThreshold(UInt_t i) {fThreshold=i;}
139   void SetOccupancyLimit(Float_t f) {fOccupancyLimit=f;}
140   void SetSignalThreshold(Int_t i) {fSignalThreshold=i;}
141   void SetNSigmaThreshold(Double_t d) {fNSigmaThreshold=d;}
142   void SetMatchWidth(UInt_t i) {fMatch=i;}
143   void SetSTDOutput(Bool_t f=kFALSE) {fStdout=f;}  
144   void SetCalcErr(Bool_t f=kTRUE) {fCalcerr=f;}
145   void SetRawSP(Bool_t f=kFALSE) {fRawSP=f;}
146   void SetReader(AliHLTTPCDigitReader* f){fDigitReader = f;}
147   Int_t GetNumberOfClusters() const {return fNClusters;}
148
149   //----------------------------------Methods for the new unsorted way of reading data ----------
150   void ReadDataUnsorted(void* ptr,unsigned long size);
151   void FindClusters();
152   void WriteClusters(Int_t nclusters,AliHLTTPCClusters *list);
153   void SetUnsorted(Int_t unsorted){fUnsorted=unsorted;}
154   void SetPatch(Int_t patch){fCurrentPatch=patch;}
155   void InitializePadArray();
156   Int_t DeInitializePadArray();
157   Bool_t ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCClusters* candidate,Int_t nextPadToRead);
158
159   void SetDoPadSelection(Bool_t input){fDoPadSelection=input;}
160   
161   Int_t FillHWAddressList(AliHLTUInt16_t *hwaddlist, Int_t maxHWAddress);
162   
163   vector<AliHLTUInt16_t> fClustersHWAddressVector;  //! transient
164   
165   typedef vector<AliHLTTPCPad*> AliHLTTPCPadVector;
166   
167   vector<AliHLTTPCPadVector> fRowPadVector;      //! transient
168  
169  protected: 
170   /** copy constructor prohibited */
171   AliHLTTPCClusterFinder(const AliHLTTPCClusterFinder&);
172   /** assignment operator prohibited */
173   AliHLTTPCClusterFinder& operator=(const AliHLTTPCClusterFinder&);
174
175   AliHLTTPCSpacePointData *fSpacePointData; //! array of space points
176   AliHLTTPCDigitReader *fDigitReader;       //! reader instance
177
178   UChar_t* fPtr;   //! pointer to packed block
179   unsigned long fSize; //packed block size
180   Bool_t fDeconvTime; //deconv in time direction
181   Bool_t fDeconvPad;  //deconv in pad direction
182   Bool_t fStdout;     //have print out in write clusters
183   Bool_t fCalcerr;    //calculate centroid sigmas
184   Bool_t fRawSP;      //store centroids in raw system
185
186
187   Int_t fFirstRow;       //first row
188   Int_t fLastRow;        //last row
189   Int_t fCurrentRow;     //current active row
190   Int_t fCurrentSlice;   //current slice
191   Int_t fCurrentPatch;   //current patch
192   Int_t fMatch;          //size of match
193   UInt_t fThreshold;     //threshold for clusters
194   /** threshold for zero suppression (applied per bin) */
195   Int_t fSignalThreshold;// see above
196   /** threshold for zero suppression 2007 December run */
197   Double_t fNSigmaThreshold; // see above
198   Int_t fNClusters;      //number of found clusters
199   Int_t fMaxNClusters;   //max. number of clusters
200   Float_t fXYErr;        //fixed error in XY
201   Float_t fZErr;         //fixed error in Z
202   
203   Float_t fOccupancyLimit; // Occupancy Limit
204
205   Int_t fUnsorted;       // enable for processing of unsorted digit data
206   Bool_t fVectorInitialized;
207
208   //typedef vector<AliHLTTPCPad*> AliHLTTPCPadVector;
209
210   //vector<AliHLTTPCPadVector> fRowPadVector;                        //! transient
211
212   vector<AliHLTTPCClusters> fClusters;                             //! transient
213   
214   UInt_t* fNumberOfPadsInRow;                                      //! transient
215   
216   UInt_t fNumberOfRows;                                            //! transient
217   
218   UInt_t fRowOfFirstCandidate;                                     //! transient
219
220   Bool_t fDoPadSelection;                                          //! transient
221
222
223 #ifdef do_mc
224   void GetTrackID(Int_t pad,Int_t time,Int_t *trackID);
225 #endif
226   
227   ClassDef(AliHLTTPCClusterFinder,5) //Fast cluster finder
228 };
229 #endif