ATLAS Offline Software
Loading...
Searching...
No Matches
TileOFC.h File Reference
#include <vector>
Include dependency graph for TileOFC.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void Double2Int_calib (double calib_constant, unsigned int &scale, unsigned int &offset, bool verbose=false)
void Double2Int_ofc (int w_off_size, const std::vector< double > &w_off, std::vector< int > &w_dsp, int &w_sum_dsp, int &scale, bool verbose=false)
bool ConvertOFC (const std::vector< std::vector< std::vector< std::vector< double > > > > &w_off, const std::vector< std::vector< double > > &calibration, int calibtype, int runtype, std::vector< unsigned int > &OFC, bool verbose=false)
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 index_channel, int phase, double calibration, std::vector< unsigned int > &OFC, bool verbose=false)
 Format6.
bool Format5 (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, std::vector< unsigned int > &OFC, bool verbose=false)
 Format5.
bool Format5calib (double calib, std::vector< unsigned int > &OFC, bool verbose=false)
bool FormatInfo (int nsamples, int calibrationtype, int algorithm, int runtype, std::vector< unsigned int > &OFC, bool verbose=false)
bool ReadOFfile (std::vector< std::vector< std::vector< std::vector< double > > > > &w_off, char *OFCfile, bool verbose=false)

Function Documentation

◆ ConvertOFC()

bool ConvertOFC ( const std::vector< std::vector< std::vector< std::vector< double > > > > & w_off,
const std::vector< std::vector< double > > & calibration,
int calibtype,
int runtype,
std::vector< unsigned int > & OFC,
bool verbose = false )

Definition at line 88 of file TileOFC.cxx.

90 {
91 bool flag;
92
93 // Select number of phases and step inside DSP
94 //int format = 5;
95 //format = format;
96 float dsp_step = 1. ;
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. );
100
101 if (1)
102 {
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;
108 }
109
110 // Number of phases and step of the offline Opt. filte constants
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. );
115 if (verbose)
116 {
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;
122 }
123
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();
128
129 if ( dsp_step < off_step ){
130 cout<<"ERROR: DSP phase step smaller than Offline phase step"<<endl;
131 return false;
132 }
133 if (ngains != 2){
134 cout<<"ERROR: Incorrect number of gains"<<endl;
135 return false;
136 }
137 if (off_phases != nphases){
138 cout<<"ERROR: Incorrect number of phases"<<endl;
139 return false;
140 }
141 if (dsp_min_phase < off_min_phase){
142 cout<<"ERROR: Incorrect minimum phase"<<endl;
143 return false;
144 }
145 if (dsp_max_phase > off_max_phase){
146 cout<<"ERROR: Incorrecto maximum phase"<<endl;
147 return false;
148 }
149
150 int algorithm;
151 if (nparams == 3){
152 algorithm = 0; // OF1
153 }else if (nparams == 4){
154 algorithm = 1; // OF2
155 }else{
156 cout<<"ERROR: Incorrect algorithm type"<<endl;
157 return false;
158 }
159
160 // Get Calibration
161 int ig;
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;
166 return false;
167 }
168 vector<double> calibration_lo;
169 vector<double> calibration_hi;
170 for (int i=0; i<calib_size; i++)
171 {
172 ig = 0; // low gain
173 calibration_lo.push_back( calibration[ig][i] );
174 ig = 1; // high gain
175 calibration_hi.push_back( calibration[ig][i] );
176 }
177 if (calibtype != 0) calibration_hi[1] = calibration_hi[1]*64.;
178
179 if (verbose)
180 {
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;
185 }
186
187 // Get Optimal filtering constants
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);
198
199 // Select phases for the DSP
200 int index;
201 float current_phase;
202
203 // bln
204 const float inv_off_step = 1. / off_step;
205 for (int i=0; i<dsp_phases; i++){
206
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++)
211 {
212 ig = 0; // low gain
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];
216 // missing c_lo, h_lo
217
218 ig = 1; // high gain
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];
222 // missing c_hi, h_hi
223
224 }
225
226
227 // convert Format5
228 if (verbose) cout<<"---- LOW GAIN ----"<<endl;
229 flag = Format5( a_lo, b_lo, c_lo, g_lo, h_lo, OFC, verbose);
230 if (!flag) return flag;
231 if (verbose) cout<<"---- HIGH GAIN ----"<<endl;
232 flag = Format5( a_hi, b_hi, c_hi, g_hi, h_hi, OFC, verbose);
233 if (!flag) return flag;
234
235 }
236
237 cout << "ERROR!!! Format 5 in this call is incomplete (OFC::ConvertOFC)" << endl;
238
239 flag = FormatInfo( nsamples, calibtype, algorithm, runtype, OFC, verbose);
240 if (!flag) return flag;
241
242 a_lo.clear();
243 b_lo.clear();
244 g_lo.clear();
245 a_hi.clear();
246 b_hi.clear();
247 g_hi.clear();
248 calibration_lo.clear();
249 calibration_hi.clear();
250
251 return true;
252}
bool FormatInfo(int nsamples, int calibrationtype, int algorithm, int runtype, vector< unsigned int > &OFC, bool verbose)
Definition TileOFC.cxx:437
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.
Definition TileOFC.cxx:359
std::string algorithm
Definition hcg.cxx:85
bool verbose
Definition hcg.cxx:73
Definition index.py:1
bool flag
Definition master.py:29

◆ Double2Int_calib()

void Double2Int_calib ( double calib_constant,
unsigned int & scale,
unsigned int & offset,
bool verbose = false )

Definition at line 18 of file TileOFC.cxx.

19{
20 // Number of bits of the integer word (signed -1 )
21 int NumberBits = 16;
22 NumberBits = NumberBits - 1;
23
24 // Get Scale
25 scale = 0;
26 double max = fabs(calib);
27 if (max!=0) scale = (unsigned int) truncf(log((pow(2.,NumberBits)-1.)/max)*(1./log(2.)));
28
29 // Convert to integer
30 offset = (unsigned int) roundf(calib*pow(2.,(int)scale));
31
32 if (verbose) cout << "Calib = " << hex << calib
33 << " ==> ( scale: " << scale
34 << " , offset: " << offset
35 << ")" << dec << endl;
36
37}
constexpr int pow(int base, int exp) noexcept
#define max(a, b)
Definition cfImp.cxx:41

◆ Double2Int_ofc()

void Double2Int_ofc ( int w_off_size,
const std::vector< double > & w_off,
std::vector< int > & w_dsp,
int & w_sum_dsp,
int & scale,
bool verbose = false )

Definition at line 41 of file TileOFC.cxx.

42{
43 // Number of bits of the integer word (signed -1 )
44 int NumberBits = 16;
45 NumberBits = NumberBits - 1;
46
47 // Get Absolute Maximum
48 double max = -10000.;
49 double sum = 0.;
50 for (int i=0; i<w_off_size; i++)
51 {
52 sum += w_off[i];
53 if ( fabs(w_off[i]) > max ) max = fabs(w_off[i]);
54 }
55 if (fabs(sum) > max) max = fabs(sum);
56
57 // Get Scale at Maximum
58 scale = 0;
59 if (max!=0) scale = (int) truncf(log((pow(2.,NumberBits)-1.)/max)*(1./log(2.)));
60
61 // Convert to Integer the weights and the sum
62 for (int i=0; i<w_off_size; i++) w_dsp.push_back( (int) roundf(w_off[i]*pow(2.,scale)) );
63 w_sum_dsp = (int) roundf(sum*pow(2.,scale));
64
65
66 if (verbose) {
67 printf("\nAbsolute Max value = %15.8f -> Scale = %3d\n",max,scale);
68
69 for (int i=0; i<w_off_size; i++)
70 {
71 if ( i == 0){
72 printf("\n Offline Off*Scale Dsp/scale Dsp Scale \n");
73 printf("----------------------------------------------------------------------------------\n");
74 printf(" %17.10f %17.10f %17.10f 0x%04X %3d \n",
75 w_off[i],w_off[i]*pow(2.,scale), w_dsp[i]/pow(2.,scale),(unsigned int) w_dsp[i] ,scale);
76 } else {
77 printf(" %17.10f %17.10f %17.10f 0x%04X \n",
78 w_off[i],w_off[i]*pow(2.,scale),w_dsp[i]/pow(2.,scale),(unsigned int)w_dsp[i]);
79 }
80 }
81 printf(" %17.10f %17.10f %17.10f 0x%04X <- SUM\n",
82 sum,sum*pow(2.,scale),w_sum_dsp/pow(2.,scale),(unsigned int)w_sum_dsp);
83 }
84
85 return ;
86}

◆ Format5()

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.

Format used in the OFW with iterations

Parameters
avector of A weights to compute energy
bvector of B weights to compute phase
cvector of C weights to compute pedestal
gvector of G weights to compute QF
hvector of derivative of G weights to compute QF
OFCreference to OFW vector
verboseboolean value
Returns
bool true on success

Definition at line 359 of file TileOFC.cxx.

366{
367 vector<int> adsp;
368 vector<int> bdsp;
369 vector<int> cdsp;
370 vector<int> gdsp;
371 vector<int> hdsp;
372
373 int asum;
374 int bsum;
375 int dump;
376
377 int ascale;
378 int bscale;
379 int cscale;
380 int gscale;
381 int hscale;
382
383 Double2Int_ofc( (int) a.size(), a, adsp, asum, ascale, verbose );
384 Double2Int_ofc( (int) b.size(), b, bdsp, bsum, bscale, verbose );
385 Double2Int_ofc( (int) c.size(), c, cdsp, dump, cscale, verbose );
386 Double2Int_ofc( (int) g.size(), g, gdsp, dump, gscale, verbose );
387 Double2Int_ofc( (int) h.size(), h, hdsp, dump, hscale, verbose );
388
389 // Start formating
390 int n_2 = (int) trunc(a.size()/2.);
391
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) );
395
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) );
399
400 OFC.push_back( ( (bscale << 16 )& 0xFFFF0000) | ( ascale & 0x0000FFFF) );
401
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) ) ;
405
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) );
409
410 adsp.clear();
411 bdsp.clear();
412 cdsp.clear();
413 gdsp.clear();
414 hdsp.clear();
415
416 if (verbose) cout<<"size of OFC: "<<OFC.size()<<endl;
417 return true;
418
419}
static Double_t a
void Double2Int_ofc(int w_off_size, const vector< double > &w_off, vector< int > &w_dsp, int &w_sum_dsp, int &scale, bool verbose)
Definition TileOFC.cxx:41
Header file for AthHistogramAlgorithm.
void ascale(TH1F *h, double s_)
-event-from-file

◆ Format5calib()

bool Format5calib ( double calib,
std::vector< unsigned int > & OFC,
bool verbose = false )

Definition at line 421 of file TileOFC.cxx.

421 {
422
423 unsigned int offset_scale = 0;
424 unsigned int offset = 0;
425
426 unsigned int slope_scale;
427 unsigned int slope;
428
429 Double2Int_calib( calib, slope_scale, slope, verbose );
430
431 OFC.push_back( ( (offset_scale << 16) & 0xFFFF0000) | ( slope_scale & 0x0000FFFF) );
432 OFC.push_back( ( (offset << 16) & 0xFFFF0000) | ( slope & 0x0000FFFF) );
433
434 return true;
435}
void Double2Int_calib(double calib, unsigned int &scale, unsigned int &offset, bool verbose)
Definition TileOFC.cxx:18

◆ Format6()

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.

Format used in the OFW without iterations

Parameters
avector of A weights to compute energy
bvector of B weights to compute phase
cvector of C weights to compute pedestal
gvector of G weights to compute QF
hvector of derivative of G weights to compute QF
channel_indexchannel index [0:48]
phaserounded scaled integer value of the channel's best phase
calibrationcalibration factor to be applied to the energy
OFCreference to OFW vector
verboseboolean value
Returns
bool true on success

Definition at line 270 of file TileOFC.cxx.

280{
281 vector<int> adsp;
282 vector<int> bdsp;
283 vector<int> cdsp;
284 vector<int> gdsp;
285 vector<int> hdsp;
286
287 int dump;
288
289 int ascale;
290 int bscale;
291 int cscale;
292 int gscale;
293 int hscale;
294
295 Double2Int_ofc( (int) a.size(), a, adsp, dump, ascale, verbose );
296 Double2Int_ofc( (int) b.size(), b, bdsp, dump, bscale, verbose );
297 Double2Int_ofc( (int) c.size(), c, cdsp, dump, cscale, verbose );
298 Double2Int_ofc( (int) g.size(), g, gdsp, dump, gscale, verbose );
299 Double2Int_ofc( (int) h.size(), h, hdsp, dump, hscale, verbose );
300
301 unsigned int slope_scale;
302 unsigned int slope;
303
304 Double2Int_calib( calibration, slope_scale, slope, verbose );
305
306 // Start formating
307 int n_2 = (int) trunc(a.size()/2.);
308
309 // OFC for energy
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) );
313
314 // Calibration
315 OFC.push_back( ( (slope << 16) & 0xFFFF0000) | ( (ascale + slope_scale ) & 0xFFFF ) );
316
317 // OFC for phase
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) );
321
322 // OFC for pedestal
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) );
326
327 // OFC for quality factor
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) );
331
332 // codificar index channel y fase
333 OFC.push_back( ( (channel_index << 16) & 0xFFFF0000) | (phase & 0xFFFF) ) ;
334
335 if (verbose) cout<<"size of OFC: "<<OFC.size()<<endl;
336
337 adsp.clear();
338 bdsp.clear();
339 cdsp.clear();
340 gdsp.clear();
341 hdsp.clear();
342
343 return true;
344}

◆ FormatInfo()

bool FormatInfo ( int nsamples,
int calibrationtype,
int algorithm,
int runtype,
std::vector< unsigned int > & OFC,
bool verbose = false )

Definition at line 437 of file TileOFC.cxx.

438{
439 int in = 1;
440 if (nsamples == 9){
441 in = 1;
442 }else if(nsamples == 7){
443 in = 0;
444 }else {
445 cout<<"ERROR: [FormatInfo] Incorrect number of samples"<<endl;
446 return false;
447 }
448
449 if (calibrationtype > 3 || calibrationtype < 0 ) {
450 cout<<"ERROR: [FormatInfo] Unknown calibration type"<<endl;
451 return false;
452 }
453
454 // poner lo mismo con runtype
455
456 if (algorithm != 0 && algorithm!=1){
457 cout<<"ERROR: [FormatInfo] Unknown algorithm type"<<endl;
458 return false;
459 }
460
461 OFC.push_back( ((calibrationtype & 0x3)<<6) | ((runtype & 0x3)<<4) | ((in & 0x1)<<3) | ((algorithm & 0x1) << 2) );
462
463 if (verbose) printf("OFC info: 0x%08x\n", ((calibrationtype & 0x3)<<6) | ((runtype & 0x3)<<4) | ((in & 0x1)<<3) | ((algorithm & 0x1) << 2) );
464
465 return true;
466}

◆ ReadOFfile()

bool ReadOFfile ( std::vector< std::vector< std::vector< std::vector< double > > > > & w_off,
char * OFCfile,
bool verbose = false )

Definition at line 468 of file TileOFC.cxx.

469{
470 // OPEN FILE
471 ifstream fin;
472 fin.open(OFCfile, ios::in);
473 if (!fin.is_open())
474 {
475 cout<<"Error opening file "<<(OFCfile)<<endl;
476 return false;
477 }
478
479 // input file settings
480 float f_samples = 9; // 9 samples
481 float f_phi = -100; // ns (-100,100) ns
482 float f_step = 0.1;
483 int nphases = (int) roundf(-f_phi*2./f_step + 1.);
484 int ngains = 2;
485 int nsamples = (int) roundf(f_samples);
486
487 // get number of parameters
488 string s;
489 double tmp1;
490 int nparams=0;
491 getline(fin,s);
492 istringstream ss(s);
493 while (ss >> tmp1) {
494 nparams++;
495 }
496 cout<<"Number of parameters: "<<nparams<<endl;
497
498 // Resize w_off vector
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);
506 }
507 }
508 }
509 fin.close();
510
511 // read file
512 fin.open(OFCfile, ios::in);
513 for (int it=0; it<nphases; it++)
514 {
515 for (int is=0; is<nsamples; is++)
516 {
517 for (int ig=0; ig<ngains; ig++)
518 {
519 int ip = 0;
520 getline(fin,s);
521 istringstream ss(s);
522 while (ss >> tmp1) {
523 w_off[ig][it][ip][is] = tmp1;
524 ip++;
525 }
526 }
527 }
528 }
529
530 verbose = true;
531 if (verbose)
532 {
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;
539 }
540
541 // CLOSE FILE
542 fin.close();
543
544 return true;
545}
static Double_t ss