Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:04

0001 // Tools for unpacking and packing EMTF data
0002 
0003 #ifndef EventFilter_L1TRawToDigi_EMTFUnpackerTools_h
0004 #define EventFilter_L1TRawToDigi_EMTFUnpackerTools_h
0005 
0006 // Generally useful includes
0007 #include <iostream>
0008 #include <iomanip>  // For things like std::setw
0009 #include <array>
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "DataFormats/L1TMuon/interface/EMTFDaqOut.h"
0012 #include "DataFormats/L1TMuon/interface/EMTFHit.h"
0013 #include "DataFormats/L1TMuon/interface/EMTFTrack.h"
0014 #include "L1Trigger/L1TMuonEndCap/interface/TrackTools.h"
0015 
0016 namespace l1t {
0017   namespace stage2 {
0018     namespace emtf {
0019       namespace L1TMuonEndCap =
0020           ::emtf;  // use alias 'L1TMuonEndCap' for the namespace 'emtf' used in L1Trigger/L1TMuonEndCap
0021 
0022       void ImportME(EMTFHit& _hit, const l1t::emtf::ME _ME, const int _endcap, const int _evt_sector);
0023       void ImportRPC(EMTFHit& _hit, const l1t::emtf::RPC _RPC, const int _endcap, const int _evt_sector);
0024       void ImportGEM(EMTFHit& _hit, const l1t::emtf::GEM& _GEM, const int _endcap, const int _evt_sector);
0025       void ImportSP(EMTFTrack& _track, const l1t::emtf::SP _SP, const int _endcap, const int _evt_sector);
0026 
0027       // Integer version of pow() - returns base^exp
0028       inline int PowInt(int base, int exp) {
0029         if (exp == 0)
0030           return 1;
0031         if (exp == 1)
0032           return base;
0033         return base * PowInt(base, exp - 1);
0034       }
0035 
0036       // Compute the two's complement of an integer
0037       inline int TwosCompl(int nBits, int bits) {
0038         if (bits >> (nBits - 1) == 0)
0039           return bits;
0040         else
0041           return bits - PowInt(2, nBits);
0042       };
0043 
0044       // Get the integer value of specified bits from a 16-bit word (0xffff)
0045       inline uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit) {
0046         return ((word >> lowBit) & (PowInt(2, (1 + highBit - lowBit)) - 1));
0047       }
0048 
0049       // Get the integer value of specified bits from a 32-bit word (0xffffffff)
0050       inline uint32_t GetHexBits(uint32_t word, uint32_t lowBit, uint32_t highBit) {
0051         return ((word >> lowBit) & (PowInt(2, (1 + highBit - lowBit)) - 1));
0052       }
0053 
0054       // Get the integer value of specified bits from two 16-bit words (0xffff, 0xffff)
0055       inline uint32_t GetHexBits(
0056           uint16_t word1, uint16_t lowBit1, uint16_t highBit1, uint16_t word2, uint16_t lowBit2, uint16_t highBit2) {
0057         uint16_t word1_sel = (word1 >> lowBit1) & (PowInt(2, (1 + highBit1 - lowBit1)) - 1);
0058         uint16_t word2_sel = (word2 >> lowBit2) & (PowInt(2, (1 + highBit2 - lowBit2)) - 1);
0059         return ((word2_sel << (1 + highBit1 - lowBit1)) | word1_sel);
0060       }
0061 
0062     }  // End namespace emtf
0063   }    // End namespace stage2
0064 }  // End namespace l1t
0065 
0066 #endif /* define EventFilter_L1TRawToDigi_EMTFUnpackerTools_h */