Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CondFormatsL1TObjects_L1MuScale_h
00020 #define CondFormatsL1TObjects_L1MuScale_h
00021
00022 #include <iostream>
00023 #include <sstream>
00024 #include <iomanip>
00025 #include <vector>
00026 #include <math.h>
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028 #include "CondFormats/L1TObjects/interface/L1MuPacking.h"
00029
00036 class L1MuScale {
00037 public:
00038 L1MuScale() {}
00039
00040 virtual ~L1MuScale() {}
00041
00043 virtual float getCenter(unsigned packed) const = 0;
00044
00046 virtual float getLowEdge(unsigned packed) const = 0;
00047
00049 virtual float getHighEdge(unsigned packed) const = 0;
00050
00052 virtual float getScaleMax() const = 0;
00053
00055 virtual float getScaleMin() const = 0;
00056
00058 virtual unsigned getPacked(float value) const = 0;
00059
00061 virtual unsigned getNBins() const = 0;
00062
00064 virtual float getValue(unsigned i) const = 0;
00065
00066 virtual std::string print() const = 0;
00067
00068 private:
00069 };
00070
00071
00072
00073
00074
00075
00091 class L1MuBinnedScale : public L1MuScale {
00092 public:
00093
00101 L1MuBinnedScale() {}
00102
00105
00106 L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, const std::vector<double> Scale, int idx_offset=0)
00107 : m_nbits( nbits ),
00108 m_signedPacking( signedPacking )
00109 {
00110 m_NBins = NBins;
00111 m_idxoffset = idx_offset;
00112
00113 m_Scale.reserve(m_NBins + 1);
00114 for (int i=0; i<m_NBins + 1; i++)
00115
00116 m_Scale.push_back( Scale[i] ) ;
00117 };
00118
00129 L1MuBinnedScale(unsigned int nbits, bool signedPacking, int NBins, float xmin, float xmax, int idx_offset=0)
00130 : m_nbits( nbits ),
00131 m_signedPacking( signedPacking )
00132 {
00133 m_NBins = NBins;
00134 m_idxoffset = idx_offset;
00135
00136 m_Scale.reserve(m_NBins + 1);
00137 for (int i=0; i<m_NBins + 1; i++)
00138
00139 m_Scale.push_back( xmin + i * (xmax-xmin) / m_NBins ) ;
00140 };
00141
00143 virtual ~L1MuBinnedScale() {
00144
00145 };
00146
00147
00149 virtual float getCenter(unsigned packed) const {
00150 int idx = get_idx(packed);
00151 return (m_Scale[idx] + m_Scale[idx+1] )/ 2.;
00152 };
00153
00155 virtual float getLowEdge(unsigned packed) const{
00156 return m_Scale[get_idx(packed)];
00157 };
00158
00160 virtual float getHighEdge(unsigned packed) const{
00161 return m_Scale[get_idx(packed)+1];
00162 };
00163
00165
00166 virtual unsigned getPacked(float value) const {
00167 if (value < m_Scale[0] || value > m_Scale[m_NBins])
00168 edm::LogWarning("ScaleRangeViolation") << "L1MuBinnedScale::getPacked: value out of scale range: " << value << std::endl;
00169 int idx = 0;
00170 if (value < m_Scale[0]) idx=0;
00171 else if (value >= m_Scale[m_NBins]) idx = m_NBins-1;
00172 else {
00173 for (; idx<m_NBins; idx++)
00174 if (value >= m_Scale[idx] && value < m_Scale[idx+1]) break;
00175 }
00176
00177 return ( m_signedPacking ?
00178 L1MuSignedPackingGeneric::packedFromIdx(idx-m_idxoffset, m_nbits) :
00179 L1MuUnsignedPackingGeneric::packedFromIdx(idx-m_idxoffset, m_nbits) ) ;
00180 };
00181
00183 virtual float getScaleMax() const { return m_Scale[m_NBins]; }
00184
00186 virtual float getScaleMin() const { return m_Scale[0]; }
00187
00189 virtual unsigned getNBins() const { return m_NBins; }
00190
00192 virtual float getValue(unsigned i) const { return m_Scale[i]; }
00193
00194 virtual std::string print() const {
00195 std::ostringstream str;
00196
00197 str << " ind | low edge | center | high edge" << std::endl;
00198 str << "-------------------------------------------" << std::endl;
00199 for(int i=0; i<m_NBins; i++){
00200 unsigned int ipack = getPacked(m_Scale[i]);
00201 str << std::setw(4) << ipack <<
00202 " | " << std::setw(10) << getLowEdge(ipack) <<
00203 " | " << std::setw(10) << getCenter(ipack) <<
00204 " | " << std::setw(10) << getHighEdge(ipack) << std::endl;
00205 }
00206
00207 return str.str();
00208 }
00209
00210
00211 protected:
00212 int get_idx (unsigned packed) const {
00213 int idxFromPacked = m_signedPacking ?
00214 L1MuSignedPackingGeneric::idxFromPacked( packed, m_nbits ) :
00215 L1MuUnsignedPackingGeneric::idxFromPacked( packed, m_nbits ) ;
00216 int idx = idxFromPacked + m_idxoffset;
00217 if (idx<0) idx=0;
00218 if (idx>=m_NBins) idx=m_NBins-1;
00219 return idx;
00220 }
00221
00222 unsigned int m_nbits ;
00223 bool m_signedPacking ;
00224 int m_NBins;
00225 int m_idxoffset;
00226 std::vector<float> m_Scale;
00227 };
00228
00240 class L1MuSymmetricBinnedScale : public L1MuScale {
00241 public:
00242
00250
00251 L1MuSymmetricBinnedScale() {}
00252
00255
00256 L1MuSymmetricBinnedScale(int nbits, int NBins, const std::vector<double> Scale)
00257 : m_packing (L1MuPseudoSignedPacking(nbits)) {
00258 m_NBins = NBins;
00259 m_Scale.reserve(m_NBins + 1);
00260 for (int i=0; i<m_NBins + 1; i++)
00261
00262 m_Scale.push_back( Scale[i] ) ;
00263 };
00264
00275 L1MuSymmetricBinnedScale(int nbits, int NBins, float xmin, float xmax)
00276 : m_packing (L1MuPseudoSignedPacking(nbits)) {
00277 m_NBins = NBins;
00278 m_Scale.reserve(m_NBins + 1);
00279 for (int i=0; i<m_NBins + 1; i++)
00280
00281 m_Scale.push_back( xmin + i * (xmax-xmin) / m_NBins ) ;
00282 };
00283
00285 virtual ~L1MuSymmetricBinnedScale() {
00286
00287 };
00288
00290 virtual float getCenter(unsigned packed) const {
00291 int absidx = abs ( m_packing.idxFromPacked( packed ) );
00292 if (absidx>=m_NBins) absidx=m_NBins-1;
00293 float center = (m_Scale[absidx] + m_Scale[absidx+1] )/ 2.;
00294 float fsign = m_packing.signFromPacked( packed ) == 0 ? 1. : -1.;
00295 return center * fsign;
00296 };
00297
00299 virtual float getLowEdge(unsigned packed) const{
00300 int absidx = abs ( m_packing.idxFromPacked( packed ) );
00301 if (absidx>=m_NBins) absidx=m_NBins-1;
00302 float low = m_Scale[absidx];
00303 float fsign = m_packing.signFromPacked( packed ) == 0 ? 1. : -1.;
00304 return low * fsign;
00305 };
00306
00308 virtual float getHighEdge(unsigned packed) const{
00309 edm::LogWarning("NotImplemented") << "L1MuSymmetricBinnedScale::getHighEdge not implemented" << std::endl;
00310 return 0;
00311 };
00312
00314 virtual unsigned getPacked(float value) const {
00315 float absval = fabs ( value );
00316 if (absval < m_Scale[0] || absval > m_Scale[m_NBins]) edm::LogWarning("ScaleRangeViolation")
00317 << "L1MuSymmetricBinnedScale::getPacked: value out of scale range!!! abs(val) = "
00318 << absval << " min= " << m_Scale[0] << " max = " << m_Scale[m_NBins] << std::endl;
00319 int idx = 0;
00320 for (; idx<m_NBins; idx++)
00321 if (absval >= m_Scale[idx] && absval < m_Scale[idx+1]) break;
00322 if (idx >= m_NBins) idx = m_NBins-1;
00323 return m_packing.packedFromIdx(idx, (value>=0) ? 0 : 1);
00324 };
00326 virtual float getScaleMax() const { return m_Scale[m_NBins]; }
00327
00329 virtual float getScaleMin() const { return m_Scale[0]; }
00330
00332 virtual unsigned getNBins() const { return m_NBins; }
00333
00335 virtual float getValue(unsigned i) const { return m_Scale[i]; }
00336
00337 virtual std::string print() const {
00338 std::ostringstream str;
00339
00340 str << " ind | low edge | center" << std::endl;
00341 str << "-------------------------------------------" << std::endl;
00342 for(int i=0; i<m_NBins; i++){
00343 unsigned int ipack = getPacked(m_Scale[i]);
00344 str << std::setw(4) << ipack <<
00345 " | " << std::setw(10) << getLowEdge(ipack) <<
00346 " | " << std::setw(10) << getCenter(ipack) << std::endl;
00347 }
00348
00349 return str.str();
00350 }
00351
00352 protected:
00353 L1MuPseudoSignedPacking m_packing;
00354 int m_NBins;
00355 std::vector<float> m_Scale;
00356 };
00357 #endif
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398