]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCPad.h
- added TPCPad handling class
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCPad.h
1 // @(#) $Id$
2
3 #ifndef ALIHLTPAD_H
4 #define ALIHLTPAD_H
5 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6  * See cxx source for full Copyright notice                               */
7
8 /** @file   AliHLTTPCPad.h
9     @author Matthias Richter
10     @date   
11     @brief  Container Class for TPC Pads.
12 */
13
14 #include "AliHLTLogging.h"
15
16 typedef Int_t AliHLTTPCSignal_t;
17
18 /**
19  * @class AliHLTTPCPad
20  * The class is a container for the raw ADC data of one TPCS pad. In order to
21  * avoid multiple unpacking/handling of the incoming raw data, the class holds
22  * a copy of the incoming data for one event. The copy is released when the
23  * end of the event was announced.
24  * The class calculates the base line of a TPC channel. Currently, only the
25  * average value is calculated, but further extension will include channel by
26  * channel histograming. The baseline history is kept and used for baseline
27  * re-evaluation and correction of subsequent events.
28  * @ingroup alihlt_tpc
29  */
30 class AliHLTTPCPad : public AliHLTLogging {
31  public:
32   /** standard constructor */
33   AliHLTTPCPad();
34
35   /** 
36    * Constructor
37    * @param offset   The number of bins to ignore at the beginning
38    *                 of the channels
39    * @param nofBins  The total number of bins for one channel
40    */
41   AliHLTTPCPad(Int_t offset, Int_t nofBins);
42
43   /** not a valid copy constructor, defined according to effective C++ style */
44   AliHLTTPCPad(const AliHLTTPCPad&);
45   /** not a valid assignment op, but defined according to effective C++ style */
46   AliHLTTPCPad& operator=(const AliHLTTPCPad&);
47   /** standard destructor */
48   virtual ~AliHLTTPCPad();
49
50   /**
51    * Set the address the pad.
52    * The address consists of row and pad number.
53    * @param rowno    The row number
54    * @param padno    The pad number.
55    */
56   Int_t SetID(Int_t rowno, Int_t padno);
57
58   /**
59    * Get the row number.
60    */
61   Int_t GetRowNumber() const {return fRowNo;}
62
63   /**
64    * Get the pad number.
65    */
66   Int_t GetPadNumber() const {return fPadNo;}
67
68   /**
69    * Start accumulation for a new event.
70    * The class holds internally a history of the event data. The data can
71    * be fetched from the class without unpacking the input stream again.
72    * @return neg. error value if failed
73    *         - ENOMEM memory allocation failed
74    *         - EALREADY event data acquisition already started
75    */
76   Int_t StartEvent();
77
78   /**
79    * Check whether the event is started
80    * @return 1 if started, 0 if not
81    */
82   Int_t IsStarted() const { return fpRawData!=NULL;};
83
84   /**
85    * Calculate the base line from the current event data.
86    * Only available within an event cycle. <br>
87    * The calculation requires a minimum number of bins which contribute
88    * to the sum, which can be specified by @param reqMinCount. The base line
89    * calculation will also be skipped if the number of contributing bins is 
90    * less than half of the total number of time bins. 
91    * @param reqMinCount    the minimum number of bins contributing to the sum
92    * @return neg. error value if failed
93    *         - ENODATA to little contributing bins
94    *         - ENOBUFS no raw data available
95    */
96   Int_t CalculateBaseLine(Int_t reqMinCount=1);
97
98   /**
99    * Stop processing of one event.
100    * The data history of the event will be released.
101    * @return neg. error value if failed
102    *         - EBADF event not started 
103    */
104   Int_t StopEvent();
105
106   /**
107    * Reset the base line history.
108    * @return neg. error code if failed 
109    */
110   Int_t ResetHistory();
111
112   /**
113    * Set threshold.
114    * The threshold effects to corrected data, signals smaller than threshold
115    * are suppressed.
116    * @param thresh   Threshold for signal correction
117    * @return neg. error code if failed 
118    */
119   Int_t SetThreshold(AliHLTTPCSignal_t thresh);
120
121   /**
122    * Set the raw data value of a certain channel.
123    * @param bin      Channel number
124    * @param value    ADC value
125    * @return neg. error value if failed
126    *         - ERANGE bin out of range
127    *         - BADF event cycle not started
128    */
129   Int_t SetRawData(Int_t bin, AliHLTTPCSignal_t value);
130
131   /**
132    * Get the raw data value of the current bin.
133    * The class holds the current read position which can be incremented by
134    * @ref Next() and reseted by @ref Rewind().
135    * Raw data is only available within an event cycle.
136    * @return raw data value
137    */
138   AliHLTTPCSignal_t GetRawData() const {return GetRawData(fReadPos);}
139
140   /**
141    * Get the corrected data value the current bin.
142    * Corrected raw data is only available within an event cycle.
143    * The base line value is substracted from the bin's value and suppressed
144    * by the threshold. Bins smaller than the first bin considered for base
145    * line calculation return 0.
146    * The class holds the current read position which can be incremented by
147    * @ref Next() and reseted by @ref Rewind().
148    * @return corrected value
149    */
150   AliHLTTPCSignal_t GetCorrectedData() const {return GetCorrectedData(fReadPos);}
151
152   /**
153    * Increment the read position.
154    * @param bZeroSuppression  skip all bins effected by the zero suppression
155    * @return 1 if more data available, 0 if not
156    */
157   Int_t Next(Int_t bZeroSuppression=kTRUE);
158
159   /**
160    * Rewind the read position.
161    * The read position is set to the first bin over the zero suppression.
162    * @param bZeroSuppression  skip all bins effected by the zero suppression
163    * @return 1 if more data available, 0 if not
164    */
165   Int_t Rewind(Int_t bZeroSuppression=kTRUE);
166
167   /**
168    * Get the current read position.
169    * @return read position, -1 if no data available
170    */
171   Int_t GetCurrentPosition() const {return fReadPos<fNofBins?fReadPos:-1;}
172
173   /**
174    * Get the raw data value of a certain bin.
175    * Raw data is only available within an event cycle.
176    * @param bin      Channel number
177    * @return raw data value
178    */
179   AliHLTTPCSignal_t GetRawData(Int_t bin) const;
180
181   /**
182    * Get the corrected data value of a certain bin.
183    * Corrected raw data is only available within an event cycle.
184    * The base line value is substracted from the bin's value and suppressed
185    * by the threshold. Bins smaller than the first bin considered for base
186    * line calculation return 0.
187    * @param bin      Channel number
188    * @return corrected value
189    */
190   AliHLTTPCSignal_t GetCorrectedData(Int_t bin) const;
191
192   /**
193    * Get the base line value of a certain channel.
194    * @param bin      Channel number
195    * @param base line value at bin
196    */
197   AliHLTTPCSignal_t GetBaseLine(Int_t bin) const;
198
199   /**
200    * Get the avarage base line value.
201    * @return average base line value
202    */ 
203   AliHLTTPCSignal_t GetAverage() const;
204
205   /**
206    * Get the size (number of time bins) of the pad
207    * @return number of bins 
208    */
209    Int_t GetSize() const {return fNofBins;}
210
211  private:
212   /**
213    * Add a value to the base line calculation.
214    * The value is been added to the sum if it exceeds the current base line
215    * and bin is equal or greater than the first bin for base line calculation.
216    * @param bin      Channel number
217    * @param value    ADC value
218    */
219   Int_t AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value);
220
221   /** The row number of the pad */
222   Int_t fRowNo;
223   /** The pad number of the pad */
224   Int_t fPadNo;
225   /** Threshold for zero suppression */
226   AliHLTTPCSignal_t fThreshold;
227   /** The average base line value */
228   AliHLTTPCSignal_t fAverage;
229   /** Number of events included in the base line calculation*/
230   Int_t fNofEvents;
231   /** The sum within one event */
232   AliHLTTPCSignal_t fSum;
233   /** The number of bins contributing to the sum */
234   Int_t fCount;
235   /** The total number of bins already set during the event */
236   Int_t fTotal;
237   /** The maximum base line value within one event */
238   AliHLTTPCSignal_t fBLMax;
239   /** The bin for the maximum bl value within one event */
240   Int_t fBLMaxBin;
241   /** The first bin included in the base line calculation */
242   Int_t fFirstBLBin;
243   /** Number of bins */
244   Int_t fNofBins;
245
246   /** The current read position */
247   Int_t fReadPos;
248
249   /** The raw data history */
250   AliHLTTPCSignal_t* fpRawData;
251
252   ClassDef(AliHLTTPCPad, 0)
253 };
254 #endif