CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
11 // system include files
12 #include <memory>
13 #include "boost/shared_ptr.hpp"
14 
15 // user include files
20 
24 
28 
29 // class declaration
30 //
31 typedef std::map<short, short, std::less<short> > LUT;
32 
34  public:
37  int load_pt(std::vector<LUT>& , std::vector<int>&, unsigned short int, std::string);
38  int load_phi(std::vector<LUT>& , unsigned short int, unsigned short int, std::string);
39  int load_ext(std::vector<L1TMuonBarrelParams::LUTParams::extLUT>&, unsigned short int, unsigned short int );
40  //void print(std::vector<LUT>& , std::vector<int>& ) const;
41  int getPtLutThreshold(int ,std::vector<int>& ) const;
42  typedef boost::shared_ptr<L1TMuonBarrelParams> ReturnType;
43 
45  private:
47 };
48 
49 //
50 // constants, enums and typedefs
51 //
52 
53 //
54 // static data member definitions
55 //
56 
57 //
58 // constructors and destructor
59 //
61 {
62  //the following line is needed to tell the framework what
63  // data is being produced
64  setWhatProduced(this);
65  // Firmware version
66  unsigned fwVersion = iConfig.getParameter<unsigned>("fwVersion");
67 
68  m_params.setFwVersion(fwVersion);
69  //cout<<"FW VERSION "<<fwVersion<<endl;
70  std::string AssLUTpath = iConfig.getParameter<std::string>("AssLUTPath");
71  m_params.setAssLUTPath(AssLUTpath);
72 
73  int PT_Assignment_nbits_Phi = iConfig.getParameter<int>("PT_Assignment_nbits_Phi");
74  int PT_Assignment_nbits_PhiB = iConfig.getParameter<int>("PT_Assignment_nbits_PhiB");
75  int PHI_Assignment_nbits_Phi = iConfig.getParameter<int>("PHI_Assignment_nbits_Phi");
76  int PHI_Assignment_nbits_PhiB = iConfig.getParameter<int>("PHI_Assignment_nbits_PhiB");
77  int Extrapolation_nbits_Phi = iConfig.getParameter<int>("Extrapolation_nbits_Phi");
78  int Extrapolation_nbits_PhiB = iConfig.getParameter<int>("Extrapolation_nbits_PhiB");
79  int BX_min = iConfig.getParameter<int>("BX_min");
80  int BX_max = iConfig.getParameter<int>("BX_max");
81  int Extrapolation_Filter = iConfig.getParameter<int>("Extrapolation_Filter");
82  int OutOfTime_Filter_Window = iConfig.getParameter<int>("OutOfTime_Filter_Window");
83  bool OutOfTime_Filter = iConfig.getParameter<bool>("OutOfTime_Filter");
84  bool Open_LUTs = iConfig.getParameter<bool>("Open_LUTs");
85  bool EtaTrackFinder = iConfig.getParameter<bool>("EtaTrackFinder");
86  bool Extrapolation_21 = iConfig.getParameter<bool>("Extrapolation_21");
87 
88  m_params.set_PT_Assignment_nbits_Phi(PT_Assignment_nbits_Phi);
89  m_params.set_PT_Assignment_nbits_PhiB(PT_Assignment_nbits_PhiB);
90  m_params.set_PHI_Assignment_nbits_Phi(PHI_Assignment_nbits_Phi);
91  m_params.set_PHI_Assignment_nbits_PhiB(PHI_Assignment_nbits_PhiB);
92  m_params.set_Extrapolation_nbits_Phi(Extrapolation_nbits_Phi);
93  m_params.set_Extrapolation_nbits_PhiB(Extrapolation_nbits_PhiB);
94  m_params.set_BX_min(BX_min);
95  m_params.set_BX_max(BX_max);
96  m_params.set_Extrapolation_Filter(Extrapolation_Filter);
97  m_params.set_OutOfTime_Filter_Window(OutOfTime_Filter_Window);
98  m_params.set_OutOfTime_Filter(OutOfTime_Filter);
99  m_params.set_Open_LUTs(Open_LUTs);
100  m_params.set_EtaTrackFinder(EtaTrackFinder);
101  m_params.set_Extrapolation_21(Extrapolation_21);
102 
103 
105  std::vector<LUT> pta_lut; pta_lut.reserve(19);
106  std::vector<int> pta_threshold(10);
107  if ( load_pt(pta_lut,pta_threshold, PT_Assignment_nbits_Phi, AssLUTpath) != 0 ) {
108  cout << "Can not open files to load pt-assignment look-up tables for L1TMuonBarrelTrackProducer!" << endl;
109  }
110  m_params.setpta_lut(pta_lut);
111  m_params.setpta_threshold(pta_threshold);
112 
114  std::vector<LUT> phi_lut; phi_lut.reserve(2);
115  if ( load_phi(phi_lut, PHI_Assignment_nbits_Phi, PHI_Assignment_nbits_PhiB, AssLUTpath) != 0 ) {
116  cout << "Can not open files to load phi-assignment look-up tables for L1TMuonBarrelTrackProducer!" << endl;
117  }
118  m_params.setphi_lut(phi_lut);
119 
120 
122  //std::vector<L1TMuonBarrelParams::LUTParams::extLUT> ext_lut(0); ext_lut.reserve(12);
123  //if ( load_ext(ext_lut, PHI_Assignment_nbits_Phi, PHI_Assignment_nbits_PhiB) != 0 ) {
124  // cout << "Can not open files to load extrapolation look-up tables for L1TMuonBarrelTrackProducer!" << endl;
125  //}
126  //m_params.setext_lut(ext_lut);
127  //m_params.l1mudttfparams.set_soc_openlut_extr(1,1,false);
128 
129  std::vector <std::string> mask_phtf_st1 = iConfig.getParameter< std::vector <string> >("mask_phtf_st1");
130  std::vector <std::string> mask_phtf_st2 = iConfig.getParameter< std::vector <string> >("mask_phtf_st2");
131  std::vector <std::string> mask_phtf_st3 = iConfig.getParameter< std::vector <string> >("mask_phtf_st3");
132  std::vector <std::string> mask_phtf_st4 = iConfig.getParameter< std::vector <string> >("mask_phtf_st4");
133 
134  std::vector <std::string> mask_ettf_st1 = iConfig.getParameter< std::vector <string> >("mask_ettf_st1");
135  std::vector <std::string> mask_ettf_st2 = iConfig.getParameter< std::vector <string> >("mask_ettf_st2");
136  std::vector <std::string> mask_ettf_st3 = iConfig.getParameter< std::vector <string> >("mask_ettf_st3");
137 
138  for( int wh=-3; wh<4; wh++ ) {
139  int sec = 0;
140  for(char& c : mask_phtf_st1[wh+3]) {
141  int mask = c - '0';
143  sec++;
144  }
145  sec = 0;
146  for(char& c : mask_phtf_st2[wh+3]) {
147  int mask = c - '0';
149  sec++;
150  }
151  sec = 0;
152  for(char& c : mask_phtf_st3[wh+3]) {
153  int mask = c - '0';
155  sec++;
156  }
157  sec = 0;
158  for(char& c : mask_phtf_st4[wh+3]) {
159  int mask = c - '0';
161  sec++;
162  }
163  sec = 0;
164  for(char& c : mask_ettf_st1[wh+3]) {
165  int mask = c - '0';
167  sec++;
168  }
169  sec = 0;
170  for(char& c : mask_ettf_st2[wh+3]) {
171  int mask = c - '0';
173  sec++;
174  }
175  sec = 0;
176  for(char& c : mask_ettf_st3[wh+3]) {
177  int mask = c - '0';
179  sec++;
180  //Not used in BMTF init to false
182 
183  }
184 
185  }
186  /*
187 cout<<"===="<<endl;
188  for( int wh=-3; wh<4; wh++ ) {
189  for( int sec=0; sec<12; sec++ ) {
190  // m_params.l1mudttfmasks.set_inrec_chdis_st1(wh,sec,false);
191  m_params.l1mudttfmasks.set_inrec_chdis_st2(wh,sec,false);
192  m_params.l1mudttfmasks.set_inrec_chdis_st3(wh,sec,false);
193  m_params.l1mudttfmasks.set_inrec_chdis_st4(wh,sec,false);
194  m_params.l1mudttfmasks.set_etsoc_chdis_st1(wh,sec,false);
195  m_params.l1mudttfmasks.set_etsoc_chdis_st2(wh,sec,false);
196  m_params.l1mudttfmasks.set_etsoc_chdis_st3(wh,sec,false);
197  m_params.l1mudttfmasks.set_inrec_chdis_csc(wh,sec,false);
198 
199  //if(wh==3 || wh==-3) m_params.l1mudttfmasks.set_inrec_chdis_st1(wh,sec,true);
200 
201  }
202  }
203 */
204 
205 
206 }
207 
208 
210 {
211 
212 }
213 
214 int L1TMuonBarrelParamsESProducer::load_pt(std::vector<LUT>& pta_lut,
215  std::vector<int>& pta_threshold,
216  unsigned short int nbitphi,
217  std::string AssLUTpath
218  ){
219 
220 
221 // maximal number of pt assignment methods
222 const int MAX_PTASSMETH = 19;
223 const int MAX_PTASSMETHA = 12;
224 
225 // pt assignment methods
228  PB12H, PB13H, PB14H, PB21H, PB23H, PB24H, PB34H,
229  NODEF };
230 
231  // get directory name
232  string pta_str = "";
233  // precision : in the look-up tables the following precision is used :
234  // phi ...12 bits (address) and pt ...5 bits
235  // now convert phi and phib to the required precision
236  int nbit_phi = nbitphi;
237  int sh_phi = 12 - nbit_phi;
238 
239  // loop over all pt-assignment methods
240  for ( int pam = 0; pam < MAX_PTASSMETH; pam++ ) {
241  switch ( pam ) {
242  case PT12L : { pta_str = "pta12l"; break; }
243  case PT12H : { pta_str = "pta12h"; break; }
244  case PT13L : { pta_str = "pta13l"; break; }
245  case PT13H : { pta_str = "pta13h"; break; }
246  case PT14L : { pta_str = "pta14l"; break; }
247  case PT14H : { pta_str = "pta14h"; break; }
248  case PT23L : { pta_str = "pta23l"; break; }
249  case PT23H : { pta_str = "pta23h"; break; }
250  case PT24L : { pta_str = "pta24l"; break; }
251  case PT24H : { pta_str = "pta24h"; break; }
252  case PT34L : { pta_str = "pta34l"; break; }
253  case PT34H : { pta_str = "pta34h"; break; }
254  case PB12H : { pta_str = "ptb12h_Feb2016"; break; }
255  case PB13H : { pta_str = "ptb13h_Feb2016"; break; }
256  case PB14H : { pta_str = "ptb14h_Feb2016"; break; }
257  case PB21H : { pta_str = "ptb21h_Feb2016"; break; }
258  case PB23H : { pta_str = "ptb23h_Feb2016"; break; }
259  case PB24H : { pta_str = "ptb24h_Feb2016"; break; }
260  case PB34H : { pta_str = "ptb34h_Feb2016"; break; }
261 
262  }
263 
264  // assemble file name
265  string lutpath = AssLUTpath;
266  edm::FileInPath lut_f = edm::FileInPath(string(lutpath + pta_str + ".lut"));
267  string pta_file = lut_f.fullPath();
268 
269  // open file
270  L1TriggerLutFile file(pta_file);
271  if ( file.open() != 0 ) return -1;
272 
273  // get the right shift factor
274  int shift = sh_phi;
275  int adr_old = -2048 >> shift;
276  if (pam >= MAX_PTASSMETHA) adr_old = -512 >> shift;
277 
278  LUT tmplut;
279 
280  int number = -1;
281  int sum_pt = 0;
282 
283  if ( file.good() ) {
284  int threshold = file.readInteger();
285  pta_threshold[pam/2] = threshold;
286  }
287 
288  // read values and shift to correct precision
289  while ( file.good() ) {
290 
291  int adr = (file.readInteger()) >> shift;
292  int pt = file.readInteger();
293 
294  number++;
295  //cout<<pam<<" "<<number<<" "<<MAX_PTASSMETHA<<endl;
296  if ( adr != adr_old ) {
297  assert(number);
298  tmplut.insert(make_pair( adr_old, (sum_pt/number) ));
299 
300  adr_old = adr;
301  number = 0;
302  sum_pt = 0;
303  }
304 
305  sum_pt += pt;
306 
307  if ( !file.good() ) file.close();
308 
309  }
310 
311  file.close();
312  pta_lut.push_back(tmplut);
313  }
314  return 0;
315 
316 }
317 
318 
319 
320 
321 int L1TMuonBarrelParamsESProducer::load_phi(std::vector<LUT>& phi_lut,
322  unsigned short int nbit_phi,
323  unsigned short int nbit_phib,
324  std::string AssLUTpath
325  ) {
326 
327 
328  // precision : in the look-up tables the following precision is used :
329  // address (phib) ...10 bits, phi ... 12 bits
330 
331  int sh_phi = 12 - nbit_phi;
332  int sh_phib = 10 - nbit_phib;
333 
334  string phi_str;
335  // loop over all phi-assignment methods
336  for ( int idx = 0; idx < 2; idx++ ) {
337  switch ( idx ) {
338  case 0 : { phi_str = "phi12"; break; }
339  case 1 : { phi_str = "phi42"; break; }
340  }
341 
342  // assemble file name
343  edm::FileInPath lut_f = edm::FileInPath(string(AssLUTpath + phi_str + ".lut"));
344  string phi_file = lut_f.fullPath();
345 
346  // open file
347  L1TriggerLutFile file(phi_file);
348  if ( file.open() != 0 ) return -1;
349 
350  LUT tmplut;
351 
352  int number = -1;
353  int adr_old = -512 >> sh_phib;
354  int sum_phi = 0;
355 
356  // read values
357  while ( file.good() ) {
358 
359  int adr = (file.readInteger()) >> sh_phib;
360  int phi = file.readInteger();
361 
362  number++;
363 
364  if ( adr != adr_old ) {
365  assert(number);
366  tmplut.insert(make_pair( adr_old, ((sum_phi/number) >> sh_phi) ));
367 
368  adr_old = adr;
369  number = 0;
370  sum_phi = 0;
371  }
372 
373  sum_phi += phi;
374 
375  if ( !file.good() ) file.close();
376 
377  }
378 
379  file.close();
380  phi_lut.push_back(tmplut);
381  }
382  return 0;
383 
384 }
385 
386 int L1TMuonBarrelParamsESProducer::getPtLutThreshold(int pta_ind, std::vector<int>& pta_threshold) const {
387 
388  if ( pta_ind >= 0 && pta_ind < 13/2 ) {
389  return pta_threshold[pta_ind];
390  }
391  else {
392  cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
393  return 0;
394  }
395 
396 }
397 
398 
399 
400 
401 
402 
403 //
404 // load extrapolation look-up tables
405 //
406 int L1TMuonBarrelParamsESProducer::load_ext(std::vector<L1TMuonBarrelParams::LUTParams::extLUT>& ext_lut,
407  unsigned short int nbit_phi,
408  unsigned short int nbit_phib) {
409 
410  //max. number of Extrapolations
411  const int MAX_EXT = 12;
412 
413  // extrapolation types
414  enum Extrapolation { EX12, EX13, EX14, EX21, EX23, EX24, EX34,
415  EX15, EX16, EX25, EX26, EX56 };
416 
417  // get directory name
418  string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
419  string ext_dir = "L1TriggerData/DTTrackFinder/Ext/";
420  string ext_str = "";
421 
422  // precision : in the look-up tables the following precision is used :
423  // phi ...12 bits (low, high), phib ...10 bits (address)
424  // now convert phi and phib to the required precision
425 
426  int sh_phi = 12 - nbit_phi;
427  int sh_phib = 10 - nbit_phib;
428 
429  // loop over all extrapolations
430  for ( int ext = 0; ext < MAX_EXT; ext++ ) {
431  switch (ext) {
432  case EX12 : ext_str = "ext12"; break;
433  case EX13 : ext_str = "ext13"; break;
434  case EX14 : ext_str = "ext14"; break;
435  case EX21 : ext_str = "ext21"; break;
436  case EX23 : ext_str = "ext23"; break;
437  case EX24 : ext_str = "ext24"; break;
438  case EX34 : ext_str = "ext34"; break;
439  case EX15 : ext_str = "ext15"; break;
440  case EX16 : ext_str = "ext16"; break;
441  case EX25 : ext_str = "ext25"; break;
442  case EX26 : ext_str = "ext26"; break;
443  case EX56 : ext_str = "ext56"; break;
444  }
445 
446  // assemble file name
447  edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
448  string ext_file = lut_f.fullPath();
449 
450  // open file
451  L1TriggerLutFile file(ext_file);
452  if ( file.open() != 0 ) return -1;
453  // if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
454  // << file.getName() << endl;
455 
457 
458  int number = -1;
459  int adr_old = -512 >> sh_phib;
460  int sum_low = 0;
461  int sum_high = 0;
462 
463  // read values and shift to correct precision
464  while ( file.good() ) {
465 
466  int adr = ( file.readInteger() ) >> sh_phib; // address (phib)
467  int low = ( file.readInteger() ); // low value (phi)
468  int high = ( file.readInteger() ); // high value (phi)
469 
470  number++;
471 
472  if ( adr != adr_old ) {
473 
474  tmplut.low[adr_old] = sum_low >> sh_phi;
475  tmplut.high[adr_old] = sum_high >> sh_phi;
476 
477  adr_old = adr;
478  number = 0;
479  sum_low = 0;
480  sum_high = 0;
481 
482  }
483 
484  if (number == 0) sum_low = low;
485  if (number == 0) sum_high = high;
486 
487  if ( !file.good() ) file.close();
488  }
489 
490  file.close();
491  ext_lut.push_back(tmplut);
492  }
493  return 0;
494 
495 }
496 
497 
498 //
499 // member functions
500 //
501 
502 // ------------ method called to produce the data ------------
505 {
506  using namespace edm::es;
507  boost::shared_ptr<L1TMuonBarrelParams> pBMTFParams;
508 
509  pBMTFParams = boost::shared_ptr<L1TMuonBarrelParams>(new L1TMuonBarrelParams(m_params));
510  return pBMTFParams;
511 }
512 
513 //define this as a plug-in
T getParameter(std::string const &) const
void set_Extrapolation_Filter(int par1)
void set_etsoc_chdis_st1(int wh, int sc, const bool val)
int getPtLutThreshold(int, std::vector< int > &) const
int load_phi(std::vector< LUT > &, unsigned short int, unsigned short int, std::string)
void setAssLUTPath(std::string path)
assert(m_qm.get())
void set_etsoc_chdis_st2(int wh, int sc, const bool val)
void setFwVersion(unsigned fwVersion)
bool good()
return status of file stream
void set_Extrapolation_nbits_Phi(int par1)
void set_EtaTrackFinder(bool par1)
void setpta_threshold(std::vector< int > ptathresh)
void set_Extrapolation_nbits_PhiB(int par1)
void setpta_lut(std::vector< LUT > ptalut)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void set_Open_LUTs(bool par1)
L1MuDTTFMasks l1mudttfmasks
void close()
close file
const int MAX_EXT
void set_inrec_chdis_st4(int wh, int sc, const bool val)
Extrapolation
L1TMuonBarrelParamsESProducer(const edm::ParameterSet &)
void set_Extrapolation_21(bool par1)
boost::shared_ptr< L1TMuonBarrelParams > ReturnType
int load_pt(std::vector< LUT > &, std::vector< int > &, unsigned short int, std::string)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void set_inrec_chdis_st2(int wh, int sc, const bool val)
void set_PT_Assignment_nbits_PhiB(int par1)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void set_inrec_chdis_st3(int wh, int sc, const bool val)
void set_PT_Assignment_nbits_Phi(int par1)
void set_etsoc_chdis_st3(int wh, int sc, const bool val)
void set_PHI_Assignment_nbits_Phi(int par1)
int readInteger()
read one integer from file
void setphi_lut(std::vector< LUT > philut)
ReturnType produce(const L1TMuonBarrelParamsRcd &)
static unsigned int const shift
void set_OutOfTime_Filter_Window(int par1)
void set_PHI_Assignment_nbits_PhiB(int par1)
tuple cout
Definition: gather_cfg.py:145
std::string fullPath() const
Definition: FileInPath.cc:184
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:32
int open()
open file
void set_OutOfTime_Filter(bool par1)
void set_inrec_chdis_csc(int wh, int sc, const bool val)
int load_ext(std::vector< L1TMuonBarrelParams::LUTParams::extLUT > &, unsigned short int, unsigned short int)
const int MAX_PTASSMETH
void set_inrec_chdis_st1(int wh, int sc, const bool val)
PtAssMethod