CMS 3D CMS Logo

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 <cmath>
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:
72 };
73 
74 //
75 // define default scale implementations
76 //
77 
93 class L1MuBinnedScale : public L1MuScale {
94 public:
103 
106  // L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const float* Scale, int idx_offset=0)
108  unsigned int nbits, bool signedPacking, int NBins, const std::vector<double>& Scale, int idx_offset = 0)
109  : m_nbits(nbits), m_signedPacking(signedPacking) {
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), m_signedPacking(signedPacking) {
131  m_NBins = NBins;
132  m_idxoffset = idx_offset;
133 
134  m_Scale.reserve(m_NBins + 1);
135  for (int i = 0; i < m_NBins + 1; i++)
136  // m_Scale[i] = xmin + i * (xmax-xmin) / m_NBins;
137  m_Scale.push_back(xmin + i * (xmax - xmin) / m_NBins);
138  };
139 
141  ~L1MuBinnedScale() override{
142  // delete m_packing;
143  };
144 
146  float getCenter(unsigned packed) const override {
147  int idx = get_idx(packed);
148  return (m_Scale[idx] + m_Scale[idx + 1]) / 2.;
149  };
150 
152  float getLowEdge(unsigned packed) const override { return m_Scale[get_idx(packed)]; };
153 
155  float getHighEdge(unsigned packed) const override { return m_Scale[get_idx(packed) + 1]; };
156 
158 
159  unsigned getPacked(float value) const override {
160  if (value < m_Scale[0] || value > m_Scale[m_NBins])
161  edm::LogWarning("ScaleRangeViolation")
162  << "L1MuBinnedScale::getPacked: value out of scale range: " << value << std::endl;
163  int idx = 0;
164  if (value < m_Scale[0])
165  idx = 0;
166  else if (value >= m_Scale[m_NBins])
167  idx = m_NBins - 1;
168  else {
169  for (; idx < m_NBins; idx++)
170  if (value >= m_Scale[idx] && value < m_Scale[idx + 1])
171  break;
172  }
173 
176  };
177 
179  float getScaleMax() const override { return m_Scale[m_NBins]; }
180 
182  float getScaleMin() const override { return m_Scale[0]; }
183 
185  unsigned getNBins() const override { return m_NBins; }
186 
188  float getValue(unsigned i) const override { return m_Scale[i]; }
189 
190  std::string print() const override {
191  std::ostringstream str;
192 
193  str << " ind | low edge | center | high edge" << std::endl;
194  str << "-------------------------------------------" << std::endl;
195  for (int i = 0; i < m_NBins; i++) {
196  unsigned int ipack = getPacked(m_Scale[i]);
197  str << std::setw(4) << ipack << " | " << std::setw(10) << getLowEdge(ipack) << " | " << std::setw(10)
198  << getCenter(ipack) << " | " << std::setw(10) << getHighEdge(ipack) << std::endl;
199  }
200 
201  return str.str();
202  }
203 
204 protected:
205  int get_idx(unsigned packed) const {
208  int idx = idxFromPacked + m_idxoffset;
209  if (idx < 0)
210  idx = 0;
211  if (idx >= m_NBins)
212  idx = m_NBins - 1;
213  return idx;
214  }
215 
216  unsigned int m_nbits;
218  int m_NBins;
220  std::vector<float> m_Scale;
221 
223 };
224 
237 public:
245 
247 
250  // L1MuSymmetricBinnedScale(int nbits, int NBins, const float* Scale)
251  L1MuSymmetricBinnedScale(int nbits, int NBins, const std::vector<double>& Scale)
253  m_NBins = NBins;
254  m_Scale.reserve(m_NBins + 1);
255  for (int i = 0; i < m_NBins + 1; i++)
256  // m_Scale[i] = Scale[i];
257  m_Scale.push_back(Scale[i]);
258  };
259 
270  L1MuSymmetricBinnedScale(int nbits, int NBins, float xmin, float xmax) : m_packing(L1MuPseudoSignedPacking(nbits)) {
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] = xmin + i * (xmax-xmin) / m_NBins;
275  m_Scale.push_back(xmin + i * (xmax - xmin) / m_NBins);
276  };
277 
280  // delete m_packing;
281  };
282 
284  float getCenter(unsigned packed) const override {
285  int absidx = abs(m_packing.idxFromPacked(packed));
286  if (absidx >= m_NBins)
287  absidx = m_NBins - 1;
288  float center = (m_Scale[absidx] + m_Scale[absidx + 1]) / 2.;
289  float fsign = m_packing.signFromPacked(packed) == 0 ? 1. : -1.;
290  return center * fsign;
291  };
292 
294  float getLowEdge(unsigned packed) const override { // === edge towards 0
295  int absidx = abs(m_packing.idxFromPacked(packed));
296  if (absidx >= m_NBins)
297  absidx = m_NBins - 1;
298  float low = m_Scale[absidx];
299  float fsign = m_packing.signFromPacked(packed) == 0 ? 1. : -1.;
300  return low * fsign;
301  };
302 
304  float getHighEdge(unsigned packed) const override {
305  edm::LogWarning("NotImplemented") << "L1MuSymmetricBinnedScale::getHighEdge not implemented" << std::endl;
306  return 0;
307  };
308 
310  unsigned getPacked(float value) const override {
311  float absval = fabs(value);
312  if (absval < m_Scale[0] || absval > m_Scale[m_NBins])
313  edm::LogWarning("ScaleRangeViolation")
314  << "L1MuSymmetricBinnedScale::getPacked: value out of scale range!!! abs(val) = " << absval
315  << " min= " << m_Scale[0] << " max = " << m_Scale[m_NBins] << std::endl;
316  int idx = 0;
317  for (; idx < m_NBins; idx++)
318  if (absval >= m_Scale[idx] && absval < m_Scale[idx + 1])
319  break;
320  if (idx >= m_NBins)
321  idx = m_NBins - 1;
322  return m_packing.packedFromIdx(idx, (value >= 0) ? 0 : 1);
323  };
325  float getScaleMax() const override { return m_Scale[m_NBins]; }
326 
328  float getScaleMin() const override { return m_Scale[0]; }
329 
331  unsigned getNBins() const override { return m_NBins; }
332 
334  float getValue(unsigned i) const override { return m_Scale[i]; }
335 
336  std::string print() const override {
337  std::ostringstream str;
338 
339  str << " ind | low edge | center" << std::endl;
340  str << "-------------------------------------------" << std::endl;
341  for (int i = 0; i < m_NBins; i++) {
342  unsigned int ipack = getPacked(m_Scale[i]);
343  str << std::setw(4) << ipack << " | " << std::setw(10) << getLowEdge(ipack) << " | " << std::setw(10)
344  << getCenter(ipack) << std::endl;
345  }
346 
347  return str.str();
348  }
349 
350 protected:
352  int m_NBins;
353  std::vector<float> m_Scale;
354 
356 };
357 #endif
L1MuBinnedScale::m_Scale
std::vector< float > m_Scale
Definition: L1MuScale.h:220
L1MuPseudoSignedPacking::packedFromIdx
unsigned packedFromIdx(int idx) const override
get the packed notation of a value, check range
Definition: L1MuPacking.h:157
L1MuBinnedScale::m_nbits
unsigned int m_nbits
Definition: L1MuScale.h:216
L1MuSymmetricBinnedScale::L1MuSymmetricBinnedScale
L1MuSymmetricBinnedScale(int nbits, int NBins, float xmin, float xmax)
Definition: L1MuScale.h:270
mps_fire.i
i
Definition: mps_fire.py:355
L1MuScale::getNBins
virtual unsigned getNBins() const =0
get number of bins
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
L1MuUnsignedPackingGeneric::idxFromPacked
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (always positive)
Definition: L1MuPacking.h:77
L1MuPacking.h
L1MuSymmetricBinnedScale::m_NBins
int m_NBins
Definition: L1MuScale.h:352
L1MuSymmetricBinnedScale::~L1MuSymmetricBinnedScale
~L1MuSymmetricBinnedScale() override
destructor
Definition: L1MuScale.h:279
L1MuScale
Definition: L1MuScale.h:38
COND_SERIALIZABLE
#define COND_SERIALIZABLE
Definition: Serializable.h:39
L1MuSymmetricBinnedScale::getNBins
unsigned getNBins() const override
get number of bins
Definition: L1MuScale.h:331
L1MuScale::getValue
virtual float getValue(unsigned i) const =0
get value of the underlying vector for bin i
charmTagsComputerCvsB_cfi.idx
idx
Definition: charmTagsComputerCvsB_cfi.py:108
L1MuSymmetricBinnedScale::m_packing
L1MuPseudoSignedPacking m_packing
Definition: L1MuScale.h:351
L1MuSymmetricBinnedScale::getScaleMax
float getScaleMax() const override
get the upper edge of the last bin (posivie half)
Definition: L1MuScale.h:325
L1MuSymmetricBinnedScale::L1MuSymmetricBinnedScale
L1MuSymmetricBinnedScale(int nbits, int NBins, const std::vector< double > &Scale)
Definition: L1MuScale.h:251
L1MuBinnedScale::getHighEdge
float getHighEdge(unsigned packed) const override
get the upper edge of bin represented by packed
Definition: L1MuScale.h:155
L1MuBinnedScale::getPacked
unsigned getPacked(float value) const override
pack a value
Definition: L1MuScale.h:159
L1MuBinnedScale::m_signedPacking
bool m_signedPacking
Definition: L1MuScale.h:217
L1MuSignedPackingGeneric::idxFromPacked
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:119
L1MuBinnedScale::L1MuBinnedScale
L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, float xmin, float xmax, int idx_offset=0)
Definition: L1MuScale.h:129
L1MuPseudoSignedPacking
Definition: L1MuPacking.h:140
L1MuBinnedScale::~L1MuBinnedScale
~L1MuBinnedScale() override
destructor
Definition: L1MuScale.h:141
str
#define str(s)
Definition: TestProcessor.cc:48
L1MuScale::getLowEdge
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
L1MuBinnedScale::L1MuBinnedScale
L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const std::vector< double > &Scale, int idx_offset=0)
Definition: L1MuScale.h:107
L1MuPseudoSignedPacking::idxFromPacked
int idxFromPacked(unsigned packed) const override
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:150
L1MuBinnedScale::print
std::string print() const override
Definition: L1MuScale.h:190
L1MuScale::getScaleMin
virtual float getScaleMin() const =0
get the lower edge of the first bin
L1MuSymmetricBinnedScale::getValue
float getValue(unsigned i) const override
get value of the underlying vector for bin i
Definition: L1MuScale.h:334
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1MuSignedPackingGeneric::packedFromIdx
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check range
Definition: L1MuPacking.h:123
edm::LogWarning
Definition: MessageLogger.h:141
L1MuSymmetricBinnedScale::getPacked
unsigned getPacked(float value) const override
pack a value
Definition: L1MuScale.h:310
L1MuPseudoSignedPacking::signFromPacked
int signFromPacked(unsigned packed) const override
get the (pseudo-)sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:147
L1MuBinnedScale::L1MuBinnedScale
L1MuBinnedScale()
Definition: L1MuScale.h:102
L1MuBinnedScale::getLowEdge
float getLowEdge(unsigned packed) const override
get the low edge of bin represented by packed
Definition: L1MuScale.h:152
L1MuScale::getHighEdge
virtual float getHighEdge(unsigned packed) const =0
get the upper edge of bin represented by packed
L1MuSymmetricBinnedScale::getScaleMin
float getScaleMin() const override
get the lower edge of the first bin (positive half)
Definition: L1MuScale.h:328
L1MuScale::~L1MuScale
virtual ~L1MuScale()
Definition: L1MuScale.h:42
Serializable.h
value
Definition: value.py:1
L1MuSymmetricBinnedScale::print
std::string print() const override
Definition: L1MuScale.h:336
L1MuSymmetricBinnedScale::getLowEdge
float getLowEdge(unsigned packed) const override
get the low edge of bin represented by packed
Definition: L1MuScale.h:294
SiStripSourceConfigP5_cff.NBins
NBins
Definition: SiStripSourceConfigP5_cff.py:4
L1MuBinnedScale::getScaleMax
float getScaleMax() const override
get the upper edge of the last bin
Definition: L1MuScale.h:179
L1MuBinnedScale
Definition: L1MuScale.h:93
L1MuBinnedScale::getNBins
unsigned getNBins() const override
get number of bins
Definition: L1MuScale.h:185
L1MuSymmetricBinnedScale
Definition: L1MuScale.h:236
L1MuSymmetricBinnedScale::L1MuSymmetricBinnedScale
L1MuSymmetricBinnedScale()
Definition: L1MuScale.h:246
L1MuSymmetricBinnedScale::getCenter
float getCenter(unsigned packed) const override
get the center of bin represented by packed
Definition: L1MuScale.h:284
L1MuBinnedScale::getValue
float getValue(unsigned i) const override
get value of the underlying vector for bin i
Definition: L1MuScale.h:188
L1MuUnsignedPackingGeneric::packedFromIdx
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check the range
Definition: L1MuPacking.h:79
L1MuBinnedScale::getCenter
float getCenter(unsigned packed) const override
get the center of bin represented by packed
Definition: L1MuScale.h:146
TrackerOfflineValidation_Dqm_cff.xmax
xmax
Definition: TrackerOfflineValidation_Dqm_cff.py:11
L1MuSymmetricBinnedScale::getHighEdge
float getHighEdge(unsigned packed) const override
get the upper edge of bin represented by packed
Definition: L1MuScale.h:304
L1MuScale::L1MuScale
L1MuScale()
Definition: L1MuScale.h:40
L1MuScale::print
virtual std::string print() const =0
L1MuBinnedScale::get_idx
int get_idx(unsigned packed) const
Definition: L1MuScale.h:205
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1MuBinnedScale::getScaleMin
float getScaleMin() const override
get the lower edge of the first bin
Definition: L1MuScale.h:182
L1MuScale::getPacked
virtual unsigned getPacked(float value) const =0
pack a value
TrackerOfflineValidation_Dqm_cff.xmin
xmin
Definition: TrackerOfflineValidation_Dqm_cff.py:10
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
L1MuBinnedScale::m_NBins
int m_NBins
Definition: L1MuScale.h:218
L1MuScale::getScaleMax
virtual float getScaleMax() const =0
get the upper edge of the last bin
L1MuSymmetricBinnedScale::m_Scale
std::vector< float > m_Scale
Definition: L1MuScale.h:353
L1MuScale::getCenter
virtual float getCenter(unsigned packed) const =0
get the center of bin represented by packed
L1MuBinnedScale::m_idxoffset
int m_idxoffset
Definition: L1MuScale.h:219