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: Timm Steinbeck, Matthias Richter *
8 //* Developers: Kenneth Aamodt <kenneth.aamodt@student.uib.no> *
9 //* for The ALICE HLT Project. *
11 //* Permission to use, copy, modify and distribute this software and its *
12 //* documentation strictly for non-commercial purposes is hereby granted *
13 //* without fee, provided that the above copyright notice appears in all *
14 //* copies and that both the copyright notice and this permission notice *
15 //* appear in the supporting documentation. The authors make no claims *
16 //* about the suitability of this software for any purpose. It is *
17 //* provided "as is" without express or implied warranty. *
18 //**************************************************************************
20 /** @file AliHLTTPCPad.cxx
21 @author Matthias Richter, Kenneth Aamodt
23 @brief Container Class for TPC Pads.
31 #include "AliHLTTPCPad.h"
32 #include "AliHLTStdIncludes.h"
36 #include "AliHLTTPCTransform.h"
37 #include "AliHLTTPCClusters.h"
41 //------------------------------
43 /** margin for the base line be re-avaluated */
44 #define ALIHLTPAD_BASELINE_MARGIN (2*fAverage)
46 /** ROOT macro for the implementation of ROOT specific class methods */
47 ClassImp(AliHLTTPCPad)
49 AliHLTTPCPad::AliHLTTPCPad()
52 fUsedClusterCandidates(),
72 fSignalPositionArray(NULL),
73 fSizeOfSignalPositionArray(0),
75 fCandidateDigitsVector()
77 // see header file for class documentation
79 // refer to README to build package
81 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
82 // HLTInfo("Entering default constructor");
83 fDataSignals= new AliHLTTPCSignal_t[AliHLTTPCTransform::GetNTimeBins()];
84 memset( fDataSignals, 0xFF, sizeof(Int_t)*(AliHLTTPCTransform::GetNTimeBins()));
86 fSignalPositionArray= new Int_t[AliHLTTPCTransform::GetNTimeBins()];
87 memset( fSignalPositionArray, 0xFF, sizeof(Int_t)*(AliHLTTPCTransform::GetNTimeBins()));
88 fSizeOfSignalPositionArray=0;
92 AliHLTTPCPad::AliHLTTPCPad(Int_t dummy)
95 fUsedClusterCandidates(),
115 fSignalPositionArray(NULL),
116 fSizeOfSignalPositionArray(0),
117 fNGoodSignalsSent(0),
118 fCandidateDigitsVector()
120 // see header file for class documentation
122 // refer to README to build package
124 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
125 dummy=0;//to get rid of warning until things are cleaned up better
128 AliHLTTPCPad::AliHLTTPCPad(Int_t offset, Int_t nofBins)
130 fClusterCandidates(),
131 fUsedClusterCandidates(),
132 fSelectedPad(kFALSE),
151 fSignalPositionArray(NULL),
152 fSizeOfSignalPositionArray(0),
153 fNGoodSignalsSent(0),
154 fCandidateDigitsVector()
156 // see header file for class documentation
159 AliHLTTPCPad::~AliHLTTPCPad()
161 // see header file for class documentation
163 HLTWarning("event data acquisition not stopped");
167 delete [] fDataSignals;
170 if (fSignalPositionArray!=NULL) {
171 delete [] fSignalPositionArray;
172 fSignalPositionArray=NULL;
176 Int_t AliHLTTPCPad::SetID(Int_t rowno, Int_t padno)
178 // see header file for class documentation
185 Int_t AliHLTTPCPad::StartEvent()
187 // see header file for class documentation
189 if (fpRawData==NULL) {
198 fpRawData=new AliHLTTPCSignal_t[fNofBins];
200 for (int i=0; i<fNofBins; i++) fpRawData[i]=-1;
202 HLTError("memory allocation failed");
207 HLTWarning("event data acquisition already started");
213 Int_t AliHLTTPCPad::CalculateBaseLine(Int_t reqMinCount)
215 // see header file for class documentation
217 AliHLTTPCSignal_t avBackup=fAverage;
218 //HLTDebug("reqMinCount=%d fCount=%d fTotal=%d fSum=%d fBLMax=%d fBLMin=%d", reqMinCount, fCount, fTotal, fSum, fBLMax, fBLMin);
219 if (fCount>=reqMinCount && fCount>=fTotal/2) {
220 fAverage=fCount>0?fSum/fCount:0;
222 //HLTDebug("average for current event %d (%d - %d)", fAverage, fBLMax, fBLMin);
224 if (fBLMax>ALIHLTPAD_BASELINE_MARGIN) {
226 //HLTDebug("maximum value %d exceeds margin for base line (%d) "
227 // "-> re-evaluate base line", fBLMax, ALIHLTPAD_BASELINE_MARGIN);
229 for (Int_t i=fFirstBLBin; i<fNofBins; i++)
230 if (fpRawData[i]>=0) AddBaseLineValue(i, fpRawData[i]);
231 if (fCount>0 && fCount>=reqMinCount && fCount>=fTotal/2) {
232 fAverage=fSum/fCount;
233 //HLTDebug("new average %d", fAverage);
235 // HLTDebug("baseline re-eveluation skipped because of to few "
236 // "contributing bins: total=%d, contributing=%d, req=%d"
237 // "\ndata might be already zero suppressed"
238 // , fTotal, fCount, reqMinCount);
243 HLTError("missing raw data for base line calculation");
248 // calculate average for all events
249 fAverage=((avBackup*fNofEvents)+fAverage)/(fNofEvents+1);
250 //HLTDebug("base line average for %d event(s): %d", fNofEvents+1, fAverage);
258 // HLTDebug("baseline calculation skipped because of to few contributing "
259 // "bins: total=%d, contributing=%d, required=%d \ndata might be "
260 // "already zero suppressed", fTotal, fCount, reqMinCount);
266 Int_t AliHLTTPCPad::StopEvent()
268 // see header file for class documentation
271 AliHLTTPCSignal_t* pData=fpRawData;
277 } else if (fNofBins>0) {
278 HLTError("event data acquisition not started");
284 Int_t AliHLTTPCPad::ResetHistory()
286 // see header file for class documentation
293 Int_t AliHLTTPCPad::SetThreshold(AliHLTTPCSignal_t thresh)
295 // see header file for class documentation
301 Int_t AliHLTTPCPad::AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value)
303 // see header file for class documentation
305 if (bin>=fFirstBLBin) {
306 if (fAverage<0 || value<ALIHLTPAD_BASELINE_MARGIN) {
307 // add to the current sum and count
311 // keep the maximum value for later quality control of the base
316 if (fBLMin<0 || fBLMin>value) {
317 // keep the minimum value for later quality control of the base
323 // HLTDebug("ignoring value %d (bin %d) for base line calculation "
324 // "(current average is %d)",
325 // value, bin, fAverage);
331 Int_t AliHLTTPCPad::SetRawData(Int_t bin, AliHLTTPCSignal_t value)
333 // see header file for class documentation
334 // printf("Row: %d Pad: %d Time: %d Charge %d", fRowNo, fPadNo, bin, value);
339 if (fpRawData[bin]<0) {
340 AddBaseLineValue(bin, value);
343 // ignore value for average calculation
344 HLTWarning("overriding content of bin %d (%d)", bin, fpRawData[bin]);
346 fpRawData[bin]=value;
348 HLTWarning("ignoring neg. raw data");
351 HLTWarning("bin %d out of range (%d)", bin, fNofBins);
354 } else if (fNofBins>0) {
355 HLTError("event cycle not started");
361 Int_t AliHLTTPCPad::Next(Int_t bZeroSuppression)
363 // see header file for class documentation
364 if (fpRawData==NULL) return 0;
365 Int_t iResult=fReadPos<fNofBins;
366 if (iResult>0 && (iResult=(++fReadPos<fNofBins))>0) {
367 if (bZeroSuppression) {
368 while ((iResult=(fReadPos<fNofBins))>0 &&
369 GetCorrectedData(fReadPos)<=0)
376 Int_t AliHLTTPCPad::Rewind(Int_t bZeroSuppression)
378 // see header file for class documentation
379 fReadPos=(bZeroSuppression>0?0:fFirstBLBin)-1;
380 return Next(bZeroSuppression);
383 AliHLTTPCSignal_t AliHLTTPCPad::GetRawData(Int_t bin) const
385 // see header file for class documentation
386 AliHLTTPCSignal_t data=0;
391 HLTWarning("requested bin %d out of range (%d)", bin, fNofBins);
393 } else if (fNofBins>0) {
394 HLTWarning("data only available within event cycle");
399 AliHLTTPCSignal_t AliHLTTPCPad::GetCorrectedData(Int_t bin) const
401 // see header file for class documentation
402 AliHLTTPCSignal_t data=GetRawData(bin)-GetBaseLine(bin);
403 AliHLTTPCSignal_t prev=0;
404 if (bin>1) prev=GetRawData(bin-1)-GetBaseLine(bin-1);
405 AliHLTTPCSignal_t succ=0;
406 if (bin+1<GetSize()) succ=GetRawData(bin+1)-GetBaseLine(bin+1);
414 // the signal is below the base-line and threshold
418 // the neighboring bins are both below base-line/threshold
419 // a real signal is always more than one bin wide because of the shaper
420 if (prev<=0 && succ<=0) data=0;
423 // the bin is inside the range of ignored bins
424 if (bin<fFirstBLBin) data=0;
425 //HLTDebug("fReadPos=%d data=%d threshold=%d raw data=%d base line=%d", fReadPos, data, fThreshold, GetRawData(bin), GetBaseLine(bin));
429 AliHLTTPCSignal_t AliHLTTPCPad::GetBaseLine(Int_t /*bin*/) const //TODO: Why is bin being ignored?
431 // see header file for class documentation
432 AliHLTTPCSignal_t val=0;
434 // we take the minumum value as the base line if it doesn't differ from
435 // the average to much
438 const AliHLTTPCSignal_t kMaxDifference=15;
439 if ((fAverage-fBLMin)<=kMaxDifference) val=fBLMin;
440 else val>kMaxDifference?val-=kMaxDifference:0;
444 // here we should never get
446 HLTFatal("wrong base line value");
451 AliHLTTPCSignal_t AliHLTTPCPad::GetAverage() const
453 // see header file for class documentation
454 return fAverage>0?fAverage:0;
457 Float_t AliHLTTPCPad::GetOccupancy() const
459 // see header file for class documentation
461 if (fpRawData && fNofBins>0) {
462 for (Int_t i=fFirstBLBin; i<fNofBins; i++) {
463 if (GetCorrectedData(i)>0) occupancy+=1;
465 if (fNofBins-fFirstBLBin>0)
466 occupancy/=fNofBins-fFirstBLBin;
471 Float_t AliHLTTPCPad::GetAveragedOccupancy() const
473 // see header file for class documentation
475 // history is not yet implemented
476 return GetOccupancy();
478 void AliHLTTPCPad::PrintRawData()
480 // see header file for class documentation
481 for(Int_t bin=0;bin<AliHLTTPCTransform::GetNTimeBins();bin++){
482 if(GetDataSignal(bin)>0)
483 //This cout should be here since using logging produces output that is much more difficult to read
484 cout<<fRowNo<<"\t"<<fPadNo<<"\t"<<bin<<"\t"<<GetDataSignal(bin)<<endl;
488 void AliHLTTPCPad::ClearCandidates(){
489 fClusterCandidates.clear();
490 fUsedClusterCandidates.clear();
491 fCandidateDigitsVector.clear();
494 void AliHLTTPCPad::SetDataToDefault()
496 // see header file for class documentation
497 // if(fDataSignals && fSignalPositionArray){
498 for(Int_t i =0;i<fSizeOfSignalPositionArray;i++){
499 fDataSignals[fSignalPositionArray[i]]=-1;
501 fSizeOfSignalPositionArray=0;
502 fNGoodSignalsSent = 0;
506 void AliHLTTPCPad::SetDataSignal(Int_t bin,Int_t signal)
508 // see header file for class documentation
509 fDataSignals[bin]=signal;
510 fSignalPositionArray[fSizeOfSignalPositionArray]=bin;
511 fSizeOfSignalPositionArray++;
514 Bool_t AliHLTTPCPad::GetNextGoodSignal(Int_t &time,Int_t &bunchSize){
516 if(fNGoodSignalsSent<fSizeOfSignalPositionArray&&fSizeOfSignalPositionArray>0){
517 time = fSignalPositionArray[fNGoodSignalsSent];
520 while(fNGoodSignalsSent<fSizeOfSignalPositionArray){
521 if(fDataSignals[time+bunchSize+1]>0){
529 // fNGoodSignalsSent++;
535 Int_t AliHLTTPCPad::GetDataSignal(Int_t bin) const
537 // see header file for class documentation
538 return fDataSignals[bin];
541 void AliHLTTPCPad::ZeroSuppress(Double_t nRMS, Int_t threshold, Int_t reqMinPoint, Int_t beginTime, Int_t endTime, Int_t timebinsLeft, Int_t timebinsRight, Int_t valueUnderAverage, bool speedup){
542 //see headerfile for documentation
544 //HLTDebug("In Pad: nRMS=%d, threshold=%d, reqMinPoint=%d, beginTime=%d, endTime=%d, timebinsLeft=%d timebinsRight=%d valueUnderAverage=%d \n",nRMS,threshold,reqMinPoint,beginTime,endTime,timebinsLeft,timebinsRight,valueUnderAverage);
546 Bool_t useRMS= kFALSE;
550 HLTInfo("Both RMSThreshold and SignalThreshold defined, using RMSThreshold");
553 if(threshold<1 && nRMS<=0){
554 //setting the data to -1 for this pad
555 HLTInfo("Neither of RMSThreshold and SignalThreshold set, zerosuppression aborted");
559 Int_t fThresholdUsed=threshold;
564 fSizeOfSignalPositionArray=0;
566 for(Int_t i=beginTime;i<endTime+1;i++){
567 if(fDataSignals[i]>0){
569 sumNAdded+=fDataSignals[i]*fDataSignals[i];
570 if (maxVal<fDataSignals[i]) maxVal=fDataSignals[i];
574 else if(threshold>0){
575 for(Int_t i=beginTime;i<endTime+1;i++){
576 if(fDataSignals[i]>0){
578 sumNAdded+=fDataSignals[i];
579 if (maxVal<fDataSignals[i]) maxVal=fDataSignals[i];
584 HLTFatal("This should never happen because this is tested earlier in the code.(nRMSThreshold<1&&signal-threshold<1)");
586 if(nAdded<reqMinPoint){
587 HLTInfo("Number of signals is less than required, zero suppression aborted");
592 HLTInfo("No signals added for this pad, zerosuppression aborted: pad %d row %d",fPadNo,fRowNo);
596 Double_t averageValue=(Double_t)sumNAdded/nAdded;//true average for threshold approach, average of signals squared for rms approach
601 fThresholdUsed =(Int_t)(TMath::Sqrt(averageValue)*nRMS);
604 HLTFatal("average value in ZeroSuppression less than 0, investigation needed. This should never happen");
608 fThresholdUsed = (Int_t)(averageValue + threshold);
610 if (maxVal<fThresholdUsed) return;
612 // Do zero suppression on the adc values within [beginTime,endTime](add the good values)
613 for(Int_t i=beginTime;i<endTime;i++){
614 if(fDataSignals[i]>fThresholdUsed){
615 Int_t firstSignalTime=i;
616 for(Int_t left=1;left<timebinsLeft;left++){//looking 5 to the left of the signal to add tail
617 if(fDataSignals[i-left]-averageValue+valueUnderAverage>0 && i-left>=beginTime){
624 Int_t lastSignalTime=i;
625 while(fDataSignals[lastSignalTime+1]>fThresholdUsed && lastSignalTime+1<endTime){
628 for(Int_t right=1;right<timebinsRight;right++){//looking 5 to the left of the signal to add tail
629 if(fDataSignals[i+right]-averageValue+valueUnderAverage>0&&i+right<endTime){
637 for(Int_t t=firstSignalTime;t<lastSignalTime;t++){
638 fDataSignals[t]=(AliHLTTPCSignal_t)(fDataSignals[t]-averageValue + valueUnderAverage);
639 fSignalPositionArray[fSizeOfSignalPositionArray]=t;
640 fSizeOfSignalPositionArray++;
641 // Matthias Oct 10 2008: trying hard to make the code faster for the
642 // AltroChannelSelection. For that we only need to know there is data
648 //reset the rest of the data
649 Int_t counterSize=fSizeOfSignalPositionArray;
651 for(Int_t d=endTime;d>=beginTime;d--){
652 if(d==fSignalPositionArray[counterSize-1]&&counterSize-1>=0){
659 if(fDataSignals[beginTime+1]<1){
660 fDataSignals[beginTime]=0;
664 void AliHLTTPCPad::AddClusterCandidate(AliHLTTPCClusters candidate){
665 fClusterCandidates.push_back(candidate);
666 fUsedClusterCandidates.push_back(0);
669 void AliHLTTPCPad::AddCandidateDigits(vector<AliHLTTPCDigitData> candidateDigits){
670 fCandidateDigitsVector.push_back(candidateDigits);
673 vector<AliHLTTPCDigitData> AliHLTTPCPad::GetCandidateDigits(Int_t candidateIndex){
674 return fCandidateDigitsVector.at(candidateIndex);