2 * @brief The Altro class implements the Altro digital Chain in C++
4 * This Class represents a C++ version of the ALTRO. For a complete Documentation of the Altro
5 * Look at : http://ep-ed-alice-tpc.web.cern.ch/ep-ed-alice-tpc/altro_chip.htm\n
6 * Due to the fact that the real ALTRO constantly samples in between the recorded events,
7 * it has the knowledge on what happened in the period. This affects the BSL1, TCF and BSL2 module.
8 * In the BSL1 the ALTRO follows slow baseline drifts e.g. temperature change, the TCF has a infinite
9 * (IIR Filter) memory of "old samples" i.e. a cluster at the start of a readout cycle will be treated
10 * differently, and the BSL2 has a 8 step pipeline. The ALTRO Class can't emulate this behavior,
11 * since the data is not recorded.\n
13 * @author Roland Bramm
14 * @version $LastChangedRevision: 688 $
15 * @date $LastChangedDate: 2005-12-16 14:07:11 +0100 (Fri, 16 Dec 2005) $
17 * \verbinclude Altro/Altro.C.log
20 /////////////////////////////////////////////////////////////////////////////////////////////////////
21 // Class for emulation of the ALTRO chip (Altro digital Chain) in C++ //
22 // Author: Roland Bramm //
24 // NOTE: This class has been modified to be conform with the coding conventions of the //
25 // ALICE Off-line Project. Keywords for setting the mode of BSC1 were modified //
26 // and are shown in the header file ... //
27 // Stefan Rossegger, 8th february 2008 //
28 /////////////////////////////////////////////////////////////////////////////////////////////////////
30 #include "AliTPCAltroEmulator.h"
32 /** @brief Consturctor of Altro Class
34 * Consturctor of Altro Class, some variables are set.\n
35 * The input Data is altered, so after running the complete emulation you have the
36 * Altro Processed Data in the Channel Pointer.\n
38 * @param timebins an <tt> int </tt> sets the length of the input Data (Channel)
39 * @param Channel an <tt> short* </tt> Pointer to a 1d short Array with the input Data
42 AliTPCAltroEmulator::AliTPCAltroEmulator(int timebins, short* Channel){
44 // Constructor of Altro Class
49 fChannelShort = Channel;
64 AliTPCAltroEmulator::AliTPCAltroEmulator(const AliTPCAltroEmulator &altro){
66 // copy constructor of Altro Class
71 /** @brief Destructor of Altro Class
73 * Destructor of Altro Class\n
75 AliTPCAltroEmulator::~AliTPCAltroEmulator(){
77 // Destructor of Altro Class
80 if(fConfiguredZSU == 1)
84 //_____________________________________________________________________________
85 AliTPCAltroEmulator& AliTPCAltroEmulator::operator = (const AliTPCAltroEmulator &source)
88 // AliTPCAltroEmulator assignment operator
91 if (&source == this) return *this;
92 new (this) AliTPCAltroEmulator(source);
100 /** @brief Configures which modules of the Altro should be on.
102 * Configures which modules of the Altro should be on. Each of the modules
103 * which are configured to be on, have to be configured later before running
106 * @param ONBaselineCorrection1 an <tt> int </tt> Switch (0,1) to turn on the Base Line Correction 1 (BSL1) Module
107 * @param ONTailcancellation an <tt> int </tt> Switch (0,1) to turn on the Tail Cancellation Filter (TCF) Module
108 * @param ONBaselineCorrection2 an <tt> int </tt> Switch (0,1) to turn on the Moving Average Filter (BSL2) Module
109 * @param ONClipping an <tt> int </tt> Switch (0,1) to turn on the Clipping Module. This is not possible in the real Altro, there it is always on.
110 * @param ONZerosuppression an <tt> int </tt> Switch (0,1) to turn on the Zero Suppression (ZSU) Module
111 * @param ONDataFormatting an <tt> int </tt> Switch (0,1) to turn on the Data Formatting on (not implemented)
113 void AliTPCAltroEmulator::ConfigAltro(int ONBaselineCorrection1, int ONTailcancellation, int ONBaselineCorrection2, int ONClipping, int ONZerosuppression, int ONDataFormatting){
115 // Configures which modules of the Altro should be on
117 fOnBSL1 = InRange(ONBaselineCorrection1,0,1,"AliTPCAltroEmulator::ConfigAltro","ONBaselineCorrection1");
118 fOnTCF = InRange(ONTailcancellation,0,1,"AliTPCAltroEmulator::ConfigAltro","ONTailcancellation");
119 fOnBSL2 = InRange(ONBaselineCorrection2,0,1,"AliTPCAltroEmulator::ConfigAltro","ONBaselineCorrection2");
120 fOnClip = InRange(ONClipping,0,1,"AliTPCAltroEmulator::ConfigAltro","ONClipping");
121 fOnZSU = InRange(ONZerosuppression,0,1,"AliTPCAltroEmulator::ConfigAltro","ONZerosuppression");
122 fConfiguredAltro = 1;
125 /** @brief Configures the Base Line Correction 1 (BSL1) Module
127 * Configures the Base Line Correction 1 (BSL1) Module. You dont have to build a proper pedestalMemory
128 * array, a pointer of the correct type is enough, of course you are not allowed to use Basline
129 * Correction Modes which need then the array ...\n
130 * All configurable values are "Range checked" and if out of the Range set to the nearest extreme.
131 * So the Emulation will work, but the result is maybe not the expected one.
133 * @param mode an <tt> int </tt> sets the mode of the Baseline Correction. See the Altro manual for a description
134 * @param ValuePeDestal an <tt> int </tt> this is the baseline of the Channel.
135 * @param PedestalMem an <tt> *int </tt> Pointer to a 1d short Array with the pedestal memory Data
136 * @param polarity an <tt> int </tt> Switch (0,1) for the polarity
138 void AliTPCAltroEmulator::ConfigBaselineCorrection1(int mode, int ValuePeDestal, int *PedestalMem, int polarity){
140 // Configures the Base Line Correction 1 (BSL1) Module
142 fBSL1mode = InRange(mode,0,10,"AliTPCAltroEmulator::ConfigBaselineCorrection1","mode");
143 fBSL1ValuePeDestal = InRange(ValuePeDestal,0,1023,"AliTPCAltroEmulator::BaselineCorrection1","ValuePeDestal");
144 fBSL1PedestalMem = PedestalMem;
145 fBSL1polarity = InRange(polarity,0,1,"AliTPCAltroEmulator::BaselineCorrection1","polarity");
149 /** @brief Configures the Tail Cancellation Filter (TCF) Module
151 * Configures the Tail Cancellation Filter (TCF) Module. You have to set the coefficients in the
153 * To convert from int to float use (int)*(pow(2,-16)-1)
154 * To convert from float to int usw (float)*(pow(2,16)-1)
155 * All configurable values are "Range checked" and if out of the Range set to the nearest extreme.
156 * So the Emulation will work, but the result is maybe not the expected one.
158 * @param K1 an <tt> int </tt> sets the K1 coeeficient of the TCF
159 * @param K2 an <tt> int </tt> sets the K2 coeeficient of the TCF
160 * @param K3 an <tt> int </tt> sets the K3 coeeficient of the TCF
161 * @param L1 an <tt> int </tt> sets the L1 coeeficient of the TCF
162 * @param L2 an <tt> int </tt> sets the L2 coeeficient of the TCF
163 * @param L3 an <tt> int </tt> sets the L3 coeeficient of the TCF
165 void AliTPCAltroEmulator::ConfigTailCancellationFilter(int K1, int K2, int K3, int L1, int L2, int L3){
167 // Configures the Tail Cancellation Filter (TCF) Module
169 // conf from int to fp: (int)*(pow(2,-16)-1)
170 // backway: (float)*(pow(2,16)-1)
171 fTCFK1Int = InRange(K1,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K1");
172 fTCFK2Int = InRange(K2,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K2");
173 fTCFK3Int = InRange(K3,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","K3");
175 fTCFL1Int = InRange(L1,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L1");
176 fTCFL2Int = InRange(L2,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L2");
177 fTCFL3Int = InRange(L3,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L3");
181 /** @brief Configures the Moving Average Filter (BSL2) Module
183 * Configures the Moving Average Filter (BSL2) Module.
184 * All configurable values are "Range checked" and if out of the Range set to the nearest extreme.
185 * So the Emulation will work, but the result is maybe not the expected one.
187 * @param HighThreshold an <tt> int </tt> sets the high Threshold
188 * @param LowThreshold an <tt> int </tt> sets the low Theshold
189 * @param Offset an <tt> int </tt> sets the the offset which is added to the Signal
190 * @param Presamples an <tt> int </tt> sets the number of pre samples excluded from the moving average caclulation
191 * @param Postsamples an <tt> int </tt> sets the number of post samples excluded from the moving average caclulation
193 void AliTPCAltroEmulator::ConfigBaselineCorrection2(int HighThreshold, int LowThreshold, int Offset, int Presamples, int Postsamples){
195 // Configures the Moving Average Filter (BSL2) Module
197 fBSL2HighThreshold = InRange(HighThreshold,0,1023,"AliTPCAltroEmulator::ConfigBaselineCorrection2","HighThreshold");
198 fBSL2LowThreshold = InRange(LowThreshold,0,1023,"AliTPCAltroEmulator::ConfigBaselineCorrection2","LowThreshold");
199 fBSL2Offset = InRange(Offset,0,1023,"AliTPCAltroEmulator::ConfigBaselineCorrection2","Offset");
200 fBSL2Presamples = InRange(Presamples,0,3,"AliTPCAltroEmulator::ConfigBaselineCorrection2","Presamples");
201 fBSL2Postsamples = InRange(Postsamples,0,15,"AliTPCAltroEmulator::ConfigBaselineCorrection2","Postsamples");
205 /** @brief Configures the Zero Suppression Module (ZSU)
207 * Configures the Zero Suppression Module (ZSU).
208 * All configurable values are "Range checked" and if out of the Range set to the nearest extreme.
209 * So the Emulation will work, but the result is maybe not the expected one.
211 * @param Threshold an <tt> int </tt> sets the Threshold
212 * @param MinSamplesaboveThreshold an <tt> int </tt> sets the minimum number of samples which have to be greater than the threshold
213 * @param Presamples an <tt> int </tt> sets the number of pre samples which are kept
214 * @param Postsamples an <tt> int </tt> sets the number of post samples which are kept
216 void AliTPCAltroEmulator::ConfigZerosuppression(int Threshold, int MinSamplesaboveThreshold, int Presamples, int Postsamples){
218 // Configures the Zero Suppression Module (ZSU)
220 fZSUThreshold = InRange(Threshold,0,1023,"AliTPCAltroEmulator::BaselineCorrection1","Threshold");
221 fZSUMinSamplesaboveThreshold = InRange(MinSamplesaboveThreshold,1,3,"AliTPCAltroEmulator::BaselineCorrection1","MinSamplesaboveThreshold");
222 fZSUPresamples = InRange(Presamples,0,3,"AliTPCAltroEmulator::BaselineCorrection1","Presamples");
223 fZSUPostsamples = InRange(Postsamples,0,7,"AliTPCAltroEmulator::BaselineCorrection1","Postsamples");
224 fADCkeep = (short *)calloc(sizeof(short),ftimebins);
226 for(int i = 0; i < ftimebins; i++){
232 /** @brief Prints the set Parameters, if module is configured
234 * Prints the set Parameters, if module is configured.
236 void AliTPCAltroEmulator::PrintParameters(){
238 // Prints the set Parameters, if module is configured
240 cout << "+-------------------------------------------+" << endl;
241 cout << "| Configured Parameters of the Altro Module |" << endl;
242 cout << "+-------------------------------------------+" << endl << endl;
244 cout << "Parameters set in the Altro Modules:" << endl << endl;
245 cout << "ONBaselineCorrection1: " << fOnBSL1 << endl;
246 cout << "ONTailcancellation : " << fOnTCF << endl;
247 cout << "ONBaselineCorrection2: " << fOnBSL2 << endl;
248 cout << "ONClipping : " << fOnClip << endl;
249 cout << "ONZerosuppression : " << fOnZSU << endl << endl << endl;
250 if(fConfiguredBSL1 == 1){
251 cout << "Parameters set in the BSL1 (Baseline Correction 1) Module:" << endl << endl;
252 cout << "mode : " << fBSL1mode << endl;
253 cout << "ValuePeDestal : " << fBSL1ValuePeDestal << endl;
254 cout << "polarity : " << fBSL1ValuePeDestal << endl << endl << endl;
256 cout << "BSL1 (Baseline Correction 1) Module not configured!" << endl << endl << endl;
258 if(fConfiguredTCF == 1){
259 cout << "Parameters set in the TCF (TailCancellation Filter) Module:" << endl << endl;
260 cout << "K1 (int|float) : " << fTCFK1Int << " | " << fTCFK1Int/(float)((1<<16)-1) << endl;
261 cout << "K2 (int|float) : " << fTCFK2Int << " | " << fTCFK2Int/(float)((1<<16)-1) << endl;
262 cout << "K3 (int|float) : " << fTCFK3Int << " | " << fTCFK3Int/(float)((1<<16)-1) << endl;
263 cout << "L1 (int|float) : " << fTCFL1Int << " | " << fTCFL1Int/(float)((1<<16)-1) << endl;
264 cout << "L2 (int|float) : " << fTCFL2Int << " | " << fTCFL2Int/(float)((1<<16)-1) << endl;
265 cout << "L3 (int|float) : " << fTCFL3Int << " | " << fTCFL3Int/(float)((1<<16)-1) << endl << endl << endl;
267 cout << "TCF (TailCancellation Filter) Module not configured!" << endl << endl << endl;
269 if(fConfiguredBSL2 == 1){
270 cout << "Parameters set in the BSL2 (Baseline Correction 2) Module:" << endl << endl;
271 cout << "HighThreshold : " << fBSL2HighThreshold << endl;
272 cout << "LowThreshold : " << fBSL2LowThreshold << endl;
273 cout << "Offset : " << fBSL2Offset << endl;
274 cout << "Presamples : " << fBSL2Presamples << endl;
275 cout << "Postsamples : " << fBSL2Postsamples << endl << endl << endl;
277 cout << "BSL2 (Baseline Correction 2) Module not configured!" << endl << endl << endl;
279 if(fConfiguredZSU == 1){
280 cout << "Parameters set in the ZSU (Zero Suppression Unit) Module:" << endl << endl;
281 cout << "Threshold : " << fZSUThreshold << endl;
282 cout << "MinSampaboveThreshold: " << fZSUMinSamplesaboveThreshold << endl;
283 cout << "Presamples : " << fZSUPresamples << endl;
284 cout << "Postsamples : " << fZSUPostsamples << endl << endl << endl;
286 cout << "ZSU (Zero Suppression Unit) Module not configured!" << endl << endl << endl;
290 /** @brief Runs the emulation of all configured Modules.
292 * Runs the emulation of all configured Modules. This changes then the content of the
295 void AliTPCAltroEmulator::RunEmulation(){
297 // Runs the emulation of all configured Modules.
300 //cout << "AliTPCAltroEmulator::RunEmulation | start" << endl;
301 if(fConfiguredAltro == 0){
302 cout << "ERROR cant run Altro Emulation because not configured" << endl;
306 //cout << "AliTPCAltroEmulator::RunEmulation | start BSL1 on: " << fOnBSL1 << " configures: " << fConfiguredBSL1 << endl;
308 if(fConfiguredBSL1 == 1){
309 BaselineCorrection1(fBSL1mode, fBSL1ValuePeDestal, fBSL1PedestalMem, fBSL1polarity);
311 cout << "ERROR cant run Baseline Correction 1 because not configured" << endl;
316 //cout << "AliTPCAltroEmulator::RunEmulation | start TCF on: " << fOnTCF << " configures: " << fConfiguredTCF << endl;
318 if(fConfiguredTCF == 1){
319 TailCancellationFilterFixedPoint(fTCFK1Int, fTCFK2Int, fTCFK3Int, fTCFL1Int, fTCFL2Int, fTCFL3Int);
321 cout << "ERROR cant run Tail Cancellation Filter because not configured" << endl;
326 //cout << "AliTPCAltroEmulator::RunEmulation | start BSL2 on: " << fOnBSL2 << " configures: " << fConfiguredBSL2 << endl;
328 if(fConfiguredBSL2 == 1){
329 BaselineCorrection2RTL(fBSL2HighThreshold, fBSL2LowThreshold, fBSL2Offset, fBSL2Presamples, fBSL2Postsamples);
331 cout << "ERROR cant run Baseline Correction 2 because not configured" << endl;
335 //cout << "AliTPCAltroEmulator::RunEmulation | start CLIP on: " << fOnClip << endl;
339 //cout << "AliTPCAltroEmulator::RunEmulation | start ZSU on: " << fOnZSU << " configures: " << fConfiguredZSU << endl;
341 if(fConfiguredZSU == 1){
342 Zerosuppression(fZSUThreshold,fZSUMinSamplesaboveThreshold,fZSUPresamples,fZSUPostsamples);
344 cout << "ERROR cant run Zero Suppression Unit because not configured" << endl;
350 void AliTPCAltroEmulator::BaselineCorrection1(int mode, int ValuePeDestal, int *PedestalMem, int polarity){
352 // BaselineCorrection1
356 int fixedPeDestal = 0;
359 for(int i = 0; i < ftimebins; i++){
360 fChannelShort[i] = 1023 - fChannelShort[i];
366 for(int i = 0; i < ftimebins; i++)
367 fChannelShort[i] = fChannelShort[i] - fixedPeDestal;
370 for(int i = 0; i < ftimebins; i++)
371 fChannelShort[i] = fChannelShort[i] - PedestalMem[i];
374 for(int i = 0; i < ftimebins; i++)
375 fChannelShort[i] = fChannelShort[i] - PedestalMem[ fChannelShort[i] ];
378 for(int i = 0; i < ftimebins; i++)
379 fChannelShort[i] = fChannelShort[i] - PedestalMem[ fChannelShort[i] - ValuePeDestal];
382 for(int i = 0; i < ftimebins; i++)
383 fChannelShort[i] = fChannelShort[i] - ValuePeDestal - fixedPeDestal;
386 for(int i = 0; i < ftimebins; i++)
387 fChannelShort[i] = fChannelShort[i] - ValuePeDestal - PedestalMem[i];
390 for(int i = 0; i < ftimebins; i++)
391 fChannelShort[i] = fChannelShort[i] - ValuePeDestal - PedestalMem[ fChannelShort[i] ];
393 case kDINxVPDxFDINxVPD:
394 for(int i = 0; i < ftimebins; i++)
395 fChannelShort[i] = fChannelShort[i] - ValuePeDestal - PedestalMem[ fChannelShort[i] - ValuePeDestal ];
398 for(int i = 0; i < ftimebins; i++)
399 fChannelShort[i] = PedestalMem[ fChannelShort[i] ] - fixedPeDestal;
402 for(int i = 0; i < ftimebins; i++)
403 fChannelShort[i] = PedestalMem[ fChannelShort[i] - ValuePeDestal ] - fixedPeDestal;
406 for(int i = 0; i < ftimebins; i++)
407 fChannelShort[i] = PedestalMem[i] - fixedPeDestal;
412 int AliTPCAltroEmulator::Multiply36(int P, int N){
414 // multiply function to emulate the 36 bit fixed point multiplication of the Altro.
419 temp = (long long)P*(long long)N;
420 vAX = (( Mask(temp,35,18) + ((long long)(-P)<<18) ) + Mask(temp,17,0));
421 if ( Maskandshift(N,17,17) == 1){
422 retval = ((Maskandshift(vAX,35,35)<<17) + Maskandshift(vAX,32,16));
424 retval = Maskandshift(temp,32,16);
428 long long AliTPCAltroEmulator::Mask(long long in, int left, int right){
434 long long length = abs(left - right)+1;
435 pattern = ((1<<length)-1)<<right;
440 long long AliTPCAltroEmulator::Maskandshift(long long in, int left, int right){
446 long long length = abs(left - right)+1;
447 pattern = ((1<<length)-1);
448 retval = (in>>right)&pattern;
452 void AliTPCAltroEmulator::TailCancellationFilterFixedPoint(int K1, int K2, int K3, int L1, int L2, int L3){
454 // TailCancellationFilterFixedPoint
456 int c1n = 0, c2n = 0, c3n = 0;
457 int c1o = 0, c2o = 0, c3o = 0;
462 for(int i = 0; i < ftimebins; i++){
463 din = fChannelShort[i];
466 c1n = Mask( (Mask(din,17,0) + Multiply36(K1,Mask(c1o,17,0)) ) ,17,0);
467 d1 = Mask( (Mask(c1n,17,0) - Multiply36(L1,Mask(c1o,17,0)) ) ,17,0);
468 //d1 = Mask( (Mask(c1n,17,0) + Mask(~Multiply36(L1,Mask(c1o,17,0))+1,17,0) ) ,17,0);
470 c2n = Mask( (Mask(d1 ,17,0) + Multiply36(K2,Mask(c2o,17,0)) ) ,17,0);
471 d2 = Mask( (Mask(c2n,17,0) - Multiply36(L2,Mask(c2o,17,0)) ) ,17,0);
472 //d2 = Mask( (Mask(c2n,17,0) + Mask(~Multiply36(L2,Mask(c2o,17,0))+1,17,0) ) ,17,0);
474 c3n = Mask( (Mask(d2 ,17,0) + Multiply36(K3,Mask(c3o,17,0)) ) ,17,0);
475 dout = Mask( (Mask(c3n,17,0) - Multiply36(L3,Mask(c3o,17,0)) ) ,17,0);
476 //dout = Mask( (Mask(c3n,17,0) + Mask(~Multiply36(L3,Mask(c3o,17,0))+1,17,0) ) ,17,0);
478 if( (Maskandshift(dout,2,2) == 1) || (Maskandshift(dout,1,1) == 1)){
484 dout = ((dout>>3)<<1) + bit;
485 if(Maskandshift(dout,15,15) == 1){
486 //is needed to get the correct coding when getting negative results
487 dout = -Mask((-Mask(dout,9,0)),9,0);
489 dout = Mask(dout,9,0);
492 fChannelShort[i] = (short) dout;
499 void AliTPCAltroEmulator::BaselineCorrection2RTL(int HighThreshold, int LowThreshold, int Offset, int Presamples, int Postsamples){
501 // BaselineCorrection2RTL
504 //cout << "Altro::BaselineCorrection2RTL | HighThreshold: " << HighThreshold << " LowThreshold: " << LowThreshold << " Offset: " << Offset << " Presamples: " << Presamples << " Postsamples: " << Postsamples << endl;
505 //more or less direct "translation" of the hdl code.
509 int edges[6]; // = Postsamples*4 + Presamples;
511 int thrlo = LowThreshold;//called thr_mau[19] ...
512 int thrhi = HighThreshold;
515 int fOld[4]; //flag pipe
516 int fNew[4]; //flag pipe
517 int dOld[4]; //data pipe
518 int dNew[4]; //data pipe
521 int pstscnt; // Counter for Postsamples
522 int zOld[9]; // Filter stages
523 int zNew[9]; // Filter stages
524 int zxOld; //Accumulator stage
525 int zxNew; //Accumulator stage
526 int valcntOld; //Valid sample counter
527 int valcntNew = 0; //Valid sample counter
529 int valid; //Valid flag
530 int fx; //postsample flag
531 //int s07; // differentiator result
532 int s8; // Acc + Diff result
534 //int bsth; //baseline threshold
535 //int din_p; //Data input strictly positive
537 //int dx_bsls; // dx -bsl
538 //int dx_clip; // dxbsl clipped
542 for(int i = 0; i < 9 ; i++)
544 for(int i = 0; i < 4 ; i++){
553 for(int i = 0; i < 2 ; i++){
554 edges[i] = (Presamples&(1<<i))>>i;
556 for(int i = 0; i < 4 ; i++){
557 edges[(3-i)+2] = (Postsamples&(1<<i))>>i;
560 for(int i = 0; i < 6 ; i++)
561 cout << edges[i] << ":";
562 cout << " Presamples: " << Presamples << " Postsamples: " << Postsamples << endl;*/
565 //cout << "AliTPCAltroEmulator::BaselineCorrection2_RTL | starting Loop" << endl;
566 for(int timebin = -12; timebin < ftimebins+10; timebin++){
567 //cout << "AliTPCAltroEmulator::BaselineCorrection2_RTL | in Loop timebin: " << timebin << endl;
568 din = GetElement(fChannelShort,timebin);
570 s8 = zxOld + (zOld[8] - zOld[0]);
577 //assign flag = (din_p > thrhi) | (thrlo > din_p); // Signal samples between thresholds
578 if( (din <= (bsl + thrhi)) && (din >= (bsl - thrlo)) )
595 if( (fOld[3] == 1) || ( (flag == 1) && ( (edges[0] == 1) || (edges[1] == 1) ) ) ) //f[2] = f[3] | (flag&(edges[0]|edges[1]));
600 if( (fOld[2] == 1) || ( (edges[1] == 1) && (flag == 1) ) ) // f[1] = f[2] | (edges[1] & flag);
605 if( ( (fOld[1] == 1) || ( (flag == 1) && (edges[0] == 1) && (edges[1] == 1) ) || (fx==1) ) && (valid==1) ) // f[0] = (f[1] | (edges[1] & edges[0] & flag) | fx) & valid;
611 for(int i = 0; i < 3; i++)
615 if( (fOld[1]==1) && (fOld[2]==0) )
616 pstscnt = Postsamples;
622 valcntNew = ++valcntOld;
625 for(int i = 0; i < 8; i++)
630 for(int i = 0; i < 9; i++)
633 dout = dxOld - (bsl - offset);
637 SetElement(fChannelShort,timebin-5,(short)dout);
639 for(int i = 0; i < 9 ; i++)
642 for(int i = 0; i < 4 ; i++){
647 valcntOld = valcntNew;
651 void AliTPCAltroEmulator::Clipping(){
653 // implement if no BC2 clipping has to run
655 for(int i = 0; i < ftimebins; i++){
656 if(fChannelShort[i] < 0)
657 fChannelShort[i] = 0;
661 void AliTPCAltroEmulator::Zerosuppression(int Threshold, int MinSamplesaboveThreshold, int Presamples, int Postsamples){
663 // add again altro feature
666 //TODO: Implement "Altro zsu merging"
667 //int Postsamplecounter = 0;
668 //int setPostsample = 0;
669 for(int i = 0; i < ftimebins; i++){
670 if(fChannelShort[i] >= Threshold){
675 int startofclustersequence = -1;
676 int endofClustersInSequence = -1;
678 for(int i = 0; i < ftimebins; i++){
679 if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i-1) == 0) ){
680 startofclustersequence = i;
682 if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i+1) == 0) ){
683 endofClustersInSequence = i;
685 //cout << i << " startofclustersequence: " << startofclustersequence << " endofClustersInSequence: " << endofClustersInSequence;
686 if( (startofclustersequence != -1) && (endofClustersInSequence != -1) ){
687 //cout << " found! " << (endofClustersInSequence - startofclustersequence + 1);
688 if ( (endofClustersInSequence - startofclustersequence + 1) < MinSamplesaboveThreshold ){
689 for(int j = startofclustersequence; j <= endofClustersInSequence ; j++){
693 startofclustersequence = -1;
694 endofClustersInSequence = -1;
699 /*for(int i = 0; i < ftimebins; i++){
700 if( (GetElement(fADCkeep,i-1) == 1) && (GetElement(fADCkeep,i) == 0) && (GetElement(fADCkeep,i+1) == 1) ){
701 SetElement(fADCkeep,i,1);
705 for(int i = 0; i < ftimebins; i++){
706 if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i-1) == 0) ){
707 for(int j = i-Presamples ; j <= i; j++){
708 SetElement(fADCkeep,j,1);
712 for(int i = ftimebins; i >= 0; i--){
713 if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i+1) == 0) ){
714 for(int j = i ; j <= i+Postsamples; j++){
715 SetElement(fADCkeep,j,1);
719 /*cout << " Postsamplecounter: " << Postsamplecounter;
720 for(int j = i+1 ; j <= i+Postsamples; j++){
721 SetElement(fADCkeep,j,1);
726 cout << i << " ADCK: " << GetElement(fADCkeep,i);
727 cout << " Postsam: " << Postsamplecounter << " ADCK: " << GetElement(fADCkeep,i);*/
729 for(int i = 0; i < ftimebins; i++){
730 if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i+1) == 0) && ( (GetElement(fADCkeep,i+3) == 1) || (GetElement(fADCkeep,i+2) == 1) ) ){
731 SetElement(fADCkeep,i+1,1);
732 SetElement(fADCkeep,i+2,1);
737 /** @brief formats the data like the ALTRO. Result is a 64 bit array
739 * formats the data like the ALTRO. Result is a 64 bit array
743 void AliTPCAltroEmulator::DataFormater(){
745 // formats the data like the ALTRO. Result is a 64 bit array
752 /** @brief calculates the compression out of the bitmask
754 * calculates the compression out of the bitmask with the set adc values
756 * @return \c float consisting of the compression factor
758 float AliTPCAltroEmulator::CalculateCompression(){
760 // calculates the compression out of the bitmask
763 // calculation is based on altro 10 bit words ..
769 for(int i = 0; i < ftimebins; i++){
770 if(fADCkeep[i] == 1){
773 if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i+1) == 0) ){
777 data = sample + cluster*2;
778 data = data + data%4 + 4;
780 retval = ftimebins / (float)data;//num of timebins is equal to max number of samples
787 short AliTPCAltroEmulator::GetElement(short* Array,int index){
793 else if(index >= ftimebins)
799 void AliTPCAltroEmulator::SetElement(short* Array,int index,short value){
805 else if(index >= ftimebins)
808 Array[index] = value;
811 int AliTPCAltroEmulator::InBand(int ADC,int bsl, int LowThreshold, int HighThreshold){
815 int fLow = bsl - LowThreshold;
816 int fHigh = bsl + HighThreshold;
817 if( (ADC <= fHigh) && (ADC >= fLow) )
823 int AliTPCAltroEmulator::InRange(int parameter,int Low,int High,char *Module,char *ParameterName){
830 if(parameter > High){
831 sprintf(out,"Error | %s | Parameter %s is to big, has to be %d <= %s <= %d, is %d, now set to %d",Module,ParameterName,Low,ParameterName,High,parameter,High);
834 }else if(parameter < Low){
835 sprintf(out,"Error | %s | Parameter %s is to small, has to be %d <= %s <= %d, is %d, now set to %d",Module,ParameterName,Low,ParameterName,High,parameter,Low);
844 short AliTPCAltroEmulator::GetShortChannel(int i){
848 return GetElement(fChannelShort,i);
851 short AliTPCAltroEmulator::GetKeepChannel(int i){
855 return GetElement(fADCkeep,i);