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 
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(0); pta_lut.reserve(12);
106  std::vector<int> pta_threshold(6); pta_threshold.reserve(6);
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(0); 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 
128 
129 
130  //m_params.l1mudttfparams.set_soc_openlut_extr(1,1,false);
131 
132 }
133 
134 
136 {
137 }
138 
139 int L1TMuonBarrelParamsESProducer::load_pt(std::vector<LUT>& pta_lut,
140  std::vector<int>& pta_threshold,
141  unsigned short int nbitphi,
142  std::string AssLUTpath
143  ){
144 
145 
146 // maximal number of pt assignment methods
147 const int MAX_PTASSMETH = 13;
148 
149 // pt assignment methods
152  NODEF };
153 
154  // get directory name
155  string pta_str = "";
156  // precision : in the look-up tables the following precision is used :
157  // phi ...12 bits (address) and pt ...5 bits
158  // now convert phi and phib to the required precision
159  int nbit_phi = nbitphi;
160  int sh_phi = 12 - nbit_phi;
161 
162  // loop over all pt-assignment methods
163  for ( int pam = 0; pam < MAX_PTASSMETH; pam++ ) {
164  switch ( pam ) {
165  case PT12L : { pta_str = "pta12l"; break; }
166  case PT12H : { pta_str = "pta12h"; break; }
167  case PT13L : { pta_str = "pta13l"; break; }
168  case PT13H : { pta_str = "pta13h"; break; }
169  case PT14L : { pta_str = "pta14l"; break; }
170  case PT14H : { pta_str = "pta14h"; break; }
171  case PT23L : { pta_str = "pta23l"; break; }
172  case PT23H : { pta_str = "pta23h"; break; }
173  case PT24L : { pta_str = "pta24l"; break; }
174  case PT24H : { pta_str = "pta24h"; break; }
175  case PT34L : { pta_str = "pta34l"; break; }
176  case PT34H : { pta_str = "pta34h"; break; }
177  }
178 
179  // assemble file name
180  string lutpath = AssLUTpath;
181  edm::FileInPath lut_f = edm::FileInPath(string(lutpath + pta_str + ".lut"));
182  string pta_file = lut_f.fullPath();
183 
184  // open file
185  L1TriggerLutFile file(pta_file);
186  if ( file.open() != 0 ) return -1;
187 
188  // get the right shift factor
189  int shift = sh_phi;
190  int adr_old = -2048 >> shift;
191 
192  LUT tmplut;
193 
194  int number = -1;
195  int sum_pt = 0;
196 
197  if ( file.good() ) {
198  int threshold = file.readInteger();
199  pta_threshold[pam/2] = threshold;
200  }
201 
202  // read values and shift to correct precision
203  while ( file.good() ) {
204 
205  int adr = (file.readInteger()) >> shift;
206  int pt = file.readInteger();
207 
208  number++;
209 
210  if ( adr != adr_old ) {
211  assert(number);
212  tmplut.insert(make_pair( adr_old, (sum_pt/number) ));
213 
214  adr_old = adr;
215  number = 0;
216  sum_pt = 0;
217  }
218 
219  sum_pt += pt;
220 
221  if ( !file.good() ) file.close();
222 
223  }
224 
225  file.close();
226  pta_lut.push_back(tmplut);
227  }
228  return 0;
229 
230 }
231 
232 
233 
234 
235 int L1TMuonBarrelParamsESProducer::load_phi(std::vector<LUT>& phi_lut,
236  unsigned short int nbit_phi,
237  unsigned short int nbit_phib,
238  std::string AssLUTpath
239  ) {
240 
241 
242  // precision : in the look-up tables the following precision is used :
243  // address (phib) ...10 bits, phi ... 12 bits
244 
245  int sh_phi = 12 - nbit_phi;
246  int sh_phib = 10 - nbit_phib;
247 
248  string phi_str;
249  // loop over all phi-assignment methods
250  for ( int idx = 0; idx < 2; idx++ ) {
251  switch ( idx ) {
252  case 0 : { phi_str = "phi12"; break; }
253  case 1 : { phi_str = "phi42"; break; }
254  }
255 
256  // assemble file name
257  edm::FileInPath lut_f = edm::FileInPath(string(AssLUTpath + phi_str + ".lut"));
258  string phi_file = lut_f.fullPath();
259 
260  // open file
261  L1TriggerLutFile file(phi_file);
262  if ( file.open() != 0 ) return -1;
263 
264  LUT tmplut;
265 
266  int number = -1;
267  int adr_old = -512 >> sh_phib;
268  int sum_phi = 0;
269 
270  // read values
271  while ( file.good() ) {
272 
273  int adr = (file.readInteger()) >> sh_phib;
274  int phi = file.readInteger();
275 
276  number++;
277 
278  if ( adr != adr_old ) {
279  assert(number);
280  tmplut.insert(make_pair( adr_old, ((sum_phi/number) >> sh_phi) ));
281 
282  adr_old = adr;
283  number = 0;
284  sum_phi = 0;
285  }
286 
287  sum_phi += phi;
288 
289  if ( !file.good() ) file.close();
290 
291  }
292 
293  file.close();
294  phi_lut.push_back(tmplut);
295  }
296  return 0;
297 
298 }
299 
300 int L1TMuonBarrelParamsESProducer::getPtLutThreshold(int pta_ind, std::vector<int>& pta_threshold) const {
301 
302  if ( pta_ind >= 0 && pta_ind < 13/2 ) {
303  return pta_threshold[pta_ind];
304  }
305  else {
306  cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
307  return 0;
308  }
309 
310 }
311 
312 
313 
314 
315 
316 
317 //
318 // load extrapolation look-up tables
319 //
320 int L1TMuonBarrelParamsESProducer::load_ext(std::vector<L1TMuonBarrelParams::LUTParams::extLUT>& ext_lut,
321  unsigned short int nbit_phi,
322  unsigned short int nbit_phib) {
323 
324  //max. number of Extrapolations
325  const int MAX_EXT = 12;
326 
327  // extrapolation types
328  enum Extrapolation { EX12, EX13, EX14, EX21, EX23, EX24, EX34,
329  EX15, EX16, EX25, EX26, EX56 };
330 
331  // get directory name
332  string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
333  string ext_dir = "L1TriggerData/DTTrackFinder/Ext/";
334  string ext_str = "";
335 
336  // precision : in the look-up tables the following precision is used :
337  // phi ...12 bits (low, high), phib ...10 bits (address)
338  // now convert phi and phib to the required precision
339 
340  int sh_phi = 12 - nbit_phi;
341  int sh_phib = 10 - nbit_phib;
342 
343  // loop over all extrapolations
344  for ( int ext = 0; ext < MAX_EXT; ext++ ) {
345  switch (ext) {
346  case EX12 : ext_str = "ext12"; break;
347  case EX13 : ext_str = "ext13"; break;
348  case EX14 : ext_str = "ext14"; break;
349  case EX21 : ext_str = "ext21"; break;
350  case EX23 : ext_str = "ext23"; break;
351  case EX24 : ext_str = "ext24"; break;
352  case EX34 : ext_str = "ext34"; break;
353  case EX15 : ext_str = "ext15"; break;
354  case EX16 : ext_str = "ext16"; break;
355  case EX25 : ext_str = "ext25"; break;
356  case EX26 : ext_str = "ext26"; break;
357  case EX56 : ext_str = "ext56"; break;
358  }
359 
360  // assemble file name
361  edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
362  string ext_file = lut_f.fullPath();
363 
364  // open file
365  L1TriggerLutFile file(ext_file);
366  if ( file.open() != 0 ) return -1;
367  // if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
368  // << file.getName() << endl;
369 
371 
372  int number = -1;
373  int adr_old = -512 >> sh_phib;
374  int sum_low = 0;
375  int sum_high = 0;
376 
377  // read values and shift to correct precision
378  while ( file.good() ) {
379 
380  int adr = ( file.readInteger() ) >> sh_phib; // address (phib)
381  int low = ( file.readInteger() ); // low value (phi)
382  int high = ( file.readInteger() ); // high value (phi)
383 
384  number++;
385 
386  if ( adr != adr_old ) {
387 
388  tmplut.low[adr_old] = sum_low >> sh_phi;
389  tmplut.high[adr_old] = sum_high >> sh_phi;
390 
391  adr_old = adr;
392  number = 0;
393  sum_low = 0;
394  sum_high = 0;
395 
396  }
397 
398  if (number == 0) sum_low = low;
399  if (number == 0) sum_high = high;
400 
401  if ( !file.good() ) file.close();
402  }
403 
404  file.close();
405  ext_lut.push_back(tmplut);
406  }
407  return 0;
408 
409 }
410 
411 
412 //
413 // member functions
414 //
415 
416 // ------------ method called to produce the data ------------
419 {
420  using namespace edm::es;
421  boost::shared_ptr<L1TMuonBarrelParams> pBMTFParams;
422 
423  pBMTFParams = boost::shared_ptr<L1TMuonBarrelParams>(new L1TMuonBarrelParams(m_params));
424  return pBMTFParams;
425 }
426 
427 //define this as a plug-in
T getParameter(std::string const &) const
void set_Extrapolation_Filter(int par1)
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 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)
void close()
close file
const int MAX_EXT
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_PT_Assignment_nbits_PhiB(int par1)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void set_PT_Assignment_nbits_Phi(int par1)
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)
int load_ext(std::vector< L1TMuonBarrelParams::LUTParams::extLUT > &, unsigned short int, unsigned short int)
const int MAX_PTASSMETH
PtAssMethod