14 gPARMS->SetDefaultParameter(
"EMULATION250:FORCE_DEFAULT",
FORCE_DEFAULT,
"Set to >0 to force use of default values");
15 gPARMS->SetDefaultParameter(
"EMULATION250:NSA",
NSA_DEF,
"Set NSA for firmware emulation, will be overwritten by BORConfig if present");
16 gPARMS->SetDefaultParameter(
"EMULATION250:NSB",
NSB_DEF,
"Set NSB for firmware emulation, will be overwritten by BORConfig if present");
17 gPARMS->SetDefaultParameter(
"EMULATION250:THR",
THR_DEF,
"Set threshold for firmware emulation, will be overwritten by BORConfig if present");
18 gPARMS->SetDefaultParameter(
"EMULATION250:VERBOSE",
VERBOSE,
"Set verbosity for f250 emulation");
23 std::vector<Df250PulseTime*> &pt_objs,
24 std::vector<Df250PulsePedestal*> &pp_objs,
25 std::vector<Df250PulseIntegral*> &pi_objs)
29 jout <<
" Df250EmulatorAlgorithm_v1::EmulateFirmware ==> Starting emulation <==" << endl;
30 jout <<
"rocid : " << rawData->
rocid <<
" slot: " << rawData->
slot <<
" channel: " << rawData->
channel << endl;
34 if (rawData == NULL) {
35 jerr <<
" ERROR: Df250EmulatorAlgorithm_v1::EmulateFirmware - raw sample data is missing" << endl;
36 jerr <<
" Contact mstaib@jlab.org" << endl;
41 uint32_t channel = rawData->
channel;
47 rawData->GetSingle(f250BORConfig);
59 if (counter == 10) jout <<
" WARNING Df250EmulatorAlgorithm_v1::EmulateFirmware No Df250BORConfig == Using default values == LAST WARNING" << endl;
60 else jout <<
" WARNING Df250EmulatorAlgorithm_v1::EmulateFirmware No Df250BORConfig == Using default values" << endl;
64 NSA = f250BORConfig->
adc_nsa & 0x7F;
65 NSB = f250BORConfig->
adc_nsb & 0x7F;
67 if (
VERBOSE > 0) jout <<
"Df250EmulatorAlgorithm_v1::EmulateFirmware NSA: " << NSA <<
" NSB: " << NSB <<
" THR: " << THR << endl;
70 std::vector<const Df250PulseTime*> pulseTimes;
71 std::vector<const Df250PulsePedestal*> pulsePedestals;
72 std::vector<const Df250PulseIntegral*> pulseIntegrals;
73 rawData->Get(pulseTimes);
74 rawData->Get(pulsePedestals);
75 rawData->Get(pulseIntegrals);
82 vector<uint16_t> samples = rawData->
samples;
83 uint16_t NW = samples.size();
85 const int max_pulses = 3;
86 uint32_t TC[max_pulses] = {};
87 uint32_t
TMIN[max_pulses] = {3};
88 uint32_t pulse_integral[max_pulses] = {};
90 for (
unsigned int i=0; i < NW; i++) {
91 if (
VERBOSE > 5) jout <<
"Df250EmulatorAlgorithm_v1::EmulateFirmware samples[" << i <<
"]: " << samples[i] << endl;
94 for (
unsigned int i=0; i < NW; i++) {
95 if ((samples[i] & 0xfff) > THR) {
97 unsigned int ibegin = i > NSB ? (i - NSB) : 0;
98 unsigned int iend = (i + NSA) < uint32_t(NW) ? (i + NSA) : NW;
99 for (i = ibegin; i < iend; ++i)
100 pulse_integral[npulses] += (samples[i] & 0xfff);
101 for (; i < NW && (samples[i] & 0xfff) > THR; ++i) {}
102 if (++npulses == max_pulses)
111 uint32_t VPEAK[max_pulses] = {};
112 uint16_t TMID[max_pulses] = {};
113 uint16_t VMID[max_pulses] = {};
114 uint16_t TFINE[max_pulses] = {};
115 uint32_t pulse_time[max_pulses] = {};
116 bool reportTC[max_pulses] = {};
120 for (
unsigned int i=0; i < 4; i++) {
121 VMIN += (samples[i] & 0xfff);
128 if ((samples[i] & 0xfff) > THR){
129 if (
VERBOSE > 1) jout <<
"WARNING Df250EmulatorAlgorithm_v1::EmulateFirmware sample above threshold in pedestal calculation " << endl;
136 for (
int p=0; p < npulses; ++p) {
141 pulse_time[p] = (TC[p] << 6);
145 for (ipeak = TC[p]; ipeak < NW; ++ipeak) {
146 if ((samples[ipeak] & 0xfff) < (samples[ipeak-1] & 0xfff)) {
147 VPEAK[p] = (samples[ipeak-1] & 0xfff);
160 if (NW - ipeak < 5) {
162 pulse_time[p] = ((TC[p] - 1) << 6);
170 pulse_time[p] = (TC[p] << 6);
176 jout <<
" pulse " << p <<
": VMIN: " << VMIN <<
" reportTC: " << int(reportTC[p])
177 <<
" TC: " << TC[p] <<
" VPEAK: " << VPEAK[p] << endl;
180 VMID[p] = (VMIN + VPEAK[p]) >> 1;
181 for (
unsigned int i = TMIN[p] + 1; i < (uint32_t)ipeak; ++i) {
182 if ((samples[i] & 0xfff) > VMID[p]) {
188 #if EMULATION250_MODE_8
202 int Vnext = (samples[TMID[p]] & 0xfff);
203 int Vlast = (samples[TMID[p]-1] & 0xfff);
204 if (Vnext > Vlast && VMID[p] >= Vlast)
205 TFINE[p] = 64 * (VMID[p] - Vlast) / (Vnext - Vlast);
209 pulse_time[p] = (TMID[p] << 6) + TFINE[p];
212 VMIN = (VMIN < 99999)? VMIN : 0;
215 jout <<
" pulse " << p <<
": VMID: " << VMID[p] <<
" TMID: " << TMID[p]
216 <<
" TFINE: " << TFINE[p] <<
" time: " << pulse_time[p]
217 <<
" integral: " << pulse_integral[p] << endl;
222 f250PulseTime->
slot = rawData->
slot;
227 f250PulseTime->
time = pulse_time[p];
231 f250PulseTime->AddAssociatedObject(rawData);
232 pt_objs.push_back(f250PulseTime);
236 f250PulsePedestal->
slot = rawData->
slot;
245 f250PulsePedestal->AddAssociatedObject(rawData);
246 pp_objs.push_back(f250PulsePedestal);
250 f250PulseIntegral->
slot = rawData->
slot;
255 f250PulseIntegral->
integral = pulse_integral[p];
262 f250PulseIntegral->AddAssociatedObject(rawData);
263 pi_objs.push_back(f250PulseIntegral);
266 if (
VERBOSE > 0) jout <<
" Df250EmulatorAlgorithm_v1::EmulateFirmware ==> Emulation complete <==" << endl;
uint32_t pedestal_emulated
Calculated from raw data (when available)
void EmulateFirmware(const Df250WindowRawData *rawData, std::vector< Df250PulseTime * > &pt_objs, std::vector< Df250PulsePedestal * > &pp_objs, std::vector< Df250PulseIntegral * > &pi_objs)
uint32_t pulse_number
from Pulse Pedestal Data word
bool emulated
true if made from Window Raw Data
uint32_t quality_factor
from Pulse Integral Data word
uint32_t pulse_number
from Pulse Time Data word
uint32_t nsamples_integral
number of samples used in integral
vector< uint16_t > samples
uint32_t pulse_peak
from Pulse Pedestal Data word
bool emulated
true if made from Window Raw Data
Df250EmulatorAlgorithm_v1()
uint32_t quality_factor_emulated
Calculated from raw data if available.
uint32_t quality_factor
from Pulse Time Data word
uint32_t pulse_number
from Pulse Integral Data word
uint32_t time
from Pulse Time Data word
uint32_t time_emulated
Calculated from raw data if available.
uint32_t integral_emulated
Value calculated from raw data (if available)
bool emulated
true if made from Window Raw Data
uint32_t integral
from Pulse Integral Data word
uint32_t pedestal
from Pulse Integral Data word (future)
uint32_t pedestal_emulated
Value calculated from raw data (if available)
uint32_t pulse_peak_emulated
Calculated from raw data (when available)
uint32_t pedestal
from Pulse Pedestal Data word
uint32_t nsamples_pedestal
number of samples used in pedestal