CMS 3D CMS Logo

L1TMuonBarrelParamsHelper.cc
Go to the documentation of this file.
2 
3 void L1TMuonBarrelParamsHelper::print(std::ostream& out) const {
4  out << "L1 BMTF Parameters" << std::endl;
5 
6  out << "Firmware version: " << fwVersion_ << std::endl;
7 }
8 
11  barrelParams) //: L1TMuonBarrelParams_PUBLIC(cast_to_L1TMuonBarrelParams_PUBLIC(barrelParams)) //: m_params_helper(barrelParams)
12 {
13  // if (pnodes_.size() != 2)
14  // pnodes_.resize(2);
15 }
16 
17 void L1TMuonBarrelParamsHelper::configFromPy(std::map<std::string, int>& allInts,
18  std::map<std::string, bool>& allBools,
19  std::map<std::string, std::vector<std::string> > allMasks,
20  unsigned int fwVersion,
21  const std::string& AssLUTpath) {
22  set_PT_Assignment_nbits_Phi(allInts["PT_Assignment_nbits_Phi"]);
23  set_PT_Assignment_nbits_PhiB(allInts["PT_Assignment_nbits_PhiB"]);
24  set_PHI_Assignment_nbits_Phi(allInts["PHI_Assignment_nbits_Phi"]);
25  set_PHI_Assignment_nbits_PhiB(allInts["PHI_Assignment_nbits_PhiB"]);
26  set_Extrapolation_nbits_Phi(allInts["Extrapolation_nbits_Phi"]);
27  set_Extrapolation_nbits_PhiB(allInts["Extrapolation_nbits_PhiB"]);
28  set_BX_min(allInts["BX_min"]);
29  set_BX_max(allInts["BX_max"]);
30  set_Extrapolation_Filter(allInts["Extrapolation_Filter"]);
31  set_OutOfTime_Filter_Window(allInts["OutOfTime_Filter_Window"]);
32  set_OutOfTime_Filter(allBools["OutOfTime_Filter"]);
33  set_Open_LUTs(allBools["Open_LUTs"]);
34  set_EtaTrackFinder(allBools["EtaTrackFinder"]);
35  set_Extrapolation_21(allBools["Extrapolation_21"]);
37  set_DisableNewAlgo(allBools["DisableNewAlgo"]);
38 
39  setAssLUTPath(AssLUTpath);
41  std::vector<LUT> pta_lut(0);
42  pta_lut.reserve(19);
43  std::vector<int> pta_threshold(10);
44  if (load_pt(pta_lut, pta_threshold, allInts["PT_Assignment_nbits_Phi"], AssLUTpath) != 0) {
45  cout << "Can not open files to load pt-assignment look-up tables for L1TMuonBarrelTrackProducer!" << endl;
46  }
49 
51  std::vector<LUT> phi_lut(0);
52  phi_lut.reserve(2);
53  if (load_phi(phi_lut, allInts["PHI_Assignment_nbits_Phi"], allInts["PHI_Assignment_nbits_PhiB"], AssLUTpath) != 0) {
54  cout << "Can not open files to load phi-assignment look-up tables for L1TMuonBarrelTrackProducer!" << endl;
55  }
57 
58  l1mudttfparams.reset(); //KK
60  .load(); //KK: Do these LUTs ever change and is it safe to initialize it from the release files like that?
61  l1mudttfetaplut.load(); //KK
62  // the data members of the Helper class loaded above are transient, push those to the persistent storage of the base class:
65 
66  for (int wh = -3; wh < 4; wh++) {
67  int sec = 0;
68  for (char& c : allMasks["mask_phtf_st1"].at(wh + 3)) {
69  int mask = c - '0';
71  sec++;
72  }
73  sec = 0;
74  for (char& c : allMasks["mask_phtf_st2"].at(wh + 3)) {
75  int mask = c - '0';
77  sec++;
78  }
79  sec = 0;
80  for (char& c : allMasks["mask_phtf_st3"].at(wh + 3)) {
81  int mask = c - '0';
83  sec++;
84  }
85  sec = 0;
86  for (char& c : allMasks["mask_phtf_st4"].at(wh + 3)) {
87  int mask = c - '0';
89  sec++;
90  }
91  sec = 0;
92  for (char& c : allMasks["mask_ettf_st1"].at(wh + 3)) {
93  int mask = c - '0';
95  sec++;
96  }
97  sec = 0;
98  for (char& c : allMasks["mask_ettf_st2"].at(wh + 3)) {
99  int mask = c - '0';
101  sec++;
102  }
103  sec = 0;
104  for (char& c : allMasks["mask_ettf_st3"].at(wh + 3)) {
105  int mask = c - '0';
107  //Not used in BMTF - mask
109  sec++;
110  }
111  }
112 
114  std::vector<L1TMuonBarrelParams::LUTParams::extLUT> ext_lut(0);
115  ext_lut.reserve(12);
116  if (load_ext(ext_lut, allInts["PHI_Assignment_nbits_Phi"], allInts["PHI_Assignment_nbits_PhiB"]) != 0) {
117  cout << "Can not open files to load extrapolation look-up tables for L1TMuonBarrelTrackProducer!" << endl;
118  }
120 
121  //l1mudttfextlut.load();
122 }
123 
125  std::map<std::string, std::string> procRole = trgSys.getProcToRoleAssignment();
126 
127  //Cleaning the default masking from the prototype
129 
130  for (auto it_proc = procRole.begin(); it_proc != procRole.end(); it_proc++) {
131  std::string procId = it_proc->first;
132 
133  std::map<std::string, l1t::Parameter> settings = trgSys.getParameters(procId.c_str());
134 
135  std::vector<std::string> paths = settings["regTable"].getTableColumn<std::string>("register_path");
136  std::vector<unsigned int> vals = settings["regTable"].getTableColumn<unsigned int>("register_value");
137  for (unsigned int row = 0; row < paths.size(); row++) {
138  if (paths[row].find("open_lut") != std::string::npos) {
139  //std::cout << "Value is: " << vals[row] << std::endl;
140  set_Open_LUTs(vals[row]);
141  }
142  if (paths[row].find("sel_21") != std::string::npos) {
143  //std::cout << "Value is: " << vals[row] << std::endl;
144  set_Extrapolation_21(vals[row]);
145  }
146 
147  if (paths[row].find("dis_newalgo") != std::string::npos) {
148  //std::cout << "Value is: " << vals[row] << std::endl;
149  //int fwv = (vals[row]==1) ? 1 : 2;
150  //setFwVersion(fwv);
151  bool disnewalgo = (vals[row] == 1);
152  set_DisableNewAlgo(disnewalgo);
153  }
154 
155  string masks[5] = {"mask_ctrl_N2", "mask_ctrl_N1", "mask_ctrl_0", "mask_ctrl_P1", "mask_ctrl_P2"};
156 
157  for (int m = 0; m < 5; m++) {
158  if (paths[row].find(masks[m]) != std::string::npos) {
160  int mask = 0x1 & vals[row];
161  int mask_all = vals[row];
163  if (!(mask_all == 0x111111 || mask_all == 0x222222 || mask_all == 0x333333 || mask_all == 0x444444 ||
164  mask_all == 0x555555 || mask_all == 0x666666 || mask_all == 0x777777))
165  cerr << "BMTF: Cannot re-emulate properly. Individual link masking cannot be handled." << endl;
166 
167  if ((mask & 1) > 0) {
168  for (int sec = 0; sec < 12; sec++) {
169  if (masks[m] == "mask_ctrl_N2") {
171  //l1mudttfmasks.set_etsoc_chdis_st1(-3,sec,true);
172  }
173  if (masks[m] == "mask_ctrl_N1") {
175  //l1mudttfmasks.set_etsoc_chdis_st1(-2,sec,true);
176  }
177 
178  if (masks[m] == "mask_ctrl_0") {
181  //l1mudttfmasks.set_etsoc_chdis_st1(-1,sec,true);
182  //l1mudttfmasks.set_etsoc_chdis_st1(1,sec,true);
183  }
184  if (masks[m] == "mask_ctrl_P1") {
186  //l1mudttfmasks.set_etsoc_chdis_st1(2,sec,true);
187  }
188  if (masks[m] == "mask_ctrl_P2") {
190  //l1mudttfmasks.set_etsoc_chdis_st1(3,sec,true);
191  }
192  }
193  }
194 
195  if ((mask & 2) > 0) {
196  for (int sec = 0; sec < 12; sec++) {
197  if (masks[m] == "mask_ctrl_N2") {
199  //l1mudttfmasks.set_etsoc_chdis_st2(-3,sec,true);
200  }
201  if (masks[m] == "mask_ctrl_N1") {
203  //l1mudttfmasks.set_etsoc_chdis_st2(-2,sec,true);
204  }
205 
206  if (masks[m] == "mask_ctrl_0") {
209  //l1mudttfmasks.set_etsoc_chdis_st2(-1,sec,true);
210  //l1mudttfmasks.set_etsoc_chdis_st2(1,sec,true);
211  }
212  if (masks[m] == "mask_ctrl_P1") {
214  //l1mudttfmasks.set_etsoc_chdis_st2(2,sec,true);
215  }
216  if (masks[m] == "mask_ctrl_P2") {
218  //l1mudttfmasks.set_etsoc_chdis_st2(3,sec,true);
219  }
220  }
221  }
222 
223  if ((mask & 4) > 0) {
224  for (int sec = 0; sec < 12; sec++) {
225  if (masks[m] == "mask_ctrl_N2") {
227  //l1mudttfmasks.set_etsoc_chdis_st3(-3,sec,true);
228  }
229  if (masks[m] == "mask_ctrl_N1") {
231  //l1mudttfmasks.set_etsoc_chdis_st3(-2,sec,true);
232  }
233 
234  if (masks[m] == "mask_ctrl_0") {
237  //l1mudttfmasks.set_etsoc_chdis_st3(-1,sec,true);
238  //l1mudttfmasks.set_etsoc_chdis_st3(1,sec,true);
239  }
240  if (masks[m] == "mask_ctrl_P1") {
242  //l1mudttfmasks.set_etsoc_chdis_st3(2,sec,true);
243  }
244  if (masks[m] == "mask_ctrl_P2") {
246  //l1mudttfmasks.set_etsoc_chdis_st3(3,sec,true);
247  }
248  }
249  }
250 
251  if ((mask & 8) > 0) {
252  for (int sec = 0; sec < 12; sec++) {
253  if (masks[m] == "mask_ctrl_N2") {
255  }
256  if (masks[m] == "mask_ctrl_N1") {
258  }
259 
260  if (masks[m] == "mask_ctrl_0") {
263  }
264  if (masks[m] == "mask_ctrl_P1") {
266  }
267  if (masks[m] == "mask_ctrl_P2") {
269  }
270  }
271  }
272  }
273  }
274  }
275  }
276 }
277 
278 int L1TMuonBarrelParamsHelper::load_pt(std::vector<LUT>& pta_lut,
279  std::vector<int>& pta_threshold,
280  unsigned short int nbitphi,
281  std::string AssLUTpath) {
282  // maximal number of pt assignment methods
283  const int MAX_PTASSMETH = 19;
284  const int MAX_PTASSMETHA = 12;
285 
286  // pt assignment methods
287  enum PtAssMethod {
288  PT12L,
289  PT12H,
290  PT13L,
291  PT13H,
292  PT14L,
293  PT14H,
294  PT23L,
295  PT23H,
296  PT24L,
297  PT24H,
298  PT34L,
299  PT34H,
300  PB12H,
301  PB13H,
302  PB14H,
303  PB21H,
304  PB23H,
305  PB24H,
306  PB34H,
307  NODEF
308  };
309 
310  // get directory name
311  string pta_str = "";
312  // precision : in the look-up tables the following precision is used :
313  // phi ...12 bits (address) and pt ...5 bits
314  // now convert phi and phib to the required precision
315  int nbit_phi = nbitphi;
316  int sh_phi = 12 - nbit_phi;
317 
318  // loop over all pt-assignment methods
319  for (int pam = 0; pam < MAX_PTASSMETH; pam++) {
320  switch (pam) {
321  case PT12L: {
322  pta_str = "pta12l";
323  break;
324  }
325  case PT12H: {
326  pta_str = "pta12h";
327  break;
328  }
329  case PT13L: {
330  pta_str = "pta13l";
331  break;
332  }
333  case PT13H: {
334  pta_str = "pta13h";
335  break;
336  }
337  case PT14L: {
338  pta_str = "pta14l";
339  break;
340  }
341  case PT14H: {
342  pta_str = "pta14h";
343  break;
344  }
345  case PT23L: {
346  pta_str = "pta23l";
347  break;
348  }
349  case PT23H: {
350  pta_str = "pta23h";
351  break;
352  }
353  case PT24L: {
354  pta_str = "pta24l";
355  break;
356  }
357  case PT24H: {
358  pta_str = "pta24h";
359  break;
360  }
361  case PT34L: {
362  pta_str = "pta34l";
363  break;
364  }
365  case PT34H: {
366  pta_str = "pta34h";
367  break;
368  }
369  case PB12H: {
370  pta_str = "ptb12h_Feb2016";
371  break;
372  }
373  case PB13H: {
374  pta_str = "ptb13h_Feb2016";
375  break;
376  }
377  case PB14H: {
378  pta_str = "ptb14h_Feb2016";
379  break;
380  }
381  case PB21H: {
382  pta_str = "ptb21h_Feb2016";
383  break;
384  }
385  case PB23H: {
386  pta_str = "ptb23h_Feb2016";
387  break;
388  }
389  case PB24H: {
390  pta_str = "ptb24h_Feb2016";
391  break;
392  }
393  case PB34H: {
394  pta_str = "ptb34h_Feb2016";
395  break;
396  }
397  }
398 
399  // assemble file name
400  const string& lutpath = AssLUTpath;
401  edm::FileInPath lut_f = edm::FileInPath(string(lutpath + pta_str + ".lut"));
402  string pta_file = lut_f.fullPath();
403 
404  // open file
405  L1TriggerLutFile file(pta_file);
406  if (file.open() != 0)
407  return -1;
408 
409  // get the right shift factor
410  int shift = sh_phi;
411  int adr_old = -2048 >> shift;
412  if (pam >= MAX_PTASSMETHA)
413  adr_old = -512 >> shift;
414 
415  LUT tmplut;
416 
417  int number = -1;
418  int sum_pt = 0;
419 
420  if (file.good()) {
421  int threshold = file.readInteger();
422  pta_threshold[pam / 2] = threshold;
423  }
424 
425  // read values and shift to correct precision
426  while (file.good()) {
427  int adr = (file.readInteger()) >> shift;
428  int pt = file.readInteger();
429 
430  number++;
431  //cout<<pam<<" "<<number<<" "<<MAX_PTASSMETHA<<endl;
432  if (adr != adr_old) {
433  assert(number);
434  tmplut.insert(make_pair(adr_old, (sum_pt / number)));
435 
436  adr_old = adr;
437  number = 0;
438  sum_pt = 0;
439  }
440 
441  sum_pt += pt;
442 
443  if (!file.good())
444  file.close();
445  }
446 
447  file.close();
448  pta_lut.push_back(tmplut);
449  }
450  return 0;
451 }
452 
453 int L1TMuonBarrelParamsHelper::load_phi(std::vector<LUT>& phi_lut,
454  unsigned short int nbit_phi,
455  unsigned short int nbit_phib,
456  std::string AssLUTpath) {
457  // precision : in the look-up tables the following precision is used :
458  // address (phib) ...10 bits, phi ... 12 bits
459 
460  int sh_phi = 12 - nbit_phi;
461  int sh_phib = 10 - nbit_phib;
462 
463  string phi_str;
464  // loop over all phi-assignment methods
465  for (int idx = 0; idx < 2; idx++) {
466  switch (idx) {
467  case 0: {
468  phi_str = "phi12";
469  break;
470  }
471  case 1: {
472  phi_str = "phi42";
473  break;
474  }
475  }
476 
477  // assemble file name
478  edm::FileInPath lut_f = edm::FileInPath(string(AssLUTpath + phi_str + ".lut"));
479  string phi_file = lut_f.fullPath();
480 
481  // open file
482  L1TriggerLutFile file(phi_file);
483  if (file.open() != 0)
484  return -1;
485 
486  LUT tmplut;
487 
488  int number = -1;
489  int adr_old = -512 >> sh_phib;
490  int sum_phi = 0;
491 
492  // read values
493  while (file.good()) {
494  int adr = (file.readInteger()) >> sh_phib;
495  int phi = file.readInteger();
496 
497  number++;
498 
499  if (adr != adr_old) {
500  assert(number);
501  tmplut.insert(make_pair(adr_old, ((sum_phi / number) >> sh_phi)));
502 
503  adr_old = adr;
504  number = 0;
505  sum_phi = 0;
506  }
507 
508  sum_phi += phi;
509 
510  if (!file.good())
511  file.close();
512  }
513 
514  file.close();
515  phi_lut.push_back(tmplut);
516  }
517  return 0;
518 }
519 
520 /*
521 int L1TMuonBarrelParamsESProducer::getPtLutThreshold(int pta_ind, std::vector<int>& pta_threshold) const {
522 
523  if ( pta_ind >= 0 && pta_ind < 13/2 ) {
524  return pta_threshold[pta_ind];
525  }
526  else {
527  cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
528  return 0;
529  }
530 
531 }
532 
533 */
534 
535 //
536 // load extrapolation look-up tables
537 //
538 int L1TMuonBarrelParamsHelper::load_ext(std::vector<L1TMuonBarrelParams::LUTParams::extLUT>& ext_lut,
539  unsigned short int nbit_phi,
540  unsigned short int nbit_phib) {
541  //max. number of Extrapolations
542  const int MAX_EXT = 12;
543 
544  // extrapolation types
546 
547  // get directory name
548  string defaultPath = "L1Trigger/L1TMuon/data/bmtf_luts/";
549  string ext_dir = "LUTs_Ext/";
550  string ext_str = "";
551 
552  // precision : in the look-up tables the following precision is used :
553  // phi ...12 bits (low, high), phib ...10 bits (address)
554  // now convert phi and phib to the required precision
555 
556  int sh_phi = 12 - nbit_phi;
557  int sh_phib = 10 - nbit_phib;
558 
559  // loop over all extrapolations
560  for (int ext = 0; ext < MAX_EXT; ext++) {
561  switch (ext) {
562  case EX12:
563  ext_str = "ext12";
564  break;
565  case EX13:
566  ext_str = "ext13";
567  break;
568  case EX14:
569  ext_str = "ext14";
570  break;
571  case EX21:
572  ext_str = "ext21";
573  break;
574  case EX23:
575  ext_str = "ext23";
576  break;
577  case EX24:
578  ext_str = "ext24";
579  break;
580  case EX34:
581  ext_str = "ext34";
582  break;
583  case EX15:
584  ext_str = "ext15";
585  break;
586  case EX16:
587  ext_str = "ext16";
588  break;
589  case EX25:
590  ext_str = "ext25";
591  break;
592  case EX26:
593  ext_str = "ext26";
594  break;
595  case EX56:
596  ext_str = "ext56";
597  break;
598  }
599 
600  // assemble file name
601  edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
602  string ext_file = lut_f.fullPath();
603 
604  // open file
605  L1TriggerLutFile file(ext_file);
606  if (file.open() != 0)
607  return -1;
608  // if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
609  // << file.getName() << endl;
610 
612 
613  int number = -1;
614  int adr_old = -512 >> sh_phib;
615  int sum_low = 0;
616  int sum_high = 0;
617 
618  // read values and shift to correct precision
619  while (file.good()) {
620  int adr = (file.readInteger()) >> sh_phib; // address (phib)
621  int low = (file.readInteger()); // low value (phi)
622  int high = (file.readInteger()); // high value (phi)
623 
624  number++;
625 
626  if (adr != adr_old) {
627  tmplut.low[adr_old] = sum_low >> sh_phi;
628  tmplut.high[adr_old] = sum_high >> sh_phi;
629 
630  adr_old = adr;
631  number = 0;
632  sum_low = 0;
633  sum_high = 0;
634  }
635 
636  if (number == 0)
637  sum_low = low;
638  if (number == 0)
639  sum_high = high;
640 
641  if (!file.good())
642  file.close();
643  }
644 
645  file.close();
646  ext_lut.push_back(tmplut);
647  }
648  return 0;
649 }
L1MuBMTQualPatternLut l1mudttfqualplut
friend std::ostream& operator<<(std::ostream& o, const L1TMuonBarrelParams & p) { p...
L1MuDTTFParameters l1mudttfparams
void set_etsoc_chdis_st1(int wh, int sc, const bool val)
std::string fullPath() const
Definition: FileInPath.cc:161
int load()
load look-up tables
int load_phi(std::vector< LUT > &, unsigned short int, unsigned short int, std::string)
std::vector< LUT > phi_lut() const
int load()
load pattern look-up table
void set_etsoc_chdis_st2(int wh, int sc, const bool val)
void print(std::ostream &) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
constexpr uint32_t mask
Definition: gpuClustering.h:26
const std::map< std::string, std::string > & getProcToRoleAssignment(void) const noexcept
Definition: TriggerSystem.h:60
void setphi_lut(std::vector< LUT > philut)
int load_ext(std::vector< L1TMuonBarrelParams::LUTParams::extLUT > &, unsigned short int, unsigned short int)
L1MuDTTFMasks l1mudttfmasks
const std::map< std::string, Parameter > & getParameters(const char *processor) const
const int MAX_EXT
void setpta_lut(std::vector< LUT > ptalut)
void set_inrec_chdis_st4(int wh, int sc, const bool val)
void reset()
reset parameters to zero
Extrapolation
int load_pt(std::vector< LUT > &, std::vector< int > &, unsigned short int, std::string)
if configDB
void reset()
reset parameters to zero
void setAssLUTPath(std::string path)
std::vector< int > pta_threshold() const
void set_inrec_chdis_st2(int wh, int sc, const bool val)
std::vector< LUT > pta_lut() const
std::map< short, short, std::less< short > > LUT
L1MuBMPtaLut.
void set_inrec_chdis_st3(int wh, int sc, const bool val)
void setFwVersion(unsigned fwVersion)
void set_etsoc_chdis_st3(int wh, int sc, const bool val)
void setext_lut(std::vector< LUTParams::extLUT > extlut)
void configFromPy(std::map< std::string, int > &allInts, std::map< std::string, bool > &allBools, std::map< std::string, std::vector< std::string > > allMasks, unsigned int fwVersion, const std::string &AssLUTpath)
static unsigned int const shift
void configFromDB(l1t::TriggerSystem &trgSys)
Definition: memstream.h:15
std::vector< LUTParams::extLUT > ext_lut() const
void setpta_threshold(std::vector< int > ptathresh)
void set_inrec_chdis_csc(int wh, int sc, const bool val)
const int MAX_PTASSMETH
void set_inrec_chdis_st1(int wh, int sc, const bool val)
PtAssMethod