]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCPad.h
Update master to aliroot
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCPad.h
CommitLineData
2a083ac4 1// -*- Mode: C++ -*-
82a39a68 2// $Id$
46b33a24 3
a1dbf058 4#ifndef ALIHLTTPCPAD_H
5#define ALIHLTTPCPAD_H
297174de 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 *
46b33a24 9
82a39a68 10/// @file AliHLTTPCPad.h
11/// @author Matthias Richter
12/// @date
13/// @brief Container Class for TPC Pads.
14///
46b33a24 15
16#include "AliHLTLogging.h"
01f43166 17#include "AliHLTTPCClusters.h"
deba5d85 18#include "AliHLTTPCDigitReader.h"
afa4418c 19#include "TH1F.h"
01f43166 20#include <vector>
46b33a24 21
82a39a68 22struct AliHLTTPCDigitData;
deba5d85 23
46b33a24 24typedef Int_t AliHLTTPCSignal_t;
25
afa4418c 26
46b33a24 27/**
28 * @class AliHLTTPCPad
29 * The class is a container for the raw ADC data of one TPCS pad. In order to
30 * avoid multiple unpacking/handling of the incoming raw data, the class holds
31 * a copy of the incoming data for one event. The copy is released when the
32 * end of the event was announced.
33 * The class calculates the base line of a TPC channel. Currently, only the
34 * average value is calculated, but further extension will include channel by
35 * channel histograming. The baseline history is kept and used for baseline
36 * re-evaluation and correction of subsequent events.
37 * @ingroup alihlt_tpc
38 */
39class AliHLTTPCPad : public AliHLTLogging {
01f43166 40public:
46b33a24 41 /** standard constructor */
42 AliHLTTPCPad();
43
8252a538 44 /**
45 * Constructor
a74855c2 46 * @param dummy dummy determines if one need the raw data. If a dummy number is given, the pad object will be initialized without using memory for raw data
8252a538 47 */
a74855c2 48 AliHLTTPCPad(Int_t dummy);
8252a538 49
46b33a24 50 /**
51 * Constructor
52 * @param offset The number of bins to ignore at the beginning
53 * of the channels
54 * @param nofBins The total number of bins for one channel
55 */
56 AliHLTTPCPad(Int_t offset, Int_t nofBins);
57
46b33a24 58 /** standard destructor */
59 virtual ~AliHLTTPCPad();
60
01f43166 61
62 struct AliClusterData
63 {
64 UInt_t fTotalCharge; //tot charge of cluster
a74855c2 65 UInt_t fPad; //pad value
66 UInt_t fTime; //time value
67 ULong64_t fPad2; //for error in XY direction
68 ULong64_t fTime2; //for error in Z direction
01f43166 69 UInt_t fMean; //mean in time
70 UInt_t fFlags; //different flags
71 UInt_t fChargeFalling; //for deconvolution
72 UInt_t fLastCharge; //for deconvolution
73 UInt_t fLastMergedPad; //dont merge twice per pad
74 };
75
76 typedef struct AliClusterData AliClusterData; //!
77
78
46b33a24 79 /**
80 * Set the address the pad.
81 * The address consists of row and pad number.
82 * @param rowno The row number
83 * @param padno The pad number.
84 */
85 Int_t SetID(Int_t rowno, Int_t padno);
86
87 /**
88 * Get the row number.
a74855c2 89 * @return Row number
46b33a24 90 */
91 Int_t GetRowNumber() const {return fRowNo;}
92
93 /**
a74855c2 94 * Get the pad number on the row.
95 * @return Pad number on row
46b33a24 96 */
97 Int_t GetPadNumber() const {return fPadNo;}
98
99 /**
100 * Start accumulation for a new event.
101 * The class holds internally a history of the event data. The data can
102 * be fetched from the class without unpacking the input stream again.
103 * @return neg. error value if failed
104 * - ENOMEM memory allocation failed
105 * - EALREADY event data acquisition already started
106 */
107 Int_t StartEvent();
108
109 /**
110 * Check whether the event is started
111 * @return 1 if started, 0 if not
112 */
113 Int_t IsStarted() const { return fpRawData!=NULL;};
114
115 /**
116 * Calculate the base line from the current event data.
117 * Only available within an event cycle. <br>
118 * The calculation requires a minimum number of bins which contribute
a655eae3 119 * to the sum, which can be specified by \e reqMinCount. The base line
46b33a24 120 * calculation will also be skipped if the number of contributing bins is
121 * less than half of the total number of time bins.
122 * @param reqMinCount the minimum number of bins contributing to the sum
123 * @return neg. error value if failed
124 * - ENODATA to little contributing bins
125 * - ENOBUFS no raw data available
126 */
127 Int_t CalculateBaseLine(Int_t reqMinCount=1);
128
129 /**
130 * Stop processing of one event.
131 * The data history of the event will be released.
132 * @return neg. error value if failed
133 * - EBADF event not started
134 */
135 Int_t StopEvent();
136
137 /**
138 * Reset the base line history.
139 * @return neg. error code if failed
140 */
141 Int_t ResetHistory();
142
143 /**
144 * Set threshold.
145 * The threshold effects to corrected data, signals smaller than threshold
146 * are suppressed.
147 * @param thresh Threshold for signal correction
148 * @return neg. error code if failed
149 */
150 Int_t SetThreshold(AliHLTTPCSignal_t thresh);
151
152 /**
153 * Set the raw data value of a certain channel.
154 * @param bin Channel number
155 * @param value ADC value
156 * @return neg. error value if failed
157 * - ERANGE bin out of range
158 * - BADF event cycle not started
159 */
160 Int_t SetRawData(Int_t bin, AliHLTTPCSignal_t value);
161
162 /**
163 * Get the raw data value of the current bin.
164 * The class holds the current read position which can be incremented by
165 * @ref Next() and reseted by @ref Rewind().
166 * Raw data is only available within an event cycle.
167 * @return raw data value
168 */
169 AliHLTTPCSignal_t GetRawData() const {return GetRawData(fReadPos);}
170
171 /**
172 * Get the corrected data value the current bin.
173 * Corrected raw data is only available within an event cycle.
174 * The base line value is substracted from the bin's value and suppressed
175 * by the threshold. Bins smaller than the first bin considered for base
176 * line calculation return 0.
177 * The class holds the current read position which can be incremented by
178 * @ref Next() and reseted by @ref Rewind().
179 * @return corrected value
180 */
181 AliHLTTPCSignal_t GetCorrectedData() const {return GetCorrectedData(fReadPos);}
182
183 /**
184 * Increment the read position.
185 * @param bZeroSuppression skip all bins effected by the zero suppression
186 * @return 1 if more data available, 0 if not
187 */
188 Int_t Next(Int_t bZeroSuppression=kTRUE);
189
190 /**
191 * Rewind the read position.
192 * The read position is set to the first bin over the zero suppression.
193 * @param bZeroSuppression skip all bins effected by the zero suppression
194 * @return 1 if more data available, 0 if not
195 */
196 Int_t Rewind(Int_t bZeroSuppression=kTRUE);
197
198 /**
199 * Get the current read position.
200 * @return read position, -1 if no data available
201 */
202 Int_t GetCurrentPosition() const {return fReadPos<fNofBins?fReadPos:-1;}
203
204 /**
205 * Get the raw data value of a certain bin.
206 * Raw data is only available within an event cycle.
207 * @param bin Channel number
208 * @return raw data value
209 */
210 AliHLTTPCSignal_t GetRawData(Int_t bin) const;
211
212 /**
213 * Get the corrected data value of a certain bin.
214 * Corrected raw data is only available within an event cycle.
215 * The base line value is substracted from the bin's value and suppressed
216 * by the threshold. Bins smaller than the first bin considered for base
217 * line calculation return 0.
218 * @param bin Channel number
219 * @return corrected value
220 */
221 AliHLTTPCSignal_t GetCorrectedData(Int_t bin) const;
222
223 /**
224 * Get the base line value of a certain channel.
225 * @param bin Channel number
600e6a1b 226 * @return base line value at bin
46b33a24 227 */
228 AliHLTTPCSignal_t GetBaseLine(Int_t bin) const;
229
230 /**
231 * Get the avarage base line value.
232 * @return average base line value
233 */
234 AliHLTTPCSignal_t GetAverage() const;
235
5235c3e9 236 /**
237 * Get the occupancy for the pad in fractions of 1
238 * The occupancy is calculated from the number of time bins with non zero data
239 * after zero suppression.
240 * @return occupancy in percent
241 */
242 Float_t GetOccupancy() const;
243
244 /**
245 * Get the occupancy average for the pad in fractions of 1
246 * The occupancy is calculated from the number of time bins with non zero data
247 * after zero suppression and averaged over all events.
248 * @return occupancy in percent
249 */
250 Float_t GetAveragedOccupancy() const;
251
46b33a24 252 /**
253 * Get the size (number of time bins) of the pad
254 * @return number of bins
255 */
01f43166 256 Int_t GetSize() const {return fNofBins;}
257
a74855c2 258 /*
259 * Clears the vector of cluster candidates.
260 */
8252a538 261 void ClearCandidates();
262
01f43166 263 /**
264 * Set the data array to -1
265 */
266 void SetDataToDefault();
a74855c2 267
01f43166 268 /**
269 * Stores the signal in the data array, stores the timebin number of the signal,
270 * and increments a counter.
a74855c2 271 * @param bin Timebin nuber of signal
272 * @param signal Size of signal
01f43166 273 */
274 void SetDataSignal(Int_t bin,Int_t signal);
275
276 /**
277 * Returns the signal in the specified bin
a74855c2 278 * @param bin Timebin number
279 * @return Signal in the given timebin
01f43166 280 */
a1dbf058 281 Int_t GetDataSignal(Int_t bin) const;
282
b1c46961 283 /**
284 * Zerosuppression where one can choose wether one want to cut on sigma(default 3) or a given adc threshold above baseline
285 * It works like this: Finds the signals above baseline+threshold, it then looks to the right of the signals adding the
286 * the signal below threshold but over the average. It stops when the adc value rises (since you should expect a fall)
287 * or if the signal in that bin is below average. It now does the same thing to the left.
288 * This is a very timeconsuming approach(but good), and will likely only be used only for cosmics and laser.
289 * If you use sigma approach you can give as input n sigma or stick with default=3. For channels with very large signals
290 * the (value-average)² is not calculated when value-average>50. This is due to sigma shooting sky high for only a few values.
291 * The method is checked with 2006 cosmics data, and it looks good.
292 * If you want to use the threshold approach you HAVE to set nSigma=-1 and threshold>0. For example: If you want all signals
293 * 30 adc counts above threshold you should call the function like this: ZeroSuppress(-1,30)
a74855c2 294 * @param nRMS Specify nRMS threshold
295 * @param threshold Specify what adc threshold above average (remember to give nRMS=-1 if you want to use this approach)
296 * @param reqMinPoint Required minimum number of points to do zerosuppression default AliHLTTPCTransform::GetNTimeBins/2 (1024/2).
297 * @param beginTime Lowest timebin value. Gating grid causes some problems in the first timebins.
298 * @param endTime Highest timebin value.
299 * @param timebinsLeft Timebins to include left of the signals above threshold (to include tails)
300 * @param timebinsRight Timebins to include right of the signals above threshold (to include tails)
301 * @param valueBelowAverage The number of adc-counts below the average value. (sometimes there can be useful to also add some signals below average for your signals, especially when there is a lot of noise) It means that more of the tails of the signal is added.
9783a5cf 302 * @param speedup Do not the full zero suppression but terminate if it is clear wheter the channel has some signal or not.
b1c46961 303 */
74b8bf74 304 void ZeroSuppress(Double_t nRMS,Int_t threshold,Int_t reqMinPoint,Int_t beginTime,Int_t endTime,Int_t timebinsLeft, Int_t timebinsRight, Int_t valueBelowAverage, bool speedup=false);
afa4418c 305
a74855c2 306 /**
307 * Bool method which returns the timein number of the first signal and number of consecutive signals, used together with GetPointer(bin) to access data
308 * @param time Refernence to timebin number
309 * @param bunchSize Refernence to number of consecutive signals
310 * @return True if there are more signals
311 */
c0971196 312 Bool_t GetNextGoodSignal(Int_t &time,Int_t &bunchSize);
a74855c2 313
314 /**
315 * Returns number of signals added
316 * @return Number of signals
317 */
afa4418c 318 UInt_t GetNAddedSignals(){return fSizeOfSignalPositionArray;}
b1c46961 319
01f43166 320 /**
a74855c2 321 * Returns the pointer to the first data signal
322 * @param bin Timebin number
323 * @return pointer to data signal in bin
01f43166 324 */
a74855c2 325 UInt_t* GetPointer(Int_t bin){return (UInt_t*)&fDataSignals[bin]; }
8252a538 326
327 /**
328 * Adds cluster candidate to the fClusterCandidates.
329 */
bd8210c3 330 void AddClusterCandidate(const AliHLTTPCClusters& candidate);
8252a538 331
deba5d85 332 /**
333 * Adds the digits belonging to the candidate.
334 */
bd8210c3 335 void AddCandidateDigits(const vector<AliHLTTPCDigitData>& candidateDigits);
deba5d85 336
337
338 /**
339 * Returns the digit vector belonging to the candidate
340 */
0f98f30d 341 vector<AliHLTTPCDigitData> *GetCandidateDigits(Int_t candidateIndex);
deba5d85 342
343 void ClearCandidateDigits(){fCandidateDigitsVector.clear();}
344
01f43166 345 /**
346 * Prints the raw data og this pad.
347 */
348 void PrintRawData();
b1c46961 349
01f43166 350 /**
351 * Vector of cluster candidates
352 */
a1dbf058 353 vector<AliHLTTPCClusters> fClusterCandidates; //! transient
01f43166 354
355 /**
356 * Vector of used clustercandidates, used so one do not use candidates multiple times
357 */
2fdb1ae7 358 vector<Int_t> fUsedClusterCandidates; //! transient
359 Bool_t fSelectedPad; //! transient
360 AliHLTUInt16_t fHWAddress; //! transient
361
46b33a24 362 private:
a1dbf058 363 /** copy constructor prohibited */
364 AliHLTTPCPad(const AliHLTTPCPad&);
365 /** assignment operator prohibited */
366 AliHLTTPCPad& operator=(const AliHLTTPCPad&);
367
46b33a24 368 /**
369 * Add a value to the base line calculation.
370 * The value is been added to the sum if it exceeds the current base line
371 * and bin is equal or greater than the first bin for base line calculation.
372 * @param bin Channel number
373 * @param value ADC value
374 */
375 Int_t AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value);
376
377 /** The row number of the pad */
2a083ac4 378 Int_t fRowNo; // see above
46b33a24 379 /** The pad number of the pad */
2a083ac4 380 Int_t fPadNo; // see above
46b33a24 381 /** Threshold for zero suppression */
2a083ac4 382 AliHLTTPCSignal_t fThreshold; // see above
46b33a24 383 /** The average base line value */
2a083ac4 384 AliHLTTPCSignal_t fAverage; // see above
46b33a24 385 /** Number of events included in the base line calculation*/
2a083ac4 386 Int_t fNofEvents; // see above
46b33a24 387 /** The sum within one event */
2a083ac4 388 AliHLTTPCSignal_t fSum; // see above
46b33a24 389 /** The number of bins contributing to the sum */
2a083ac4 390 Int_t fCount; // see above
46b33a24 391 /** The total number of bins already set during the event */
2a083ac4 392 Int_t fTotal; // see above
46b33a24 393 /** The maximum base line value within one event */
2a083ac4 394 AliHLTTPCSignal_t fBLMax; // see above
46b33a24 395 /** The bin for the maximum bl value within one event */
2a083ac4 396 Int_t fBLMaxBin; // see above
84645eb0 397 /** The minimum base line value within one event */
2a083ac4 398 AliHLTTPCSignal_t fBLMin; // see above
84645eb0 399 /** The bin for the minimum bl value within one event */
2a083ac4 400 Int_t fBLMinBin; // see above
46b33a24 401 /** The first bin included in the base line calculation */
2a083ac4 402 Int_t fFirstBLBin; // see above
46b33a24 403 /** Number of bins */
2a083ac4 404 Int_t fNofBins; // see above
46b33a24 405
406 /** The current read position */
2a083ac4 407 Int_t fReadPos; // see above
46b33a24 408
409 /** The raw data history */
2a083ac4 410 AliHLTTPCSignal_t* fpRawData; //! transient
46b33a24 411
01f43166 412 /**
413 * Array containing the data
414 */
a1dbf058 415 AliHLTTPCSignal_t* fDataSignals; //! transient
01f43166 416
417 /**
418 * Array containing info on which bins have signals
419 */
a1dbf058 420 Int_t *fSignalPositionArray; //! transient
a74855c2 421
422 /** Size of signals in fSignalPositionArray */
a1dbf058 423 Int_t fSizeOfSignalPositionArray; //! transient
afa4418c 424
a74855c2 425 /** Number of good signals sent (good signals is signals surviving ZeroSuppression) */
afa4418c 426 Int_t fNGoodSignalsSent;
b1c46961 427
deba5d85 428 vector<vector<AliHLTTPCDigitData> > fCandidateDigitsVector;
429
430 ClassDef(AliHLTTPCPad, 7)
46b33a24 431};
a1dbf058 432#endif // ALIHLTTPCPAD_H