CMS 3D CMS Logo

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