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;
107 m_signedPacking(
false ),
115 L1MuBinnedScale(
unsigned int nbits,
bool signedPacking,
int NBins,
const std::vector<double>& Scale,
int idx_offset=0)
117 m_signedPacking( signedPacking )
120 m_idxoffset = idx_offset;
122 m_Scale.reserve(m_NBins + 1);
123 for (
int i=0;
i<m_NBins + 1;
i++)
125 m_Scale.push_back( Scale[
i] ) ;
140 m_signedPacking( signedPacking )
143 m_idxoffset = idx_offset;
145 m_Scale.reserve(m_NBins + 1);
146 for (
int i=0;
i<m_NBins + 1;
i++)
148 m_Scale.push_back( xmin +
i * (xmax-xmin) / m_NBins ) ;
159 int idx = get_idx(packed);
160 return (m_Scale[idx] + m_Scale[idx+1] )/ 2.;
165 return m_Scale[get_idx(packed)];
170 return m_Scale[get_idx(packed)+1];
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;
179 if (value < m_Scale[0]) idx=0;
180 else if (value >= m_Scale[m_NBins]) idx = m_NBins-1;
182 for (; idx<m_NBins; idx++)
183 if (value >= m_Scale[idx] && value < m_Scale[idx+1])
break;
186 return ( m_signedPacking ?
198 virtual unsigned getNBins()
const {
return m_NBins; }
201 virtual float getValue(
unsigned i)
const {
return m_Scale[
i]; }
204 std::ostringstream
str;
206 str <<
" ind | low edge | center | high edge" << std::endl;
207 str <<
"-------------------------------------------" << std::endl;
208 for(
int i=0;
i<m_NBins;
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;
222 int idxFromPacked = m_signedPacking ?
225 int idx = idxFromPacked + m_idxoffset;
227 if (idx>=m_NBins) idx=m_NBins-1;
272 m_Scale.reserve(m_NBins + 1);
273 for (
int i=0;
i<m_NBins + 1;
i++)
275 m_Scale.push_back( Scale[
i] ) ;
291 m_Scale.reserve(m_NBins + 1);
292 for (
int i=0;
i<m_NBins + 1;
i++)
294 m_Scale.push_back( xmin +
i * (xmax-xmin) / m_NBins ) ;
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;
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.;
322 edm::LogWarning(
"NotImplemented") <<
"L1MuSymmetricBinnedScale::getHighEdge not implemented" << std::endl;
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;
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);
345 virtual unsigned getNBins()
const {
return m_NBins; }
348 virtual float getValue(
unsigned i)
const {
return m_Scale[
i]; }
351 std::ostringstream
str;
353 str <<
" ind | low edge | center" << std::endl;
354 str <<
"-------------------------------------------" << std::endl;
355 for(
int i=0;
i<m_NBins;
i++){
357 str << std::setw(4) << ipack <<
358 " | " << std::setw(10) <<
getLowEdge(ipack) <<
359 " | " << std::setw(10) <<
getCenter(ipack) << std::endl;
virtual float getScaleMin() const
get the lower edge of the first bin
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (always positive)
std::vector< float > m_Scale
virtual float getScaleMax() const
get the upper edge of the last bin (posivie half)
virtual ~L1MuSymmetricBinnedScale()
destructor
virtual std::string print() const
virtual float getCenter(unsigned packed) const =0
get the center of bin represented by packed
virtual unsigned getNBins() const
get number of bins
virtual float getHighEdge(unsigned packed) const
get the upper edge of bin represented by packed
virtual unsigned getPacked(float value) const
pack a value
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)
virtual float getLowEdge(unsigned packed) const
get the low edge of bin represented by packed
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)
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)
L1MuSymmetricBinnedScale(int nbits, int NBins, float xmin, float xmax)
virtual ~L1MuBinnedScale()
destructor
virtual unsigned getNBins() const =0
get number of bins
virtual float getCenter(unsigned packed) const
get the center of bin represented by packed
virtual float getScaleMax() const
get the upper edge of the last bin
virtual float getCenter(unsigned packed) const
get the center of bin represented by packed
virtual float getHighEdge(unsigned packed) const
get the upper edge of bin represented by packed
L1MuPseudoSignedPacking m_packing
L1MuSymmetricBinnedScale()
virtual std::string print() const =0
virtual float getValue(unsigned i) const
get value of the underlying vector for bin i
#define COND_SERIALIZABLE
virtual unsigned getNBins() const
get number of bins
L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const std::vector< double > &Scale, int idx_offset=0)
virtual float getScaleMin() const
get the lower edge of the first bin (positive half)
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
virtual float getValue(unsigned i) const
get value of the underlying vector for bin i
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check the range
virtual unsigned getPacked(float value) const =0
pack a value
virtual float getLowEdge(unsigned packed) const
get the low edge of bin represented by packed
virtual float getScaleMax() const =0
get the upper edge of the last bin
virtual std::string print() const
int get_idx(unsigned packed) const
virtual float getValue(unsigned i) const =0
get value of the underlying vector for bin i
virtual unsigned getPacked(float value) const
pack a value