34 channelShort = Channel;
55 if(fConfiguredZSU == 1)
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");
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");
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");
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");
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");
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);
183 cout <<
"+-------------------------------------------+" << endl;
184 cout <<
"| Configured Parameters of the Altro Module |" << endl;
185 cout <<
"+-------------------------------------------+" << endl << endl;
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;
199 cout <<
"BSL1 (Baseline Correction 1) Module not configured!" << endl << endl << endl;
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;
210 cout <<
"TCF (TailCancellation Filter) Module not configured!" << endl << endl << endl;
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;
220 cout <<
"BSL2 (Baseline Correction 2) Module not configured!" << endl << endl << endl;
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;
229 cout <<
"ZSU (Zero Suppression Unit) Module not configured!" << endl << endl << endl;
240 if(fConfiguredAltro == 0){
241 cout <<
"ERROR cant run Altro Emulation because not configured" << endl;
244 for(
int i = 0; i < ftimebins; i++){
250 if(fConfiguredBSL1 == 1){
251 BaselineCorrection_1(fBSL1mode, fBSL1ValuePeDestal, fBSL1PedestalMem, fBSL1polarity);
253 cout <<
"ERROR cant run Baseline Correction 1 because not configured" << endl;
260 if(fConfiguredTCF == 1){
261 TailCancellationFilter_FixedPoint(fTCFK1Int, fTCFK2Int, fTCFK3Int, fTCFL1Int, fTCFL2Int, fTCFL3Int);
263 cout <<
"ERROR cant run Tail Cancellation Filter because not configured" << endl;
270 if(fConfiguredBSL2 == 1){
271 BaselineCorrection_2_RTL(fBSL2HighThreshold, fBSL2LowThreshold, fBSL2Offset, fBSL2Presamples, fBSL2Postsamples);
273 cout <<
"ERROR cant run Baseline Correction 2 because not configured" << endl;
283 if(fConfiguredZSU == 1){
284 Zerosuppression(fZSUThreshold,fZSUMinSamplesaboveThreshold,fZSUPresamples,fZSUPostsamples);
286 cout <<
"ERROR cant run Zero Suppression Unit because not configured" << endl;
290 for(
int i = 0; i < ftimebins; i++){
291 if (! ADCkeep[i]) channelShort[i] = 0;
295 void Altro::BaselineCorrection_1(
int mode,
int ValuePeDestal,
int *PedestalMem,
int polarity){
297 int FixedPeDestal = 0;
300 for(
int i = 0; i < ftimebins; i++){
301 channelShort[i] = 1023 - channelShort[i];
307 for(
int i = 0; i < ftimebins; i++)
308 channelShort[i] = channelShort[i] - FixedPeDestal;
311 for(
int i = 0; i < ftimebins; i++)
312 channelShort[i] = channelShort[i] - PedestalMem[i];
315 for(
int i = 0; i < ftimebins; i++)
316 channelShort[i] = channelShort[i] - PedestalMem[ channelShort[i] ];
319 for(
int i = 0; i < ftimebins; i++)
320 channelShort[i] = channelShort[i] - PedestalMem[ channelShort[i] - ValuePeDestal];
323 for(
int i = 0; i < ftimebins; i++)
324 channelShort[i] = channelShort[i] - ValuePeDestal - FixedPeDestal;
327 for(
int i = 0; i < ftimebins; i++)
328 channelShort[i] = channelShort[i] - ValuePeDestal - PedestalMem[i];
331 for(
int i = 0; i < ftimebins; i++)
332 channelShort[i] = channelShort[i] - ValuePeDestal - PedestalMem[ channelShort[i] ];
335 for(
int i = 0; i < ftimebins; i++)
336 channelShort[i] = channelShort[i] - ValuePeDestal - PedestalMem[ channelShort[i] - ValuePeDestal ];
339 for(
int i = 0; i < ftimebins; i++)
340 channelShort[i] = PedestalMem[ channelShort[i] ] - FixedPeDestal;
343 for(
int i = 0; i < ftimebins; i++)
344 channelShort[i] = PedestalMem[ channelShort[i] - ValuePeDestal ] - FixedPeDestal;
347 for(
int i = 0; i < ftimebins; i++)
348 channelShort[i] = PedestalMem[i] - FixedPeDestal;
353 int Altro::multiply36(
int P,
int N){
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));
363 retval = maskandshift(temp,32,16);
367 long long Altro::mask(
long long in,
int left,
int right){
370 long long length = abs(left - right)+1;
371 pattern = ((1<<length)-1)<<right;
376 long long Altro::maskandshift(
long long in,
int left,
int right){
379 long long length = abs(left - right)+1;
380 pattern = ((1<<length)-1);
381 retval = (in>>right)&pattern;
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;
392 for(
int i = 0; i < ftimebins; i++){
393 din = channelShort[i];
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);
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);
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);
408 if( (maskandshift(dout,2,2) == 1) || (maskandshift(dout,1,1) == 1)){
414 dout = ((dout>>3)<<1) + bit;
415 if(maskandshift(dout,15,15) == 1){
417 dout = -mask((-mask(dout,9,0)),9,0);
419 dout = mask(dout,9,0);
422 channelShort[i] = (short) dout;
429 void Altro::BaselineCorrection_2_RTL(
int HighThreshold,
int LowThreshold,
int Offset,
int Presamples,
int Postsamples){
437 int thrlo = LowThreshold;
438 int thrhi = HighThreshold;
468 for(
int i = 0; i < 9 ; i++)
470 for(
int i = 0; i < 4 ; i++){
479 for(
int i = 0; i < 2 ; i++){
480 edges[i] = (Presamples&(1<<i))>>i;
482 for(
int i = 0; i < 4 ; i++){
483 edges[(3-i)+2] = (Postsamples&(1<<i))>>i;
492 for(
int timebin = -12; timebin < ftimebins+10; timebin++){
494 din = getElement(channelShort,timebin);
496 s8 = zxOld + (zOld[8] - zOld[0]);
504 if( (din <= (bsl + thrhi)) && (din >= (bsl - thrlo)) )
521 if( (fOld[3] == 1) || ( (flag == 1) && ( (edges[0] == 1) || (edges[1] == 1) ) ) )
526 if( (fOld[2] == 1) || ( (edges[1] == 1) && (flag == 1) ) )
531 if( ( (fOld[1] == 1) || ( (flag == 1) && (edges[0] == 1) && (edges[1] == 1) ) || (fx==1) ) && (valid==1) )
537 for(
int i = 0; i < 3; i++)
541 if( (fOld[1]==1) && (fOld[2]==0) )
542 pstscnt = Postsamples;
548 valcntNew = ++valcntOld;
551 for(
int i = 0; i < 8; i++)
556 for(
int i = 0; i < 9; i++)
559 dout = dxOld - (bsl - offset);
563 setElement(channelShort,timebin-5,(
short)dout);
565 for(
int i = 0; i < 9 ; i++)
568 for(
int i = 0; i < 4 ; i++){
573 valcntOld = valcntNew;
577 void Altro::Clipping(){
578 for(
int i = 0; i < ftimebins; i++){
579 if(channelShort[i] < 0)
584 void Altro::Zerosuppression(
int Threshold,
int MinSamplesaboveThreshold,
int Presamples,
int Postsamples){
588 for(
int i = 0; i < ftimebins; i++){
589 if(channelShort[i] >= Threshold){
594 int startofclustersequence = -1;
595 int endofClustersInSequence = -1;
597 for(
int i = 0; i < ftimebins; i++){
598 if( (ADCkeep[i] == 1) && (getElement(ADCkeep,i-1) == 0) ){
599 startofclustersequence = i;
601 if( (ADCkeep[i] == 1) && (getElement(ADCkeep,i+1) == 0) ){
602 endofClustersInSequence = i;
605 if( (startofclustersequence != -1) && (endofClustersInSequence != -1) ){
607 if ( (endofClustersInSequence - startofclustersequence + 1) < MinSamplesaboveThreshold ){
608 for(
int j = startofclustersequence; j <= endofClustersInSequence ; j++){
612 startofclustersequence = -1;
613 endofClustersInSequence = -1;
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);
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);
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);
669 for(
int i = 0; i < ftimebins; i++){
673 if( (ADCkeep[i] == 1) && (getElement(ADCkeep,i+1) == 0) ){
677 data = sample + cluster*2;
678 data = data + data%4 + 4;
680 retval = ftimebins / (float)data;
687 short Altro::getElement(
short* Array,
int index){
690 else if(index >= ftimebins)
696 void Altro::setElement(
short* Array,
int index,
short value){
699 else if(index >= ftimebins)
702 Array[index] = value;
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) )
714 int Altro::inRange(
int parameter,
int Low,
int High,
const char *Module,
const char *ParameterName){
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);
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);
731 short Altro::GetShortChannel(
int i){
732 return getElement(channelShort,i);
735 short Altro::GetKeepChannel(
int i){
736 return getElement(ADCkeep,i);
Altro(int timebins, short *Channel)
Consturctor of Altro Class.
void ConfigAltro(int ONBaselineCorrection1, int ONTailcancellation, int ONBaselineCorrection2, int ONClipping, int ONZerosuppression)
Configures which modules of the Altro should be on.
~Altro()
Destructor of Altro Class.
void ConfigTailCancellationFilter(int K1, int K2, int K3, int L1, int L2, int L3)
Configures the Tail Cancellation Filter (TCF) Module.
This the header File for the Altro class.
void PrintParameters()
Prints the set Parameters, if module is configured.
void RunEmulation()
Runs the emulation of all configured Modules.
void ConfigBaselineCorrection_2(int HighThreshold, int LowThreshold, int Offset, int Presamples, int Postsamples)
Configures the Moving Average Filter (BSL2) Module.
void ConfigBaselineCorrection_1(int mode, int ValuePeDestal, int *PedestalMem, int polarity)
Configures the Base Line Correction 1 (BSL1) Module.
float calculatecompression()
calculates the compression out of the bitmask
void ConfigZerosuppression(int Threshold, int MinSamplesaboveThreshold, int Presamples, int Postsamples)
Configures the Zero Suppression Module (ZSU)