3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file AliHLTTPCPad.cxx
20 @author Matthias Richter
22 @brief Container Class for TPC Pads.
30 #include "AliHLTTPCPad.h"
31 #include "AliHLTStdIncludes.h"
33 /** margin for the base line be re-avaluated */
34 #define ALIHLTPAD_BASELINE_MARGIN (2*fAverage)
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTTPCPad)
39 AliHLTTPCPad::AliHLTTPCPad()
58 // see header file for class documentation
60 // refer to README to build package
62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65 AliHLTTPCPad::AliHLTTPCPad(Int_t offset, Int_t nofBins)
84 // see header file for class documentation
87 AliHLTTPCPad::AliHLTTPCPad(const AliHLTTPCPad& srcPad)
89 fRowNo(srcPad.fRowNo),
90 fPadNo(srcPad.fPadNo),
106 // see header file for class documentation
107 HLTFatal("copy constructor not implemented");
110 AliHLTTPCPad& AliHLTTPCPad::operator=(const AliHLTTPCPad&)
112 // see header file for class documentation
113 HLTFatal("assignment operator not implemented");
117 AliHLTTPCPad::~AliHLTTPCPad()
119 // see header file for class documentation
121 HLTWarning("event data acquisition not stopped");
126 Int_t AliHLTTPCPad::SetID(Int_t rowno, Int_t padno)
128 // see header file for class documentation
134 Int_t AliHLTTPCPad::StartEvent()
136 // see header file for class documentation
138 if (fpRawData==NULL) {
147 fpRawData=new AliHLTTPCSignal_t[fNofBins];
149 for (int i=0; i<fNofBins; i++) fpRawData[i]=-1;
151 HLTError("memory allocation failed");
156 HLTWarning("event data acquisition already started");
162 Int_t AliHLTTPCPad::CalculateBaseLine(Int_t reqMinCount)
164 // see header file for class documentation
166 AliHLTTPCSignal_t avBackup=fAverage;
167 //HLTDebug("reqMinCount=%d fCount=%d fTotal=%d fSum=%d fBLMax=%d fBLMin=%d", reqMinCount, fCount, fTotal, fSum, fBLMax, fBLMin);
168 if (fCount>=reqMinCount && fCount>=fTotal/2) {
169 fAverage=fCount>0?fSum/fCount:0;
171 //HLTDebug("average for current event %d (%d - %d)", fAverage, fBLMax, fBLMin);
173 if (fBLMax>ALIHLTPAD_BASELINE_MARGIN) {
175 //HLTDebug("maximum value %d exceeds margin for base line (%d) "
176 // "-> re-evaluate base line", fBLMax, ALIHLTPAD_BASELINE_MARGIN);
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;
182 //HLTDebug("new average %d", fAverage);
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);
192 HLTError("missing raw data for base line calculation");
197 // calculate average for all events
198 fAverage=((avBackup*fNofEvents)+fAverage)/(fNofEvents+1);
199 //HLTDebug("base line average for %d event(s): %d", fNofEvents+1, fAverage);
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);
215 Int_t AliHLTTPCPad::StopEvent()
217 // see header file for class documentation
220 AliHLTTPCSignal_t* pData=fpRawData;
226 } else if (fNofBins>0) {
227 HLTError("event data acquisition not started");
233 Int_t AliHLTTPCPad::ResetHistory()
235 // see header file for class documentation
242 Int_t AliHLTTPCPad::SetThreshold(AliHLTTPCSignal_t thresh)
244 // see header file for class documentation
250 Int_t AliHLTTPCPad::AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value)
252 // see header file for class documentation
254 if (bin>=fFirstBLBin) {
255 if (fAverage<0 || value<ALIHLTPAD_BASELINE_MARGIN) {
256 // add to the current sum and count
260 // keep the maximum value for later quality control of the base
265 if (fBLMin<0 || fBLMin>value) {
266 // keep the minimum value for later quality control of the base
272 // HLTDebug("ignoring value %d (bin %d) for base line calculation "
273 // "(current average is %d)",
274 // value, bin, fAverage);
280 Int_t AliHLTTPCPad::SetRawData(Int_t bin, AliHLTTPCSignal_t value)
282 // see header file for class documentation
287 if (fpRawData[bin]<0) {
288 AddBaseLineValue(bin, value);
291 // ignore value for average calculation
292 HLTWarning("overriding content of bin %d (%d)", bin, fpRawData[bin]);
294 fpRawData[bin]=value;
296 HLTWarning("ignoring neg. raw data");
299 HLTWarning("bin %d out of range (%d)", bin, fNofBins);
302 } else if (fNofBins>0) {
303 HLTError("event cycle not started");
309 Int_t AliHLTTPCPad::Next(Int_t bZeroSuppression)
311 // see header file for class documentation
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)
324 Int_t AliHLTTPCPad::Rewind(Int_t bZeroSuppression)
326 // see header file for class documentation
327 fReadPos=(bZeroSuppression>0?0:fFirstBLBin)-1;
328 return Next(bZeroSuppression);
331 AliHLTTPCSignal_t AliHLTTPCPad::GetRawData(Int_t bin) const
333 // see header file for class documentation
334 AliHLTTPCSignal_t data=0;
339 HLTWarning("requested bin %d out of range (%d)", bin, fNofBins);
341 } else if (fNofBins>0) {
342 HLTWarning("data only available within event cycle");
347 AliHLTTPCSignal_t AliHLTTPCPad::GetCorrectedData(Int_t bin) const
349 // see header file for class documentation
350 AliHLTTPCSignal_t data=GetRawData(bin)-GetBaseLine(bin);
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);
362 // the signal is below the base-line and threshold
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;
371 // the bin is inside the range of ignored bins
372 if (bin<fFirstBLBin) data=0;
373 //HLTDebug("fReadPos=%d data=%d threshold=%d raw data=%d base line=%d", fReadPos, data, fThreshold, GetRawData(bin), GetBaseLine(bin));
377 AliHLTTPCSignal_t AliHLTTPCPad::GetBaseLine(Int_t bin) const
379 // see header file for class documentation
380 AliHLTTPCSignal_t val=0;
382 // we take the minumum value as the base line if it doesn't differ from
383 // the average to much
386 const AliHLTTPCSignal_t kMaxDifference=15;
387 if ((fAverage-fBLMin)<=kMaxDifference) val=fBLMin;
388 else val>kMaxDifference?val-=kMaxDifference:0;
392 // here we should never get
394 HLTFatal("wrong base line value");
399 AliHLTTPCSignal_t AliHLTTPCPad::GetAverage() const
401 // see header file for class documentation
402 return fAverage>0?fAverage:0;
405 Float_t AliHLTTPCPad::GetOccupancy() const
407 // see header file for class documentation
409 if (fpRawData && fNofBins>0) {
410 for (Int_t i=fFirstBLBin; i<fNofBins; i++) {
411 if (GetCorrectedData(i)>0) occupancy+=1;
413 if (fNofBins-fFirstBLBin>0)
414 occupancy/=fNofBins-fFirstBLBin;
419 Float_t AliHLTTPCPad::GetAveragedOccupancy() const
421 // see header file for class documentation
423 // history is not yet implemented
424 return GetOccupancy();