]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCClusterFinder.h
Added functionality to read the magnetic field value, and setting the recoparam objec...
[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 #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
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  */
106 class AliHLTTPCClusterFinder : public AliHLTLogging {
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
121     Int_t fRow;             //row value
122     UInt_t fQMax;           //qmax
123   };
124   typedef struct AliClusterData AliClusterData; //!
125
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
139   /** standard constructor */
140   AliHLTTPCClusterFinder();
141
142   /** destructor */
143   virtual ~AliHLTTPCClusterFinder();
144
145   /** Initialize the slice */
146   void InitSlice(Int_t slice,Int_t patch,Int_t maxpoints);
147
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
169  /**  Fills the mc info */
170   Int_t FillOutputMCInfo(AliHLTTPCClusterFinder::ClusterMCInfo * outputMCInfo, Int_t maxNumberOfClusterMCInfo);
171
172   /** Set the pointer to the outputbuffer */
173   void SetOutputArray(AliHLTTPCSpacePointData *pt);
174
175   /** Returns the number of clusters */
176   Int_t GetNumberOfClusters() const {return fNClusters;}
177
178   /** Returns the Ocuppancy limit */
179   Float_t GetOccupancyLimit() {return fOccupancyLimit;}
180   
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;}
190   void UpdateLastTimeBin(){fLastTimeBin=AliHLTTPCTransform::GetNTimeBins();}
191
192 //---------------------------------- Under this line the old sorted clusterfinder functions can be found --------------------------------
193   void Read(void* ptr,unsigned long size);
194   void ProcessDigits();
195   void WriteClusters(Int_t n_clusters,AliClusterData *list);
196   void WriteClusters(Int_t nclusters,AliHLTTPCClusters *list);
197   void PrintClusters();
198   void SetXYError(Float_t f) {fXYErr=f;}
199   void SetZError(Float_t f) {fZErr=f;}
200   void SetThreshold(UInt_t i) {fThreshold=i;}
201   void SetOccupancyLimit(Float_t f) {fOccupancyLimit=f;}
202   void SetMatchWidth(UInt_t i) {fMatch=i;}
203   void SetSTDOutput(Bool_t f=kFALSE) {fStdout=f;}  
204   void SetCalcErr(Bool_t f=kTRUE) {fCalcerr=f;}
205   void SetRawSP(Bool_t f=kFALSE) {fRawSP=f;}
206   void SetReader(AliHLTTPCDigitReader* f){fDigitReader = f;}
207
208   void Set32BitFormat(Bool_t flag){f32BitFormat = flag;}
209
210   void SetDoMC(Bool_t flag){fDoMC = flag;}
211   
212   vector<AliHLTUInt16_t> fClustersHWAddressVector;  //! transient
213   
214   typedef vector<AliHLTTPCPad*> AliHLTTPCPadVector;
215   
216   vector<AliHLTTPCPadVector> fRowPadVector;      //! transient
217   
218   void FillMCClusterVector(vector<AliHLTTPCDigitData> digitData);
219
220   vector<AliHLTTPCClusterFinder::MCWeight> GetClusterMCInfo(){return fClusterMCVector;}
221
222   Bool_t UpdateCalibDB();
223
224  protected: 
225   /** copy constructor prohibited */
226   AliHLTTPCClusterFinder(const AliHLTTPCClusterFinder&);
227   /** assignment operator prohibited */
228   AliHLTTPCClusterFinder& operator=(const AliHLTTPCClusterFinder&);
229
230   AliHLTTPCSpacePointData *fSpacePointData; //! array of space points
231   AliHLTTPCDigitReader *fDigitReader;       //! reader instance
232
233   UChar_t* fPtr;           //! pointer to packed block
234   unsigned long fSize;     //! packed block size
235   Bool_t fDeconvTime;      //! deconv in time direction
236   Bool_t fDeconvPad;       //! deconv in pad direction
237   Bool_t fStdout;          //! have print out in write clusters
238   Bool_t fCalcerr;         //! calculate centroid sigmas
239   Bool_t fRawSP;           //! store centroids in raw system
240
241
242   Int_t fFirstRow;       //! first row
243   Int_t fLastRow;        //! last row
244   Int_t fCurrentRow;     //! current active row
245   Int_t fCurrentSlice;   //! current slice
246   Int_t fCurrentPatch;   //! current patch
247   Int_t fMatch;          //! size of match
248   UInt_t fThreshold;     //! threshold for clusters
249   Int_t fNClusters;      //! number of found clusters
250   Int_t fMaxNClusters;   //! max. number of clusters
251   Float_t fXYErr;        //! fixed error in XY
252   Float_t fZErr;         //! fixed error in Z
253   
254   Float_t fOccupancyLimit;    //! Occupancy Limit
255
256   Int_t fUnsorted;            //! enable for processing of unsorted digit data
257   Bool_t fVectorInitialized;  //! flag to check if pad vector is initialized
258  
259   vector<AliHLTTPCClusters> fClusters;                             //! transient
260
261   vector<ClusterMCInfo> fClustersMCInfo;                           //! transient
262
263   vector<AliHLTTPCDigitData> fMCDigits;                            //! transient
264   
265   UInt_t* fNumberOfPadsInRow;                                      //! transient
266   
267   UInt_t fNumberOfRows;                                            //! transient
268   
269   UInt_t fRowOfFirstCandidate;                                     //! transient
270
271   Bool_t fDoPadSelection;                                          //! transient
272
273   Int_t fFirstTimeBin;                                             //! transient
274   
275   Int_t fLastTimeBin;                                              //! transient
276
277   UInt_t fTotalChargeOfPreviousClusterCandidate;                   //! transient
278
279   Bool_t fChargeOfCandidatesFalling;                               //! transient
280
281   Bool_t f32BitFormat;                                             //! transient
282
283   Bool_t fDoMC;                                                    //! transient
284
285   vector<MCWeight> fClusterMCVector;                               //! transient
286
287   AliTPCTransform * fOfflineTransform;                             //! transient
288
289   AliTPCRecoParam fOfflineTPCRecoParam;                            //! transient
290
291   Float_t fTimeMeanDiff;                                           //! transient
292
293 #ifdef do_mc
294   void GetTrackID(Int_t pad,Int_t time,Int_t *trackID);
295 #endif
296   
297   ClassDef(AliHLTTPCClusterFinder,10) //Fast cluster finder
298 };
299 #endif