StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Altro.cxx
1 
20 #include "Altro.h"
21 
31 Altro::Altro(int timebins, short* Channel){
32  ftimebins = timebins;
33 
34  channelShort = Channel;
35 
36  fOnBSL1 = 0;
37  fOnTCF = 0;
38  fOnBSL2 = 0;
39  fOnClip = 0;
40  fOnZSU = 0;
41 
42  fConfiguredAltro = 0;
43  fConfiguredBSL1 = 0;
44  fConfiguredTCF = 0;
45  fConfiguredBSL2 = 0;
46  fConfiguredZSU = 0;
47  ADCkeep = 0;
48 }
49 
55  if(fConfiguredZSU == 1)
56 //VP delete ADCkeep;
57  free(ADCkeep);
58 }
59 
72 void Altro::ConfigAltro(int ONBaselineCorrection1, int ONTailcancellation, int ONBaselineCorrection2, int ONClipping, int ONZerosuppression){
73  fOnBSL1 = inRange(ONBaselineCorrection1,0,1,"Altro::ConfigAltro","ONBaselineCorrection1");
74  fOnTCF = inRange(ONTailcancellation,0,1,"Altro::ConfigAltro","ONTailcancellation");
75  fOnBSL2 = inRange(ONBaselineCorrection2,0,1,"Altro::ConfigAltro","ONBaselineCorrection2");
76  fOnClip = inRange(ONClipping,0,1,"Altro::ConfigAltro","ONClipping");
77  fOnZSU = inRange(ONZerosuppression,0,1,"Altro::ConfigAltro","ONZerosuppression");
78  fConfiguredAltro = 1;
79 }
80 
94 void Altro::ConfigBaselineCorrection_1(int mode, int ValuePeDestal, int *PedestalMem, int polarity){
95  fBSL1mode = inRange(mode,0,10,"Altro::ConfigBaselineCorrection_1","mode");
96  fBSL1ValuePeDestal = inRange(ValuePeDestal,0,1023,"Altro::BaselineCorrection_1","ValuePeDestal");
97  fBSL1PedestalMem = PedestalMem;
98  fBSL1polarity = inRange(polarity,0,1,"Altro::BaselineCorrection_1","polarity");
99  fConfiguredBSL1 = 1;
100 }
101 
118 void Altro::ConfigTailCancellationFilter(int K1, int K2, int K3, int L1, int L2, int L3){
119  // conf from int to fp:
120  //(int)*(pow(2,-16)-1)
121  //backway.
122  //float*(pow(2,16)-1)
123  fTCFK1Int = inRange(K1,0,65535,"Altro::ConfigTailCancellationFilter","K1");
124  fTCFK2Int = inRange(K2,0,65535,"Altro::ConfigTailCancellationFilter","K2");
125  fTCFK3Int = inRange(K3,0,65535,"Altro::ConfigTailCancellationFilter","K3");
126 
127  fTCFL1Int = inRange(L1,0,65535,"Altro::ConfigTailCancellationFilter","L1");
128  fTCFL2Int = inRange(L2,0,65535,"Altro::ConfigTailCancellationFilter","L2");
129  fTCFL3Int = inRange(L3,0,65535,"Altro::ConfigTailCancellationFilter","L3");
130  fConfiguredTCF = 1;
131 }
132 
145 void Altro::ConfigBaselineCorrection_2(int HighThreshold, int LowThreshold, int Offset, int Presamples, int Postsamples){
146  fBSL2HighThreshold = inRange(HighThreshold,0,1023,"Altro::ConfigBaselineCorrection_2","HighThreshold");
147  fBSL2LowThreshold = inRange(LowThreshold,0,1023,"Altro::ConfigBaselineCorrection_2","LowThreshold");
148  fBSL2Offset = inRange(Offset,0,1023,"Altro::ConfigBaselineCorrection_2","Offset");
149  fBSL2Presamples = inRange(Presamples,0,3,"Altro::ConfigBaselineCorrection_2","Presamples");
150  fBSL2Postsamples = inRange(Postsamples,0,15,"Altro::ConfigBaselineCorrection_2","Postsamples");
151  fConfiguredBSL2 = 1;
152 }
153 
165 void Altro::ConfigZerosuppression(int Threshold, int MinSamplesaboveThreshold, int Presamples, int Postsamples){
166  fZSUThreshold = inRange(Threshold,0,1023,"Altro::BaselineCorrection_1","Threshold");
167  fZSUMinSamplesaboveThreshold = inRange(MinSamplesaboveThreshold,1,3,"Altro::BaselineCorrection_1","MinSamplesaboveThreshold");
168  fZSUPresamples = inRange(Presamples,0,3,"Altro::BaselineCorrection_1","Presamples");
169  fZSUPostsamples = inRange(Postsamples,0,7,"Altro::BaselineCorrection_1","Postsamples");
170  ADCkeep = (short *)calloc(sizeof(short),ftimebins);
171 
172 // for(int i = 0; i < ftimebins; i++){
173 // ADCkeep[i] = 0;
174 // }
175  fConfiguredZSU = 1;
176 }
177 
183  cout << "+-------------------------------------------+" << endl;
184  cout << "| Configured Parameters of the Altro Module |" << endl;
185  cout << "+-------------------------------------------+" << endl << endl;
186 
187  cout << "Parameters set in the Altro Modules:" << endl << endl;
188  cout << "ONBaselineCorrection1: " << fOnBSL1 << endl;
189  cout << "ONTailcancellation : " << fOnTCF << endl;
190  cout << "ONBaselineCorrection2: " << fOnBSL2 << endl;
191  cout << "ONClipping : " << fOnClip << endl;
192  cout << "ONZerosuppression : " << fOnZSU << endl << endl << endl;
193  if(fConfiguredBSL1 == 1){
194  cout << "Parameters set in the BSL1 (Baseline Correction 1) Module:" << endl << endl;
195  cout << "mode : " << fBSL1mode << endl;
196  cout << "ValuePeDestal : " << fBSL1ValuePeDestal << endl;
197  cout << "polarity : " << fBSL1ValuePeDestal << endl << endl << endl;
198  }else{
199  cout << "BSL1 (Baseline Correction 1) Module not configured!" << endl << endl << endl;
200  }
201  if(fConfiguredTCF == 1){
202  cout << "Parameters set in the TCF (TailCancellation Filter) Module:" << endl << endl;
203  cout << "K1 (int|float) : " << fTCFK1Int << " | " << fTCFK1Int/(float)((1<<16)-1) << endl;
204  cout << "K2 (int|float) : " << fTCFK2Int << " | " << fTCFK2Int/(float)((1<<16)-1) << endl;
205  cout << "K3 (int|float) : " << fTCFK3Int << " | " << fTCFK3Int/(float)((1<<16)-1) << endl;
206  cout << "L1 (int|float) : " << fTCFL1Int << " | " << fTCFL1Int/(float)((1<<16)-1) << endl;
207  cout << "L2 (int|float) : " << fTCFL2Int << " | " << fTCFL2Int/(float)((1<<16)-1) << endl;
208  cout << "L3 (int|float) : " << fTCFL3Int << " | " << fTCFL3Int/(float)((1<<16)-1) << endl << endl << endl;
209  }else{
210  cout << "TCF (TailCancellation Filter) Module not configured!" << endl << endl << endl;
211  }
212  if(fConfiguredBSL2 == 1){
213  cout << "Parameters set in the BSL2 (Baseline Correction 2) Module:" << endl << endl;
214  cout << "HighThreshold : " << fBSL2HighThreshold << endl;
215  cout << "LowThreshold : " << fBSL2LowThreshold << endl;
216  cout << "Offset : " << fBSL2Offset << endl;
217  cout << "Presamples : " << fBSL2Presamples << endl;
218  cout << "Postsamples : " << fBSL2Postsamples << endl << endl << endl;
219  }else{
220  cout << "BSL2 (Baseline Correction 2) Module not configured!" << endl << endl << endl;
221  }
222  if(fConfiguredZSU == 1){
223  cout << "Parameters set in the ZSU (Zero Suppression Unit) Module:" << endl << endl;
224  cout << "Threshold : " << fZSUThreshold << endl;
225  cout << "MinSampaboveThreshold: " << fZSUMinSamplesaboveThreshold << endl;
226  cout << "Presamples : " << fZSUPresamples << endl;
227  cout << "Postsamples : " << fZSUPostsamples << endl << endl << endl;
228  }else{
229  cout << "ZSU (Zero Suppression Unit) Module not configured!" << endl << endl << endl;
230  }
231 }
232 
239  //cout << "Altro::RunEmulation | start" << endl;
240  if(fConfiguredAltro == 0){
241  cout << "ERROR cant run Altro Emulation because not configured" << endl;
242  return;
243  }
244  for(int i = 0; i < ftimebins; i++){
245  ADCkeep[i] = 0;
246  }
247 
248  //cout << "Altro::RunEmulation | start BSL1 on: " << fOnBSL1 << " configures: " << fConfiguredBSL1 << endl;
249  if(fOnBSL1 == 1){
250  if(fConfiguredBSL1 == 1){
251  BaselineCorrection_1(fBSL1mode, fBSL1ValuePeDestal, fBSL1PedestalMem, fBSL1polarity);
252  }else{
253  cout << "ERROR cant run Baseline Correction 1 because not configured" << endl;
254  return;
255  }
256  }
257 
258  //cout << "Altro::RunEmulation | start TCF on: " << fOnTCF << " configures: " << fConfiguredTCF << endl;
259  if(fOnTCF == 1){
260  if(fConfiguredTCF == 1){
261  TailCancellationFilter_FixedPoint(fTCFK1Int, fTCFK2Int, fTCFK3Int, fTCFL1Int, fTCFL2Int, fTCFL3Int);
262  }else{
263  cout << "ERROR cant run Tail Cancellation Filter because not configured" << endl;
264  return;
265  }
266  }
267 
268  //cout << "Altro::RunEmulation | start BSL2 on: " << fOnBSL2 << " configures: " << fConfiguredBSL2 << endl;
269  if(fOnBSL2 == 1){
270  if(fConfiguredBSL2 == 1){
271  BaselineCorrection_2_RTL(fBSL2HighThreshold, fBSL2LowThreshold, fBSL2Offset, fBSL2Presamples, fBSL2Postsamples);
272  }else{
273  cout << "ERROR cant run Baseline Correction 2 because not configured" << endl;
274  return;
275  }
276  }
277  //cout << "Altro::RunEmulation | start CLIP on: " << fOnClip << endl;
278  if(fOnClip == 1){
279  Clipping();
280  }
281  //cout << "Altro::RunEmulation | start ZSU on: " << fOnZSU << " configures: " << fConfiguredZSU << endl;
282  if(fOnZSU == 1){
283  if(fConfiguredZSU == 1){
284  Zerosuppression(fZSUThreshold,fZSUMinSamplesaboveThreshold,fZSUPresamples,fZSUPostsamples);
285  }else{
286  cout << "ERROR cant run Zero Suppression Unit because not configured" << endl;
287  return;
288  }
289  }
290  for(int i = 0; i < ftimebins; i++){
291  if (! ADCkeep[i]) channelShort[i] = 0;
292  }
293 }
294 
295 void Altro::BaselineCorrection_1(int mode, int ValuePeDestal, int *PedestalMem, int polarity){
296  //VPD == 0 !!
297  int FixedPeDestal = 0;
298 
299  if(polarity ==1){
300  for(int i = 0; i < ftimebins; i++){
301  channelShort[i] = 1023 - channelShort[i];
302  }
303  }
304 
305  switch(mode) {
306  case DIN_FPD:
307  for(int i = 0; i < ftimebins; i++)
308  channelShort[i] = channelShort[i] - FixedPeDestal;
309  break;
310  case DIN_FT:
311  for(int i = 0; i < ftimebins; i++)
312  channelShort[i] = channelShort[i] - PedestalMem[i];
313  break;
314  case DIN_FDIN:
315  for(int i = 0; i < ftimebins; i++)
316  channelShort[i] = channelShort[i] - PedestalMem[ channelShort[i] ];
317  break;
318  case DIN_FDIN_VPD:
319  for(int i = 0; i < ftimebins; i++)
320  channelShort[i] = channelShort[i] - PedestalMem[ channelShort[i] - ValuePeDestal];
321  break;
322  case DIN_VPD_FPD:
323  for(int i = 0; i < ftimebins; i++)
324  channelShort[i] = channelShort[i] - ValuePeDestal - FixedPeDestal;
325  break;
326  case DIN_VPD_FT:
327  for(int i = 0; i < ftimebins; i++)
328  channelShort[i] = channelShort[i] - ValuePeDestal - PedestalMem[i];
329  break;
330  case DIN_VPD_FDIN:
331  for(int i = 0; i < ftimebins; i++)
332  channelShort[i] = channelShort[i] - ValuePeDestal - PedestalMem[ channelShort[i] ];
333  break;
334  case DIN_VPD_FDIN_VPD:
335  for(int i = 0; i < ftimebins; i++)
336  channelShort[i] = channelShort[i] - ValuePeDestal - PedestalMem[ channelShort[i] - ValuePeDestal ];
337  break;
338  case FDIN_FPD:
339  for(int i = 0; i < ftimebins; i++)
340  channelShort[i] = PedestalMem[ channelShort[i] ] - FixedPeDestal;
341  break;
342  case FDIN_VPD_FPD:
343  for(int i = 0; i < ftimebins; i++)
344  channelShort[i] = PedestalMem[ channelShort[i] - ValuePeDestal ] - FixedPeDestal;
345  break;
346  case FT_FPD:
347  for(int i = 0; i < ftimebins; i++)
348  channelShort[i] = PedestalMem[i] - FixedPeDestal;
349  break;
350  }
351 }
352 
353 int Altro::multiply36(int P, int N){
354  //multiply function to emulate the 36 bit fixed point multiplication of the Altro.
355  long long retval =0;
356  long long temp = 0;
357  long long AX = 0;
358  temp = (long long)P*(long long)N;
359  AX = (( mask(temp,35,18) + ((long long)(-P)<<18) ) + mask(temp,17,0));
360  if ( maskandshift(N,17,17) == 1){
361  retval = ((maskandshift(AX,35,35)<<17) + maskandshift(AX,32,16));
362  }else{
363  retval = maskandshift(temp,32,16);
364  }
365  return retval;
366 }
367 long long Altro::mask(long long in, int left, int right){
368  long long retval;
369  long long pattern;
370  long long length = abs(left - right)+1;
371  pattern = ((1<<length)-1)<<right;
372  retval = in&pattern;
373  return retval;
374 }
375 
376 long long Altro::maskandshift(long long in, int left, int right){
377  long long retval;
378  long long pattern;
379  long long length = abs(left - right)+1;
380  pattern = ((1<<length)-1);
381  retval = (in>>right)&pattern;
382  return retval;
383 }
384 
385 void Altro::TailCancellationFilter_FixedPoint(int K1, int K2, int K3, int L1, int L2, int L3){
386  int c1n = 0, c2n = 0, c3n = 0;
387  int c1o = 0, c2o = 0, c3o = 0;
388  int d1 = 0, d2 = 0;
389  int dout = 0;
390  int din = 0;
391  int bit = 0;
392  for(int i = 0; i < ftimebins; i++){
393  din = channelShort[i];
394 
395  din = (din<<2);
396  c1n = mask( (mask(din,17,0) + multiply36(K1,mask(c1o,17,0)) ) ,17,0);
397  d1 = mask( (mask(c1n,17,0) - multiply36(L1,mask(c1o,17,0)) ) ,17,0);
398  //d1 = mask( (mask(c1n,17,0) + mask(~multiply36(L1,mask(c1o,17,0))+1,17,0) ) ,17,0);
399 
400  c2n = mask( (mask(d1 ,17,0) + multiply36(K2,mask(c2o,17,0)) ) ,17,0);
401  d2 = mask( (mask(c2n,17,0) - multiply36(L2,mask(c2o,17,0)) ) ,17,0);
402  //d2 = mask( (mask(c2n,17,0) + mask(~multiply36(L2,mask(c2o,17,0))+1,17,0) ) ,17,0);
403 
404  c3n = mask( (mask(d2 ,17,0) + multiply36(K3,mask(c3o,17,0)) ) ,17,0);
405  dout = mask( (mask(c3n,17,0) - multiply36(L3,mask(c3o,17,0)) ) ,17,0);
406  //dout = mask( (mask(c3n,17,0) + mask(~multiply36(L3,mask(c3o,17,0))+1,17,0) ) ,17,0);
407 
408  if( (maskandshift(dout,2,2) == 1) || (maskandshift(dout,1,1) == 1)){
409  bit = 1;
410  }else{
411  bit = 0;
412  }
413 
414  dout = ((dout>>3)<<1) + bit;
415  if(maskandshift(dout,15,15) == 1){
416  //is needed to get the correct coding when getting negative results
417  dout = -mask((-mask(dout,9,0)),9,0);
418  }else{
419  dout = mask(dout,9,0);
420  }
421 
422  channelShort[i] = (short) dout;
423  c1o = c1n;
424  c2o = c2n;
425  c3o = c3n;
426  }
427 }
428 
429 void Altro::BaselineCorrection_2_RTL(int HighThreshold, int LowThreshold, int Offset, int Presamples, int Postsamples){
430  //cout << "Altro::BaselineCorrection_2_RTL | HighThreshold: " << HighThreshold << " LowThreshold: " << LowThreshold << " Offset: " << Offset << " Presamples: " << Presamples << " Postsamples: " << Postsamples << endl;
431  //more or less direct "translation" of the hdl code.
432  //Input signals
433  int din;
434  int dout;
435  int edges[6]; // = Postsamples*4 + Presamples;
436  int offset = Offset;
437  int thrlo = LowThreshold;//called thr_mau[19] ...
438  int thrhi = HighThreshold;
439 
440  // Variables
441  int fOld[4]; //flag pipe
442  int fNew[4]; //flag pipe
443  int dOld[4]; //data pipe
444  int dNew[4]; //data pipe
445  int dxOld;
446  int dxNew;
447  int pstscnt; // Counter for Postsamples
448  int zOld[9]; // Filter stages
449  int zNew[9]; // Filter stages
450  int zxOld; //Accumulator stage
451  int zxNew; //Accumulator stage
452  int valcntOld; //Valid sample counter
453  int valcntNew = 0; //Valid sample counter
454 
455  int valid; //Valid flag
456  int fx; //postsample flag
457  //int s07; // differentiator result
458  int s8; // Acc + Diff result
459  int flag;
460  //int bsth; //baseline threshold
461  //int din_p; //Data input strictly positive
462  int bsl;
463  //int dx_bsls; // dx -bsl
464  //int dx_clip; // dxbsl clipped
465  //int bsl_of = 0;
466 
467  //initialisation
468  for(int i = 0; i < 9 ; i++)
469  zOld[i] = 0;
470  for(int i = 0; i < 4 ; i++){
471  fOld[i] = 0;
472  dOld[i] = 0;
473  }
474  dxOld= 0;
475  pstscnt = 0;
476  zxOld = 0;
477  valcntOld = 0;
478  valid = 0;
479  for(int i = 0; i < 2 ; i++){
480  edges[i] = (Presamples&(1<<i))>>i;
481  }
482  for(int i = 0; i < 4 ; i++){
483  edges[(3-i)+2] = (Postsamples&(1<<i))>>i;
484  }
485  /*cout << "edges :";
486  for(int i = 0; i < 6 ; i++)
487  cout << edges[i] << ":";
488  cout << " Presamples: " << Presamples << " Postsamples: " << Postsamples << endl;*/
489 
490  //Loop
491  //cout << "Altro::BaselineCorrection_2_RTL | starting Loop" << endl;
492  for(int timebin = -12; timebin < ftimebins+10; timebin++){
493  //cout << "Altro::BaselineCorrection_2_RTL | in Loop timebin: " << timebin << endl;
494  din = getElement(channelShort,timebin);
495 
496  s8 = zxOld + (zOld[8] - zOld[0]);
497 
498  if(valid == 1)
499  bsl = s8>>3;// ...
500  else
501  bsl = 0;
502 
503  //assign flag = (din_p > thrhi) | (thrlo > din_p); // Signal samples between thresholds
504  if( (din <= (bsl + thrhi)) && (din >= (bsl - thrlo)) )
505  flag = 0;
506  else
507  flag = 1;
508 
509  if(pstscnt == 0)
510  fx = 0;
511  else
512  fx = 1;
513 
514  if(valcntOld >= 12)
515  valid = 1;
516  else
517  valid = 0;
518 
519  fNew[3] = flag;
520 
521  if( (fOld[3] == 1) || ( (flag == 1) && ( (edges[0] == 1) || (edges[1] == 1) ) ) ) //f[2] = f[3] | (flag&(edges[0]|edges[1]));
522  fNew[2] = 1;
523  else
524  fNew[2] = 0;
525 
526  if( (fOld[2] == 1) || ( (edges[1] == 1) && (flag == 1) ) ) // f[1] = f[2] | (edges[1] & flag);
527  fNew[1] = 1;
528  else
529  fNew[1] = 0;
530 
531  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;
532  fNew[0] = 1;
533  else
534  fNew[0] = 0;
535 
536  dxNew = dOld[0];
537  for(int i = 0; i < 3; i++)
538  dNew[i] = dOld[i+1];
539  dNew[3] = din;
540 
541  if( (fOld[1]==1) && (fOld[2]==0) )
542  pstscnt = Postsamples;
543  else if(fx == 1)
544  pstscnt--;
545 
546  if(fOld[0] == 0){
547  if(valid == 0)
548  valcntNew = ++valcntOld;
549 
550  zxNew = s8;
551  for(int i = 0; i < 8; i++)
552  zNew[i] = zOld[i+1];
553  zNew[8] = dOld[0];
554  }else{
555  zxNew = zxOld;
556  for(int i = 0; i < 9; i++)
557  zNew[i] = zOld[i];
558  }
559  dout = dxOld - (bsl - offset);
560  //if(dout <0)
561  // dout = 0;
562 
563  setElement(channelShort,timebin-5,(short)dout);
564  //sim clockschange
565  for(int i = 0; i < 9 ; i++)
566  zOld[i] = zNew[i];
567  zxOld = zxNew;
568  for(int i = 0; i < 4 ; i++){
569  fOld[i] = fNew[i];
570  dOld[i] = dNew[i];
571  }
572  dxOld = dxNew;
573  valcntOld = valcntNew;
574  }
575 }
576 
577 void Altro::Clipping(){ // implement if no BC2 clipping has to run
578  for(int i = 0; i < ftimebins; i++){
579  if(channelShort[i] < 0)
580  channelShort[i] = 0;
581  }
582 }
583 
584 void Altro::Zerosuppression(int Threshold, int MinSamplesaboveThreshold, int Presamples, int Postsamples){ // add again altro feature
585  //TODO: Implement "Altro Bug"
586  //int Postsamplecounter = 0;
587  //int setPostsample = 0;
588  for(int i = 0; i < ftimebins; i++){
589  if(channelShort[i] >= Threshold){
590  ADCkeep[i] = 1;
591  }
592  }
593 
594  int startofclustersequence = -1;
595  int endofClustersInSequence = -1;
596 
597  for(int i = 0; i < ftimebins; i++){
598  if( (ADCkeep[i] == 1) && (getElement(ADCkeep,i-1) == 0) ){
599  startofclustersequence = i;
600  }
601  if( (ADCkeep[i] == 1) && (getElement(ADCkeep,i+1) == 0) ){
602  endofClustersInSequence = i;
603  }
604  //cout << i << " startofclustersequence: " << startofclustersequence << " endofClustersInSequence: " << endofClustersInSequence;
605  if( (startofclustersequence != -1) && (endofClustersInSequence != -1) ){
606  //cout << " found! " << (endofClustersInSequence - startofclustersequence + 1);
607  if ( (endofClustersInSequence - startofclustersequence + 1) < MinSamplesaboveThreshold ){
608  for(int j = startofclustersequence; j <= endofClustersInSequence ; j++){
609  ADCkeep[j] = 0;
610  }
611  }
612  startofclustersequence = -1;
613  endofClustersInSequence = -1;
614  }
615  //cout << endl;
616  }
617 
618  /*for(int i = 0; i < ftimebins; i++){
619  if( (getElement(ADCkeep,i-1) == 1) && (getElement(ADCkeep,i) == 0) && (getElement(ADCkeep,i+1) == 1) ){
620  setElement(ADCkeep,i,1);
621  }
622  }*/
623 
624  for(int i = 0; i < ftimebins; i++){
625  if( (ADCkeep[i] == 1) && (getElement(ADCkeep,i-1) == 0) ){
626  for(int j = i-Presamples ; j <= i; j++){
627  setElement(ADCkeep,j,1);
628  }
629  }
630  }
631  for(int i = ftimebins-1; i >= 0; i--){
632  if( (ADCkeep[i] == 1) && (getElement(ADCkeep,i+1) == 0) ){
633  for(int j = i ; j <= i+Postsamples; j++){
634  setElement(ADCkeep,j,1);
635  }
636  }
637  }
638  /*cout << " Postsamplecounter: " << Postsamplecounter;
639  for(int j = i+1 ; j <= i+Postsamples; j++){
640  setElement(ADCkeep,j,1);
641  i+=Postsamples;
642  }
643  cout << endl;
644  }
645  cout << i << " ADCK: " << getElement(ADCkeep,i);
646  cout << " Postsam: " << Postsamplecounter << " ADCK: " << getElement(ADCkeep,i);*/
647 
648  for(int i = 0; i < ftimebins; i++){
649  if( (ADCkeep[i] == 1) && (getElement(ADCkeep,i+1) == 0) && ( (getElement(ADCkeep,i+3) == 1) || (getElement(ADCkeep,i+2) == 1) ) ){
650  setElement(ADCkeep,i+1,1);
651  setElement(ADCkeep,i+2,1);
652  }
653  }
654 }
655 
663  // calculation is based on altro 10 bit words ..
664  int sample = 0;
665  int cluster = 0;
666  int data = 0;
667  float retval = 0.0;
668 
669  for(int i = 0; i < ftimebins; i++){
670  if(ADCkeep[i] == 1){
671  sample++;
672  }
673  if( (ADCkeep[i] == 1) && (getElement(ADCkeep,i+1) == 0) ){
674  cluster++;
675  }
676  }
677  data = sample + cluster*2;
678  data = data + data%4 + 4;
679  if(data >0){
680  retval = ftimebins / (float)data;//num of timebins is equal to max number of samples
681  }else{
682  retval = 1.0;
683  }
684  return retval;
685 }
686 
687 short Altro::getElement(short* Array,int index){
688  if (index < 0)
689  return 0;
690  else if(index >= ftimebins)
691  return 0;
692  else
693  return Array[index];
694 }
695 
696 void Altro::setElement(short* Array,int index,short value){
697  if (index < 0)
698  return;
699  else if(index >= ftimebins)
700  return;
701  else
702  Array[index] = value;
703 }
704 
705 int Altro::inBand(int ADC,int bsl, int LowThreshold, int HighThreshold){
706  int fLow = bsl - LowThreshold;
707  int fHigh = bsl + HighThreshold;
708  if( (ADC <= fHigh) && (ADC >= fLow) )
709  return 1;
710  else
711  return 0;
712 }
713 
714 int Altro::inRange(int parameter,int Low,int High,const char *Module,const char *ParameterName){
715  char out[255];
716  int retval;
717  if(parameter > High){
718  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);
719  cout << out << endl;
720  retval = High;
721  }else if(parameter < Low){
722  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);
723  cout << out << endl;
724  retval = Low;
725  }else{
726  retval = parameter;
727  }
728  return retval;
729 }
730 
731 short Altro::GetShortChannel(int i){
732  return getElement(channelShort,i);
733 }
734 
735 short Altro::GetKeepChannel(int i){
736  return getElement(ADCkeep,i);
737 }
Altro(int timebins, short *Channel)
Consturctor of Altro Class.
Definition: Altro.cxx:31
void ConfigAltro(int ONBaselineCorrection1, int ONTailcancellation, int ONBaselineCorrection2, int ONClipping, int ONZerosuppression)
Configures which modules of the Altro should be on.
Definition: Altro.cxx:72
~Altro()
Destructor of Altro Class.
Definition: Altro.cxx:54
void ConfigTailCancellationFilter(int K1, int K2, int K3, int L1, int L2, int L3)
Configures the Tail Cancellation Filter (TCF) Module.
Definition: Altro.cxx:118
This the header File for the Altro class.
void PrintParameters()
Prints the set Parameters, if module is configured.
Definition: Altro.cxx:182
void RunEmulation()
Runs the emulation of all configured Modules.
Definition: Altro.cxx:238
void ConfigBaselineCorrection_2(int HighThreshold, int LowThreshold, int Offset, int Presamples, int Postsamples)
Configures the Moving Average Filter (BSL2) Module.
Definition: Altro.cxx:145
void ConfigBaselineCorrection_1(int mode, int ValuePeDestal, int *PedestalMem, int polarity)
Configures the Base Line Correction 1 (BSL1) Module.
Definition: Altro.cxx:94
float calculatecompression()
calculates the compression out of the bitmask
Definition: Altro.cxx:662
void ConfigZerosuppression(int Threshold, int MinSamplesaboveThreshold, int Presamples, int Postsamples)
Configures the Zero Suppression Module (ZSU)
Definition: Altro.cxx:165