1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
5 * for The ALICE Off-line Project. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 /** @file AliHLTTPCPad.cxx
17 @author Matthias Richter
19 @brief Container Class for TPC Pads.
27 #include "AliHLTTPCPad.h"
28 #include "AliHLTStdIncludes.h"
30 /** margin for the base line be re-avaluated */
31 #define ALIHLTPAD_BASELINE_MARGIN (2*fAverage)
33 /** ROOT macro for the implementation of ROOT specific class methods */
34 ClassImp(AliHLTTPCPad)
36 AliHLTTPCPad::AliHLTTPCPad()
57 AliHLTTPCPad::AliHLTTPCPad(Int_t offset, Int_t nofBins)
78 AliHLTTPCPad::AliHLTTPCPad(const AliHLTTPCPad& srcPad)
80 fRowNo(srcPad.fRowNo),
81 fPadNo(srcPad.fPadNo),
97 HLTFatal("copy constructor not implemented");
100 AliHLTTPCPad& AliHLTTPCPad::operator=(const AliHLTTPCPad&)
102 HLTFatal("assignment operator not implemented");
106 AliHLTTPCPad::~AliHLTTPCPad()
109 HLTWarning("event data acquisition not stopped");
114 Int_t AliHLTTPCPad::SetID(Int_t rowno, Int_t padno)
120 Int_t AliHLTTPCPad::StartEvent()
123 if (fpRawData==NULL) {
132 fpRawData=new AliHLTTPCSignal_t[fNofBins];
134 for (int i=0; i<fNofBins; i++) fpRawData[i]=-1;
136 HLTError("memory allocation failed");
141 HLTWarning("event data acquisition already started");
147 Int_t AliHLTTPCPad::CalculateBaseLine(Int_t reqMinCount)
150 AliHLTTPCSignal_t avBackup=fAverage;
151 //HLTDebug("reqMinCount=%d fCount=%d fTotal=%d fSum=%d fBLMax=%d fBLMin=%d", reqMinCount, fCount, fTotal, fSum, fBLMax, fBLMin);
152 if (fCount>=reqMinCount && fCount>=fTotal/2) {
153 fAverage=fCount>0?fSum/fCount:0;
155 //HLTDebug("average for current event %d (%d - %d)", fAverage, fBLMax, fBLMin);
157 if (fBLMax>ALIHLTPAD_BASELINE_MARGIN) {
159 HLTDebug("maximum value %d exceeds margin for base line (%d) "
160 "-> re-evaluate base line", fBLMax, ALIHLTPAD_BASELINE_MARGIN);
162 for (Int_t i=fFirstBLBin; i<fNofBins; i++)
163 if (fpRawData[i]>=0) AddBaseLineValue(i, fpRawData[i]);
164 if (fCount>0 && fCount>=reqMinCount && fCount>=fTotal/2) {
165 fAverage=fSum/fCount;
166 HLTDebug("new average %d", fAverage);
168 HLTDebug("baseline re-eveluation skipped because of to few "
169 "contributing bins: total=%d, contributing=%d, req=%d"
170 "\ndata might be already zero suppressed"
171 , fTotal, fCount, reqMinCount);
176 HLTError("missing raw data for base line calculation");
181 // calculate average for all events
182 fAverage=((avBackup*fNofEvents)+fAverage)/(fNofEvents+1);
183 //HLTDebug("base line average for %d event(s): %d", fNofEvents+1, fAverage);
191 HLTDebug("baseline calculation skipped because of to few contributing "
192 "bins: total=%d, contributing=%d, required=%d \ndata might be "
193 "already zero suppressed", fTotal, fCount, reqMinCount);
199 Int_t AliHLTTPCPad::StopEvent()
203 AliHLTTPCSignal_t* pData=fpRawData;
209 } else if (fNofBins>0) {
210 HLTError("event data acquisition not started");
216 Int_t AliHLTTPCPad::ResetHistory()
224 Int_t AliHLTTPCPad::SetThreshold(AliHLTTPCSignal_t thresh)
231 Int_t AliHLTTPCPad::AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value)
234 if (bin>=fFirstBLBin) {
235 if (fAverage<0 || value<ALIHLTPAD_BASELINE_MARGIN) {
236 // add to the current sum and count
240 // keep the maximum value for later quality control of the base
245 if (fBLMin<0 || fBLMin>value) {
246 // keep the minimum value for later quality control of the base
252 HLTDebug("ignoring value %d (bin %d) for base line calculation "
253 "(current average is %d)",
254 value, bin, fAverage);
260 Int_t AliHLTTPCPad::SetRawData(Int_t bin, AliHLTTPCSignal_t value)
266 if (fpRawData[bin]<0) {
267 AddBaseLineValue(bin, value);
270 // ignore value for average calculation
271 HLTWarning("overriding content of bin %d (%d)", bin, fpRawData[bin]);
273 fpRawData[bin]=value;
275 HLTWarning("ignoring neg. raw data");
278 HLTWarning("bin %d out of range (%d)", bin, fNofBins);
281 } else if (fNofBins>0) {
282 HLTError("event cycle not started");
288 Int_t AliHLTTPCPad::Next(Int_t bZeroSuppression)
290 if (fpRawData==NULL) return 0;
291 Int_t iResult=fReadPos<fNofBins;
292 if (iResult>0 && (iResult=(++fReadPos<fNofBins))>0) {
293 if (bZeroSuppression) {
294 while ((iResult=(fReadPos<fNofBins))>0 &&
295 GetCorrectedData(fReadPos)<=0)
302 Int_t AliHLTTPCPad::Rewind(Int_t bZeroSuppression)
304 fReadPos=(bZeroSuppression>0?0:fFirstBLBin)-1;
305 return Next(bZeroSuppression);
308 AliHLTTPCSignal_t AliHLTTPCPad::GetRawData(Int_t bin) const
310 AliHLTTPCSignal_t data=0;
315 HLTWarning("requested bin %d out of range (%d)", bin, fNofBins);
317 } else if (fNofBins>0) {
318 HLTWarning("data only available within event cycle");
323 AliHLTTPCSignal_t AliHLTTPCPad::GetCorrectedData(Int_t bin) const
325 AliHLTTPCSignal_t data=GetRawData(bin)-GetBaseLine(bin);
326 if (fThreshold>0) data-=fThreshold;
328 if (bin<fFirstBLBin) data=0;
329 //HLTDebug("fReadPos=%d data=%d threshold=%d raw data=%d base line=%d", fReadPos, data, fThreshold, GetRawData(bin), GetBaseLine(bin));
333 AliHLTTPCSignal_t AliHLTTPCPad::GetBaseLine(Int_t bin) const
335 AliHLTTPCSignal_t val=0;
337 // we take the minumum value as the base line if it doesn't differ from
338 // the average to much
339 const AliHLTTPCSignal_t kMaxDifference=15;
341 if ((fAverage-fBLMin)<=kMaxDifference) val=fBLMin;
342 else val>kMaxDifference?val-=kMaxDifference:0;
345 // here we should never get
347 HLTFatal("wrong base line value");
352 AliHLTTPCSignal_t AliHLTTPCPad::GetAverage() const
354 return fAverage>0?fAverage:0;