CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1MuScale.h
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // \class L1MuScale
4 //
5 // Description: A Scale for use in the L1 muon trigger
6 //
7 //
8 //
9 // $Date: 2011/05/30 04:59:35 $
10 // $Revision: 1.8 $
11 //
12 // Original Author :
13 // Hannes Sakulin HEPHY / Vienna
14 //
15 // Migrated to CMSSW:
16 // I. Mikulec
17 //
18 //--------------------------------------------------
19 #ifndef CondFormatsL1TObjects_L1MuScale_h
20 #define CondFormatsL1TObjects_L1MuScale_h
21 
22 #include <iostream>
23 #include <sstream>
24 #include <iomanip>
25 #include <vector>
26 #include <math.h>
29 
36 class L1MuScale {
37  public:
38  L1MuScale() {}
39 
40  virtual ~L1MuScale() {}
41 
43  virtual float getCenter(unsigned packed) const = 0;
44 
46  virtual float getLowEdge(unsigned packed) const = 0;
47 
49  virtual float getHighEdge(unsigned packed) const = 0;
50 
52  virtual float getScaleMax() const = 0;
53 
55  virtual float getScaleMin() const = 0;
56 
58  virtual unsigned getPacked(float value) const = 0;
59 
61  virtual unsigned getNBins() const = 0;
62 
64  virtual float getValue(unsigned i) const = 0;
65 
66  virtual std::string print() const = 0;
67 
68  private:
69 };
70 
71 //
72 // define default scale implementations
73 //
74 
75 
91 class L1MuBinnedScale : public L1MuScale {
92  public:
93 
102  m_nbits( 0 ),
104  m_NBins( 0 ),
105  m_idxoffset( 0 )
106  {}
107 
110  // L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const float* Scale, int idx_offset=0)
111  L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const std::vector<double> Scale, int idx_offset=0)
112  : m_nbits( nbits ),
113  m_signedPacking( signedPacking )
114  {
115  m_NBins = NBins;
116  m_idxoffset = idx_offset;
117 
118  m_Scale.reserve(m_NBins + 1);
119  for (int i=0; i<m_NBins + 1; i++)
120  //m_Scale[i] = Scale[i];
121  m_Scale.push_back( Scale[i] ) ;
122  };
123 
134  L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, float xmin, float xmax, int idx_offset=0)
135  : m_nbits( nbits ),
136  m_signedPacking( signedPacking )
137  {
138  m_NBins = NBins;
139  m_idxoffset = idx_offset;
140 
141  m_Scale.reserve(m_NBins + 1);
142  for (int i=0; i<m_NBins + 1; i++)
143  // m_Scale[i] = xmin + i * (xmax-xmin) / m_NBins;
144  m_Scale.push_back( xmin + i * (xmax-xmin) / m_NBins ) ;
145  };
146 
148  virtual ~L1MuBinnedScale() {
149 // delete m_packing;
150  };
151 
152 
154  virtual float getCenter(unsigned packed) const {
155  int idx = get_idx(packed);
156  return (m_Scale[idx] + m_Scale[idx+1] )/ 2.;
157  };
158 
160  virtual float getLowEdge(unsigned packed) const{
161  return m_Scale[get_idx(packed)];
162  };
163 
165  virtual float getHighEdge(unsigned packed) const{
166  return m_Scale[get_idx(packed)+1];
167  };
168 
170 
171  virtual unsigned getPacked(float value) const {
172  if (value < m_Scale[0] || value > m_Scale[m_NBins])
173  edm::LogWarning("ScaleRangeViolation") << "L1MuBinnedScale::getPacked: value out of scale range: " << value << std::endl;
174  int idx = 0;
175  if (value < m_Scale[0]) idx=0;
176  else if (value >= m_Scale[m_NBins]) idx = m_NBins-1;
177  else {
178  for (; idx<m_NBins; idx++)
179  if (value >= m_Scale[idx] && value < m_Scale[idx+1]) break;
180  }
181 
182  return ( m_signedPacking ?
185  };
186 
188  virtual float getScaleMax() const { return m_Scale[m_NBins]; }
189 
191  virtual float getScaleMin() const { return m_Scale[0]; }
192 
194  virtual unsigned getNBins() const { return m_NBins; }
195 
197  virtual float getValue(unsigned i) const { return m_Scale[i]; }
198 
199  virtual std::string print() const {
200  std::ostringstream str;
201 
202  str << " ind | low edge | center | high edge" << std::endl;
203  str << "-------------------------------------------" << std::endl;
204  for(int i=0; i<m_NBins; i++){
205  unsigned int ipack = getPacked(m_Scale[i]);
206  str << std::setw(4) << ipack <<
207  " | " << std::setw(10) << getLowEdge(ipack) <<
208  " | " << std::setw(10) << getCenter(ipack) <<
209  " | " << std::setw(10) << getHighEdge(ipack) << std::endl;
210  }
211 
212  return str.str();
213  }
214 
215 
216  protected:
217  int get_idx (unsigned packed) const {
218  int idxFromPacked = m_signedPacking ?
221  int idx = idxFromPacked + m_idxoffset;
222  if (idx<0) idx=0;
223  if (idx>=m_NBins) idx=m_NBins-1;
224  return idx;
225  }
226 
227  unsigned int m_nbits ;
229  int m_NBins;
231  std::vector<float> m_Scale;
232 };
233 
246  public:
247 
255 
257  m_NBins( 0 )
258  {}
259 
262  // L1MuSymmetricBinnedScale(int nbits, int NBins, const float* Scale)
263  L1MuSymmetricBinnedScale(int nbits, int NBins, const std::vector<double> Scale)
265  m_NBins = NBins;
266  m_Scale.reserve(m_NBins + 1);
267  for (int i=0; i<m_NBins + 1; i++)
268  // m_Scale[i] = Scale[i];
269  m_Scale.push_back( Scale[i] ) ;
270  };
271 
282  L1MuSymmetricBinnedScale(int nbits, int NBins, float xmin, float xmax)
284  m_NBins = NBins;
285  m_Scale.reserve(m_NBins + 1);
286  for (int i=0; i<m_NBins + 1; i++)
287  // m_Scale[i] = xmin + i * (xmax-xmin) / m_NBins;
288  m_Scale.push_back( xmin + i * (xmax-xmin) / m_NBins ) ;
289  };
290 
293 // delete m_packing;
294  };
295 
297  virtual float getCenter(unsigned packed) const {
298  int absidx = abs ( m_packing.idxFromPacked( packed ) );
299  if (absidx>=m_NBins) absidx=m_NBins-1;
300  float center = (m_Scale[absidx] + m_Scale[absidx+1] )/ 2.;
301  float fsign = m_packing.signFromPacked( packed ) == 0 ? 1. : -1.;
302  return center * fsign;
303  };
304 
306  virtual float getLowEdge(unsigned packed) const{ // === edge towards 0
307  int absidx = abs ( m_packing.idxFromPacked( packed ) );
308  if (absidx>=m_NBins) absidx=m_NBins-1;
309  float low = m_Scale[absidx];
310  float fsign = m_packing.signFromPacked( packed ) == 0 ? 1. : -1.;
311  return low * fsign;
312  };
313 
315  virtual float getHighEdge(unsigned packed) const{
316  edm::LogWarning("NotImplemented") << "L1MuSymmetricBinnedScale::getHighEdge not implemented" << std::endl;
317  return 0;
318  };
319 
321  virtual unsigned getPacked(float value) const {
322  float absval = fabs ( value );
323  if (absval < m_Scale[0] || absval > m_Scale[m_NBins]) edm::LogWarning("ScaleRangeViolation")
324  << "L1MuSymmetricBinnedScale::getPacked: value out of scale range!!! abs(val) = "
325  << absval << " min= " << m_Scale[0] << " max = " << m_Scale[m_NBins] << std::endl;
326  int idx = 0;
327  for (; idx<m_NBins; idx++)
328  if (absval >= m_Scale[idx] && absval < m_Scale[idx+1]) break;
329  if (idx >= m_NBins) idx = m_NBins-1;
330  return m_packing.packedFromIdx(idx, (value>=0) ? 0 : 1);
331  };
333  virtual float getScaleMax() const { return m_Scale[m_NBins]; }
334 
336  virtual float getScaleMin() const { return m_Scale[0]; }
337 
339  virtual unsigned getNBins() const { return m_NBins; }
340 
342  virtual float getValue(unsigned i) const { return m_Scale[i]; }
343 
344  virtual std::string print() const {
345  std::ostringstream str;
346 
347  str << " ind | low edge | center" << std::endl;
348  str << "-------------------------------------------" << std::endl;
349  for(int i=0; i<m_NBins; i++){
350  unsigned int ipack = getPacked(m_Scale[i]);
351  str << std::setw(4) << ipack <<
352  " | " << std::setw(10) << getLowEdge(ipack) <<
353  " | " << std::setw(10) << getCenter(ipack) << std::endl;
354  }
355 
356  return str.str();
357  }
358 
359  protected:
361  int m_NBins;
362  std::vector<float> m_Scale;
363 };
364 #endif
365 
366 
367 
368 
369 
370 
371 
372 
373 
374 
375 
376 
377 
378 
379 
380 
381 
382 
383 
384 
385 
386 
387 
388 
389 
390 
391 
392 
393 
394 
395 
396 
397 
398 
399 
400 
401 
402 
403 
404 
405 
virtual float getScaleMax() const =0
get the upper edge of the last bin
virtual float getScaleMin() const
get the lower edge of the first bin
Definition: L1MuScale.h:191
int i
Definition: DBlmapReader.cc:9
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (always positive)
Definition: L1MuPacking.h:69
std::vector< float > m_Scale
Definition: L1MuScale.h:362
virtual float getScaleMax() const
get the upper edge of the last bin (posivie half)
Definition: L1MuScale.h:333
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
virtual ~L1MuSymmetricBinnedScale()
destructor
Definition: L1MuScale.h:292
#define abs(x)
Definition: mlp_lapack.h:159
L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const std::vector< double > Scale, int idx_offset=0)
Definition: L1MuScale.h:111
virtual std::string print() const
Definition: L1MuScale.h:199
virtual unsigned getNBins() const
get number of bins
Definition: L1MuScale.h:339
virtual float getCenter(unsigned packed) const =0
get the center of bin represented by packed
virtual float getHighEdge(unsigned packed) const
get the upper edge of bin represented by packed
Definition: L1MuScale.h:165
virtual unsigned getPacked(float value) const
pack a value
Definition: L1MuScale.h:321
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check range
Definition: L1MuPacking.h:111
unsigned int m_nbits
Definition: L1MuScale.h:227
virtual float getLowEdge(unsigned packed) const
get the low edge of bin represented by packed
Definition: L1MuScale.h:160
L1MuSymmetricBinnedScale(int nbits, int NBins, const std::vector< double > Scale)
Definition: L1MuScale.h:263
virtual float getHighEdge(unsigned packed) const =0
get the upper edge of bin represented by packed
L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, float xmin, float xmax, int idx_offset=0)
Definition: L1MuScale.h:134
std::vector< float > m_Scale
Definition: L1MuScale.h:231
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:109
virtual float getValue(unsigned i) const =0
get value of the underlying vector for bin i
virtual float getScaleMin() const =0
get the lower edge of the first bin
L1MuSymmetricBinnedScale(int nbits, int NBins, float xmin, float xmax)
Definition: L1MuScale.h:282
virtual ~L1MuBinnedScale()
destructor
Definition: L1MuScale.h:148
virtual float getCenter(unsigned packed) const
get the center of bin represented by packed
Definition: L1MuScale.h:154
virtual float getScaleMax() const
get the upper edge of the last bin
Definition: L1MuScale.h:188
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check range
Definition: L1MuPacking.h:144
virtual float getCenter(unsigned packed) const
get the center of bin represented by packed
Definition: L1MuScale.h:297
virtual float getHighEdge(unsigned packed) const
get the upper edge of bin represented by packed
Definition: L1MuScale.h:315
L1MuPseudoSignedPacking m_packing
Definition: L1MuScale.h:360
virtual float getValue(unsigned i) const
get value of the underlying vector for bin i
Definition: L1MuScale.h:197
virtual unsigned getNBins() const =0
get number of bins
virtual unsigned getNBins() const
get number of bins
Definition: L1MuScale.h:194
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:137
virtual float getScaleMin() const
get the lower edge of the first bin (positive half)
Definition: L1MuScale.h:336
bool m_signedPacking
Definition: L1MuScale.h:228
virtual unsigned getPacked(float value) const =0
pack a value
virtual float getValue(unsigned i) const
get value of the underlying vector for bin i
Definition: L1MuScale.h:342
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check the range
Definition: L1MuPacking.h:71
virtual ~L1MuScale()
Definition: L1MuScale.h:40
L1MuScale()
Definition: L1MuScale.h:38
virtual float getLowEdge(unsigned packed) const
get the low edge of bin represented by packed
Definition: L1MuScale.h:306
virtual std::string print() const
Definition: L1MuScale.h:344
virtual std::string print() const =0
virtual int signFromPacked(unsigned packed) const
get the (pseudo-)sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:134
int get_idx(unsigned packed) const
Definition: L1MuScale.h:217
virtual unsigned getPacked(float value) const
pack a value
Definition: L1MuScale.h:171