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