Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:25

0001 #include "EventFilter/CSCRawToDigi/interface/CSCAnodeData2006.h"
0002 #include "EventFilter/CSCRawToDigi/interface/CSCALCTHeader.h"
0003 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <cstring>  // for bzero
0006 #include <iostream>
0007 
0008 CSCAnodeDataFrame2006::CSCAnodeDataFrame2006(unsigned chip, unsigned tbin, unsigned data) : theFrame(0) {
0009   // lowest bit, plus the OR of the next two.
0010   unsigned packedChip = ((chip & 1) + 2 * (chip > 1));
0011   theFrame = data + ((tbin & 0x1F) << 8) + (packedChip << 13);
0012 }
0013 
0014 CSCAnodeData2006::CSCAnodeData2006(const CSCALCTHeader &header)  ///for digi->raw packing
0015     : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins()) {
0016   LogTrace("CSCAnodeData|CSCRawToDigi") << "Making Anode data " << sizeInWords() << " AFEB " << nAFEBs_ << " TBINS "
0017                                         << nTimeBins_;
0018   bzero(theDataFrames, sizeInWords() * 2);
0019   for (int afeb = 0; afeb < nAFEBs_; ++afeb) {
0020     for (int tbin = 0; tbin < nTimeBins_; ++tbin) {
0021       for (int layer = CSCDetId::minLayerId(); layer <= CSCDetId::maxLayerId(); ++layer) {
0022         for (int halfLayer = 0; halfLayer < 2; ++halfLayer) {
0023           theDataFrames[index(afeb, tbin, layer) + halfLayer] = CSCAnodeDataFrame2006(afeb, tbin, 0).frame();
0024         }
0025       }
0026     }
0027   }
0028   /// To get BX from ALCT digis
0029   alctBX_ = header.BXNCount();
0030 }
0031 
0032 // initialize
0033 CSCAnodeData2006::CSCAnodeData2006(const CSCALCTHeader &header, const unsigned short *buf)
0034     : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins()) {
0035   ///the sizes of raw words vary depending on type of the ALCT board
0036   ///                         number of layer parts for various
0037   ///                         alct board types:     1  2  3     5  6
0038   LogTrace("CSCAnodeData|CSCRawToDigi") << "nAFEBs = " << nAFEBs_ << "  nTimeBins = " << nTimeBins_
0039                                         << " nFrames = " << sizeInWords();
0040   LogTrace("CSCAnodeData|CSCRawToDigi") << header << " HEADER CHECK " << header.check();
0041 
0042   memcpy(theDataFrames, buf, sizeInWords() * 2);  ///dont memcpy if not 2006 or 2007
0043 }
0044 
0045 std::vector<CSCWireDigi> CSCAnodeData2006::wireDigis(int layer) const {
0046   std::vector<CSCWireDigi> digis;
0047   uint32_t tbinbits = 0;
0048   uint16_t wireGroup = 0;
0049   for (int afeb = 0; afeb < nAFEBs_; ++afeb) {
0050     for (int halfLayer = 0; halfLayer < 2; ++halfLayer) {
0051       for (int j = 0; j < 8; ++j) {
0052         for (int tbin = 0; tbin < nTimeBins_; ++tbin) {
0053           CSCAnodeDataFrame2006 frame(rawHit(afeb, tbin, layer, halfLayer));
0054           // see if there's anything in 1st 8 bits.  Usually zero
0055           if (frame.data() != 0) {
0056             if (frame.isHit(j)) {
0057               tbinbits = tbinbits + (1 << tbin);
0058             }
0059           }
0060         }  //end of tbin loop
0061         if (tbinbits != 0) {
0062           wireGroup = (afeb * 16 + halfLayer * 8 + j) + 1;
0063           uint32_t wireGroupBX = alctBX_;
0064           wireGroup = wireGroup | (wireGroupBX << 16);
0065           CSCWireDigi digi(wireGroup, tbinbits);
0066           LogTrace("CSCAnodeData|CSCRawToDigi") << "Layer " << layer << " " << digi;
0067           digis.push_back(digi);
0068           tbinbits = 0;
0069         }
0070       }
0071     }
0072   }
0073 
0074   return digis;
0075 }
0076 
0077 void CSCAnodeData2006::add(const CSCWireDigi &digi, int layer) {
0078   int wireGroup = digi.getWireGroup();
0079   int bxn = digi.getBeamCrossingTag();
0080   int alctBoard = (wireGroup - 1) / 16;
0081   int localGroup = (wireGroup - 1) % 16;
0082 
0083   // crash if there's a bad wire number, but don't freak out
0084   // if a time bin is out of range
0085   //  assert(alctBoard < nAFEBs_);
0086   if (alctBoard > nAFEBs_) {
0087     edm::LogError("CSCAnodeData|CSCRawToDigi") << "Bad Wire Number for this digi.";
0088     return;
0089   }
0090   if (bxn >= 0 && bxn < nTimeBins_) {
0091     // 12 16-bit words per time bin, two per layer
0092     // wiregroups 0-7 go on the first line, 8-15 go on the 2nd.
0093     unsigned halfLayer = (localGroup > 7);
0094     unsigned bitNumber = localGroup % 8;
0095     // and pack it in the 8 bits allocated
0096     addHit(alctBoard, bxn, layer, halfLayer, bitNumber);
0097   } else {
0098     LogTrace("CSCAnodeData|CSCRawToDigi") << "warning: not saving anode data in bx " << bxn << ": out of range ";
0099   }
0100 }
0101 
0102 void CSCAnodeData2006::addHit(int afeb, int tbin, int layer, int halfLayer, unsigned wireBit) {
0103   int i = index(afeb, tbin, layer) + halfLayer;
0104   CSCAnodeDataFrame2006 frame(theDataFrames[i]);
0105   frame.addHit(wireBit);
0106   theDataFrames[i] = frame.frame();
0107 }
0108 
0109 CSCAnodeDataFrame2006 CSCAnodeData2006::rawHit(int afeb, int tbin, int layer, int halfLayer) const {
0110   return CSCAnodeDataFrame2006(theDataFrames[index(afeb, tbin, layer) + halfLayer]);
0111 }
0112 
0113 int CSCAnodeData2006::index(int afeb, int tbin, int layer) const {
0114   int result = (layer - 1) * 2 + 12 * tbin + afeb * 12 * nTimeBins_;
0115   assert(result < sizeInWords());
0116   return result;
0117 }
0118 
0119 #include <iostream>
0120 void CSCAnodeData2006::selfTest() {
0121   CSCAnodeDataFrame2006 frame(2, 15, 32);
0122   assert(frame.chip() == 2);
0123   assert(frame.tbin() == 15);
0124   assert(frame.data() == 32);
0125   assert(frame.isHit(5));
0126   assert(!frame.isHit(7));
0127   frame.addHit(7);
0128   assert(frame.isHit(7));
0129 
0130   CSCWireDigi wireDigi(10, (1 << 4));
0131   CSCALCTHeader header(7);
0132   CSCAnodeData2006 anodeData(header);
0133   anodeData.add(wireDigi, 1);
0134   anodeData.add(wireDigi, 6);
0135 
0136   std::vector<CSCWireDigi> wires1 = anodeData.wireDigis(1);
0137   std::vector<CSCWireDigi> wires6 = anodeData.wireDigis(6);
0138 
0139   assert(wires1.size() == 1);
0140   assert(wires6.size() == 1);
0141   assert(wires1[0].getWireGroup() == 10);
0142   assert(wires6[0].getWireGroup() == 10);
0143 }