Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-21 02:53:03

0001 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0002 #include "EventFilter/CSCRawToDigi/interface/CSCCFEBTimeSlice.h"
0003 #include <cassert>
0004 #include <iomanip>
0005 #include <cstdint>
0006 
0007 // a Gray code is An ordering of 2n binary numbers such that
0008 // only one bit changes from one entry to the next
0009 // const unsigned layerGrayCode[] = {3,1,5,6,4,2};
0010 const unsigned layerInverseGrayCode[] = {1, 5, 0, 4, 2, 3};
0011 // const unsigned channelGrayCode[] = {0,1,3,2, 6,7,5,4, 12,13,15,14, 10,11,9,8};
0012 const unsigned channelInverseGrayCode[] = {0, 1, 3, 2, 7, 6, 4, 5, 15, 14, 12, 13, 8, 9, 11, 10};
0013 
0014 CSCCFEBTimeSlice::CSCCFEBTimeSlice() {
0015   bzero(this, 99 * 2);
0016   dummy = 0x7FFF;
0017   blank_space_1 = 0x7;
0018   blank_space_3 = 0x7;
0019 }
0020 
0021 CSCCFEBSCAControllerWord::CSCCFEBSCAControllerWord(unsigned short frame)
0022 // trig_time( frame & 0xFF ),
0023 // sca_blk( (frame>>8) & 0xF ),
0024 // l1a_phase((frame>>12( & 0x1),
0025 // lct_phase((frame>>13( & 0x1),
0026 // sca_full((frame>>14) & 0x1),
0027 // ts_flag(((frame>>15) & 0x1)
0028 {
0029   memcpy(this, &frame, 2);
0030 }
0031 
0032 CSCCFEBDataWord *CSCCFEBTimeSlice::timeSample(int layer, int channel, bool isDCFEB) const {
0033   assert(layer >= CSCDetId::minLayerId());
0034   assert(layer <= CSCDetId::maxLayerId());
0035   assert(channel >= 1 && channel <= 16);
0036   int layerIndex = layerInverseGrayCode[layer - 1];
0037 
0038   unsigned channelIndex = channelInverseGrayCode[channel - 1];
0039   if (isDCFEB)
0040     channelIndex = channel - 1;  //!!! New DCFEBs don't use gray coding for channels
0041   unsigned scaBin = channelIndex * 6 + layerIndex;
0042   assert(scaBin < 96U);  // scaBin >= 0, since scaBin is unsigned
0043   return timeSample(scaBin);
0044 }
0045 
0046 CSCCFEBSCAControllerWord CSCCFEBTimeSlice::scaControllerWord(int layer) const {
0047   unsigned int result = 0;
0048   for (unsigned i = 0; i < 16; ++i) {
0049     result |= timeSample(i * 6 + layer - 1)->controllerData << i;
0050   }
0051   return CSCCFEBSCAControllerWord(result);
0052 }
0053 
0054 void CSCCFEBTimeSlice::setControllerWord(const CSCCFEBSCAControllerWord &controllerWord) {
0055   for (int layer = CSCDetId::minLayerId(); layer <= CSCDetId::maxLayerId(); ++layer) {
0056     for (int channel = 1; channel <= 16; ++channel) {
0057       const unsigned short *shortWord = reinterpret_cast<const unsigned short *>(&controllerWord);
0058       timeSample(layer, channel)->controllerData = (*shortWord >> (channel - 1)) & 1;
0059     }
0060   }
0061 }
0062 
0063 unsigned CSCCFEBTimeSlice::calcCRC() const {
0064   unsigned CRC = 0;
0065   for (uint16_t pos = 0; pos < 96; ++pos)
0066     CRC = (theSamples[pos] & 0x1fff) ^ ((theSamples[pos] & 0x1fff) << 1) ^
0067           (((CRC & 0x7ffc) >> 2) | ((0x0003 & CRC) << 13)) ^ ((CRC & 0x7ffc) >> 1);
0068   return CRC;
0069 }
0070 
0071 std::ostream &operator<<(std::ostream &os, const CSCCFEBTimeSlice &slice) {
0072   for (int ichannel = 1; ichannel <= 16; ++ichannel) {
0073     for (int ilayer = CSCDetId::minLayerId(); ilayer <= CSCDetId::maxLayerId(); ++ilayer) {
0074       //unsigned index = (ilayer-1) + (ichannel-1)*6;
0075       //int value = (slice.timeSample(index))->adcCounts - 560;
0076       int value = (slice.timeSample(ilayer, ichannel))->adcCounts - 560;
0077       os << " " << std::setw(5) << std::dec << value;
0078     }
0079     os << std::endl;
0080   }
0081   return os;
0082 }