88bool ConvertOFC(
const vector<vector<vector<vector<double> > > >& w_off,
89 const vector<vector<double> >& calibration,
int calibtype,
int runtype,
90 vector<unsigned int> &OFC,
bool verbose) {
97 float dsp_min_phase = -100.;
98 float dsp_max_phase = -dsp_min_phase;
99 int dsp_phases = (int) roundf( (dsp_max_phase - dsp_min_phase)*(1./dsp_step) +1. );
103 cout<<
"----- DSP -----"<<endl;
104 cout<<
"Step: "<<dsp_step<<
" ns"<<endl;
105 cout<<
"Min Phase: "<<dsp_min_phase<<
" ns"<<endl;
106 cout<<
"Max Phase: "<<dsp_max_phase<<
" ns"<<endl;
107 cout<<
"Nb phases: "<<dsp_phases<<endl;
111 const float off_step = 0.1;
112 float off_min_phase = -100.;
113 float off_max_phase = -off_min_phase;
114 int off_phases = (int) roundf( (off_max_phase - off_min_phase)*(1./off_step) + 1. );
117 cout<<
"----- OFFLINE -----"<<endl;
118 cout<<
"Step: "<<off_step<<
" ns"<<endl;
119 cout<<
"Min Phase: "<<off_min_phase<<
" ns"<<endl;
120 cout<<
"Max Phase: "<<off_max_phase<<
" ns"<<endl;
121 cout<<
"Nb phases: "<<off_phases<<endl;
124 int ngains = (int) w_off.size();
125 int nphases = (int) w_off[0].size();
126 int nparams = (int) w_off[0][0].size();
127 int nsamples = (int) w_off[0][0][0].size();
129 if ( dsp_step < off_step ){
130 cout<<
"ERROR: DSP phase step smaller than Offline phase step"<<endl;
134 cout<<
"ERROR: Incorrect number of gains"<<endl;
137 if (off_phases != nphases){
138 cout<<
"ERROR: Incorrect number of phases"<<endl;
141 if (dsp_min_phase < off_min_phase){
142 cout<<
"ERROR: Incorrect minimum phase"<<endl;
145 if (dsp_max_phase > off_max_phase){
146 cout<<
"ERROR: Incorrecto maximum phase"<<endl;
153 }
else if (nparams == 4){
156 cout<<
"ERROR: Incorrect algorithm type"<<endl;
162 int calib_gain = (int) calibration.size();
163 int calib_size = (int) calibration[0].size();
164 if (calib_gain!=ngains){
165 cout<<
"ERROR: Number of gain in calibration vector incorrect"<<endl;
168 vector<double> calibration_lo;
169 vector<double> calibration_hi;
170 for (
int i=0; i<calib_size; i++)
173 calibration_lo.push_back( calibration[ig][i] );
175 calibration_hi.push_back( calibration[ig][i] );
177 if (calibtype != 0) calibration_hi[1] = calibration_hi[1]*64.;
181 cout<<
"--- calibration ---"<<endl;
182 cout<<
"[low gain] -> offset: "<<calibration_lo[0]<<
" slope: "<<calibration_lo[1]<<endl;
183 cout<<
"[high gain] -> offset: "<<calibration_hi[0]<<
" slope: "<<calibration_hi[1]<<endl;
184 cout<<
"If calibtype != ADC then slope is multiplied by a factor 64"<<endl;
188 vector<double> a_lo(nsamples,0);
189 vector<double> b_lo(nsamples,0);
190 vector<double> c_lo(nsamples,0);
191 vector<double> g_lo(nsamples,0);
192 vector<double> h_lo(nsamples,0);
193 vector<double> a_hi(nsamples,0);
194 vector<double> b_hi(nsamples,0);
195 vector<double> c_hi(nsamples,0);
196 vector<double> g_hi(nsamples,0);
197 vector<double> h_hi(nsamples,0);
204 const float inv_off_step = 1. / off_step;
205 for (
int i=0; i<dsp_phases; i++){
207 current_phase = dsp_min_phase + i*dsp_step;
208 index = (int) roundf((current_phase - off_min_phase)*inv_off_step);
209 if (
verbose) cout<<
"["<<
index<<
"]: Phase "<<current_phase<<
" ns"<<endl;
210 for (
int is=0; is<nsamples; is++)
213 a_lo[is] = w_off[ig][
index][0][is];
214 b_lo[is] = w_off[ig][
index][1][is];
215 g_lo[is] = w_off[ig][
index][nparams-1][is];
219 a_hi[is] = w_off[ig][
index][0][is];
220 b_hi[is] = w_off[ig][
index][1][is];
221 g_hi[is] = w_off[ig][
index][nparams-1][is];
228 if (
verbose) cout<<
"---- LOW GAIN ----"<<endl;
230 if (!flag)
return flag;
231 if (
verbose) cout<<
"---- HIGH GAIN ----"<<endl;
233 if (!flag)
return flag;
237 cout <<
"ERROR!!! Format 5 in this call is incomplete (OFC::ConvertOFC)" << endl;
240 if (!flag)
return flag;
248 calibration_lo.clear();
249 calibration_hi.clear();
271 const std::vector<double>& b,
272 const std::vector<double>& c,
273 const std::vector<double>& g,
274 const std::vector<double>&
h,
275 unsigned int channel_index,
278 std::vector<unsigned int> &OFC,
301 unsigned int slope_scale;
307 int n_2 = (int) trunc(
a.size()/2.);
310 OFC.push_back( ( (adsp[0] << 16) & 0xFFFF0000) | ( (
ascale-1) & 0xFFFF) );
311 for (
int i=1; i<=n_2; i++)
312 OFC.push_back( ( (adsp[2*i] << 16) & 0xFFFF0000) | ( adsp[2*i-1] & 0xFFFF) );
315 OFC.push_back( ( (slope << 16) & 0xFFFF0000) | ( (
ascale + slope_scale ) & 0xFFFF ) );
318 OFC.push_back( ( (bdsp[0] << 16) & 0xFFFF0000) | ( (bscale-4) & 0xFFFF) );
319 for (
int i=1; i<=n_2; i++)
320 OFC.push_back( ( (bdsp[2*i] << 16) & 0xFFFF0000) | ( bdsp[2*i-1] & 0xFFFF) );
323 OFC.push_back( ( (cdsp[0] << 16) & 0xFFFF0000) | ( (cscale) & 0xFFFF) );
324 for (
int i=1; i<=n_2; i++)
325 OFC.push_back( ( (cdsp[2*i] << 16) & 0xFFFF0000) | ( cdsp[2*i-1] & 0xFFFF) );
328 OFC.push_back( ( (hscale << 16) & 0xFFFF0000) | ( (gscale+1) & 0xFFFF) );
329 for (
size_t i=0; i<g.size(); i++)
330 OFC.push_back( ( (hdsp[i] << 16) & 0xFFFF0000) | ( gdsp[i] & 0xFFFF) );
333 OFC.push_back( ( (channel_index << 16) & 0xFFFF0000) | (phase & 0xFFFF) ) ;
335 if (
verbose) cout<<
"size of OFC: "<<OFC.size()<<endl;
360 const vector<double>& b ,
361 const vector<double>& c,
362 const vector<double>& g,
363 const vector<double>&
h,
364 vector<unsigned int> &OFC ,
390 int n_2 = (int) trunc(
a.size()/2.);
392 for (
int i=0; i<n_2; i++)
393 OFC.push_back( ( (adsp[2*i] << 16 )& 0xFFFF0000) | ( adsp[2*i+1] & 0x0000FFFF) ) ;
394 OFC.push_back( ( (adsp[2*n_2] << 16 )& 0xFFFF0000) | ( (-asum) & 0x0000FFFF) );
396 for (
int i=0; i<n_2; i++)
397 OFC.push_back( ( (bdsp[2*i] << 16 )& 0xFFFF0000) | ( bdsp[2*i+1] & 0x0000FFFF) ) ;
398 OFC.push_back( ( (bdsp[2*n_2] << 16 )& 0xFFFF0000) | ( (-bsum) & 0x0000FFFF) );
400 OFC.push_back( ( (bscale << 16 )& 0xFFFF0000) | (
ascale & 0x0000FFFF) );
402 OFC.push_back( ( (cdsp[0] << 16 )& 0xFFFF0000) | ( cscale & 0x0000FFFF) );
403 for (
int i=1; i<=n_2; i++)
404 OFC.push_back( ( (cdsp[2*i] << 16 )& 0xFFFF0000) | ( cdsp[2*i-1] & 0x0000FFFF) ) ;
406 OFC.push_back( ( (hscale << 16 )& 0xFFFF0000) | ( gscale & 0x0000FFFF) );
407 for (
size_t i=0; i<g.size();i++)
408 OFC.push_back( ( (hdsp[i] << 16 )& 0xFFFF0000) | ( gdsp[i] & 0x0000FFFF) );
416 if (
verbose) cout<<
"size of OFC: "<<OFC.size()<<endl;
472 fin.open(OFCfile, ios::in);
475 cout<<
"Error opening file "<<(OFCfile)<<endl;
483 int nphases = (int) roundf(-f_phi*2./f_step + 1.);
485 int nsamples = (int) roundf(f_samples);
496 cout<<
"Number of parameters: "<<nparams<<endl;
499 w_off.resize(ngains);
500 for (
int ig=0; ig<ngains; ig++){
501 w_off[ig].resize(nphases);
502 for (
int it=0; it<nphases; it++){
503 w_off[ig][it].resize(nparams);
504 for (
int ip=0; ip<nparams; ip++){
505 w_off[ig][it][ip].resize(nsamples,0);
512 fin.open(OFCfile, ios::in);
513 for (
int it=0; it<nphases; it++)
515 for (
int is=0; is<nsamples; is++)
517 for (
int ig=0; ig<ngains; ig++)
523 w_off[ig][it][ip][is] = tmp1;
533 cout<<
"Optimal Filtering file: "<<(OFCfile)<<endl;
534 cout<<
"Nb phases: "<<w_off[0].size()<<endl;
535 cout<<
"Nb samples: "<<w_off[0][0][0].size()<<endl;
536 cout<<
"Nb gains: "<<w_off.size()<<endl;
537 if ((
int) w_off[0][0].size() == 3 ) cout<<
"Algorithm: OF1"<<endl;
538 else if ((
int) w_off[0][0].size() == 4 ) cout<<
"Algorithm: OF2"<<endl;
bool ConvertOFC(const vector< vector< vector< vector< double > > > > &w_off, const vector< vector< double > > &calibration, int calibtype, int runtype, vector< unsigned int > &OFC, bool verbose)
bool Format6(const std::vector< double > &a, const std::vector< double > &b, const std::vector< double > &c, const std::vector< double > &g, const std::vector< double > &h, unsigned int channel_index, int phase, double calibration, std::vector< unsigned int > &OFC, bool verbose)
Format6.
bool Format5(const vector< double > &a, const vector< double > &b, const vector< double > &c, const vector< double > &g, const vector< double > &h, vector< unsigned int > &OFC, bool verbose)
Format5.