CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1TMuonBarrelParamsESProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: L1TMuonBarrelParamsESProducer
4 //
5 // Original Author: Giannis Flouris
6 // Created:
7 //
8 //
9 
10 // system include files
11 #include <memory>
12 
13 // user include files
18 
22 
26 
31 
33 
34 // class declaration
35 //
36 typedef std::map<short, short, std::less<short> > LUT;
37 
39 public:
42  int load_pt(std::vector<LUT>&, std::vector<int>&, unsigned short int, std::string);
43  int load_phi(std::vector<LUT>&, unsigned short int, unsigned short int, std::string);
44  int load_ext(std::vector<L1TMuonBarrelParams::LUTParams::extLUT>&, unsigned short int, unsigned short int);
45  //void print(std::vector<LUT>& , std::vector<int>& ) const;
46  int getPtLutThreshold(int, std::vector<int>&) const;
47  using ReturnType = std::unique_ptr<L1TMuonBarrelParams>;
48 
50 
51 private:
52  //L1TMuonBarrelParams m_params;
54 };
55 
56 //
57 // constants, enums and typedefs
58 //
59 
60 //
61 // static data member definitions
62 //
63 
64 //
65 // constructors and destructor
66 //
68  //the following line is needed to tell the framework what
69  // data is being produced
70  setWhatProduced(this);
71  // Firmware version
72  unsigned fwVersion = iConfig.getParameter<unsigned>("fwVersion");
73  std::string AssLUTpath = iConfig.getParameter<std::string>("AssLUTPath");
74  //m_params.setAssLUTPath(AssLUTpath);
75 
76  // int PT_Assignment_nbits_Phi = iConfig.getParameter<int>("PT_Assignment_nbits_Phi");
77  // int PT_Assignment_nbits_PhiB = iConfig.getParameter<int>("PT_Assignment_nbits_PhiB");
78  // int PHI_Assignment_nbits_Phi = iConfig.getParameter<int>("PHI_Assignment_nbits_Phi");
79  // int PHI_Assignment_nbits_PhiB = iConfig.getParameter<int>("PHI_Assignment_nbits_PhiB");
80  // int Extrapolation_nbits_Phi = iConfig.getParameter<int>("Extrapolation_nbits_Phi");
81  // int Extrapolation_nbits_PhiB = iConfig.getParameter<int>("Extrapolation_nbits_PhiB");
82  // int BX_min = iConfig.getParameter<int>("BX_min");
83  // int BX_max = iConfig.getParameter<int>("BX_max");
84  // int Extrapolation_Filter = iConfig.getParameter<int>("Extrapolation_Filter");
85  // int OutOfTime_Filter_Window = iConfig.getParameter<int>("OutOfTime_Filter_Window");
86  // bool OutOfTime_Filter = iConfig.getParameter<bool>("OutOfTime_Filter");
87  // bool Open_LUTs = iConfig.getParameter<bool>("Open_LUTs");
88  // bool EtaTrackFinder = iConfig.getParameter<bool>("EtaTrackFinder");
89  // bool Extrapolation_21 = iConfig.getParameter<bool>("Extrapolation_21");
90  bool configFromXML = iConfig.getParameter<bool>("configFromXML");
91  // bool DisableNewAlgo = iConfig.getParameter<bool>("DisableNewAlgo");
92 
93  std::map<std::string, int> allInts;
94  std::map<std::string, bool> allBools;
95  std::map<std::string, std::vector<std::string> > allMasks;
96 
97  allInts["PT_Assignment_nbits_Phi"] = iConfig.getParameter<int>("PT_Assignment_nbits_Phi");
98  allInts["PT_Assignment_nbits_PhiB"] = iConfig.getParameter<int>("PT_Assignment_nbits_PhiB");
99  allInts["PHI_Assignment_nbits_Phi"] = iConfig.getParameter<int>("PHI_Assignment_nbits_Phi");
100  allInts["PHI_Assignment_nbits_PhiB"] = iConfig.getParameter<int>("PHI_Assignment_nbits_PhiB");
101  allInts["Extrapolation_nbits_Phi"] = iConfig.getParameter<int>("Extrapolation_nbits_Phi");
102  allInts["Extrapolation_nbits_PhiB"] = iConfig.getParameter<int>("Extrapolation_nbits_PhiB");
103  allInts["BX_min"] = iConfig.getParameter<int>("BX_min");
104  allInts["BX_max"] = iConfig.getParameter<int>("BX_max");
105  allInts["Extrapolation_Filter"] = iConfig.getParameter<int>("Extrapolation_Filter");
106  allInts["OutOfTime_Filter_Window"] = iConfig.getParameter<int>("OutOfTime_Filter_Window");
107  allBools["OutOfTime_Filter"] = iConfig.getParameter<bool>("OutOfTime_Filter");
108  allBools["Open_LUTs"] = iConfig.getParameter<bool>("Open_LUTs");
109  allBools["EtaTrackFinder"] = iConfig.getParameter<bool>("EtaTrackFinder");
110  allBools["Extrapolation_21"] = iConfig.getParameter<bool>("Extrapolation_21");
111  allBools["configFromXML"] = iConfig.getParameter<bool>("configFromXML");
112  allBools["DisableNewAlgo"] = iConfig.getParameter<bool>("DisableNewAlgo");
113 
114  allMasks["mask_phtf_st1"] = iConfig.getParameter<std::vector<string> >("mask_phtf_st1");
115  allMasks["mask_phtf_st2"] = iConfig.getParameter<std::vector<string> >("mask_phtf_st2");
116  allMasks["mask_phtf_st3"] = iConfig.getParameter<std::vector<string> >("mask_phtf_st3");
117  allMasks["mask_phtf_st4"] = iConfig.getParameter<std::vector<string> >("mask_phtf_st4");
118 
119  allMasks["mask_ettf_st1"] = iConfig.getParameter<std::vector<string> >("mask_ettf_st1");
120  allMasks["mask_ettf_st2"] = iConfig.getParameter<std::vector<string> >("mask_ettf_st2");
121  allMasks["mask_ettf_st3"] = iConfig.getParameter<std::vector<string> >("mask_ettf_st3");
122 
123  /*
124  m_params.set_PT_Assignment_nbits_Phi(PT_Assignment_nbits_Phi);
125  m_params.set_PT_Assignment_nbits_PhiB(PT_Assignment_nbits_PhiB);
126  m_params.set_PHI_Assignment_nbits_Phi(PHI_Assignment_nbits_Phi);
127  m_params.set_PHI_Assignment_nbits_PhiB(PHI_Assignment_nbits_PhiB);
128  m_params.set_Extrapolation_nbits_Phi(Extrapolation_nbits_Phi);
129  m_params.set_Extrapolation_nbits_PhiB(Extrapolation_nbits_PhiB);
130  m_params.set_BX_min(BX_min);
131  m_params.set_BX_max(BX_max);
132  m_params.set_Extrapolation_Filter(Extrapolation_Filter);
133  m_params.set_OutOfTime_Filter_Window(OutOfTime_Filter_Window);
134  m_params.set_OutOfTime_Filter(OutOfTime_Filter);
135  m_params.set_Open_LUTs(Open_LUTs);
136  m_params.set_EtaTrackFinder(EtaTrackFinder);
137  m_params.set_Extrapolation_21(Extrapolation_21);
138  m_params.setFwVersion(fwVersion);
139  m_params.set_DisableNewAlgo(DisableNewAlgo);
140 
141 
143  std::vector<LUT> pta_lut(0); pta_lut.reserve(19);
144  std::vector<int> pta_threshold(6); pta_threshold.reserve(9);
145  if ( load_pt(pta_lut,pta_threshold, PT_Assignment_nbits_Phi, AssLUTpath) != 0 ) {
146  cout << "Can not open files to load pt-assignment look-up tables for L1TMuonBarrelTrackProducer!" << endl;
147  }
148  m_params.setpta_lut(pta_lut);
149  m_params.setpta_threshold(pta_threshold);
150 
152  std::vector<LUT> phi_lut(0); phi_lut.reserve(2);
153  if ( load_phi(phi_lut, PHI_Assignment_nbits_Phi, PHI_Assignment_nbits_PhiB, AssLUTpath) != 0 ) {
154  cout << "Can not open files to load phi-assignment look-up tables for L1TMuonBarrelTrackProducer!" << endl;
155  }
156  m_params.setphi_lut(phi_lut);
157 
158 
159 
160 
161  m_params.l1mudttfparams.reset();
162 
163  std::vector <std::string> mask_phtf_st1 = iConfig.getParameter< std::vector <string> >("mask_phtf_st1");
164  std::vector <std::string> mask_phtf_st2 = iConfig.getParameter< std::vector <string> >("mask_phtf_st2");
165  std::vector <std::string> mask_phtf_st3 = iConfig.getParameter< std::vector <string> >("mask_phtf_st3");
166  std::vector <std::string> mask_phtf_st4 = iConfig.getParameter< std::vector <string> >("mask_phtf_st4");
167 
168  std::vector <std::string> mask_ettf_st1 = iConfig.getParameter< std::vector <string> >("mask_ettf_st1");
169  std::vector <std::string> mask_ettf_st2 = iConfig.getParameter< std::vector <string> >("mask_ettf_st2");
170  std::vector <std::string> mask_ettf_st3 = iConfig.getParameter< std::vector <string> >("mask_ettf_st3");
171 
172  for( int wh=-3; wh<4; wh++ ) {
173  int sec = 0;
174  for(char& c : mask_phtf_st1[wh+3]) {
175  int mask = c - '0';
176  m_params.l1mudttfmasks.set_inrec_chdis_st1(wh,sec,mask);
177  sec++;
178  }
179  sec = 0;
180  for(char& c : mask_phtf_st2[wh+3]) {
181  int mask = c - '0';
182  m_params.l1mudttfmasks.set_inrec_chdis_st2(wh,sec,mask);
183  sec++;
184  }
185  sec = 0;
186  for(char& c : mask_phtf_st3[wh+3]) {
187  int mask = c - '0';
188  m_params.l1mudttfmasks.set_inrec_chdis_st3(wh,sec,mask);
189  sec++;
190  }
191  sec = 0;
192  for(char& c : mask_phtf_st4[wh+3]) {
193  int mask = c - '0';
194  m_params.l1mudttfmasks.set_inrec_chdis_st4(wh,sec,mask);
195  sec++;
196  }
197  sec = 0;
198  for(char& c : mask_ettf_st1[wh+3]) {
199  int mask = c - '0';
200  m_params.l1mudttfmasks.set_etsoc_chdis_st1(wh,sec,mask);
201  sec++;
202  }
203  sec = 0;
204  for(char& c : mask_ettf_st2[wh+3]) {
205  int mask = c - '0';
206  m_params.l1mudttfmasks.set_etsoc_chdis_st2(wh,sec,mask);
207  sec++;
208  }
209  sec = 0;
210  for(char& c : mask_ettf_st3[wh+3]) {
211  int mask = c - '0';
212  m_params.l1mudttfmasks.set_etsoc_chdis_st3(wh,sec,mask);
213  //Not used in BMTF - mask
214  m_params.l1mudttfmasks.set_inrec_chdis_csc(wh,sec,true);
215  sec++;
216  }
217 
218  }
219 
220 
222  std::vector<L1TMuonBarrelParams::LUTParams::extLUT> ext_lut(0); ext_lut.reserve(12);
223  if ( load_ext(ext_lut, PHI_Assignment_nbits_Phi, PHI_Assignment_nbits_PhiB) != 0 ) {
224  cout << "Can not open files to load extrapolation look-up tables for L1TMuonBarrelTrackProducer!" << endl;
225  }
226  m_params.setext_lut(ext_lut);
227 
228  //m_params.l1mudttfextlut.load();
229 
230  */
231 
232  m_params_helper.configFromPy(allInts, allBools, allMasks, fwVersion, AssLUTpath);
233  if (configFromXML) {
234  cout << "Configuring BMTF Emulator from xml files.\n";
235  edm::FileInPath hwXmlFile(iConfig.getParameter<std::string>("hwXmlFile"));
236  edm::FileInPath topCfgXmlFile(iConfig.getParameter<std::string>("topCfgXmlFile"));
237  std::string xmlCfgKey = iConfig.getParameter<std::string>("xmlCfgKey");
238 
239  l1t::TriggerSystem trgSys;
240  trgSys.configureSystemFromFiles(hwXmlFile.fullPath().c_str(), topCfgXmlFile.fullPath().c_str(), xmlCfgKey.c_str());
241 
242  /* std::map<std::string, std::string> procRole = trgSys.getProcRole();
243 
244  for(auto it_proc=procRole.begin(); it_proc!=procRole.end(); it_proc++ ){
245 
246  std::string procId = it_proc->first;
247 
248  std::map<std::string, l1t::Setting> settings = trgSys.getSettings(procId);
249  std::vector<l1t::TableRow> tRow = settings["regTable"].getTableRows();
250  for(auto it=tRow.begin(); it!=tRow.end(); it++)
251  {
252  if (it->getRowValue<std::string>("register_path").find("open_lut") != std::string::npos){
253  //std::cout << "Value is: " << it->getRowValue<bool>("register_value") << std::endl;
254  m_params.set_Open_LUTs(it->getRowValue<bool>("register_value"));
255  }
256  if (it->getRowValue<std::string>("register_path").find("sel_21") != std::string::npos){
257  //std::cout << "Value is: " << it->getRowValue<bool>("register_value") << std::endl;
258  m_params.set_Extrapolation_21(it->getRowValue<bool>("register_value"));
259  }
260 
261  if (it->getRowValue<std::string>("register_path").find("dis_newalgo") != std::string::npos){
262  //std::cout << "Value is: " << it->getRowValue<int>("register_value") << std::endl;
263  //int fwv = (it->getRowValue<int>("register_value")==1) ? 1 : 2;
264  //m_params.setFwVersion(fwv);
265  bool disnewalgo = (it->getRowValue<int>("register_value")==1);
266  m_params.set_DisableNewAlgo(disnewalgo);
267  }
268 
269  string masks[5] = {"mask_ctrl_N2", "mask_ctrl_N1", "mask_ctrl_0", "mask_ctrl_P1", "mask_ctrl_P2"};
270 
271  for(int m=0; m<5; m++){
272 
273  if (it->getRowValue<std::string>("register_path").find(masks[m]) != std::string::npos){
274  string mask_ctrl = it->getRowValue<string>("register_value");
275  const char *hexstring = mask_ctrl.c_str();
277  int mask = (int)strtol((hexstring+7), NULL, 16);
278  int mask_all = (int)strtol((hexstring), NULL, 16);
280  if(!( mask_all==0x111111 || mask_all==0x222222 || mask_all==0x333333 || mask_all==0x444444 ||
281  mask_all==0x555555 || mask_all==0x666666 || mask_all==0x777777) )
282  cerr<<"BMTF: Cannot re-emulate properly. Individual link masking cannot be handled."<<endl;
283 
284  if((mask&1)>0) {
285  for(int sec=0; sec<12; sec++){
286  if(masks[m]=="mask_ctrl_N2"){
287  m_params.l1mudttfmasks.set_inrec_chdis_st1(-3,sec,true);
288  m_params.l1mudttfmasks.set_etsoc_chdis_st1(-3,sec,true);
289  }
290  if(masks[m]=="mask_ctrl_N1"){
291  m_params.l1mudttfmasks.set_inrec_chdis_st1(-2,sec,true);
292  m_params.l1mudttfmasks.set_etsoc_chdis_st1(-2,sec,true);
293  }
294 
295  if(masks[m]=="mask_ctrl_0"){
296  m_params.l1mudttfmasks.set_inrec_chdis_st1(-1,sec,true);
297  m_params.l1mudttfmasks.set_inrec_chdis_st1(1,sec,true);
298  m_params.l1mudttfmasks.set_etsoc_chdis_st1(-1,sec,true);
299  m_params.l1mudttfmasks.set_etsoc_chdis_st1(1,sec,true);
300  }
301  if(masks[m]=="mask_ctrl_P1"){
302  m_params.l1mudttfmasks.set_inrec_chdis_st1(2,sec,true);
303  m_params.l1mudttfmasks.set_etsoc_chdis_st1(2,sec,true);
304  }
305  if(masks[m]=="mask_ctrl_P2"){
306  m_params.l1mudttfmasks.set_inrec_chdis_st1(3,sec,true);
307  m_params.l1mudttfmasks.set_etsoc_chdis_st1(3,sec,true);
308  }
309  }
310 
311  }
312 
313  if((mask&2)>0) {
314  for(int sec=0; sec<12; sec++){
315  if(masks[m]=="mask_ctrl_N2"){
316  m_params.l1mudttfmasks.set_inrec_chdis_st2(-3,sec,true);
317  m_params.l1mudttfmasks.set_etsoc_chdis_st2(-3,sec,true);
318  }
319  if(masks[m]=="mask_ctrl_N1"){
320  m_params.l1mudttfmasks.set_inrec_chdis_st2(-2,sec,true);
321  m_params.l1mudttfmasks.set_etsoc_chdis_st2(-2,sec,true);
322  }
323 
324  if(masks[m]=="mask_ctrl_0"){
325  m_params.l1mudttfmasks.set_inrec_chdis_st2(-1,sec,true);
326  m_params.l1mudttfmasks.set_inrec_chdis_st2(1,sec,true);
327  m_params.l1mudttfmasks.set_etsoc_chdis_st2(-1,sec,true);
328  m_params.l1mudttfmasks.set_etsoc_chdis_st2(1,sec,true);
329  }
330  if(masks[m]=="mask_ctrl_P1"){
331  m_params.l1mudttfmasks.set_inrec_chdis_st2(2,sec,true);
332  m_params.l1mudttfmasks.set_etsoc_chdis_st2(2,sec,true);
333  }
334  if(masks[m]=="mask_ctrl_P2"){
335  m_params.l1mudttfmasks.set_inrec_chdis_st2(3,sec,true);
336  m_params.l1mudttfmasks.set_etsoc_chdis_st2(3,sec,true);
337  }
338  }
339  }
340 
341  if((mask&4)>0) {
342  for(int sec=0; sec<12; sec++){
343  if(masks[m]=="mask_ctrl_N2"){
344  m_params.l1mudttfmasks.set_inrec_chdis_st3(-3,sec,true);
345  m_params.l1mudttfmasks.set_etsoc_chdis_st3(-3,sec,true);
346  }
347  if(masks[m]=="mask_ctrl_N1"){
348  m_params.l1mudttfmasks.set_inrec_chdis_st3(-2,sec,true);
349  m_params.l1mudttfmasks.set_etsoc_chdis_st3(-2,sec,true);
350  }
351 
352  if(masks[m]=="mask_ctrl_0"){
353  m_params.l1mudttfmasks.set_inrec_chdis_st3(-1,sec,true);
354  m_params.l1mudttfmasks.set_inrec_chdis_st3(1,sec,true);
355  m_params.l1mudttfmasks.set_etsoc_chdis_st3(-1,sec,true);
356  m_params.l1mudttfmasks.set_etsoc_chdis_st3(1,sec,true);
357  }
358  if(masks[m]=="mask_ctrl_P1"){
359  m_params.l1mudttfmasks.set_inrec_chdis_st3(2,sec,true);
360  m_params.l1mudttfmasks.set_etsoc_chdis_st3(2,sec,true);
361  }
362  if(masks[m]=="mask_ctrl_P2"){
363  m_params.l1mudttfmasks.set_inrec_chdis_st3(3,sec,true);
364  m_params.l1mudttfmasks.set_etsoc_chdis_st3(3,sec,true);
365  }
366  }
367  }
368 
369  if((mask&8)>0) {
370  for(int sec=0; sec<12; sec++){
371  if(masks[m]=="mask_ctrl_N2"){
372  m_params.l1mudttfmasks.set_inrec_chdis_st4(-3,sec,true);
373  }
374  if(masks[m]=="mask_ctrl_N1"){
375  m_params.l1mudttfmasks.set_inrec_chdis_st4(-2,sec,true);
376  }
377 
378  if(masks[m]=="mask_ctrl_0"){
379  m_params.l1mudttfmasks.set_inrec_chdis_st4(-1,sec,true);
380  m_params.l1mudttfmasks.set_inrec_chdis_st4(1,sec,true);
381  }
382  if(masks[m]=="mask_ctrl_P1"){
383  m_params.l1mudttfmasks.set_inrec_chdis_st4(2,sec,true);
384  }
385  if(masks[m]=="mask_ctrl_P2"){
386  m_params.l1mudttfmasks.set_inrec_chdis_st4(3,sec,true);
387  }
388  }
389  }
390  }///if register path
391  }///for masks
392  }///for it tRow
393  }///for it procRole */
395  }
396  //m_params = cast_to_L1TMuonBarrelParams((L1TMuonBarrelParams_PUBLIC)m_params_helper);
397 }
398 
400 
401 /*int L1TMuonBarrelParamsESProducer::load_pt(std::vector<LUT>& pta_lut,
402  std::vector<int>& pta_threshold,
403  unsigned short int nbitphi,
404  std::string AssLUTpath
405  ){
406 
407 
408 // maximal number of pt assignment methods
409 const int MAX_PTASSMETH = 19;
410 const int MAX_PTASSMETHA = 12;
411 
412 // pt assignment methods
413 enum PtAssMethod { PT12L, PT12H, PT13L, PT13H, PT14L, PT14H,
414  PT23L, PT23H, PT24L, PT24H, PT34L, PT34H,
415  PB12H, PB13H, PB14H, PB21H, PB23H, PB24H, PB34H,
416  NODEF };
417 
418  // get directory name
419  string pta_str = "";
420  // precision : in the look-up tables the following precision is used :
421  // phi ...12 bits (address) and pt ...5 bits
422  // now convert phi and phib to the required precision
423  int nbit_phi = nbitphi;
424  int sh_phi = 12 - nbit_phi;
425 
426  // loop over all pt-assignment methods
427  for ( int pam = 0; pam < MAX_PTASSMETH; pam++ ) {
428  switch ( pam ) {
429  case PT12L : { pta_str = "pta12l"; break; }
430  case PT12H : { pta_str = "pta12h"; break; }
431  case PT13L : { pta_str = "pta13l"; break; }
432  case PT13H : { pta_str = "pta13h"; break; }
433  case PT14L : { pta_str = "pta14l"; break; }
434  case PT14H : { pta_str = "pta14h"; break; }
435  case PT23L : { pta_str = "pta23l"; break; }
436  case PT23H : { pta_str = "pta23h"; break; }
437  case PT24L : { pta_str = "pta24l"; break; }
438  case PT24H : { pta_str = "pta24h"; break; }
439  case PT34L : { pta_str = "pta34l"; break; }
440  case PT34H : { pta_str = "pta34h"; break; }
441  case PB12H : { pta_str = "ptb12h_Feb2016"; break; }
442  case PB13H : { pta_str = "ptb13h_Feb2016"; break; }
443  case PB14H : { pta_str = "ptb14h_Feb2016"; break; }
444  case PB21H : { pta_str = "ptb21h_Feb2016"; break; }
445  case PB23H : { pta_str = "ptb23h_Feb2016"; break; }
446  case PB24H : { pta_str = "ptb24h_Feb2016"; break; }
447  case PB34H : { pta_str = "ptb34h_Feb2016"; break; }
448 
449  }
450 
451  // assemble file name
452  string lutpath = AssLUTpath;
453  edm::FileInPath lut_f = edm::FileInPath(string(lutpath + pta_str + ".lut"));
454  string pta_file = lut_f.fullPath();
455 
456  // open file
457  L1TriggerLutFile file(pta_file);
458  if ( file.open() != 0 ) return -1;
459 
460  // get the right shift factor
461  int shift = sh_phi;
462  int adr_old = -2048 >> shift;
463  if (pam >= MAX_PTASSMETHA) adr_old = -512 >> shift;
464 
465  LUT tmplut;
466 
467  int number = -1;
468  int sum_pt = 0;
469 
470  if ( file.good() ) {
471  int threshold = file.readInteger();
472  pta_threshold[pam/2] = threshold;
473  }
474 
475  // read values and shift to correct precision
476  while ( file.good() ) {
477 
478  int adr = (file.readInteger()) >> shift;
479  int pt = file.readInteger();
480 
481  number++;
482  //cout<<pam<<" "<<number<<" "<<MAX_PTASSMETHA<<endl;
483  if ( adr != adr_old ) {
484  assert(number);
485  tmplut.insert(make_pair( adr_old, (sum_pt/number) ));
486 
487  adr_old = adr;
488  number = 0;
489  sum_pt = 0;
490  }
491 
492  sum_pt += pt;
493 
494  if ( !file.good() ) file.close();
495 
496  }
497 
498  file.close();
499  pta_lut.push_back(tmplut);
500  }
501  return 0;
502 
503 }
504 
505 
506 
507 
508 int L1TMuonBarrelParamsESProducer::load_phi(std::vector<LUT>& phi_lut,
509  unsigned short int nbit_phi,
510  unsigned short int nbit_phib,
511  std::string AssLUTpath
512  ) {
513 
514 
515  // precision : in the look-up tables the following precision is used :
516  // address (phib) ...10 bits, phi ... 12 bits
517 
518  int sh_phi = 12 - nbit_phi;
519  int sh_phib = 10 - nbit_phib;
520 
521  string phi_str;
522  // loop over all phi-assignment methods
523  for ( int idx = 0; idx < 2; idx++ ) {
524  switch ( idx ) {
525  case 0 : { phi_str = "phi12"; break; }
526  case 1 : { phi_str = "phi42"; break; }
527  }
528 
529  // assemble file name
530  edm::FileInPath lut_f = edm::FileInPath(string(AssLUTpath + phi_str + ".lut"));
531  string phi_file = lut_f.fullPath();
532 
533  // open file
534  L1TriggerLutFile file(phi_file);
535  if ( file.open() != 0 ) return -1;
536 
537  LUT tmplut;
538 
539  int number = -1;
540  int adr_old = -512 >> sh_phib;
541  int sum_phi = 0;
542 
543  // read values
544  while ( file.good() ) {
545 
546  int adr = (file.readInteger()) >> sh_phib;
547  int phi = file.readInteger();
548 
549  number++;
550 
551  if ( adr != adr_old ) {
552  assert(number);
553  tmplut.insert(make_pair( adr_old, ((sum_phi/number) >> sh_phi) ));
554 
555  adr_old = adr;
556  number = 0;
557  sum_phi = 0;
558  }
559 
560  sum_phi += phi;
561 
562  if ( !file.good() ) file.close();
563 
564  }
565 
566  file.close();
567  phi_lut.push_back(tmplut);
568  }
569  return 0;
570 
571 }
572 
573 
574 int L1TMuonBarrelParamsESProducer::getPtLutThreshold(int pta_ind, std::vector<int>& pta_threshold) const {
575 
576  if ( pta_ind >= 0 && pta_ind < 13/2 ) {
577  return pta_threshold[pta_ind];
578  }
579  else {
580  cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
581  return 0;
582  }
583 
584 }
585 
586 */
587 
588 //
589 // load extrapolation look-up tables
590 //
591 /*
592 int L1TMuonBarrelParamsESProducer::load_ext(std::vector<L1TMuonBarrelParams::LUTParams::extLUT>& ext_lut,
593  unsigned short int nbit_phi,
594  unsigned short int nbit_phib) {
595 
596  //max. number of Extrapolations
597  const int MAX_EXT = 12;
598 
599  // extrapolation types
600  enum Extrapolation { EX12, EX13, EX14, EX21, EX23, EX24, EX34,
601  EX15, EX16, EX25, EX26, EX56 };
602 
603  // get directory name
604  string defaultPath = "L1Trigger/L1TMuon/data/bmtf_luts/";
605  string ext_dir = "LUTs_Ext/";
606  string ext_str = "";
607 
608  // precision : in the look-up tables the following precision is used :
609  // phi ...12 bits (low, high), phib ...10 bits (address)
610  // now convert phi and phib to the required precision
611 
612  int sh_phi = 12 - nbit_phi;
613  int sh_phib = 10 - nbit_phib;
614 
615  // loop over all extrapolations
616  for ( int ext = 0; ext < MAX_EXT; ext++ ) {
617  switch (ext) {
618  case EX12 : ext_str = "ext12"; break;
619  case EX13 : ext_str = "ext13"; break;
620  case EX14 : ext_str = "ext14"; break;
621  case EX21 : ext_str = "ext21"; break;
622  case EX23 : ext_str = "ext23"; break;
623  case EX24 : ext_str = "ext24"; break;
624  case EX34 : ext_str = "ext34"; break;
625  case EX15 : ext_str = "ext15"; break;
626  case EX16 : ext_str = "ext16"; break;
627  case EX25 : ext_str = "ext25"; break;
628  case EX26 : ext_str = "ext26"; break;
629  case EX56 : ext_str = "ext56"; break;
630  }
631 
632  // assemble file name
633  edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
634  string ext_file = lut_f.fullPath();
635 
636  // open file
637  L1TriggerLutFile file(ext_file);
638  if ( file.open() != 0 ) return -1;
639  // if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
640  // << file.getName() << endl;
641 
642  L1TMuonBarrelParams::LUTParams::extLUT tmplut;
643 
644  int number = -1;
645  int adr_old = -512 >> sh_phib;
646  int sum_low = 0;
647  int sum_high = 0;
648 
649  // read values and shift to correct precision
650  while ( file.good() ) {
651 
652  int adr = ( file.readInteger() ) >> sh_phib; // address (phib)
653  int low = ( file.readInteger() ); // low value (phi)
654  int high = ( file.readInteger() ); // high value (phi)
655 
656  number++;
657 
658  if ( adr != adr_old ) {
659 
660  tmplut.low[adr_old] = sum_low >> sh_phi;
661  tmplut.high[adr_old] = sum_high >> sh_phi;
662 
663  adr_old = adr;
664  number = 0;
665  sum_low = 0;
666  sum_high = 0;
667 
668  }
669 
670  if (number == 0) sum_low = low;
671  if (number == 0) sum_high = high;
672 
673  if ( !file.good() ) file.close();
674  }
675 
676  file.close();
677  ext_lut.push_back(tmplut);
678  }
679  return 0;
680 
681 }
682 
683 
684 //
685 // member functions
686 //
687 */
688 // ------------ method called to produce the data ------------
690  return std::make_unique<L1TMuonBarrelParams>(m_params_helper);
691 }
692 
693 //define this as a plug-in
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
int getPtLutThreshold(int, std::vector< int > &) const
int load_phi(std::vector< LUT > &, unsigned short int, unsigned short int, std::string)
void configureSystemFromFiles(const char *hwCfgFile, const char *topCfgFile, const char *key)
Definition: TriggerSystem.cc:8
L1TMuonBarrelParamsESProducer(const edm::ParameterSet &)
int load_pt(std::vector< LUT > &, std::vector< int > &, unsigned short int, std::string)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
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)
ReturnType produce(const L1TMuonBarrelParamsRcd &)
std::string fullPath() const
Definition: FileInPath.cc:161
void configFromDB(l1t::TriggerSystem &trgSys)
tuple cout
Definition: gather_cfg.py:144
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
std::unique_ptr< L1TMuonBarrelParams > ReturnType
int load_ext(std::vector< L1TMuonBarrelParams::LUTParams::extLUT > &, unsigned short int, unsigned short int)