]>
Commit | Line | Data |
---|---|---|
2a083ac4 | 1 | // @(#) $Id$ |
2 | ||
46b33a24 | 3 | /************************************************************************** |
9be2600f | 4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
46b33a24 | 6 | * * |
9be2600f | 7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
01f43166 | 8 | * Kenneth Aamodt <Kenneth.aamodt@ift.uib.no> * |
9be2600f | 9 | * for The ALICE HLT Project. * |
46b33a24 | 10 | * * |
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 | **************************************************************************/ | |
19 | ||
20 | /** @file AliHLTTPCPad.cxx | |
01f43166 | 21 | @author Matthias Richter, Kenneth Aamodt |
46b33a24 | 22 | @date |
23 | @brief Container Class for TPC Pads. | |
24 | */ | |
25 | ||
a1dbf058 | 26 | // see header file for class documentation |
27 | // or | |
28 | // refer to README to build package | |
29 | // or | |
30 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
31 | ||
46b33a24 | 32 | #if __GNUC__>= 3 |
33 | using namespace std; | |
34 | #endif | |
35 | ||
36 | #include <cerrno> | |
37 | #include "AliHLTTPCPad.h" | |
84645eb0 | 38 | #include "AliHLTStdIncludes.h" |
46b33a24 | 39 | |
01f43166 | 40 | |
41 | //added by kenneth | |
42 | #include "AliHLTTPCTransform.h" | |
43 | #include "AliHLTTPCClusters.h" | |
44 | #include <sys/time.h> | |
afa4418c | 45 | #include "TMath.h" |
46 | #include "TFile.h" | |
01f43166 | 47 | //------------------------------ |
48 | ||
46b33a24 | 49 | /** margin for the base line be re-avaluated */ |
50 | #define ALIHLTPAD_BASELINE_MARGIN (2*fAverage) | |
51 | ||
52 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
53 | ClassImp(AliHLTTPCPad) | |
54 | ||
55 | AliHLTTPCPad::AliHLTTPCPad() | |
56 | : | |
a1dbf058 | 57 | fClusterCandidates(), |
58 | fUsedClusterCandidates(), | |
2fdb1ae7 | 59 | fSelectedPad(kFALSE), |
60 | fHWAddress(0), | |
46b33a24 | 61 | fRowNo(-1), |
62 | fPadNo(-1), | |
63 | fThreshold(0), | |
64 | fAverage(-1), | |
65 | fNofEvents(0), | |
66 | fSum(0), | |
2a083ac4 | 67 | fCount(0), |
68 | fTotal(0), | |
46b33a24 | 69 | fBLMax(-1), |
70 | fBLMaxBin(-1), | |
84645eb0 | 71 | fBLMin(-1), |
72 | fBLMinBin(-1), | |
46b33a24 | 73 | fFirstBLBin(0), |
74 | fNofBins(0), | |
2a083ac4 | 75 | fReadPos(0), |
01f43166 | 76 | fpRawData(NULL), |
01f43166 | 77 | fDataSignals(NULL), |
78 | fSignalPositionArray(NULL), | |
b1c46961 | 79 | fSizeOfSignalPositionArray(0), |
afa4418c | 80 | fNGoodSignalsSent(0), |
a74855c2 | 81 | fNSigmaThreshold(0), |
82 | fSignalThreshold(0) | |
46b33a24 | 83 | { |
2a083ac4 | 84 | // see header file for class documentation |
85 | // or | |
86 | // refer to README to build package | |
87 | // or | |
88 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
01f43166 | 89 | // HLTInfo("Entering default constructor"); |
90 | fDataSignals= new AliHLTTPCSignal_t[AliHLTTPCTransform::GetNTimeBins()]; | |
91 | memset( fDataSignals, 0xFF, sizeof(Int_t)*(AliHLTTPCTransform::GetNTimeBins())); | |
8252a538 | 92 | |
a74855c2 | 93 | fSignalPositionArray= new Int_t[AliHLTTPCTransform::GetNTimeBins()]; |
01f43166 | 94 | memset( fSignalPositionArray, 0xFF, sizeof(Int_t)*(AliHLTTPCTransform::GetNTimeBins())); |
95 | fSizeOfSignalPositionArray=0; | |
afa4418c | 96 | |
46b33a24 | 97 | } |
98 | ||
a74855c2 | 99 | AliHLTTPCPad::AliHLTTPCPad(Int_t dummy) |
8252a538 | 100 | : |
a74855c2 | 101 | fClusterCandidates(), |
102 | fUsedClusterCandidates(), | |
2fdb1ae7 | 103 | fSelectedPad(kFALSE), |
104 | fHWAddress(0), | |
8252a538 | 105 | fRowNo(-1), |
106 | fPadNo(-1), | |
107 | fThreshold(0), | |
108 | fAverage(-1), | |
109 | fNofEvents(0), | |
110 | fSum(0), | |
111 | fCount(0), | |
112 | fTotal(0), | |
113 | fBLMax(-1), | |
114 | fBLMaxBin(-1), | |
115 | fBLMin(-1), | |
116 | fBLMinBin(-1), | |
117 | fFirstBLBin(0), | |
118 | fNofBins(0), | |
119 | fReadPos(0), | |
120 | fpRawData(NULL), | |
121 | fDataSignals(NULL), | |
122 | fSignalPositionArray(NULL), | |
123 | fSizeOfSignalPositionArray(0), | |
afa4418c | 124 | fNGoodSignalsSent(0), |
a74855c2 | 125 | fNSigmaThreshold(0), |
126 | fSignalThreshold(0) | |
8252a538 | 127 | { |
128 | // see header file for class documentation | |
129 | // or | |
130 | // refer to README to build package | |
131 | // or | |
132 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
a74855c2 | 133 | dummy=0;//to get rid of warning until things are cleaned up better |
8252a538 | 134 | } |
135 | ||
46b33a24 | 136 | AliHLTTPCPad::AliHLTTPCPad(Int_t offset, Int_t nofBins) |
137 | : | |
a1dbf058 | 138 | fClusterCandidates(), |
139 | fUsedClusterCandidates(), | |
2fdb1ae7 | 140 | fSelectedPad(kFALSE), |
141 | fHWAddress(0), | |
46b33a24 | 142 | fRowNo(-1), |
143 | fPadNo(-1), | |
144 | fThreshold(0), | |
145 | fAverage(-1), | |
146 | fNofEvents(0), | |
147 | fSum(0), | |
2a083ac4 | 148 | fCount(0), |
149 | fTotal(0), | |
46b33a24 | 150 | fBLMax(-1), |
151 | fBLMaxBin(-1), | |
84645eb0 | 152 | fBLMin(-1), |
153 | fBLMinBin(-1), | |
46b33a24 | 154 | fFirstBLBin(offset), |
155 | fNofBins(nofBins), | |
2a083ac4 | 156 | fReadPos(0), |
01f43166 | 157 | fpRawData(NULL), |
01f43166 | 158 | fDataSignals(NULL), |
159 | fSignalPositionArray(NULL), | |
b1c46961 | 160 | fSizeOfSignalPositionArray(0), |
afa4418c | 161 | fNGoodSignalsSent(0), |
a74855c2 | 162 | fNSigmaThreshold(0), |
163 | fSignalThreshold(0) | |
46b33a24 | 164 | { |
2a083ac4 | 165 | // see header file for class documentation |
46b33a24 | 166 | } |
167 | ||
46b33a24 | 168 | AliHLTTPCPad::~AliHLTTPCPad() |
169 | { | |
2a083ac4 | 170 | // see header file for class documentation |
46b33a24 | 171 | if (fpRawData) { |
172 | HLTWarning("event data acquisition not stopped"); | |
173 | StopEvent(); | |
174 | } | |
01f43166 | 175 | if (fDataSignals) { |
afa4418c | 176 | delete [] fDataSignals; |
01f43166 | 177 | fDataSignals=NULL; |
01f43166 | 178 | } |
a74855c2 | 179 | if (fSignalPositionArray!=NULL) { |
afa4418c | 180 | delete [] fSignalPositionArray; |
01f43166 | 181 | fSignalPositionArray=NULL; |
01f43166 | 182 | } |
46b33a24 | 183 | } |
184 | ||
185 | Int_t AliHLTTPCPad::SetID(Int_t rowno, Int_t padno) | |
186 | { | |
2a083ac4 | 187 | // see header file for class documentation |
46b33a24 | 188 | fRowNo=rowno; |
189 | fPadNo=padno; | |
afa4418c | 190 | |
2a083ac4 | 191 | return 0; |
46b33a24 | 192 | } |
193 | ||
194 | Int_t AliHLTTPCPad::StartEvent() | |
195 | { | |
2a083ac4 | 196 | // see header file for class documentation |
46b33a24 | 197 | Int_t iResult=0; |
198 | if (fpRawData==NULL) { | |
199 | fBLMax=-1; | |
200 | fBLMaxBin=-1; | |
84645eb0 | 201 | fBLMin=-1; |
202 | fBLMinBin=-1; | |
46b33a24 | 203 | fSum=0; |
204 | fCount=0; | |
205 | fTotal=0; | |
206 | if (fNofBins>0) { | |
207 | fpRawData=new AliHLTTPCSignal_t[fNofBins]; | |
208 | if (fpRawData) { | |
209 | for (int i=0; i<fNofBins; i++) fpRawData[i]=-1; | |
210 | } else { | |
211 | HLTError("memory allocation failed"); | |
212 | iResult=-ENOMEM; | |
213 | } | |
214 | } | |
215 | } else { | |
216 | HLTWarning("event data acquisition already started"); | |
217 | iResult=-EALREADY; | |
218 | } | |
219 | return iResult; | |
220 | } | |
221 | ||
222 | Int_t AliHLTTPCPad::CalculateBaseLine(Int_t reqMinCount) | |
223 | { | |
2a083ac4 | 224 | // see header file for class documentation |
46b33a24 | 225 | Int_t iResult=0; |
226 | AliHLTTPCSignal_t avBackup=fAverage; | |
84645eb0 | 227 | //HLTDebug("reqMinCount=%d fCount=%d fTotal=%d fSum=%d fBLMax=%d fBLMin=%d", reqMinCount, fCount, fTotal, fSum, fBLMax, fBLMin); |
46b33a24 | 228 | if (fCount>=reqMinCount && fCount>=fTotal/2) { |
229 | fAverage=fCount>0?fSum/fCount:0; | |
230 | if (fAverage>0) { | |
84645eb0 | 231 | //HLTDebug("average for current event %d (%d - %d)", fAverage, fBLMax, fBLMin); |
46b33a24 | 232 | fCount=0;fSum=-1; |
233 | if (fBLMax>ALIHLTPAD_BASELINE_MARGIN) { | |
234 | // calculate again | |
21b6a334 | 235 | //HLTDebug("maximum value %d exceeds margin for base line (%d) " |
236 | // "-> re-evaluate base line", fBLMax, ALIHLTPAD_BASELINE_MARGIN); | |
46b33a24 | 237 | if (fpRawData) { |
238 | for (Int_t i=fFirstBLBin; i<fNofBins; i++) | |
239 | if (fpRawData[i]>=0) AddBaseLineValue(i, fpRawData[i]); | |
240 | if (fCount>0 && fCount>=reqMinCount && fCount>=fTotal/2) { | |
241 | fAverage=fSum/fCount; | |
3cde846d | 242 | //HLTDebug("new average %d", fAverage); |
46b33a24 | 243 | } else { |
b1c46961 | 244 | // HLTDebug("baseline re-eveluation skipped because of to few " |
245 | // "contributing bins: total=%d, contributing=%d, req=%d" | |
246 | // "\ndata might be already zero suppressed" | |
247 | // , fTotal, fCount, reqMinCount); | |
46b33a24 | 248 | iResult=-ENODATA; |
249 | } | |
250 | fCount=0;fSum=-1; | |
251 | } else { | |
252 | HLTError("missing raw data for base line calculation"); | |
253 | iResult=-ENOBUFS; | |
254 | } | |
255 | } | |
256 | if (iResult>=0) { | |
257 | // calculate average for all events | |
258 | fAverage=((avBackup*fNofEvents)+fAverage)/(fNofEvents+1); | |
84645eb0 | 259 | //HLTDebug("base line average for %d event(s): %d", fNofEvents+1, fAverage); |
46b33a24 | 260 | } else { |
261 | fAverage=avBackup; | |
262 | } | |
263 | } else { | |
264 | fAverage=avBackup; | |
265 | } | |
266 | } else { | |
b1c46961 | 267 | // HLTDebug("baseline calculation skipped because of to few contributing " |
268 | // "bins: total=%d, contributing=%d, required=%d \ndata might be " | |
269 | // "already zero suppressed", fTotal, fCount, reqMinCount); | |
46b33a24 | 270 | } |
271 | ||
272 | return iResult; | |
273 | } | |
274 | ||
275 | Int_t AliHLTTPCPad::StopEvent() | |
276 | { | |
2a083ac4 | 277 | // see header file for class documentation |
46b33a24 | 278 | Int_t iResult=0; |
279 | if (fpRawData) { | |
280 | AliHLTTPCSignal_t* pData=fpRawData; | |
281 | fpRawData=NULL; | |
282 | delete [] pData; | |
283 | fTotal=0; | |
284 | fNofEvents++; | |
285 | Rewind(); | |
286 | } else if (fNofBins>0) { | |
287 | HLTError("event data acquisition not started"); | |
288 | iResult=-EBADF; | |
289 | } | |
290 | return iResult; | |
291 | } | |
292 | ||
293 | Int_t AliHLTTPCPad::ResetHistory() | |
294 | { | |
2a083ac4 | 295 | // see header file for class documentation |
46b33a24 | 296 | Int_t iResult=0; |
297 | fAverage=-1; | |
298 | fNofEvents=0; | |
299 | return iResult; | |
300 | } | |
301 | ||
302 | Int_t AliHLTTPCPad::SetThreshold(AliHLTTPCSignal_t thresh) | |
303 | { | |
2a083ac4 | 304 | // see header file for class documentation |
46b33a24 | 305 | Int_t iResult=0; |
306 | fThreshold=thresh; | |
307 | return iResult; | |
308 | } | |
309 | ||
310 | Int_t AliHLTTPCPad::AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value) | |
311 | { | |
2a083ac4 | 312 | // see header file for class documentation |
46b33a24 | 313 | Int_t iResult=0; |
314 | if (bin>=fFirstBLBin) { | |
315 | if (fAverage<0 || value<ALIHLTPAD_BASELINE_MARGIN) { | |
316 | // add to the current sum and count | |
317 | fSum+=value; | |
318 | fCount++; | |
319 | if (fBLMax<value) { | |
320 | // keep the maximum value for later quality control of the base | |
321 | // line calculation | |
322 | fBLMax=value; | |
323 | fBLMaxBin=bin; | |
324 | } | |
84645eb0 | 325 | if (fBLMin<0 || fBLMin>value) { |
326 | // keep the minimum value for later quality control of the base | |
327 | // line calculation | |
328 | fBLMin=value; | |
329 | fBLMinBin=bin; | |
330 | } | |
46b33a24 | 331 | } else { |
b1c46961 | 332 | // HLTDebug("ignoring value %d (bin %d) for base line calculation " |
333 | // "(current average is %d)", | |
334 | // value, bin, fAverage); | |
46b33a24 | 335 | } |
336 | } | |
337 | return iResult; | |
338 | } | |
339 | ||
340 | Int_t AliHLTTPCPad::SetRawData(Int_t bin, AliHLTTPCSignal_t value) | |
341 | { | |
2a083ac4 | 342 | // see header file for class documentation |
afa4418c | 343 | // printf("Row: %d Pad: %d Time: %d Charge %d", fRowNo, fPadNo, bin, value); |
46b33a24 | 344 | Int_t iResult=0; |
345 | if (fpRawData) { | |
346 | if (bin<fNofBins) { | |
347 | if (value>=0) { | |
348 | if (fpRawData[bin]<0) { | |
349 | AddBaseLineValue(bin, value); | |
350 | fTotal++; | |
351 | } else { | |
352 | // ignore value for average calculation | |
84645eb0 | 353 | HLTWarning("overriding content of bin %d (%d)", bin, fpRawData[bin]); |
46b33a24 | 354 | } |
355 | fpRawData[bin]=value; | |
356 | } else { | |
357 | HLTWarning("ignoring neg. raw data"); | |
358 | } | |
359 | } else { | |
360 | HLTWarning("bin %d out of range (%d)", bin, fNofBins); | |
361 | iResult=-ERANGE; | |
362 | } | |
363 | } else if (fNofBins>0) { | |
364 | HLTError("event cycle not started"); | |
365 | iResult=-EBADF; | |
366 | } | |
367 | return iResult; | |
368 | } | |
369 | ||
370 | Int_t AliHLTTPCPad::Next(Int_t bZeroSuppression) | |
371 | { | |
2a083ac4 | 372 | // see header file for class documentation |
46b33a24 | 373 | if (fpRawData==NULL) return 0; |
374 | Int_t iResult=fReadPos<fNofBins; | |
375 | if (iResult>0 && (iResult=(++fReadPos<fNofBins))>0) { | |
376 | if (bZeroSuppression) { | |
377 | while ((iResult=(fReadPos<fNofBins))>0 && | |
378 | GetCorrectedData(fReadPos)<=0) | |
379 | fReadPos++; | |
380 | } | |
381 | } | |
382 | return iResult; | |
383 | } | |
384 | ||
385 | Int_t AliHLTTPCPad::Rewind(Int_t bZeroSuppression) | |
386 | { | |
2a083ac4 | 387 | // see header file for class documentation |
46b33a24 | 388 | fReadPos=(bZeroSuppression>0?0:fFirstBLBin)-1; |
389 | return Next(bZeroSuppression); | |
390 | } | |
391 | ||
392 | AliHLTTPCSignal_t AliHLTTPCPad::GetRawData(Int_t bin) const | |
393 | { | |
2a083ac4 | 394 | // see header file for class documentation |
46b33a24 | 395 | AliHLTTPCSignal_t data=0; |
396 | if (fpRawData) { | |
397 | if (bin<fNofBins) { | |
398 | data=fpRawData[bin]; | |
399 | } else { | |
400 | HLTWarning("requested bin %d out of range (%d)", bin, fNofBins); | |
401 | } | |
402 | } else if (fNofBins>0) { | |
403 | HLTWarning("data only available within event cycle"); | |
404 | } | |
405 | return data; | |
406 | } | |
407 | ||
408 | AliHLTTPCSignal_t AliHLTTPCPad::GetCorrectedData(Int_t bin) const | |
409 | { | |
2a083ac4 | 410 | // see header file for class documentation |
46b33a24 | 411 | AliHLTTPCSignal_t data=GetRawData(bin)-GetBaseLine(bin); |
5235c3e9 | 412 | AliHLTTPCSignal_t prev=0; |
413 | if (bin>1) prev=GetRawData(bin-1)-GetBaseLine(bin-1); | |
414 | AliHLTTPCSignal_t succ=0; | |
415 | if (bin+1<GetSize()) succ=GetRawData(bin+1)-GetBaseLine(bin+1); | |
416 | if (fThreshold>0) { | |
417 | data-=fThreshold; | |
418 | prev-=fThreshold; | |
419 | succ-=fThreshold; | |
420 | } | |
421 | ||
422 | // case 1: | |
423 | // the signal is below the base-line and threshold | |
46b33a24 | 424 | if (data<0) data=0; |
5235c3e9 | 425 | |
426 | //case 2: | |
427 | // the neighboring bins are both below base-line/threshold | |
428 | // a real signal is always more than one bin wide because of the shaper | |
429 | if (prev<=0 && succ<=0) data=0; | |
430 | ||
431 | // case 3: | |
432 | // the bin is inside the range of ignored bins | |
46b33a24 | 433 | if (bin<fFirstBLBin) data=0; |
84645eb0 | 434 | //HLTDebug("fReadPos=%d data=%d threshold=%d raw data=%d base line=%d", fReadPos, data, fThreshold, GetRawData(bin), GetBaseLine(bin)); |
46b33a24 | 435 | return data; |
436 | } | |
437 | ||
5d2abf3b | 438 | AliHLTTPCSignal_t AliHLTTPCPad::GetBaseLine(Int_t /*bin*/) const //TODO: Why is bin being ignored? |
46b33a24 | 439 | { |
2a083ac4 | 440 | // see header file for class documentation |
84645eb0 | 441 | AliHLTTPCSignal_t val=0; |
442 | if (fAverage>0) { | |
443 | // we take the minumum value as the base line if it doesn't differ from | |
444 | // the average to much | |
84645eb0 | 445 | val=fAverage; |
5235c3e9 | 446 | #ifdef KEEP_NOISE |
2a083ac4 | 447 | const AliHLTTPCSignal_t kMaxDifference=15; |
84645eb0 | 448 | if ((fAverage-fBLMin)<=kMaxDifference) val=fBLMin; |
449 | else val>kMaxDifference?val-=kMaxDifference:0; | |
5235c3e9 | 450 | #endif |
84645eb0 | 451 | } |
452 | if (val<0) { | |
453 | // here we should never get | |
454 | val=0; | |
455 | HLTFatal("wrong base line value"); | |
456 | } | |
457 | return val; | |
46b33a24 | 458 | } |
459 | ||
460 | AliHLTTPCSignal_t AliHLTTPCPad::GetAverage() const | |
461 | { | |
2a083ac4 | 462 | // see header file for class documentation |
46b33a24 | 463 | return fAverage>0?fAverage:0; |
464 | } | |
465 | ||
5235c3e9 | 466 | Float_t AliHLTTPCPad::GetOccupancy() const |
467 | { | |
2a083ac4 | 468 | // see header file for class documentation |
5235c3e9 | 469 | Float_t occupancy=0; |
470 | if (fpRawData && fNofBins>0) { | |
471 | for (Int_t i=fFirstBLBin; i<fNofBins; i++) { | |
472 | if (GetCorrectedData(i)>0) occupancy+=1; | |
473 | } | |
474 | if (fNofBins-fFirstBLBin>0) | |
475 | occupancy/=fNofBins-fFirstBLBin; | |
476 | } | |
477 | return occupancy; | |
478 | } | |
479 | ||
480 | Float_t AliHLTTPCPad::GetAveragedOccupancy() const | |
481 | { | |
2a083ac4 | 482 | // see header file for class documentation |
483 | ||
5235c3e9 | 484 | // history is not yet implemented |
485 | return GetOccupancy(); | |
486 | } | |
a1dbf058 | 487 | void AliHLTTPCPad::PrintRawData() |
488 | { | |
489 | // see header file for class documentation | |
01f43166 | 490 | for(Int_t bin=0;bin<AliHLTTPCTransform::GetNTimeBins();bin++){ |
491 | if(GetDataSignal(bin)>0) | |
a74855c2 | 492 | //This cout should be here since using logging produces output that is much more difficult to read |
493 | cout<<fRowNo<<"\t"<<fPadNo<<"\t"<<bin<<"\t"<<GetDataSignal(bin)<<endl; | |
01f43166 | 494 | } |
01f43166 | 495 | } |
496 | ||
8252a538 | 497 | void AliHLTTPCPad::ClearCandidates(){ |
498 | fClusterCandidates.clear(); | |
499 | fUsedClusterCandidates.clear(); | |
500 | } | |
501 | ||
a1dbf058 | 502 | void AliHLTTPCPad::SetDataToDefault() |
503 | { | |
504 | // see header file for class documentation | |
a74855c2 | 505 | // if(fDataSignals && fSignalPositionArray){ |
afa4418c | 506 | for(Int_t i =0;i<fSizeOfSignalPositionArray;i++){ |
507 | fDataSignals[fSignalPositionArray[i]]=-1; | |
508 | } | |
01f43166 | 509 | fSizeOfSignalPositionArray=0; |
a74855c2 | 510 | fNGoodSignalsSent = 0; |
511 | // } | |
01f43166 | 512 | } |
a1dbf058 | 513 | |
514 | void AliHLTTPCPad::SetDataSignal(Int_t bin,Int_t signal) | |
515 | { | |
516 | // see header file for class documentation | |
01f43166 | 517 | fDataSignals[bin]=signal; |
518 | fSignalPositionArray[fSizeOfSignalPositionArray]=bin; | |
519 | fSizeOfSignalPositionArray++; | |
afa4418c | 520 | } |
521 | ||
a74855c2 | 522 | Bool_t AliHLTTPCPad::GetNextGoodSignal(Int_t &time, Int_t &signal){ |
afa4418c | 523 | if(fNGoodSignalsSent<fSizeOfSignalPositionArray&&fSizeOfSignalPositionArray>0){ |
524 | time = fSignalPositionArray[fNGoodSignalsSent]; | |
525 | signal = GetDataSignal(time); | |
a74855c2 | 526 | |
afa4418c | 527 | fNGoodSignalsSent++; |
528 | return kTRUE; | |
529 | } | |
530 | return kFALSE; | |
01f43166 | 531 | } |
a1dbf058 | 532 | |
a74855c2 | 533 | Bool_t AliHLTTPCPad::GetNextGoodSignal(Int_t &time,Int_t &bunchSize,Int_t dummy){ |
534 | dummy=0;//to get rid of warning until things are cleaned up better | |
535 | if(fNGoodSignalsSent<fSizeOfSignalPositionArray&&fSizeOfSignalPositionArray>0){ | |
536 | time = fSignalPositionArray[fNGoodSignalsSent]; | |
537 | bunchSize=1; | |
538 | fNGoodSignalsSent++; | |
539 | while(fNGoodSignalsSent<fSizeOfSignalPositionArray){ | |
540 | if(fDataSignals[time+bunchSize+1]>0){ | |
541 | bunchSize++; | |
542 | fNGoodSignalsSent++; | |
543 | } | |
544 | else{ | |
545 | break; | |
546 | } | |
547 | } | |
548 | fNGoodSignalsSent++; | |
549 | return kTRUE; | |
550 | } | |
551 | return kFALSE; | |
552 | } | |
553 | ||
a1dbf058 | 554 | Int_t AliHLTTPCPad::GetDataSignal(Int_t bin) const |
555 | { | |
556 | // see header file for class documentation | |
01f43166 | 557 | return fDataSignals[bin]; |
558 | } | |
a1dbf058 | 559 | |
afa4418c | 560 | 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){ |
b1c46961 | 561 | //see headerfile for documentation |
562 | ||
afa4418c | 563 | //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); |
564 | ||
565 | Bool_t useRMS= kFALSE; | |
566 | if(nRMS>0){ | |
567 | useRMS=kTRUE; | |
568 | if(threshold>0){ | |
569 | HLTInfo("Both RMSThreshold and SignalThreshold defined, using RMSThreshold"); | |
570 | } | |
b1c46961 | 571 | } |
afa4418c | 572 | if(threshold<1 && nRMS<=0){ |
b1c46961 | 573 | //setting the data to -1 for this pad |
afa4418c | 574 | HLTInfo("Neither of RMSThreshold and SignalThreshold set, zerosuppression aborted"); |
b1c46961 | 575 | return; |
576 | } | |
b1c46961 | 577 | |
578 | Int_t fThresholdUsed=threshold; | |
579 | ||
580 | Int_t nAdded=0; | |
581 | Int_t sumNAdded=0; | |
582 | fSizeOfSignalPositionArray=0; | |
afa4418c | 583 | if(useRMS){ |
584 | for(Int_t i=beginTime;i<endTime+1;i++){ | |
585 | if(fDataSignals[i]>0){ | |
586 | nAdded++; | |
587 | sumNAdded+=fDataSignals[i]*fDataSignals[i]; | |
588 | } | |
b1c46961 | 589 | } |
590 | } | |
afa4418c | 591 | else if(threshold>0){ |
592 | for(Int_t i=beginTime;i<endTime+1;i++){ | |
b1c46961 | 593 | if(fDataSignals[i]>0){ |
afa4418c | 594 | nAdded++; |
595 | sumNAdded+=fDataSignals[i]; | |
b1c46961 | 596 | } |
597 | } | |
b1c46961 | 598 | } |
afa4418c | 599 | else{ |
600 | HLTFatal("This should never happen because this is tested earlier in the code.(nRMSThreshold<1&&signal-threshold<1)"); | |
601 | } | |
602 | if(nAdded<reqMinPoint){ | |
603 | HLTInfo("Number of signals is less than required, zero suppression aborted"); | |
604 | return; | |
b1c46961 | 605 | } |
afa4418c | 606 | |
607 | if(nAdded==0){ | |
608 | HLTInfo("No signals added for this pad, zerosuppression aborted: pad %d row %d",fPadNo,fRowNo); | |
609 | return; | |
b1c46961 | 610 | } |
a74855c2 | 611 | |
afa4418c | 612 | Double_t averageValue=(Double_t)sumNAdded/nAdded;//true average for threshold approach, average of signals squared for rms approach |
b1c46961 | 613 | |
afa4418c | 614 | if(useRMS){ |
615 | //Calculate the RMS | |
616 | if(averageValue>0){ | |
617 | fThresholdUsed =(Int_t)(TMath::Sqrt(averageValue)*nRMS); | |
618 | } | |
619 | else{ | |
620 | HLTFatal("average value in ZeroSuppression less than 0, investigation needed. This should never happen"); | |
621 | } | |
622 | } | |
623 | else{ | |
624 | fThresholdUsed = (Int_t)(averageValue + threshold); | |
625 | } | |
626 | ||
a74855c2 | 627 | // Do zero suppression on the adc values within [beginTime,endTime](add the good values) |
afa4418c | 628 | for(Int_t i=beginTime;i<endTime;i++){ |
629 | if(fDataSignals[i]>fThresholdUsed){ | |
afa4418c | 630 | Int_t firstSignalTime=i; |
631 | for(Int_t left=1;left<timebinsLeft;left++){//looking 5 to the left of the signal to add tail | |
a74855c2 | 632 | if(fDataSignals[i-left]-averageValue+valueUnderAverage>0 && i-left>=beginTime){ |
afa4418c | 633 | firstSignalTime--; |
b1c46961 | 634 | } |
afa4418c | 635 | else{ |
636 | break; | |
b1c46961 | 637 | } |
638 | } | |
afa4418c | 639 | Int_t lastSignalTime=i; |
a74855c2 | 640 | while(fDataSignals[lastSignalTime+1]>fThresholdUsed && lastSignalTime+1<endTime){ |
641 | lastSignalTime++; | |
642 | } | |
afa4418c | 643 | for(Int_t right=1;right<timebinsRight;right++){//looking 5 to the left of the signal to add tail |
644 | if(fDataSignals[i+right]-averageValue+valueUnderAverage>0&&i+right<endTime){ | |
645 | lastSignalTime++; | |
b1c46961 | 646 | } |
647 | else{ | |
afa4418c | 648 | break; |
649 | } | |
650 | } | |
a74855c2 | 651 | |
afa4418c | 652 | for(Int_t t=firstSignalTime;t<lastSignalTime;t++){ |
afa4418c | 653 | fDataSignals[t]=(AliHLTTPCSignal_t)(fDataSignals[t]-averageValue + valueUnderAverage); |
afa4418c | 654 | fSignalPositionArray[fSizeOfSignalPositionArray]=t; |
655 | fSizeOfSignalPositionArray++; | |
b1c46961 | 656 | } |
afa4418c | 657 | i+=lastSignalTime; |
b1c46961 | 658 | } |
a74855c2 | 659 | } |
660 | //reset the rest of the data | |
661 | Int_t counterSize=fSizeOfSignalPositionArray; | |
662 | ||
663 | for(Int_t d=endTime;d>=beginTime;d--){ | |
664 | if(d==fSignalPositionArray[counterSize-1]&&counterSize-1>=0){ | |
665 | counterSize--; | |
666 | } | |
b1c46961 | 667 | else{ |
a74855c2 | 668 | fDataSignals[d]=-1; |
afa4418c | 669 | } |
b1c46961 | 670 | } |
a74855c2 | 671 | if(fDataSignals[beginTime+1]<1){ |
672 | fDataSignals[beginTime]=0; | |
673 | } | |
b1c46961 | 674 | } |
afa4418c | 675 | |
8252a538 | 676 | void AliHLTTPCPad::AddClusterCandidate(AliHLTTPCClusters candidate){ |
677 | fClusterCandidates.push_back(candidate); | |
678 | fUsedClusterCandidates.push_back(0); | |
679 | } |