3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * for The ALICE Off-line Project. *
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 **************************************************************************/
18 /** @file AliHLTTPCPad.cxx
19 @author Matthias Richter
21 @brief Container Class for TPC Pads.
29 #include "AliHLTTPCPad.h"
30 #include "AliHLTStdIncludes.h"
32 /** margin for the base line be re-avaluated */
33 #define ALIHLTPAD_BASELINE_MARGIN (2*fAverage)
35 /** ROOT macro for the implementation of ROOT specific class methods */
36 ClassImp(AliHLTTPCPad)
38 AliHLTTPCPad::AliHLTTPCPad()
57 // see header file for class documentation
59 // refer to README to build package
61 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64 AliHLTTPCPad::AliHLTTPCPad(Int_t offset, Int_t nofBins)
83 // see header file for class documentation
86 AliHLTTPCPad::AliHLTTPCPad(const AliHLTTPCPad& srcPad)
88 fRowNo(srcPad.fRowNo),
89 fPadNo(srcPad.fPadNo),
105 // see header file for class documentation
106 HLTFatal("copy constructor not implemented");
109 AliHLTTPCPad& AliHLTTPCPad::operator=(const AliHLTTPCPad&)
111 // see header file for class documentation
112 HLTFatal("assignment operator not implemented");
116 AliHLTTPCPad::~AliHLTTPCPad()
118 // see header file for class documentation
120 HLTWarning("event data acquisition not stopped");
125 Int_t AliHLTTPCPad::SetID(Int_t rowno, Int_t padno)
127 // see header file for class documentation
133 Int_t AliHLTTPCPad::StartEvent()
135 // see header file for class documentation
137 if (fpRawData==NULL) {
146 fpRawData=new AliHLTTPCSignal_t[fNofBins];
148 for (int i=0; i<fNofBins; i++) fpRawData[i]=-1;
150 HLTError("memory allocation failed");
155 HLTWarning("event data acquisition already started");
161 Int_t AliHLTTPCPad::CalculateBaseLine(Int_t reqMinCount)
163 // see header file for class documentation
165 AliHLTTPCSignal_t avBackup=fAverage;
166 //HLTDebug("reqMinCount=%d fCount=%d fTotal=%d fSum=%d fBLMax=%d fBLMin=%d", reqMinCount, fCount, fTotal, fSum, fBLMax, fBLMin);
167 if (fCount>=reqMinCount && fCount>=fTotal/2) {
168 fAverage=fCount>0?fSum/fCount:0;
170 //HLTDebug("average for current event %d (%d - %d)", fAverage, fBLMax, fBLMin);
172 if (fBLMax>ALIHLTPAD_BASELINE_MARGIN) {
174 //HLTDebug("maximum value %d exceeds margin for base line (%d) "
175 // "-> re-evaluate base line", fBLMax, ALIHLTPAD_BASELINE_MARGIN);
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;
181 //HLTDebug("new average %d", fAverage);
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);
191 HLTError("missing raw data for base line calculation");
196 // calculate average for all events
197 fAverage=((avBackup*fNofEvents)+fAverage)/(fNofEvents+1);
198 //HLTDebug("base line average for %d event(s): %d", fNofEvents+1, fAverage);
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);
214 Int_t AliHLTTPCPad::StopEvent()
216 // see header file for class documentation
219 AliHLTTPCSignal_t* pData=fpRawData;
225 } else if (fNofBins>0) {
226 HLTError("event data acquisition not started");
232 Int_t AliHLTTPCPad::ResetHistory()
234 // see header file for class documentation
241 Int_t AliHLTTPCPad::SetThreshold(AliHLTTPCSignal_t thresh)
243 // see header file for class documentation
249 Int_t AliHLTTPCPad::AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value)
251 // see header file for class documentation
253 if (bin>=fFirstBLBin) {
254 if (fAverage<0 || value<ALIHLTPAD_BASELINE_MARGIN) {
255 // add to the current sum and count
259 // keep the maximum value for later quality control of the base
264 if (fBLMin<0 || fBLMin>value) {
265 // keep the minimum value for later quality control of the base
271 // HLTDebug("ignoring value %d (bin %d) for base line calculation "
272 // "(current average is %d)",
273 // value, bin, fAverage);
279 Int_t AliHLTTPCPad::SetRawData(Int_t bin, AliHLTTPCSignal_t value)
281 // see header file for class documentation
286 if (fpRawData[bin]<0) {
287 AddBaseLineValue(bin, value);
290 // ignore value for average calculation
291 HLTWarning("overriding content of bin %d (%d)", bin, fpRawData[bin]);
293 fpRawData[bin]=value;
295 HLTWarning("ignoring neg. raw data");
298 HLTWarning("bin %d out of range (%d)", bin, fNofBins);
301 } else if (fNofBins>0) {
302 HLTError("event cycle not started");
308 Int_t AliHLTTPCPad::Next(Int_t bZeroSuppression)
310 // see header file for class documentation
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)
323 Int_t AliHLTTPCPad::Rewind(Int_t bZeroSuppression)
325 // see header file for class documentation
326 fReadPos=(bZeroSuppression>0?0:fFirstBLBin)-1;
327 return Next(bZeroSuppression);
330 AliHLTTPCSignal_t AliHLTTPCPad::GetRawData(Int_t bin) const
332 // see header file for class documentation
333 AliHLTTPCSignal_t data=0;
338 HLTWarning("requested bin %d out of range (%d)", bin, fNofBins);
340 } else if (fNofBins>0) {
341 HLTWarning("data only available within event cycle");
346 AliHLTTPCSignal_t AliHLTTPCPad::GetCorrectedData(Int_t bin) const
348 // see header file for class documentation
349 AliHLTTPCSignal_t data=GetRawData(bin)-GetBaseLine(bin);
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);
361 // the signal is below the base-line and threshold
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;
370 // the bin is inside the range of ignored bins
371 if (bin<fFirstBLBin) data=0;
372 //HLTDebug("fReadPos=%d data=%d threshold=%d raw data=%d base line=%d", fReadPos, data, fThreshold, GetRawData(bin), GetBaseLine(bin));
376 AliHLTTPCSignal_t AliHLTTPCPad::GetBaseLine(Int_t bin) const
378 // see header file for class documentation
379 AliHLTTPCSignal_t val=0;
381 // we take the minumum value as the base line if it doesn't differ from
382 // the average to much
385 const AliHLTTPCSignal_t kMaxDifference=15;
386 if ((fAverage-fBLMin)<=kMaxDifference) val=fBLMin;
387 else val>kMaxDifference?val-=kMaxDifference:0;
391 // here we should never get
393 HLTFatal("wrong base line value");
398 AliHLTTPCSignal_t AliHLTTPCPad::GetAverage() const
400 // see header file for class documentation
401 return fAverage>0?fAverage:0;
404 Float_t AliHLTTPCPad::GetOccupancy() const
406 // see header file for class documentation
408 if (fpRawData && fNofBins>0) {
409 for (Int_t i=fFirstBLBin; i<fNofBins; i++) {
410 if (GetCorrectedData(i)>0) occupancy+=1;
412 if (fNofBins-fFirstBLBin>0)
413 occupancy/=fNofBins-fFirstBLBin;
418 Float_t AliHLTTPCPad::GetAveragedOccupancy() const
420 // see header file for class documentation
422 // history is not yet implemented
423 return GetOccupancy();