File indexing completed on 2024-09-07 04:36:07
0001 #include "EventFilter/CSCRawToDigi/interface/CSCAnodeData2007.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 CSCAnodeData2007::CSCAnodeData2007(const CSCALCTHeader &header)
0009 : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins()) {
0010 init(header);
0011 bzero(theDataFrames, sizeInWords() * 2);
0012
0013 alctBX_ = header.BXNCount();
0014 }
0015
0016 CSCAnodeData2007::CSCAnodeData2007(const CSCALCTHeader &header, const unsigned short *buf)
0017 : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins()) {
0018 init(header);
0019 memcpy(theDataFrames, buf, sizeInWords() * 2);
0020
0021 alctBX_ = header.BXNCount();
0022 }
0023
0024 void CSCAnodeData2007::init(const CSCALCTHeader &header) {
0025
0026
0027
0028 static const unsigned short int layerParts[7] = {3, 3, 4, 6, 6, 8, 10};
0029 static const unsigned short int wireGroups[7] = {32, 32, 48, 64, 64, 96, 112};
0030
0031 sizeInWords2007_ = (1 - header.alctHeader2007().rawOverflow) * 6 * header.alctHeader2007().rawBins *
0032 layerParts[header.alctHeader2007().boardType];
0033 layerParts_ = layerParts[header.alctHeader2007().boardType];
0034 maxWireGroups_ = wireGroups[header.alctHeader2007().boardType];
0035 }
0036
0037 std::vector<CSCWireDigi> CSCAnodeData2007::wireDigis(int layer) const {
0038 std::vector<CSCWireDigi> digis;
0039 uint32_t tbinbits = 0;
0040 uint32_t wireGroup = 0;
0041
0042 for (int layerPart = 0; layerPart < layerParts_; ++layerPart) {
0043
0044 for (int j = 0; (j < 12) && ((layerPart * 12 + j) < maxWireGroups_); ++j) {
0045
0046
0047 for (int tbin = 0; tbin < nTimeBins_; ++tbin) {
0048 CSCAnodeDataFrame2007 frame = findFrame(tbin, layer, layerPart);
0049 if (frame.data() != 0) {
0050 if (frame.isHit(j)) {
0051 tbinbits = tbinbits + (1 << tbin);
0052 }
0053 }
0054 }
0055 if (tbinbits != 0) {
0056 wireGroup = (layerPart * 12 + j) + 1;
0057
0058 uint32_t wireGroupBX = alctBX_;
0059 wireGroup = wireGroup | (wireGroupBX << 16);
0060 CSCWireDigi digi(wireGroup, tbinbits);
0061 LogTrace("CSCAnodeData|CSCRawToDigi") << "Layer " << layer << " " << digi;
0062 digis.push_back(digi);
0063 tbinbits = 0;
0064 }
0065 }
0066 }
0067
0068 return digis;
0069 }
0070
0071 CSCAnodeDataFrame2007 CSCAnodeData2007::findFrame(int tbin, int layer, int layerPart) const {
0072 return CSCAnodeDataFrame2007(theDataFrames[index(tbin, layer, layerPart)]);
0073 }
0074
0075 int CSCAnodeData2007::index(int tbin, int layer, int layerPart) const {
0076 assert(tbin < nTimeBins_);
0077 assert(layer <= CSCDetId::maxLayerId());
0078 assert(layerPart < layerParts_);
0079 int result = tbin * 6 * layerParts_ + (layer - 1) * layerParts_ + layerPart;
0080 assert(result < MAXFRAMES);
0081 return result;
0082 }
0083
0084 void CSCAnodeData2007::add(const CSCWireDigi &digi, int layer) {
0085 int wireGroup = digi.getWireGroup();
0086
0087 unsigned layerPart = (wireGroup - 1) / 12;
0088 unsigned wireInPart = (wireGroup - 1) % 12;
0089
0090 std::vector<int> timeBinsOn = digi.getTimeBinsOn();
0091 for (std::vector<int>::const_iterator timeBinOn = timeBinsOn.begin(); timeBinOn != timeBinsOn.end(); ++timeBinOn) {
0092
0093
0094
0095 if (layerPart >= layerParts_) {
0096 edm::LogError("CSCAnodeData|CSCRawToDigi") << "Bad Wire Number for this digi.";
0097 return;
0098 }
0099
0100 if ((*timeBinOn) >= 0 && (*timeBinOn) < nTimeBins_) {
0101 CSCAnodeDataFrame2007 frame = findFrame(*timeBinOn, layer, layerPart);
0102 frame.addHit(wireInPart);
0103
0104 theDataFrames[index(*timeBinOn, layer, layerPart)] = frame.data();
0105 } else {
0106 LogTrace("CSCAnodeData|CSCRawToDigi")
0107 << "warning: not saving anode data in bx " << *timeBinOn << ": out of range ";
0108 }
0109 }
0110 }
0111
0112 void CSCAnodeData2007::selfTest() {
0113 int wireGroup = 12;
0114 int timeBin = 6;
0115 CSCWireDigi wireDigi(wireGroup, (1 << timeBin));
0116 CSCALCTHeader header(1);
0117 CSCAnodeData2007 anodeData(header);
0118 anodeData.add(wireDigi, 1);
0119 anodeData.add(wireDigi, 6);
0120
0121 std::vector<CSCWireDigi> wires1 = anodeData.wireDigis(1);
0122 std::vector<CSCWireDigi> wires6 = anodeData.wireDigis(6);
0123
0124 assert(wires1.size() == 1);
0125 assert(wires6.size() == 1);
0126 assert(wires1[0].getWireGroup() == wireGroup);
0127 assert(wires6[0].getWireGroup() == wireGroup);
0128 assert(wires1[0].getTimeBin() == timeBin);
0129 assert(wires6[0].getTimeBin() == timeBin);
0130 }