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: 2008/04/16 23:25:10 $
10 // $Revision: 1.6 $
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 
105  // L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const float* Scale, int idx_offset=0)
106  L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const std::vector<double> Scale, int idx_offset=0)
107  : m_nbits( nbits ),
108  m_signedPacking( signedPacking )
109  {
110  m_NBins = NBins;
111  m_idxoffset = idx_offset;
112 
113  m_Scale.reserve(m_NBins + 1);
114  for (int i=0; i<m_NBins + 1; i++)
115  //m_Scale[i] = Scale[i];
116  m_Scale.push_back( Scale[i] ) ;
117  };
118 
129  L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, float xmin, float xmax, int idx_offset=0)
130  : m_nbits( nbits ),
131  m_signedPacking( signedPacking )
132  {
133  m_NBins = NBins;
134  m_idxoffset = idx_offset;
135 
136  m_Scale.reserve(m_NBins + 1);
137  for (int i=0; i<m_NBins + 1; i++)
138  // m_Scale[i] = xmin + i * (xmax-xmin) / m_NBins;
139  m_Scale.push_back( xmin + i * (xmax-xmin) / m_NBins ) ;
140  };
141 
143  virtual ~L1MuBinnedScale() {
144 // delete m_packing;
145  };
146 
147 
149  virtual float getCenter(unsigned packed) const {
150  int idx = get_idx(packed);
151  return (m_Scale[idx] + m_Scale[idx+1] )/ 2.;
152  };
153 
155  virtual float getLowEdge(unsigned packed) const{
156  return m_Scale[get_idx(packed)];
157  };
158 
160  virtual float getHighEdge(unsigned packed) const{
161  return m_Scale[get_idx(packed)+1];
162  };
163 
165 
166  virtual unsigned getPacked(float value) const {
167  if (value < m_Scale[0] || value > m_Scale[m_NBins])
168  edm::LogWarning("ScaleRangeViolation") << "L1MuBinnedScale::getPacked: value out of scale range: " << value << std::endl;
169  int idx = 0;
170  if (value < m_Scale[0]) idx=0;
171  else if (value >= m_Scale[m_NBins]) idx = m_NBins-1;
172  else {
173  for (; idx<m_NBins; idx++)
174  if (value >= m_Scale[idx] && value < m_Scale[idx+1]) break;
175  }
176 
177  return ( m_signedPacking ?
180  };
181 
183  virtual float getScaleMax() const { return m_Scale[m_NBins]; }
184 
186  virtual float getScaleMin() const { return m_Scale[0]; }
187 
189  virtual unsigned getNBins() const { return m_NBins; }
190 
192  virtual float getValue(unsigned i) const { return m_Scale[i]; }
193 
194  virtual std::string print() const {
195  std::ostringstream str;
196 
197  str << " ind | low edge | center | high edge" << std::endl;
198  str << "-------------------------------------------" << std::endl;
199  for(int i=0; i<m_NBins; i++){
200  unsigned int ipack = getPacked(m_Scale[i]);
201  str << std::setw(4) << ipack <<
202  " | " << std::setw(10) << getLowEdge(ipack) <<
203  " | " << std::setw(10) << getCenter(ipack) <<
204  " | " << std::setw(10) << getHighEdge(ipack) << std::endl;
205  }
206 
207  return str.str();
208  }
209 
210 
211  protected:
212  int get_idx (unsigned packed) const {
213  int idxFromPacked = m_signedPacking ?
216  int idx = idxFromPacked + m_idxoffset;
217  if (idx<0) idx=0;
218  if (idx>=m_NBins) idx=m_NBins-1;
219  return idx;
220  }
221 
222  unsigned int m_nbits ;
224  int m_NBins;
226  std::vector<float> m_Scale;
227 };
228 
241  public:
242 
250 
252 
255  // L1MuSymmetricBinnedScale(int nbits, int NBins, const float* Scale)
256  L1MuSymmetricBinnedScale(int nbits, int NBins, const std::vector<double> Scale)
258  m_NBins = NBins;
259  m_Scale.reserve(m_NBins + 1);
260  for (int i=0; i<m_NBins + 1; i++)
261  // m_Scale[i] = Scale[i];
262  m_Scale.push_back( Scale[i] ) ;
263  };
264 
275  L1MuSymmetricBinnedScale(int nbits, int NBins, float xmin, float xmax)
277  m_NBins = NBins;
278  m_Scale.reserve(m_NBins + 1);
279  for (int i=0; i<m_NBins + 1; i++)
280  // m_Scale[i] = xmin + i * (xmax-xmin) / m_NBins;
281  m_Scale.push_back( xmin + i * (xmax-xmin) / m_NBins ) ;
282  };
283 
286 // delete m_packing;
287  };
288 
290  virtual float getCenter(unsigned packed) const {
291  int absidx = abs ( m_packing.idxFromPacked( packed ) );
292  if (absidx>=m_NBins) absidx=m_NBins-1;
293  float center = (m_Scale[absidx] + m_Scale[absidx+1] )/ 2.;
294  float fsign = m_packing.signFromPacked( packed ) == 0 ? 1. : -1.;
295  return center * fsign;
296  };
297 
299  virtual float getLowEdge(unsigned packed) const{ // === edge towards 0
300  int absidx = abs ( m_packing.idxFromPacked( packed ) );
301  if (absidx>=m_NBins) absidx=m_NBins-1;
302  float low = m_Scale[absidx];
303  float fsign = m_packing.signFromPacked( packed ) == 0 ? 1. : -1.;
304  return low * fsign;
305  };
306 
308  virtual float getHighEdge(unsigned packed) const{
309  edm::LogWarning("NotImplemented") << "L1MuSymmetricBinnedScale::getHighEdge not implemented" << std::endl;
310  return 0;
311  };
312 
314  virtual unsigned getPacked(float value) const {
315  float absval = fabs ( value );
316  if (absval < m_Scale[0] || absval > m_Scale[m_NBins]) edm::LogWarning("ScaleRangeViolation")
317  << "L1MuSymmetricBinnedScale::getPacked: value out of scale range!!! abs(val) = "
318  << absval << " min= " << m_Scale[0] << " max = " << m_Scale[m_NBins] << std::endl;
319  int idx = 0;
320  for (; idx<m_NBins; idx++)
321  if (absval >= m_Scale[idx] && absval < m_Scale[idx+1]) break;
322  if (idx >= m_NBins) idx = m_NBins-1;
323  return m_packing.packedFromIdx(idx, (value>=0) ? 0 : 1);
324  };
326  virtual float getScaleMax() const { return m_Scale[m_NBins]; }
327 
329  virtual float getScaleMin() const { return m_Scale[0]; }
330 
332  virtual unsigned getNBins() const { return m_NBins; }
333 
335  virtual float getValue(unsigned i) const { return m_Scale[i]; }
336 
337  virtual std::string print() const {
338  std::ostringstream str;
339 
340  str << " ind | low edge | center" << std::endl;
341  str << "-------------------------------------------" << std::endl;
342  for(int i=0; i<m_NBins; i++){
343  unsigned int ipack = getPacked(m_Scale[i]);
344  str << std::setw(4) << ipack <<
345  " | " << std::setw(10) << getLowEdge(ipack) <<
346  " | " << std::setw(10) << getCenter(ipack) << std::endl;
347  }
348 
349  return str.str();
350  }
351 
352  protected:
354  int m_NBins;
355  std::vector<float> m_Scale;
356 };
357 #endif
358 
359 
360 
361 
362 
363 
364 
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 
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:186
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:355
virtual float getScaleMax() const
get the upper edge of the last bin (posivie half)
Definition: L1MuScale.h:326
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
virtual ~L1MuSymmetricBinnedScale()
destructor
Definition: L1MuScale.h:285
#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:106
virtual std::string print() const
Definition: L1MuScale.h:194
virtual unsigned getNBins() const
get number of bins
Definition: L1MuScale.h:332
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:160
virtual unsigned getPacked(float value) const
pack a value
Definition: L1MuScale.h:314
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:222
virtual float getLowEdge(unsigned packed) const
get the low edge of bin represented by packed
Definition: L1MuScale.h:155
L1MuSymmetricBinnedScale(int nbits, int NBins, const std::vector< double > Scale)
Definition: L1MuScale.h:256
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:129
std::vector< float > m_Scale
Definition: L1MuScale.h:226
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:275
virtual ~L1MuBinnedScale()
destructor
Definition: L1MuScale.h:143
virtual float getCenter(unsigned packed) const
get the center of bin represented by packed
Definition: L1MuScale.h:149
virtual float getScaleMax() const
get the upper edge of the last bin
Definition: L1MuScale.h:183
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:290
virtual float getHighEdge(unsigned packed) const
get the upper edge of bin represented by packed
Definition: L1MuScale.h:308
L1MuPseudoSignedPacking m_packing
Definition: L1MuScale.h:353
virtual float getValue(unsigned i) const
get value of the underlying vector for bin i
Definition: L1MuScale.h:192
virtual unsigned getNBins() const =0
get number of bins
virtual unsigned getNBins() const
get number of bins
Definition: L1MuScale.h:189
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:329
bool m_signedPacking
Definition: L1MuScale.h:223
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:335
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:299
virtual std::string print() const
Definition: L1MuScale.h:337
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:212
virtual unsigned getPacked(float value) const
pack a value
Definition: L1MuScale.h:166