Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:14

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTConfigLUTs
0004 //
0005 //   Description: Configurable parameters and constants
0006 //   for Level1 Mu DT Trigger - LUTs
0007 //
0008 //
0009 //   Author List:
0010 //   S. Vanini
0011 //
0012 //-----------------------------------------------------------------------
0013 
0014 //-----------------------
0015 // This Class's Header --
0016 //-----------------------
0017 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigLUTs.h"
0018 
0019 //---------------
0020 // C++ Headers --
0021 //---------------
0022 #include <cmath>
0023 #include <cstring>
0024 
0025 //-------------------------------
0026 // Collaborating Class Headers --
0027 //-------------------------------
0028 
0029 #include "FWCore/Utilities/interface/Exception.h"
0030 
0031 //----------------
0032 // Constructors --
0033 //----------------
0034 DTConfigLUTs::DTConfigLUTs(const edm::ParameterSet& ps) { setDefaults(ps); }
0035 
0036 DTConfigLUTs::DTConfigLUTs(bool debugLUTS, unsigned short int* buffer) {
0037   m_debug = debugLUTS;
0038 
0039   // check if this is a LUT configuration string
0040   if (buffer[2] != 0xA8) {
0041     throw cms::Exception("DTTPG") << "===> ConfigLUTs constructor : not a LUT string!" << std::endl;
0042   }
0043 
0044   // decode
0045   short int memory_lut[7];
0046   int c = 3;
0047   for (int i = 0; i < 7; i++) {
0048     memory_lut[i] = (buffer[c] << 8) | buffer[c + 1];
0049     c += 2;
0050     //std::cout << hex << memory_bti[i] << "  ";
0051   }
0052 
0053   // decode
0054   int btic = memory_lut[0];
0055   float d;
0056   DSPtoIEEE32(memory_lut[1], memory_lut[2], &d);
0057   float Xcn;
0058   DSPtoIEEE32(memory_lut[3], memory_lut[4], &Xcn);
0059   int wheel = memory_lut[5];
0060 
0061   // set parameters
0062   setBTIC(btic);
0063   setD(d);
0064   setXCN(Xcn);
0065   setWHEEL(wheel);
0066 
0067   return;
0068 }
0069 
0070 //--------------
0071 // Destructor --
0072 //--------------
0073 DTConfigLUTs::~DTConfigLUTs() {}
0074 
0075 //--------------
0076 // Operations --
0077 //--------------
0078 
0079 void DTConfigLUTs::setDefaults(const edm::ParameterSet& m_ps) {
0080   // Debug flag
0081   m_debug = m_ps.getUntrackedParameter<bool>("Debug");
0082 
0083   // BTIC parameter
0084   m_btic = m_ps.getUntrackedParameter<int>("BTIC");
0085 
0086   // d: distance vertex to normal, unit cm.
0087   m_d = m_ps.getUntrackedParameter<double>("D");
0088 
0089   // Xcn: distance vertex to normal, unit cm.
0090   m_Xcn = m_ps.getUntrackedParameter<double>("XCN");
0091 
0092   // wheel sign (-1 or +1)
0093   m_wheel = m_ps.getUntrackedParameter<int>("WHEEL");
0094 }
0095 
0096 void DTConfigLUTs::print() const {
0097   std::cout << "******************************************************************************" << std::endl;
0098   std::cout << "*              DTTrigger configuration : LUT parameters             *" << std::endl;
0099   std::cout << "******************************************************************************" << std::endl
0100             << std::endl;
0101   std::cout << "Debug flag : " << debug() << std::endl;
0102   std::cout << "BTIC parameter : " << m_btic << std::endl;
0103   std::cout << "d: distance vertex to normal, unit cm. " << m_d << std::endl;
0104   std::cout << "Xcn: distance vertex to normal, unit cm. " << m_Xcn << std::endl;
0105   std::cout << "wheel sign " << m_wheel << std::endl;
0106   std::cout << "******************************************************************************" << std::endl;
0107 }
0108 
0109 void DTConfigLUTs::DSPtoIEEE32(short DSPmantissa, short DSPexp, float* f) const {
0110   DSPexp -= 15;
0111   *f = DSPmantissa * (float)pow(2.0, DSPexp);
0112   return;
0113 }
0114 
0115 void DTConfigLUTs::IEEE32toDSP(float f, short int& DSPmantissa, short int& DSPexp) const {
0116   long int pl = 0;
0117   static_assert(sizeof(decltype(pl)) >= sizeof(float));
0118 
0119   DSPmantissa = 0;
0120   DSPexp = 0;
0121 
0122   if (f != 0.0) {
0123     //pl = (long *)&f;
0124     memcpy(&pl, &f, sizeof(float));
0125     bool sign = false;
0126     if ((pl & 0x80000000) != 0)
0127       sign = true;
0128     long int lm = (0x800000 | (pl & 0x7FFFFF));  // [1][23bit mantissa]
0129     lm >>= 9;                                    //reduce to 15bits
0130     lm &= 0x7FFF;
0131     DSPexp = ((pl >> 23) & 0xFF) - 126;
0132     DSPmantissa = (short)lm;
0133     if (sign)
0134       DSPmantissa = -DSPmantissa;  // convert negative value in 2.s complement
0135   }
0136   return;
0137 }