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 */
10 /** @file AliHLTTPCPad.h
11 @author Matthias Richter
13 @brief Container Class for TPC Pads.
16 // see below for class documentation
18 // refer to README to build package
20 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
22 #include "AliHLTLogging.h"
23 #include "AliHLTTPCClusters.h"
26 typedef Int_t AliHLTTPCSignal_t;
30 * The class is a container for the raw ADC data of one TPCS pad. In order to
31 * avoid multiple unpacking/handling of the incoming raw data, the class holds
32 * a copy of the incoming data for one event. The copy is released when the
33 * end of the event was announced.
34 * The class calculates the base line of a TPC channel. Currently, only the
35 * average value is calculated, but further extension will include channel by
36 * channel histograming. The baseline history is kept and used for baseline
37 * re-evaluation and correction of subsequent events.
40 class AliHLTTPCPad : public AliHLTLogging {
42 /** standard constructor */
47 * @param offset The number of bins to ignore at the beginning
49 * @param nofBins The total number of bins for one channel
51 AliHLTTPCPad(Int_t offset, Int_t nofBins);
53 /** standard destructor */
54 virtual ~AliHLTTPCPad();
59 UInt_t fTotalCharge; //tot charge of cluster
60 UInt_t fPad; //pad value
61 UInt_t fTime; //time value
62 ULong64_t fPad2; //for error in XY direction
63 ULong64_t fTime2; //for error in Z direction
64 UInt_t fMean; //mean in time
65 UInt_t fFlags; //different flags
66 UInt_t fChargeFalling; //for deconvolution
67 UInt_t fLastCharge; //for deconvolution
68 UInt_t fLastMergedPad; //dont merge twice per pad
71 typedef struct AliClusterData AliClusterData; //!
75 * Set the address the pad.
76 * The address consists of row and pad number.
77 * @param rowno The row number
78 * @param padno The pad number.
80 Int_t SetID(Int_t rowno, Int_t padno);
85 Int_t GetRowNumber() const {return fRowNo;}
90 Int_t GetPadNumber() const {return fPadNo;}
93 * Start accumulation for a new event.
94 * The class holds internally a history of the event data. The data can
95 * be fetched from the class without unpacking the input stream again.
96 * @return neg. error value if failed
97 * - ENOMEM memory allocation failed
98 * - EALREADY event data acquisition already started
103 * Check whether the event is started
104 * @return 1 if started, 0 if not
106 Int_t IsStarted() const { return fpRawData!=NULL;};
109 * Calculate the base line from the current event data.
110 * Only available within an event cycle. <br>
111 * The calculation requires a minimum number of bins which contribute
112 * to the sum, which can be specified by \e reqMinCount. The base line
113 * calculation will also be skipped if the number of contributing bins is
114 * less than half of the total number of time bins.
115 * @param reqMinCount the minimum number of bins contributing to the sum
116 * @return neg. error value if failed
117 * - ENODATA to little contributing bins
118 * - ENOBUFS no raw data available
120 Int_t CalculateBaseLine(Int_t reqMinCount=1);
123 * Stop processing of one event.
124 * The data history of the event will be released.
125 * @return neg. error value if failed
126 * - EBADF event not started
131 * Reset the base line history.
132 * @return neg. error code if failed
134 Int_t ResetHistory();
138 * The threshold effects to corrected data, signals smaller than threshold
140 * @param thresh Threshold for signal correction
141 * @return neg. error code if failed
143 Int_t SetThreshold(AliHLTTPCSignal_t thresh);
146 * Set the raw data value of a certain channel.
147 * @param bin Channel number
148 * @param value ADC value
149 * @return neg. error value if failed
150 * - ERANGE bin out of range
151 * - BADF event cycle not started
153 Int_t SetRawData(Int_t bin, AliHLTTPCSignal_t value);
156 * Get the raw data value of the current bin.
157 * The class holds the current read position which can be incremented by
158 * @ref Next() and reseted by @ref Rewind().
159 * Raw data is only available within an event cycle.
160 * @return raw data value
162 AliHLTTPCSignal_t GetRawData() const {return GetRawData(fReadPos);}
165 * Get the corrected data value the current bin.
166 * Corrected raw data is only available within an event cycle.
167 * The base line value is substracted from the bin's value and suppressed
168 * by the threshold. Bins smaller than the first bin considered for base
169 * line calculation return 0.
170 * The class holds the current read position which can be incremented by
171 * @ref Next() and reseted by @ref Rewind().
172 * @return corrected value
174 AliHLTTPCSignal_t GetCorrectedData() const {return GetCorrectedData(fReadPos);}
177 * Increment the read position.
178 * @param bZeroSuppression skip all bins effected by the zero suppression
179 * @return 1 if more data available, 0 if not
181 Int_t Next(Int_t bZeroSuppression=kTRUE);
184 * Rewind the read position.
185 * The read position is set to the first bin over the zero suppression.
186 * @param bZeroSuppression skip all bins effected by the zero suppression
187 * @return 1 if more data available, 0 if not
189 Int_t Rewind(Int_t bZeroSuppression=kTRUE);
192 * Get the current read position.
193 * @return read position, -1 if no data available
195 Int_t GetCurrentPosition() const {return fReadPos<fNofBins?fReadPos:-1;}
198 * Get the raw data value of a certain bin.
199 * Raw data is only available within an event cycle.
200 * @param bin Channel number
201 * @return raw data value
203 AliHLTTPCSignal_t GetRawData(Int_t bin) const;
206 * Get the corrected data value of a certain bin.
207 * Corrected raw data is only available within an event cycle.
208 * The base line value is substracted from the bin's value and suppressed
209 * by the threshold. Bins smaller than the first bin considered for base
210 * line calculation return 0.
211 * @param bin Channel number
212 * @return corrected value
214 AliHLTTPCSignal_t GetCorrectedData(Int_t bin) const;
217 * Get the base line value of a certain channel.
218 * @param bin Channel number
219 * @return base line value at bin
221 AliHLTTPCSignal_t GetBaseLine(Int_t bin) const;
224 * Get the avarage base line value.
225 * @return average base line value
227 AliHLTTPCSignal_t GetAverage() const;
230 * Get the occupancy for the pad in fractions of 1
231 * The occupancy is calculated from the number of time bins with non zero data
232 * after zero suppression.
233 * @return occupancy in percent
235 Float_t GetOccupancy() const;
238 * Get the occupancy average for the pad in fractions of 1
239 * The occupancy is calculated from the number of time bins with non zero data
240 * after zero suppression and averaged over all events.
241 * @return occupancy in percent
243 Float_t GetAveragedOccupancy() const;
246 * Get the size (number of time bins) of the pad
247 * @return number of bins
249 Int_t GetSize() const {return fNofBins;}
252 * Set the data array to -1
254 void SetDataToDefault();
256 * Stores the signal in the data array, stores the timebin number of the signal,
257 * and increments a counter.
259 void SetDataSignal(Int_t bin,Int_t signal);
262 * Returns the signal in the specified bin
264 Int_t GetDataSignal(Int_t bin) const;
267 * Zerosuppression where one can choose wether one want to cut on sigma(default 3) or a given adc threshold above baseline
268 * It works like this: Finds the signals above baseline+threshold, it then looks to the right of the signals adding the
269 * the signal below threshold but over the average. It stops when the adc value rises (since you should expect a fall)
270 * or if the signal in that bin is below average. It now does the same thing to the left.
271 * This is a very timeconsuming approach(but good), and will likely only be used only for cosmics and laser.
272 * If you use sigma approach you can give as input n sigma or stick with default=3. For channels with very large signals
273 * the (value-average)² is not calculated when value-average>50. This is due to sigma shooting sky high for only a few values.
274 * The method is checked with 2006 cosmics data, and it looks good.
275 * If you want to use the threshold approach you HAVE to set nSigma=-1 and threshold>0. For example: If you want all signals
276 * 30 adc counts above threshold you should call the function like this: ZeroSuppress(-1,30)
277 * @param nSigma Specify nSigma above threshold default=3
278 * @param threshold Specify what adc threshold above average default=20 (remember to give nSigma=-1 if you want to use this approach)
279 * @param reqMinPoint Required minimum number of points to do zerosuppression default AliHLTTPCTransform::GetNTimeBins/2 (1024/2).
280 * @param beginTime Lowest timebin value. Gating grid causes some problems in the first timebins. default= 50
281 * @param endTime Highest timebin value. Default AliHLTTPCTransform::GetNTimeBins-1
283 void ZeroSuppress(Double_t nSigma,Int_t threshold,Int_t reqMinPoint,Int_t beginTime,Int_t endTime);
286 * Finds the cluster candidate. If atleast two signals in the data array are neighbours
287 * they are stored in a cluster candidate vector.
289 void FindClusterCandidates();
291 * Prints the raw data og this pad.
296 * Set the Signal Threshold
298 void SetSignalThreshold(Int_t i){fSignalThreshold=i;}
301 * Set the nSigma threshold
303 void SetNSigmaThreshold(Double_t i){fNSigmaThreshold=i;}
307 * Vector of cluster candidates
309 vector<AliHLTTPCClusters> fClusterCandidates; //! transient
312 * Vector of used clustercandidates, used so one do not use candidates multiple times
314 vector<Int_t> fUsedClusterCandidates; //! transient
317 /** copy constructor prohibited */
318 AliHLTTPCPad(const AliHLTTPCPad&);
319 /** assignment operator prohibited */
320 AliHLTTPCPad& operator=(const AliHLTTPCPad&);
323 * Add a value to the base line calculation.
324 * The value is been added to the sum if it exceeds the current base line
325 * and bin is equal or greater than the first bin for base line calculation.
326 * @param bin Channel number
327 * @param value ADC value
329 Int_t AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value);
331 /** The row number of the pad */
332 Int_t fRowNo; // see above
333 /** The pad number of the pad */
334 Int_t fPadNo; // see above
335 /** Threshold for zero suppression */
336 AliHLTTPCSignal_t fThreshold; // see above
337 /** The average base line value */
338 AliHLTTPCSignal_t fAverage; // see above
339 /** Number of events included in the base line calculation*/
340 Int_t fNofEvents; // see above
341 /** The sum within one event */
342 AliHLTTPCSignal_t fSum; // see above
343 /** The number of bins contributing to the sum */
344 Int_t fCount; // see above
345 /** The total number of bins already set during the event */
346 Int_t fTotal; // see above
347 /** The maximum base line value within one event */
348 AliHLTTPCSignal_t fBLMax; // see above
349 /** The bin for the maximum bl value within one event */
350 Int_t fBLMaxBin; // see above
351 /** The minimum base line value within one event */
352 AliHLTTPCSignal_t fBLMin; // see above
353 /** The bin for the minimum bl value within one event */
354 Int_t fBLMinBin; // see above
355 /** The first bin included in the base line calculation */
356 Int_t fFirstBLBin; // see above
357 /** Number of bins */
358 Int_t fNofBins; // see above
360 /** The current read position */
361 Int_t fReadPos; // see above
363 /** The raw data history */
364 AliHLTTPCSignal_t* fpRawData; //! transient
367 * Array containing the data
369 AliHLTTPCSignal_t* fDataSignals; //! transient
372 * Array containing info on which bins have signals
374 Int_t *fSignalPositionArray; //! transient
375 Int_t fSizeOfSignalPositionArray; //! transient
377 Double_t fNSigmaThreshold; //! transient
378 Double_t fSignalThreshold; //! transient
380 ClassDef(AliHLTTPCPad, 3)
382 #endif // ALIHLTTPCPAD_H