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