]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCPad.cxx
New class AliESDEvent, backward compatibility with the old AliESD (Christian)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCPad.cxx
CommitLineData
2a083ac4 1// @(#) $Id$
2
46b33a24 3/**************************************************************************
9be2600f 4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
46b33a24 6 * *
9be2600f 7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
46b33a24 9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTTPCPad.cxx
20 @author Matthias Richter
21 @date
22 @brief Container Class for TPC Pads.
23*/
24
25#if __GNUC__>= 3
26using namespace std;
27#endif
28
29#include <cerrno>
30#include "AliHLTTPCPad.h"
84645eb0 31#include "AliHLTStdIncludes.h"
46b33a24 32
33/** margin for the base line be re-avaluated */
34#define ALIHLTPAD_BASELINE_MARGIN (2*fAverage)
35
36/** ROOT macro for the implementation of ROOT specific class methods */
37ClassImp(AliHLTTPCPad)
38
39AliHLTTPCPad::AliHLTTPCPad()
40 :
41 fRowNo(-1),
42 fPadNo(-1),
43 fThreshold(0),
44 fAverage(-1),
45 fNofEvents(0),
46 fSum(0),
2a083ac4 47 fCount(0),
48 fTotal(0),
46b33a24 49 fBLMax(-1),
50 fBLMaxBin(-1),
84645eb0 51 fBLMin(-1),
52 fBLMinBin(-1),
46b33a24 53 fFirstBLBin(0),
54 fNofBins(0),
2a083ac4 55 fReadPos(0),
56 fpRawData(NULL)
46b33a24 57{
2a083ac4 58 // see header file for class documentation
59 // or
60 // refer to README to build package
61 // or
62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
46b33a24 63}
64
65AliHLTTPCPad::AliHLTTPCPad(Int_t offset, Int_t nofBins)
66 :
67 fRowNo(-1),
68 fPadNo(-1),
69 fThreshold(0),
70 fAverage(-1),
71 fNofEvents(0),
72 fSum(0),
2a083ac4 73 fCount(0),
74 fTotal(0),
46b33a24 75 fBLMax(-1),
76 fBLMaxBin(-1),
84645eb0 77 fBLMin(-1),
78 fBLMinBin(-1),
46b33a24 79 fFirstBLBin(offset),
80 fNofBins(nofBins),
2a083ac4 81 fReadPos(0),
82 fpRawData(NULL)
46b33a24 83{
2a083ac4 84 // see header file for class documentation
46b33a24 85}
86
87AliHLTTPCPad::AliHLTTPCPad(const AliHLTTPCPad& srcPad)
88 :
89 fRowNo(srcPad.fRowNo),
90 fPadNo(srcPad.fPadNo),
91 fThreshold(0),
92 fAverage(-1),
93 fNofEvents(0),
94 fSum(0),
2a083ac4 95 fCount(0),
96 fTotal(0),
46b33a24 97 fBLMax(-1),
98 fBLMaxBin(-1),
84645eb0 99 fBLMin(-1),
100 fBLMinBin(-1),
46b33a24 101 fFirstBLBin(0),
102 fNofBins(0),
2a083ac4 103 fReadPos(0),
104 fpRawData(NULL)
46b33a24 105{
2a083ac4 106 // see header file for class documentation
46b33a24 107 HLTFatal("copy constructor not implemented");
108}
109
110AliHLTTPCPad& AliHLTTPCPad::operator=(const AliHLTTPCPad&)
111{
2a083ac4 112 // see header file for class documentation
46b33a24 113 HLTFatal("assignment operator not implemented");
114 return (*this);
115}
116
117AliHLTTPCPad::~AliHLTTPCPad()
118{
2a083ac4 119 // see header file for class documentation
46b33a24 120 if (fpRawData) {
121 HLTWarning("event data acquisition not stopped");
122 StopEvent();
123 }
124}
125
126Int_t AliHLTTPCPad::SetID(Int_t rowno, Int_t padno)
127{
2a083ac4 128 // see header file for class documentation
46b33a24 129 fRowNo=rowno;
130 fPadNo=padno;
2a083ac4 131 return 0;
46b33a24 132}
133
134Int_t AliHLTTPCPad::StartEvent()
135{
2a083ac4 136 // see header file for class documentation
46b33a24 137 Int_t iResult=0;
138 if (fpRawData==NULL) {
139 fBLMax=-1;
140 fBLMaxBin=-1;
84645eb0 141 fBLMin=-1;
142 fBLMinBin=-1;
46b33a24 143 fSum=0;
144 fCount=0;
145 fTotal=0;
146 if (fNofBins>0) {
147 fpRawData=new AliHLTTPCSignal_t[fNofBins];
148 if (fpRawData) {
149 for (int i=0; i<fNofBins; i++) fpRawData[i]=-1;
150 } else {
151 HLTError("memory allocation failed");
152 iResult=-ENOMEM;
153 }
154 }
155 } else {
156 HLTWarning("event data acquisition already started");
157 iResult=-EALREADY;
158 }
159 return iResult;
160}
161
162Int_t AliHLTTPCPad::CalculateBaseLine(Int_t reqMinCount)
163{
2a083ac4 164 // see header file for class documentation
46b33a24 165 Int_t iResult=0;
166 AliHLTTPCSignal_t avBackup=fAverage;
84645eb0 167 //HLTDebug("reqMinCount=%d fCount=%d fTotal=%d fSum=%d fBLMax=%d fBLMin=%d", reqMinCount, fCount, fTotal, fSum, fBLMax, fBLMin);
46b33a24 168 if (fCount>=reqMinCount && fCount>=fTotal/2) {
169 fAverage=fCount>0?fSum/fCount:0;
170 if (fAverage>0) {
84645eb0 171 //HLTDebug("average for current event %d (%d - %d)", fAverage, fBLMax, fBLMin);
46b33a24 172 fCount=0;fSum=-1;
173 if (fBLMax>ALIHLTPAD_BASELINE_MARGIN) {
174 // calculate again
21b6a334 175 //HLTDebug("maximum value %d exceeds margin for base line (%d) "
176 // "-> re-evaluate base line", fBLMax, ALIHLTPAD_BASELINE_MARGIN);
46b33a24 177 if (fpRawData) {
178 for (Int_t i=fFirstBLBin; i<fNofBins; i++)
179 if (fpRawData[i]>=0) AddBaseLineValue(i, fpRawData[i]);
180 if (fCount>0 && fCount>=reqMinCount && fCount>=fTotal/2) {
181 fAverage=fSum/fCount;
3cde846d 182 //HLTDebug("new average %d", fAverage);
46b33a24 183 } else {
3cde846d 184// HLTDebug("baseline re-eveluation skipped because of to few "
185// "contributing bins: total=%d, contributing=%d, req=%d"
186// "\ndata might be already zero suppressed"
187// , fTotal, fCount, reqMinCount);
46b33a24 188 iResult=-ENODATA;
189 }
190 fCount=0;fSum=-1;
191 } else {
192 HLTError("missing raw data for base line calculation");
193 iResult=-ENOBUFS;
194 }
195 }
196 if (iResult>=0) {
197 // calculate average for all events
198 fAverage=((avBackup*fNofEvents)+fAverage)/(fNofEvents+1);
84645eb0 199 //HLTDebug("base line average for %d event(s): %d", fNofEvents+1, fAverage);
46b33a24 200 } else {
201 fAverage=avBackup;
202 }
203 } else {
204 fAverage=avBackup;
205 }
206 } else {
3cde846d 207// HLTDebug("baseline calculation skipped because of to few contributing "
208// "bins: total=%d, contributing=%d, required=%d \ndata might be "
209// "already zero suppressed", fTotal, fCount, reqMinCount);
46b33a24 210 }
211
212 return iResult;
213}
214
215Int_t AliHLTTPCPad::StopEvent()
216{
2a083ac4 217 // see header file for class documentation
46b33a24 218 Int_t iResult=0;
219 if (fpRawData) {
220 AliHLTTPCSignal_t* pData=fpRawData;
221 fpRawData=NULL;
222 delete [] pData;
223 fTotal=0;
224 fNofEvents++;
225 Rewind();
226 } else if (fNofBins>0) {
227 HLTError("event data acquisition not started");
228 iResult=-EBADF;
229 }
230 return iResult;
231}
232
233Int_t AliHLTTPCPad::ResetHistory()
234{
2a083ac4 235 // see header file for class documentation
46b33a24 236 Int_t iResult=0;
237 fAverage=-1;
238 fNofEvents=0;
239 return iResult;
240}
241
242Int_t AliHLTTPCPad::SetThreshold(AliHLTTPCSignal_t thresh)
243{
2a083ac4 244 // see header file for class documentation
46b33a24 245 Int_t iResult=0;
246 fThreshold=thresh;
247 return iResult;
248}
249
250Int_t AliHLTTPCPad::AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value)
251{
2a083ac4 252 // see header file for class documentation
46b33a24 253 Int_t iResult=0;
254 if (bin>=fFirstBLBin) {
255 if (fAverage<0 || value<ALIHLTPAD_BASELINE_MARGIN) {
256 // add to the current sum and count
257 fSum+=value;
258 fCount++;
259 if (fBLMax<value) {
260 // keep the maximum value for later quality control of the base
261 // line calculation
262 fBLMax=value;
263 fBLMaxBin=bin;
264 }
84645eb0 265 if (fBLMin<0 || fBLMin>value) {
266 // keep the minimum value for later quality control of the base
267 // line calculation
268 fBLMin=value;
269 fBLMinBin=bin;
270 }
46b33a24 271 } else {
3cde846d 272// HLTDebug("ignoring value %d (bin %d) for base line calculation "
273// "(current average is %d)",
274// value, bin, fAverage);
46b33a24 275 }
276 }
277 return iResult;
278}
279
280Int_t AliHLTTPCPad::SetRawData(Int_t bin, AliHLTTPCSignal_t value)
281{
2a083ac4 282 // see header file for class documentation
46b33a24 283 Int_t iResult=0;
284 if (fpRawData) {
285 if (bin<fNofBins) {
286 if (value>=0) {
287 if (fpRawData[bin]<0) {
288 AddBaseLineValue(bin, value);
289 fTotal++;
290 } else {
291 // ignore value for average calculation
84645eb0 292 HLTWarning("overriding content of bin %d (%d)", bin, fpRawData[bin]);
46b33a24 293 }
294 fpRawData[bin]=value;
295 } else {
296 HLTWarning("ignoring neg. raw data");
297 }
298 } else {
299 HLTWarning("bin %d out of range (%d)", bin, fNofBins);
300 iResult=-ERANGE;
301 }
302 } else if (fNofBins>0) {
303 HLTError("event cycle not started");
304 iResult=-EBADF;
305 }
306 return iResult;
307}
308
309Int_t AliHLTTPCPad::Next(Int_t bZeroSuppression)
310{
2a083ac4 311 // see header file for class documentation
46b33a24 312 if (fpRawData==NULL) return 0;
313 Int_t iResult=fReadPos<fNofBins;
314 if (iResult>0 && (iResult=(++fReadPos<fNofBins))>0) {
315 if (bZeroSuppression) {
316 while ((iResult=(fReadPos<fNofBins))>0 &&
317 GetCorrectedData(fReadPos)<=0)
318 fReadPos++;
319 }
320 }
321 return iResult;
322}
323
324Int_t AliHLTTPCPad::Rewind(Int_t bZeroSuppression)
325{
2a083ac4 326 // see header file for class documentation
46b33a24 327 fReadPos=(bZeroSuppression>0?0:fFirstBLBin)-1;
328 return Next(bZeroSuppression);
329}
330
331AliHLTTPCSignal_t AliHLTTPCPad::GetRawData(Int_t bin) const
332{
2a083ac4 333 // see header file for class documentation
46b33a24 334 AliHLTTPCSignal_t data=0;
335 if (fpRawData) {
336 if (bin<fNofBins) {
337 data=fpRawData[bin];
338 } else {
339 HLTWarning("requested bin %d out of range (%d)", bin, fNofBins);
340 }
341 } else if (fNofBins>0) {
342 HLTWarning("data only available within event cycle");
343 }
344 return data;
345}
346
347AliHLTTPCSignal_t AliHLTTPCPad::GetCorrectedData(Int_t bin) const
348{
2a083ac4 349 // see header file for class documentation
46b33a24 350 AliHLTTPCSignal_t data=GetRawData(bin)-GetBaseLine(bin);
5235c3e9 351 AliHLTTPCSignal_t prev=0;
352 if (bin>1) prev=GetRawData(bin-1)-GetBaseLine(bin-1);
353 AliHLTTPCSignal_t succ=0;
354 if (bin+1<GetSize()) succ=GetRawData(bin+1)-GetBaseLine(bin+1);
355 if (fThreshold>0) {
356 data-=fThreshold;
357 prev-=fThreshold;
358 succ-=fThreshold;
359 }
360
361 // case 1:
362 // the signal is below the base-line and threshold
46b33a24 363 if (data<0) data=0;
5235c3e9 364
365 //case 2:
366 // the neighboring bins are both below base-line/threshold
367 // a real signal is always more than one bin wide because of the shaper
368 if (prev<=0 && succ<=0) data=0;
369
370 // case 3:
371 // the bin is inside the range of ignored bins
46b33a24 372 if (bin<fFirstBLBin) data=0;
84645eb0 373 //HLTDebug("fReadPos=%d data=%d threshold=%d raw data=%d base line=%d", fReadPos, data, fThreshold, GetRawData(bin), GetBaseLine(bin));
46b33a24 374 return data;
375}
376
377AliHLTTPCSignal_t AliHLTTPCPad::GetBaseLine(Int_t bin) const
378{
2a083ac4 379 // see header file for class documentation
84645eb0 380 AliHLTTPCSignal_t val=0;
381 if (fAverage>0) {
382 // we take the minumum value as the base line if it doesn't differ from
383 // the average to much
84645eb0 384 val=fAverage;
5235c3e9 385#ifdef KEEP_NOISE
2a083ac4 386 const AliHLTTPCSignal_t kMaxDifference=15;
84645eb0 387 if ((fAverage-fBLMin)<=kMaxDifference) val=fBLMin;
388 else val>kMaxDifference?val-=kMaxDifference:0;
5235c3e9 389#endif
84645eb0 390 }
391 if (val<0) {
392 // here we should never get
393 val=0;
394 HLTFatal("wrong base line value");
395 }
396 return val;
46b33a24 397}
398
399AliHLTTPCSignal_t AliHLTTPCPad::GetAverage() const
400{
2a083ac4 401 // see header file for class documentation
46b33a24 402 return fAverage>0?fAverage:0;
403}
404
5235c3e9 405Float_t AliHLTTPCPad::GetOccupancy() const
406{
2a083ac4 407 // see header file for class documentation
5235c3e9 408 Float_t occupancy=0;
409 if (fpRawData && fNofBins>0) {
410 for (Int_t i=fFirstBLBin; i<fNofBins; i++) {
411 if (GetCorrectedData(i)>0) occupancy+=1;
412 }
413 if (fNofBins-fFirstBLBin>0)
414 occupancy/=fNofBins-fFirstBLBin;
415 }
416 return occupancy;
417}
418
419Float_t AliHLTTPCPad::GetAveragedOccupancy() const
420{
2a083ac4 421 // see header file for class documentation
422
5235c3e9 423 // history is not yet implemented
424 return GetOccupancy();
425}