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 
23 
24 #include <iostream>
25 #include <sstream>
26 #include <iomanip>
27 #include <vector>
28 #include <math.h>
31 
38 class L1MuScale {
39  public:
40  L1MuScale() {}
41 
42  virtual ~L1MuScale() {}
43 
45  virtual float getCenter(unsigned packed) const = 0;
46 
48  virtual float getLowEdge(unsigned packed) const = 0;
49 
51  virtual float getHighEdge(unsigned packed) const = 0;
52 
54  virtual float getScaleMax() const = 0;
55 
57  virtual float getScaleMin() const = 0;
58 
60  virtual unsigned getPacked(float value) const = 0;
61 
63  virtual unsigned getNBins() const = 0;
64 
66  virtual float getValue(unsigned i) const = 0;
67 
68  virtual std::string print() const = 0;
69 
70  private:
71 
73 };
74 
75 //
76 // define default scale implementations
77 //
78 
79 
95 class L1MuBinnedScale : public L1MuScale {
96  public:
97 
106  m_nbits( 0 ),
108  m_NBins( 0 ),
109  m_idxoffset( 0 )
110  {}
111 
114  // L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const float* Scale, int idx_offset=0)
115  L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const std::vector<double>& Scale, int idx_offset=0)
116  : m_nbits( nbits ),
117  m_signedPacking( signedPacking )
118  {
119  m_NBins = NBins;
120  m_idxoffset = idx_offset;
121 
122  m_Scale.reserve(m_NBins + 1);
123  for (int i=0; i<m_NBins + 1; i++)
124  //m_Scale[i] = Scale[i];
125  m_Scale.push_back( Scale[i] ) ;
126  };
127 
138  L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, float xmin, float xmax, int idx_offset=0)
139  : m_nbits( nbits ),
140  m_signedPacking( signedPacking )
141  {
142  m_NBins = NBins;
143  m_idxoffset = idx_offset;
144 
145  m_Scale.reserve(m_NBins + 1);
146  for (int i=0; i<m_NBins + 1; i++)
147  // m_Scale[i] = xmin + i * (xmax-xmin) / m_NBins;
148  m_Scale.push_back( xmin + i * (xmax-xmin) / m_NBins ) ;
149  };
150 
152  virtual ~L1MuBinnedScale() {
153 // delete m_packing;
154  };
155 
156 
158  virtual float getCenter(unsigned packed) const {
159  int idx = get_idx(packed);
160  return (m_Scale[idx] + m_Scale[idx+1] )/ 2.;
161  };
162 
164  virtual float getLowEdge(unsigned packed) const{
165  return m_Scale[get_idx(packed)];
166  };
167 
169  virtual float getHighEdge(unsigned packed) const{
170  return m_Scale[get_idx(packed)+1];
171  };
172 
174 
175  virtual unsigned getPacked(float value) const {
176  if (value < m_Scale[0] || value > m_Scale[m_NBins])
177  edm::LogWarning("ScaleRangeViolation") << "L1MuBinnedScale::getPacked: value out of scale range: " << value << std::endl;
178  int idx = 0;
179  if (value < m_Scale[0]) idx=0;
180  else if (value >= m_Scale[m_NBins]) idx = m_NBins-1;
181  else {
182  for (; idx<m_NBins; idx++)
183  if (value >= m_Scale[idx] && value < m_Scale[idx+1]) break;
184  }
185 
186  return ( m_signedPacking ?
189  };
190 
192  virtual float getScaleMax() const { return m_Scale[m_NBins]; }
193 
195  virtual float getScaleMin() const { return m_Scale[0]; }
196 
198  virtual unsigned getNBins() const { return m_NBins; }
199 
201  virtual float getValue(unsigned i) const { return m_Scale[i]; }
202 
203  virtual std::string print() const {
204  std::ostringstream str;
205 
206  str << " ind | low edge | center | high edge" << std::endl;
207  str << "-------------------------------------------" << std::endl;
208  for(int i=0; i<m_NBins; i++){
209  unsigned int ipack = getPacked(m_Scale[i]);
210  str << std::setw(4) << ipack <<
211  " | " << std::setw(10) << getLowEdge(ipack) <<
212  " | " << std::setw(10) << getCenter(ipack) <<
213  " | " << std::setw(10) << getHighEdge(ipack) << std::endl;
214  }
215 
216  return str.str();
217  }
218 
219 
220  protected:
221  int get_idx (unsigned packed) const {
222  int idxFromPacked = m_signedPacking ?
225  int idx = idxFromPacked + m_idxoffset;
226  if (idx<0) idx=0;
227  if (idx>=m_NBins) idx=m_NBins-1;
228  return idx;
229  }
230 
231  unsigned int m_nbits ;
233  int m_NBins;
235  std::vector<float> m_Scale;
236 
238 };
239 
252  public:
253 
261 
263  m_NBins( 0 )
264  {}
265 
268  // L1MuSymmetricBinnedScale(int nbits, int NBins, const float* Scale)
269  L1MuSymmetricBinnedScale(int nbits, int NBins, const std::vector<double>& Scale)
271  m_NBins = NBins;
272  m_Scale.reserve(m_NBins + 1);
273  for (int i=0; i<m_NBins + 1; i++)
274  // m_Scale[i] = Scale[i];
275  m_Scale.push_back( Scale[i] ) ;
276  };
277 
288  L1MuSymmetricBinnedScale(int nbits, int NBins, float xmin, float xmax)
290  m_NBins = NBins;
291  m_Scale.reserve(m_NBins + 1);
292  for (int i=0; i<m_NBins + 1; i++)
293  // m_Scale[i] = xmin + i * (xmax-xmin) / m_NBins;
294  m_Scale.push_back( xmin + i * (xmax-xmin) / m_NBins ) ;
295  };
296 
299 // delete m_packing;
300  };
301 
303  virtual float getCenter(unsigned packed) const {
304  int absidx = abs ( m_packing.idxFromPacked( packed ) );
305  if (absidx>=m_NBins) absidx=m_NBins-1;
306  float center = (m_Scale[absidx] + m_Scale[absidx+1] )/ 2.;
307  float fsign = m_packing.signFromPacked( packed ) == 0 ? 1. : -1.;
308  return center * fsign;
309  };
310 
312  virtual float getLowEdge(unsigned packed) const{ // === edge towards 0
313  int absidx = abs ( m_packing.idxFromPacked( packed ) );
314  if (absidx>=m_NBins) absidx=m_NBins-1;
315  float low = m_Scale[absidx];
316  float fsign = m_packing.signFromPacked( packed ) == 0 ? 1. : -1.;
317  return low * fsign;
318  };
319 
321  virtual float getHighEdge(unsigned packed) const{
322  edm::LogWarning("NotImplemented") << "L1MuSymmetricBinnedScale::getHighEdge not implemented" << std::endl;
323  return 0;
324  };
325 
327  virtual unsigned getPacked(float value) const {
328  float absval = fabs ( value );
329  if (absval < m_Scale[0] || absval > m_Scale[m_NBins]) edm::LogWarning("ScaleRangeViolation")
330  << "L1MuSymmetricBinnedScale::getPacked: value out of scale range!!! abs(val) = "
331  << absval << " min= " << m_Scale[0] << " max = " << m_Scale[m_NBins] << std::endl;
332  int idx = 0;
333  for (; idx<m_NBins; idx++)
334  if (absval >= m_Scale[idx] && absval < m_Scale[idx+1]) break;
335  if (idx >= m_NBins) idx = m_NBins-1;
336  return m_packing.packedFromIdx(idx, (value>=0) ? 0 : 1);
337  };
339  virtual float getScaleMax() const { return m_Scale[m_NBins]; }
340 
342  virtual float getScaleMin() const { return m_Scale[0]; }
343 
345  virtual unsigned getNBins() const { return m_NBins; }
346 
348  virtual float getValue(unsigned i) const { return m_Scale[i]; }
349 
350  virtual std::string print() const {
351  std::ostringstream str;
352 
353  str << " ind | low edge | center" << std::endl;
354  str << "-------------------------------------------" << std::endl;
355  for(int i=0; i<m_NBins; i++){
356  unsigned int ipack = getPacked(m_Scale[i]);
357  str << std::setw(4) << ipack <<
358  " | " << std::setw(10) << getLowEdge(ipack) <<
359  " | " << std::setw(10) << getCenter(ipack) << std::endl;
360  }
361 
362  return str.str();
363  }
364 
365  protected:
367  int m_NBins;
368  std::vector<float> m_Scale;
369 
371 };
372 #endif
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 
406 
407 
408 
409 
410 
411 
412 
413 
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:195
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:77
std::vector< float > m_Scale
Definition: L1MuScale.h:368
virtual float getScaleMax() const
get the upper edge of the last bin (posivie half)
Definition: L1MuScale.h:339
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
virtual ~L1MuSymmetricBinnedScale()
destructor
Definition: L1MuScale.h:298
virtual std::string print() const
Definition: L1MuScale.h:203
virtual unsigned getNBins() const
get number of bins
Definition: L1MuScale.h:345
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:169
virtual unsigned getPacked(float value) const
pack a value
Definition: L1MuScale.h:327
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check range
Definition: L1MuPacking.h:119
unsigned int m_nbits
Definition: L1MuScale.h:231
L1MuSymmetricBinnedScale(int nbits, int NBins, const std::vector< double > &Scale)
Definition: L1MuScale.h:269
virtual float getLowEdge(unsigned packed) const
get the low edge of bin represented by packed
Definition: L1MuScale.h:164
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:138
std::vector< float > m_Scale
Definition: L1MuScale.h:235
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:117
virtual float getValue(unsigned i) const =0
get value of the underlying vector for bin i
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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:288
virtual ~L1MuBinnedScale()
destructor
Definition: L1MuScale.h:152
virtual float getCenter(unsigned packed) const
get the center of bin represented by packed
Definition: L1MuScale.h:158
virtual float getScaleMax() const
get the upper edge of the last bin
Definition: L1MuScale.h:192
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check range
Definition: L1MuPacking.h:153
virtual float getCenter(unsigned packed) const
get the center of bin represented by packed
Definition: L1MuScale.h:303
virtual float getHighEdge(unsigned packed) const
get the upper edge of bin represented by packed
Definition: L1MuScale.h:321
L1MuPseudoSignedPacking m_packing
Definition: L1MuScale.h:366
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
virtual float getValue(unsigned i) const
get value of the underlying vector for bin i
Definition: L1MuScale.h:201
virtual unsigned getNBins() const =0
get number of bins
#define COND_SERIALIZABLE
Definition: Serializable.h:37
virtual unsigned getNBins() const
get number of bins
Definition: L1MuScale.h:198
L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const std::vector< double > &Scale, int idx_offset=0)
Definition: L1MuScale.h:115
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:146
virtual float getScaleMin() const
get the lower edge of the first bin (positive half)
Definition: L1MuScale.h:342
bool m_signedPacking
Definition: L1MuScale.h:232
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:348
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check the range
Definition: L1MuPacking.h:79
virtual ~L1MuScale()
Definition: L1MuScale.h:42
volatile std::atomic< bool > shutdown_flag false
L1MuScale()
Definition: L1MuScale.h:40
virtual float getLowEdge(unsigned packed) const
get the low edge of bin represented by packed
Definition: L1MuScale.h:312
virtual std::string print() const
Definition: L1MuScale.h:350
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:143
int get_idx(unsigned packed) const
Definition: L1MuScale.h:221
virtual unsigned getPacked(float value) const
pack a value
Definition: L1MuScale.h:175