]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCPad.h
TPC cluster finder speeded up, can process unsorted data (Kenneth); not yet enabled...
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCPad.h
1 // -*- Mode: C++ -*-
2 // @(#) $Id$
3
4 #ifndef ALIHLTPAD_H
5 #define ALIHLTPAD_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   AliHLTTPCPad.h
11     @author Matthias Richter
12     @date   
13     @brief  Container Class for TPC Pads.
14 */
15
16 #include "AliHLTLogging.h"
17 #include "AliHLTTPCClusters.h"
18 #include <vector>
19
20 typedef Int_t AliHLTTPCSignal_t;
21
22 /**
23  * @class AliHLTTPCPad
24  * The class is a container for the raw ADC data of one TPCS pad. In order to
25  * avoid multiple unpacking/handling of the incoming raw data, the class holds
26  * a copy of the incoming data for one event. The copy is released when the
27  * end of the event was announced.
28  * The class calculates the base line of a TPC channel. Currently, only the
29  * average value is calculated, but further extension will include channel by
30  * channel histograming. The baseline history is kept and used for baseline
31  * re-evaluation and correction of subsequent events.
32  * @ingroup alihlt_tpc
33  */
34 class AliHLTTPCPad : public AliHLTLogging {
35 public:
36   /** standard constructor */
37   AliHLTTPCPad();
38
39   /** 
40    * Constructor
41    * @param offset   The number of bins to ignore at the beginning
42    *                 of the channels
43    * @param nofBins  The total number of bins for one channel
44    */
45   AliHLTTPCPad(Int_t offset, Int_t nofBins);
46
47   /** not a valid copy constructor, defined according to effective C++ style */
48   AliHLTTPCPad(const AliHLTTPCPad&);
49   /** not a valid assignment op, but defined according to effective C++ style */
50   AliHLTTPCPad& operator=(const AliHLTTPCPad&);
51   /** standard destructor */
52   virtual ~AliHLTTPCPad();
53
54   
55   struct AliClusterData
56   {
57     UInt_t fTotalCharge;   //tot charge of cluster
58     UInt_t fPad;       //pad value
59     UInt_t fTime;      //time value
60     ULong64_t fPad2;   //for error in XY direction
61     ULong64_t fTime2;  //for error in Z  direction
62     UInt_t fMean;          //mean in time
63     UInt_t fFlags;         //different flags
64     UInt_t fChargeFalling; //for deconvolution
65     UInt_t fLastCharge;    //for deconvolution
66     UInt_t fLastMergedPad; //dont merge twice per pad
67   }; 
68
69   typedef struct AliClusterData AliClusterData; //!
70
71
72   /**
73    * Set the address the pad.
74    * The address consists of row and pad number.
75    * @param rowno    The row number
76    * @param padno    The pad number.
77    */
78   Int_t SetID(Int_t rowno, Int_t padno);
79
80   /**
81    * Get the row number.
82    */
83   Int_t GetRowNumber() const {return fRowNo;}
84
85   /**
86    * Get the pad number.
87    */
88   Int_t GetPadNumber() const {return fPadNo;}
89
90   /**
91    * Start accumulation for a new event.
92    * The class holds internally a history of the event data. The data can
93    * be fetched from the class without unpacking the input stream again.
94    * @return neg. error value if failed
95    *         - ENOMEM memory allocation failed
96    *         - EALREADY event data acquisition already started
97    */
98   Int_t StartEvent();
99
100   /**
101    * Check whether the event is started
102    * @return 1 if started, 0 if not
103    */
104   Int_t IsStarted() const { return fpRawData!=NULL;};
105
106   /**
107    * Calculate the base line from the current event data.
108    * Only available within an event cycle. <br>
109    * The calculation requires a minimum number of bins which contribute
110    * to the sum, which can be specified by \e reqMinCount. The base line
111    * calculation will also be skipped if the number of contributing bins is 
112    * less than half of the total number of time bins. 
113    * @param reqMinCount    the minimum number of bins contributing to the sum
114    * @return neg. error value if failed
115    *         - ENODATA to little contributing bins
116    *         - ENOBUFS no raw data available
117    */
118   Int_t CalculateBaseLine(Int_t reqMinCount=1);
119
120   /**
121    * Stop processing of one event.
122    * The data history of the event will be released.
123    * @return neg. error value if failed
124    *         - EBADF event not started 
125    */
126   Int_t StopEvent();
127
128   /**
129    * Reset the base line history.
130    * @return neg. error code if failed 
131    */
132   Int_t ResetHistory();
133
134   /**
135    * Set threshold.
136    * The threshold effects to corrected data, signals smaller than threshold
137    * are suppressed.
138    * @param thresh   Threshold for signal correction
139    * @return neg. error code if failed 
140    */
141   Int_t SetThreshold(AliHLTTPCSignal_t thresh);
142
143   /**
144    * Set the raw data value of a certain channel.
145    * @param bin      Channel number
146    * @param value    ADC value
147    * @return neg. error value if failed
148    *         - ERANGE bin out of range
149    *         - BADF event cycle not started
150    */
151   Int_t SetRawData(Int_t bin, AliHLTTPCSignal_t value);
152
153   /**
154    * Get the raw data value of the current bin.
155    * The class holds the current read position which can be incremented by
156    * @ref Next() and reseted by @ref Rewind().
157    * Raw data is only available within an event cycle.
158    * @return raw data value
159    */
160   AliHLTTPCSignal_t GetRawData() const {return GetRawData(fReadPos);}
161
162   /**
163    * Get the corrected data value the current bin.
164    * Corrected raw data is only available within an event cycle.
165    * The base line value is substracted from the bin's value and suppressed
166    * by the threshold. Bins smaller than the first bin considered for base
167    * line calculation return 0.
168    * The class holds the current read position which can be incremented by
169    * @ref Next() and reseted by @ref Rewind().
170    * @return corrected value
171    */
172   AliHLTTPCSignal_t GetCorrectedData() const {return GetCorrectedData(fReadPos);}
173
174   /**
175    * Increment the read position.
176    * @param bZeroSuppression  skip all bins effected by the zero suppression
177    * @return 1 if more data available, 0 if not
178    */
179   Int_t Next(Int_t bZeroSuppression=kTRUE);
180
181   /**
182    * Rewind the read position.
183    * The read position is set to the first bin over the zero suppression.
184    * @param bZeroSuppression  skip all bins effected by the zero suppression
185    * @return 1 if more data available, 0 if not
186    */
187   Int_t Rewind(Int_t bZeroSuppression=kTRUE);
188
189   /**
190    * Get the current read position.
191    * @return read position, -1 if no data available
192    */
193   Int_t GetCurrentPosition() const {return fReadPos<fNofBins?fReadPos:-1;}
194
195   /**
196    * Get the raw data value of a certain bin.
197    * Raw data is only available within an event cycle.
198    * @param bin      Channel number
199    * @return raw data value
200    */
201   AliHLTTPCSignal_t GetRawData(Int_t bin) const;
202
203   /**
204    * Get the corrected data value of a certain bin.
205    * Corrected raw data is only available within an event cycle.
206    * The base line value is substracted from the bin's value and suppressed
207    * by the threshold. Bins smaller than the first bin considered for base
208    * line calculation return 0.
209    * @param bin      Channel number
210    * @return corrected value
211    */
212   AliHLTTPCSignal_t GetCorrectedData(Int_t bin) const;
213
214   /**
215    * Get the base line value of a certain channel.
216    * @param bin      Channel number
217    * @return base line value at bin
218    */
219   AliHLTTPCSignal_t GetBaseLine(Int_t bin) const;
220
221   /**
222    * Get the avarage base line value.
223    * @return average base line value
224    */ 
225   AliHLTTPCSignal_t GetAverage() const;
226
227   /**
228    * Get the occupancy for the pad in fractions of 1
229    * The occupancy is calculated from the number of time bins with non zero data
230    * after zero suppression.
231    * @return occupancy in percent
232    */
233   Float_t GetOccupancy() const;
234
235   /**
236    * Get the occupancy average for the pad in fractions of 1
237    * The occupancy is calculated from the number of time bins with non zero data
238    * after zero suppression and averaged over all events.
239    * @return occupancy in percent
240    */
241   Float_t GetAveragedOccupancy() const;
242
243   /**
244    * Get the size (number of time bins) of the pad
245    * @return number of bins 
246    */
247   Int_t GetSize() const {return fNofBins;}
248   
249   /**
250    * Set the data array to -1
251    */
252   void SetDataToDefault();
253   /**
254    * Stores the signal in the data array, stores the timebin number of the signal,
255    * and increments a counter.
256    */
257   void SetDataSignal(Int_t bin,Int_t signal);
258
259   /**
260    * Returns the signal in the specified bin
261    */
262   Int_t GetDataSignal(Int_t bin);
263   /**
264    * Finds the cluster candidate. If atleast two signals in the data array are neighbours
265    * they are stored in a cluster candidate vector.
266    */
267   void FindClusterCandidates();
268   /**
269    * Prints the raw data og this pad.
270    */
271   void PrintRawData();
272  
273   /**
274    * Vector of cluster candidates
275    */
276   vector<AliHLTTPCClusters> fClusterCandidates;
277
278   /**
279    * Vector of used clustercandidates, used so one do not use candidates multiple times
280    */
281   vector<Int_t> fUsedClusterCandidates;
282
283  private:
284   /**
285    * Add a value to the base line calculation.
286    * The value is been added to the sum if it exceeds the current base line
287    * and bin is equal or greater than the first bin for base line calculation.
288    * @param bin      Channel number
289    * @param value    ADC value
290    */
291   Int_t AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value);
292
293   /** The row number of the pad */
294   Int_t fRowNo;                                                    // see above
295   /** The pad number of the pad */
296   Int_t fPadNo;                                                    // see above
297   /** Threshold for zero suppression */
298   AliHLTTPCSignal_t fThreshold;                                    // see above
299   /** The average base line value */
300   AliHLTTPCSignal_t fAverage;                                      // see above
301   /** Number of events included in the base line calculation*/
302   Int_t fNofEvents;                                                // see above
303   /** The sum within one event */
304   AliHLTTPCSignal_t fSum;                                          // see above
305   /** The number of bins contributing to the sum */
306   Int_t fCount;                                                    // see above
307   /** The total number of bins already set during the event */
308   Int_t fTotal;                                                    // see above
309   /** The maximum base line value within one event */
310   AliHLTTPCSignal_t fBLMax;                                        // see above
311   /** The bin for the maximum bl value within one event */
312   Int_t fBLMaxBin;                                                 // see above
313   /** The minimum base line value within one event */
314   AliHLTTPCSignal_t fBLMin;                                        // see above
315   /** The bin for the minimum bl value within one event */
316   Int_t fBLMinBin;                                                 // see above
317   /** The first bin included in the base line calculation */
318   Int_t fFirstBLBin;                                               // see above
319   /** Number of bins */
320   Int_t fNofBins;                                                  // see above
321
322   /** The current read position */
323   Int_t fReadPos;                                                  // see above
324
325   /** The raw data history */
326   AliHLTTPCSignal_t* fpRawData;                                    //! transient
327
328   /**
329    * Array containing the data
330    */
331   AliHLTTPCSignal_t* fDataSignals;
332
333   /**
334    * Array containing info on which bins have signals
335    */
336   Int_t *fSignalPositionArray;
337   Int_t fSizeOfSignalPositionArray;
338
339   ClassDef(AliHLTTPCPad, 0)
340 };
341 #endif