6 #define FA125_FE_NW_MASK 0x000003FF
8 #define FA125_FE_PL_MASK 0x0000FFFF
10 #define FA125_FE_THRESHOLD_MASK 0x00000FFF
12 #define FA125_FE_PED_SF_P1_MASK 0x000000FF
13 #define FA125_FE_PED_SF_P2_MASK 0x0000FF00
14 #define FA125_FE_PED_SF_IBIT_MASK 0x00070000
15 #define FA125_FE_PED_SF_ABIT_MASK 0x00380000
16 #define FA125_FE_PED_SF_PBIT_MASK 0x01C00000
17 #define FA125_FE_PED_SF_PBIT_SIGN (1<<25)
19 #define FA125_FE_TIMING_THRES_HI_MASK(x) (0x1FF<<((x%3)*9))
20 #define FA125_FE_TIMING_THRES_LO_MASK(x) (0xFF<<(8+((x%2)*16)))
22 #define FA125_FE_IE_INTEGRATION_END_MASK 0x00000FFF
23 #define FA125_FE_IE_PEDESTAL_GAP_MASK 0x000FF000
123 gPARMS->SetDefaultParameter(
"EMULATION125:FORCE_DEFAULT_CDC",
FORCE_DEFAULT_CDC,
"Set to >0 to force use of CDC default values");
124 gPARMS->SetDefaultParameter(
"EMULATION125:FORCE_DEFAULT_FDC",
FORCE_DEFAULT_FDC,
"Set to >0 to force use of FDC default values");
125 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_WS",
CDC_WS,
"Set CDC_WS for firmware emulation, will be overwritten by BORConfig if present");
126 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_WE",
CDC_WE,
"Set CDC_WE for firmware emulation, will be overwritten by BORConfig if present");
127 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_IE",
CDC_IE,
"Set CDC_IE for firmware emulation, will be overwritten by BORConfig if present");
128 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_P1",
CDC_P1,
"Set CDC_P1 for firmware emulation, will be overwritten by BORConfig if present");
129 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_P2",
CDC_P2,
"Set CDC_P2 for firmware emulation, will be overwritten by BORConfig if present");
130 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_PG",
CDC_PG,
"Set CDC_PG for firmware emulation, will be overwritten by BORConfig if present");
131 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_H",
CDC_H,
"Set CDC_H (hit threshold) for firmware emulation, will be overwritten by BORConfig if present");
132 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_TH",
CDC_TH,
"Set CDC_TH for firmware emulation, will be overwritten by BORConfig if present");
133 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_TL",
CDC_TL,
"Set CDC_TL for firmware emulation, will be overwritten by BORConfig if present");
134 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_IBIT",
CDC_IBIT,
"Set CDC_IBIT for firmware emulation, will be overwritten by BORConfig if present");
135 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_ABIT",
CDC_ABIT,
"Set CDC_ABIT for firmware emulation, will be overwritten by BORConfig if present");
136 gPARMS->SetDefaultParameter(
"EMULATION125:CDC_PBIT",
CDC_PBIT,
"Set CDC_PBIT for firmware emulation, will be overwritten by BORConfig if present");
137 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_WS",
FDC_WS,
"Set FDC_WS for firmware emulation, will be overwritten by BORConfig if present");
138 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_WE",
FDC_WE,
"Set FDC_WE for firmware emulation, will be overwritten by BORConfig if present");
139 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_IE",
FDC_IE,
"Set FDC_IE for firmware emulation, will be overwritten by BORConfig if present");
140 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_P1",
FDC_P1,
"Set FDC_P1 for firmware emulation, will be overwritten by BORConfig if present");
141 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_P2",
FDC_P2,
"Set FDC_P2 for firmware emulation, will be overwritten by BORConfig if present");
142 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_PG",
FDC_PG,
"Set FDC_PG for firmware emulation, will be overwritten by BORConfig if present");
143 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_H",
FDC_H,
"Set FDC_H (hit threshold) for firmware emulation, will be overwritten by BORConfig if present");
144 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_TH",
FDC_TH,
"Set FDC_TH for firmware emulation, will be overwritten by BORConfig if present");
145 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_TL",
FDC_TL,
"Set FDC_TL for firmware emulation, will be overwritten by BORConfig if present");
146 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_IBIT",
FDC_IBIT,
"Set FDC_IBIT for firmware emulation, will be overwritten by BORConfig if present");
147 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_ABIT",
FDC_ABIT,
"Set FDC_ABIT for firmware emulation, will be overwritten by BORConfig if present");
148 gPARMS->SetDefaultParameter(
"EMULATION125:FDC_PBIT",
FDC_PBIT,
"Set FDC_PBIT for firmware emulation, will be overwritten by BORConfig if present");
149 gPARMS->SetDefaultParameter(
"EMULATION125:VERBOSE",
VERBOSE,
"Set verbosity for f125 emulation");
156 jout <<
"=== Entering f125 Firmware Emulation === ROCID: " << rawData->
rocid <<
" SLOT: " << rawData->
slot <<
" CHANNEL: " << rawData->
channel <<endl;
160 bool isCDC = cdcPulse != NULL ?
true :
false;
161 bool isFDC = fdcPulse != NULL ?
true :
false;
164 jout <<
" Df125EmulatorAlgorithm_v2::EmulateFirmware Both FDC and CDC words present??? " << endl;
166 }
else if (!isCDC && !isFDC){
167 jout <<
" Df125EmulatorAlgorithm_v2::EmulateFirmware Neither FDC or CDC words present??? " << endl;
172 uint32_t channel = rawData->
channel;
176 Int_t WS=0,WE=0,IE=0,P1=0,P2=0,PG=0,
H=0,TH=0,TL=0;
177 Int_t IBIT=0, ABIT=0, PBIT=0;
183 Int_t CDC_IMAX = 16383;
184 Int_t CDC_AMAX = 511;
185 Int_t CDC_PMAX = 255;
188 Int_t FDC_IMAX = 4095;
189 Int_t FDC_AMAX = 4095;
190 Int_t FDC_PMAX = 2047;
199 if(BORConfig != NULL){
200 if (
VERBOSE > 0) jout <<
"--Found BORConfig" << endl;
201 Int_t NW = BORConfig->
fe[0].
nw;
204 if (NW != Int_t(rawData->
samples.size())) jout <<
"WARNING Df125EmulatorAlgorithm_v2::EmulateFirmware NW != rawData->samples.size()" << endl;
220 if (
VERBOSE > 0) jout <<
"WARNING Df125EmulatorAlgorithm_v2::EmulateFirmware Using CDC Default values" << endl;
239 if (
VERBOSE > 0) jout <<
"WARNING Df125EmulatorAlgorithm_v2::EmulateFirmware Using CDC override values" << endl;
256 if (
VERBOSE > 0) jout <<
"WARNING Df125EmulatorAlgorithm_v2::EmulateFirmware Using FDC Default values" << endl;
274 if (
VERBOSE > 0) jout <<
"WARNING Df125EmulatorAlgorithm_v2::EmulateFirmware Using FDC override values" << endl;
292 jout <<
"============ Parameters used for emulation ================" << endl;
293 jout <<
"WS: " << WS <<
" WE: " << WE <<
" IE: " << IE <<
" P1: " << P1 <<
" P2: " << P2 << endl;
294 jout <<
"PG: " << PG <<
" H: " <<
H <<
" TH: " << TH <<
" TL: " << TL << endl;
295 jout <<
"IBIT: " << IBIT <<
" ABIT: " << ABIT <<
" PBIT: " << PBIT << endl;
299 Int_t time=0, q_code=0,
pedestal=0, overflows=0, maxamp=0, pktime=0;
305 fa125_algos(time, q_code,
pedestal, integral, overflows, maxamp, pktime, &rawData->
samples[0], WS, WE, IE, P1, P2, PG,
H, TH, TL);
309 integral = integral >> IBIT;
310 maxamp = maxamp >> ABIT;
342 else if (isFDC && fdcPulse->
emulated){
352 if (
VERBOSE > 0) jout <<
"=== Exiting f125 Firmware Emulation === " << endl;
357 void Df125EmulatorAlgorithm_v2::fa125_algos(Int_t &time, Int_t &q_code, Int_t &
pedestal, Long_t &integral, Int_t &overflows, Int_t &maxamp, Int_t &pktime,
const uint16_t adc[], Int_t WINDOW_START, Int_t WINDOW_END, Int_t INT_END, Int_t P1, Int_t P2, Int_t PG, Int_t HIT_THRES, Int_t HIGH_THRESHOLD, Int_t LOW_THRESHOLD) {
362 const Int_t XTHR_SAMPLE = PED + PG;
363 Int_t adc_subset[NU];
380 fa125_hit(hitfound, hitsample, pedestal, adc, WINDOW_START, WINDOW_END, HIT_THRES, P1, P2, PG);
383 for (i=0; i<NU; i++) {
384 adc_subset[i] = adc[hitsample+i-XTHR_SAMPLE];
387 fa125_time(time, q_code, adc_subset, NU, PG, HIGH_THRESHOLD, LOW_THRESHOLD);
389 timesample = hitsample-XTHR_SAMPLE + (Int_t)(0.1*time);
391 fa125_integral(integral, overflows, timesample, adc, WINDOW_END, INT_END);
393 fa125_max(maxamp, pktime, timesample, adc, WINDOW_END);
395 time = 10*(hitsample-XTHR_SAMPLE) + time;
409 for (i=0; i<NPED; i++) {
410 pedestal += adc[WINDOW_START-NPED+i];
413 pedestal = pedestal>>P1;
414 threshold = pedestal + HIT_THRES;
419 i = WINDOW_START - 1 + PG;
422 while ((hitfound==0) && (i<WINDOW_END-1)) {
424 if (adc[i] >= threshold) {
425 if (adc[i+1] >= threshold) {
436 for (i=0; i<NPED2; i++) {
437 pedestal += adc[hitsample-PG-i];
451 if (timesample <= WINDOW_END) {
453 Int_t lastsample = timesample + INT_END - 1;
455 if (lastsample > WINDOW_END) lastsample = WINDOW_END;
457 for (i = timesample; i <= lastsample; i++ ) {
459 integral += (Long_t)adc[i];
460 if (adc[i]==(Long_t)4095) overflows++;
475 while ((adc[hitsample] <= adc[hitsample-1]) && (hitsample <= WINDOW_END)) hitsample++;
477 maxamp = adc[hitsample];
478 maxsample = hitsample;
480 for (i=hitsample; i<=WINDOW_END; i++) {
482 if (adc[i] > adc[i-1]) {
488 if (adc[i] <= adc[i-1]) ndec++;
492 if (hitsample >= WINDOW_END) {
493 maxamp = adc[WINDOW_END];
494 maxsample = WINDOW_END;
519 const Int_t NUPSAMPLED = 6;
520 const Int_t SET_ADC_MIN = 20;
521 const Int_t LIMIT_PED_MAX = 511;
524 const Int_t START_SEARCH = PED+1;
526 const Int_t
X = PED + PG;
527 const Int_t ROUGH_TIME = (X*10)-30;
529 Int_t iubuf[NUPSAMPLED] = {0};
531 Int_t adc_thres_hi = 0;
532 Int_t adc_thres_lo = 0;
540 Int_t adc_sample_hi = 0;
541 Int_t adc_sample_lo = 0;
542 Int_t adc_sample_lo2 = 0;
544 Bool_t over_threshold = kFALSE;
545 Bool_t below_threshold = kFALSE;
548 Int_t ups_adjust = 0;
558 le_time = ROUGH_TIME + 1;
562 if ((i < PED+1) && (adc[i] > LIMIT_PED_MAX)) {
563 le_time = ROUGH_TIME + 2;
569 if (q_code>0)
return;
578 if (adc[i] < adcmin) {
584 Int_t adcoffset = SET_ADC_MIN - adcmin;
587 adc[i] = adc[i] + adcoffset;
588 if (adc[i] > 4095) adc[i] = 4095;
597 adc_thres_hi = adc[PED] + THRES_HIGH;
598 adc_thres_lo = adc[PED] + THRES_LOW;
601 over_threshold = kFALSE;
604 while ((!over_threshold)&&(i<NU)) {
605 if (adc[i] >= adc_thres_hi) {
607 over_threshold = kTRUE;
612 if (!over_threshold) {
613 le_time = ROUGH_TIME + 3;
619 below_threshold = kFALSE;
622 while ((!below_threshold) && (i>=PED)) {
623 if (adc[i] <= adc_thres_lo) {
626 below_threshold = kTRUE;
631 if (adc[adc_sample_lo] == adc_thres_lo) {
637 if (adc_sample_lo > NU-7) {
638 le_time = itime1 + 4;
644 upsamplei(adc, adc_sample_lo, iubuf, NUPSAMPLED);
647 Bool_t negups = kFALSE;
649 while ((!negups)&&(i<NUPSAMPLED)) {
657 le_time = itime1 + 5;
666 ups_adjust = iubuf[0] - adc[adc_sample_lo];
669 adc_thres_lo = adc_thres_lo + ups_adjust;
672 if (iubuf[NUPSAMPLED-1]<= adc_thres_lo) {
673 le_time = itime1 + 9;
679 below_threshold = kFALSE;
682 while ((!below_threshold) && (i>=0)) {
683 if (iubuf[i] <= adc_thres_lo) {
685 below_threshold = kTRUE;
690 if (!below_threshold) {
691 printf(
"upsampled points did not go below threshold - should be impossible\n");
697 itime2 = adc_sample_lo2*2;
701 if (iubuf[adc_sample_lo2] != adc_thres_lo) {
702 if (2*adc_thres_lo >= iubuf[adc_sample_lo2] + iubuf[adc_sample_lo2+1]) itime3 = 1;
704 le_time = itime1 + itime2 + itime3;
714 const Int_t nz = NUPSAMPLED;
717 const Int_t Kscale = 16384;
718 const Int_t K[43] = {-4, -9, -13, -10, 5, 37, 82, 124, 139, 102, -1, -161, -336, -455, -436, -212, 241, 886, 1623, 2309, 2795, 2971, 2795, 2309, 1623, 886, 241, -212, -436, -455, -336, -161, -1, 102, 139, 124, 82, 37, 5, -10, -13, -9, -4};
732 Int_t firstk = 41 + (startpos-4)*5;
733 for (k=firstk; k<firstk+nz; k++) {
736 for (j=k%5;j<43;j+=5) {
737 z[dk] += x[(k-j)/5]*K[j];
740 z[dk] = (Int_t)(5*z[dk])/Kscale;
uint32_t first_max_amp
from second word
void fa125_time(Int_t &, Int_t &, Int_t[], Int_t, Int_t, Int_t, Int_t)
void fa125_max(Int_t &, Int_t &, Int_t, const uint16_t[], Int_t)
uint32_t time_quality_bit_emulated
emulated from raw data when available
#define FA125_FE_PED_SF_P2_MASK
uint32_t peak_time
from second word
#define FA125_FE_PED_SF_ABIT_MASK
#define FA125_FE_IE_INTEGRATION_END_MASK
void EmulateFirmware(const Df125WindowRawData *, Df125CDCPulse *, Df125FDCPulse *)
uint32_t peak_time_emulated
emulated from raw data when available
uint32_t peak_amp
from second word (type 9)
uint32_t pedestal
from second word
uint32_t integral
from second word (type 6)
uint32_t timing_thres_hi[2]
uint32_t overflow_count
from first word
uint32_t peak_amp_emulated
emulated from raw data when available
uint32_t time_quality_bit_emulated
emulated from raw data when available
#define FA125_FE_TIMING_THRES_LO_MASK(x)
uint32_t le_time
from first word
#define FA125_FE_TIMING_THRES_HI_MASK(x)
uint32_t le_time
from first word
void fa125_hit(Int_t &, Int_t &, Int_t &, const uint16_t[], Int_t, Int_t, Int_t, Int_t, Int_t, Int_t)
uint32_t first_max_amp_emulated
emulated from raw data when available
uint32_t timing_thres_lo[3]
#define FA125_FE_IE_PEDESTAL_GAP_MASK
vector< uint16_t > samples
uint32_t le_time_emulated
emulated from raw data when available
uint32_t time_quality_bit
from first word
uint32_t time_quality_bit
from first word
void fa125_algos(Int_t &, Int_t &, Int_t &, Long_t &, Int_t &, Int_t &, Int_t &, const uint16_t[], Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t)
bool emulated
true if emulated values are copied to the main input
#define FA125_FE_PED_SF_P1_MASK
uint32_t integral_emulated
emulated from raw data when available
void upsamplei(Int_t[], Int_t, Int_t[], Int_t)
uint32_t pedestal
from second word
uint32_t le_time_emulated
emulated from raw data when available
uint32_t overflow_count_emulated
emulated from raw data when available
static TH1I * pedestal[nChan]
uint32_t pedestal_emulated
emulated from raw data when available
void fa125_integral(Long_t &, Int_t &, Int_t, const uint16_t[], Int_t, Int_t)
uint32_t overflow_count_emulated
emulated from raw data when available
uint32_t pedestal_emulated
emulated from raw data when available
uint32_t integral
from second word
bool emulated
true if emulated values are copied to the main input
printf("string=%s", string)
#define FA125_FE_PED_SF_IBIT_MASK
Df125EmulatorAlgorithm_v2()
#define FA125_FE_PED_SF_PBIT_MASK
uint32_t overflow_count
from first word
#define FA125_FE_THRESHOLD_MASK
uint32_t integral_emulated
emulated from raw data when available