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