19 #ifndef CondFormatsL1TObjects_L1MuScale_h 20 #define CondFormatsL1TObjects_L1MuScale_h 45 virtual float getCenter(
unsigned packed)
const = 0;
48 virtual float getLowEdge(
unsigned packed)
const = 0;
51 virtual float getHighEdge(
unsigned packed)
const = 0;
63 virtual unsigned getNBins()
const = 0;
66 virtual float getValue(
unsigned i)
const = 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) {
111 m_idxoffset = idx_offset;
113 m_Scale.reserve(m_NBins + 1);
114 for (
int i = 0;
i < m_NBins + 1;
i++)
116 m_Scale.push_back(Scale[
i]);
130 : m_nbits(nbits), m_signedPacking(signedPacking) {
132 m_idxoffset = idx_offset;
134 m_Scale.reserve(m_NBins + 1);
135 for (
int i = 0;
i < m_NBins + 1;
i++)
137 m_Scale.push_back(xmin +
i * (xmax - xmin) / m_NBins);
147 int idx = get_idx(packed);
148 return (m_Scale[idx] + m_Scale[idx + 1]) / 2.;
152 float getLowEdge(
unsigned packed)
const override {
return m_Scale[get_idx(packed)]; };
155 float getHighEdge(
unsigned packed)
const override {
return m_Scale[get_idx(packed) + 1]; };
160 if (value < m_Scale[0] || value > m_Scale[m_NBins])
162 <<
"L1MuBinnedScale::getPacked: value out of scale range: " << value << std::endl;
164 if (value < m_Scale[0])
166 else if (value >= m_Scale[m_NBins])
169 for (; idx < m_NBins; idx++)
170 if (value >= m_Scale[idx] && value < m_Scale[idx + 1])
185 unsigned getNBins()
const override {
return m_NBins; }
188 float getValue(
unsigned i)
const override {
return m_Scale[
i]; }
191 std::ostringstream
str;
193 str <<
" ind | low edge | center | high edge" << std::endl;
194 str <<
"-------------------------------------------" << std::endl;
195 for (
int i = 0;
i < m_NBins;
i++) {
197 str << std::setw(4) << ipack <<
" | " << std::setw(10) <<
getLowEdge(ipack) <<
" | " << std::setw(10)
208 int idx = idxFromPacked + m_idxoffset;
254 m_Scale.reserve(m_NBins + 1);
255 for (
int i = 0;
i < m_NBins + 1;
i++)
257 m_Scale.push_back(Scale[
i]);
272 m_Scale.reserve(m_NBins + 1);
273 for (
int i = 0;
i < m_NBins + 1;
i++)
275 m_Scale.push_back(xmin +
i * (xmax - xmin) / m_NBins);
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;
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.;
305 edm::LogWarning(
"NotImplemented") <<
"L1MuSymmetricBinnedScale::getHighEdge not implemented" << std::endl;
311 float absval = fabs(value);
312 if (absval < m_Scale[0] || absval > m_Scale[m_NBins])
314 <<
"L1MuSymmetricBinnedScale::getPacked: value out of scale range!!! abs(val) = " << absval
315 <<
" min= " << m_Scale[0] <<
" max = " << m_Scale[m_NBins] << std::endl;
317 for (; idx < m_NBins; idx++)
318 if (absval >= m_Scale[idx] && absval < m_Scale[idx + 1])
322 return m_packing.packedFromIdx(idx, (value >= 0) ? 0 : 1);
331 unsigned getNBins()
const override {
return m_NBins; }
334 float getValue(
unsigned i)
const override {
return m_Scale[
i]; }
337 std::ostringstream
str;
339 str <<
" ind | low edge | center" << std::endl;
340 str <<
"-------------------------------------------" << std::endl;
341 for (
int i = 0;
i < m_NBins;
i++) {
343 str << std::setw(4) << ipack <<
" | " << std::setw(10) <<
getLowEdge(ipack) <<
" | " << std::setw(10)
float getScaleMin() const override
get the lower edge of the first bin (positive half)
unsigned getPacked(float value) const override
pack a value
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (always positive)
std::vector< float > m_Scale
float getScaleMax() const override
get the upper edge of the last bin (posivie half)
std::string print() const override
float getScaleMin() const override
get the lower edge of the first bin
float getCenter(unsigned packed) const override
get the center of bin represented by packed
virtual float getCenter(unsigned packed) const =0
get the center of bin represented by packed
float getValue(unsigned i) const override
get value of the underlying vector for bin i
float getHighEdge(unsigned packed) const override
get the upper edge of bin represented by packed
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check range
L1MuSymmetricBinnedScale(int nbits, int NBins, const std::vector< double > &Scale)
float getCenter(unsigned packed) const override
get the center of bin represented by packed
virtual float getHighEdge(unsigned packed) const =0
get the upper edge of bin represented by packed
unsigned getNBins() const override
get number of bins
float getScaleMax() const override
get the upper edge of the last bin
L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, float xmin, float xmax, int idx_offset=0)
virtual float getScaleMin() const =0
get the lower edge of the first bin
std::vector< float > m_Scale
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (+/-)
Abs< T >::type abs(const T &t)
unsigned getPacked(float value) const override
pack a value
~L1MuSymmetricBinnedScale() override
destructor
L1MuSymmetricBinnedScale(int nbits, int NBins, float xmin, float xmax)
float getLowEdge(unsigned packed) const override
get the low edge of bin represented by packed
virtual unsigned getNBins() const =0
get number of bins
L1MuPseudoSignedPacking m_packing
L1MuSymmetricBinnedScale()
virtual std::string print() const =0
~L1MuBinnedScale() override
destructor
float getLowEdge(unsigned packed) const override
get the low edge of bin represented by packed
#define COND_SERIALIZABLE
L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const std::vector< double > &Scale, int idx_offset=0)
unsigned getNBins() const override
get number of bins
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check the range
float getHighEdge(unsigned packed) const override
get the upper edge of bin represented by packed
virtual unsigned getPacked(float value) const =0
pack a value
std::string print() const override
virtual float getScaleMax() const =0
get the upper edge of the last bin
float getValue(unsigned i) const override
get value of the underlying vector for bin i
int get_idx(unsigned packed) const
virtual float getValue(unsigned i) const =0
get value of the underlying vector for bin i