File indexing completed on 2024-04-06 12:10:26
0001 #include "EventFilter/CSCRawToDigi/interface/CSCGEMData.h"
0002 #include "DataFormats/GEMDigi/interface/GEMPadDigiCluster.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "DataFormats/CSCDigi/interface/CSCConstants.h"
0005
0006 #include <string>
0007 #include <cstdio>
0008 #include <strings.h> // for bzero
0009 #include <cstring>
0010 #include <iostream>
0011
0012 #ifdef LOCAL_UNPACK
0013 bool CSCGEMData::debug = false;
0014 #else
0015 std::atomic<bool> CSCGEMData::debug{false};
0016 #endif
0017
0018 CSCGEMData::CSCGEMData(int ntbins, int gems_fibers) : ntbins_(ntbins), size_(0) {
0019 theData[0] = 0x6C04;
0020 ntbins_ = ntbins;
0021 gems_enabled_ = gems_fibers;
0022 ngems_ = 0;
0023
0024
0025
0026
0027
0028 ngems_ = 4;
0029 size_ = 2 + ntbins_ * ngems_ * 4;
0030
0031
0032 for (int i = 0; i < (size_ - 2); i++) {
0033 int gem_chamber = (i % 16) / 8;
0034 theData[i + 1] = 0x3FFF | (gem_chamber << 14);
0035 }
0036
0037 theData[size_ - 1] = 0x6D04;
0038 }
0039
0040 CSCGEMData::CSCGEMData(const unsigned short* buf, int length, int gems_fibers) : size_(length) {
0041 size_ = length;
0042 ngems_ = 0;
0043
0044
0045
0046
0047
0048 ngems_ = 4;
0049 ntbins_ = (size_ - 2) / (4 * ngems_);
0050 gems_enabled_ = gems_fibers;
0051 memcpy(theData, buf, size_ * 2);
0052 }
0053
0054 void CSCGEMData::print() const {
0055 LogTrace("CSCGEMData|CSCRawToDigi") << "CSCGEMData.Print";
0056 for (int line = 0; line < ((size_)); ++line) {
0057 LogTrace("CSCGEMData|CSCRawToDigi") << std::hex << theData[line];
0058 }
0059 }
0060
0061 int CSCGEMData::getPartitionNumber(int addr, int npads) const { return addr / (npads - 1); }
0062
0063 int CSCGEMData::getPartitionStripNumber(int address, int nPads, int etaPart) const {
0064 return address - (nPads * etaPart);
0065 }
0066
0067 std::vector<GEMPadDigiCluster> CSCGEMData::digis(int gem_chamber) const {
0068
0069 std::vector<GEMPadDigiCluster> result;
0070 result.clear();
0071 int nPads = 192;
0072 int maxClusters = 4;
0073 int nGEMs = 4;
0074
0075 for (int i = 0; i < ntbins_; i++) {
0076 for (int fiber = 0; fiber < nGEMs; fiber++) {
0077 for (int cluster = 0; cluster < maxClusters; cluster++) {
0078 int dataAddr = 1 + (i * nGEMs + fiber) * maxClusters + cluster;
0079 int gem_layer = (theData[dataAddr] >> 14) & 0x1;
0080 if (gem_layer == gem_chamber) {
0081 int cl_word = theData[dataAddr] & 0x3fff;
0082 int pad = theData[dataAddr] & 0xff;
0083 int eta = (theData[dataAddr] >> 8) & 0x7;
0084 int cluster_size = (theData[dataAddr] >> 11) & 0x7;
0085 if (pad < nPads) {
0086 int padInPart = eta * nPads + pad;
0087 if (debug)
0088 LogTrace("CSCGEMData|CSCRawToDigi")
0089 << "GEMlayer" << gem_layer << " cl_word" << dataAddr << ": 0x" << std::hex << cl_word << std::dec
0090 << " tbin: " << i << " fiber#: " << (fiber + 1) << " cluster#: " << (cluster + 1)
0091 << " padInPart: " << padInPart << " pad: " << pad << " eta: " << eta
0092 << " cluster_size: " << cluster_size << std::endl;
0093 std::vector<short unsigned int> pads;
0094 for (int iP = 0; iP <= cluster_size; ++iP)
0095 pads.push_back(padInPart + iP);
0096 GEMPadDigiCluster pad_cluster(pads, i);
0097 result.push_back(pad_cluster);
0098 }
0099 }
0100 }
0101 }
0102 }
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 return result;
0143 }
0144
0145
0146
0147
0148 std::vector<GEMPadDigiCluster> CSCGEMData::etaDigis(int gem_chamber, int eta_roll, int alctMatchTime) const {
0149
0150 std::vector<GEMPadDigiCluster> result;
0151 result.clear();
0152 int nPads = 192;
0153 int maxClusters = 4;
0154 int nGEMs = 4;
0155
0156 for (int i = 0; i < ntbins_; i++) {
0157 for (int fiber = 0; fiber < nGEMs; fiber++) {
0158 for (int cluster = 0; cluster < maxClusters; cluster++) {
0159 int dataAddr = 1 + (i * nGEMs + fiber) * maxClusters + cluster;
0160 int gem_layer = (theData[dataAddr] >> 14) & 0x1;
0161 if (gem_layer == gem_chamber) {
0162 int cl_word = theData[dataAddr] & 0x3fff;
0163 int pad = theData[dataAddr] & 0xff;
0164 int eta = (theData[dataAddr] >> 8) & 0x7;
0165 int cluster_size = (theData[dataAddr] >> 11) & 0x7;
0166 if ((pad < nPads) && (eta == eta_roll)) {
0167 int padInPart = pad;
0168 if (debug)
0169 LogTrace("CSCGEMData|CSCRawToDigi")
0170 << "GEMlayer" << gem_layer << " cl_word" << dataAddr << ": 0x" << std::hex << cl_word << std::dec
0171 << " tbin: " << i << " fiber#: " << (fiber + 1) << " cluster#: " << (cluster + 1)
0172 << " padInPart: " << padInPart << " pad: " << pad << " eta: " << eta
0173 << " cluster_size: " << cluster_size << " alctMatchTime: " << alctMatchTime << std::endl;
0174 std::vector<short unsigned int> pads;
0175 for (int iP = 0; iP <= cluster_size; ++iP)
0176 pads.push_back(padInPart + iP);
0177 GEMPadDigiCluster pad_cluster(pads, i);
0178 pad_cluster.setAlctMatchTime(alctMatchTime);
0179 result.push_back(pad_cluster);
0180 }
0181 }
0182 }
0183 }
0184 }
0185 return result;
0186 }
0187
0188
0189
0190
0191 void CSCGEMData::addEtaPadCluster(const GEMPadDigiCluster& digi, int gem_chamber, int eta_roll) {
0192 int bx = digi.bx();
0193
0194 if ((gem_chamber < 2) && (bx < ntbins_)) {
0195 int gem_layer = gem_chamber & 0x1;
0196 int cluster_size = digi.pads().size() - 1;
0197 int pad = digi.pads()[0];
0198 int eta = eta_roll;
0199 int cl_word = (gem_layer << 14) + (pad & 0xff) + ((eta & 0x7) << 8) + ((cluster_size & 0x7) << 11);
0200 int dataAddr = 1 + bx * 16 + 8 * gem_layer;
0201 int cluster_num = 0;
0202
0203 while (((theData[dataAddr + cluster_num] & 0x3fff) != 0x3fff) && (cluster_num < 8)) {
0204 cluster_num++;
0205 }
0206
0207 if (((theData[dataAddr + cluster_num] & 0x3fff) == 0x3fff) && (cluster_num < 8)) {
0208 theData[dataAddr + cluster_num] = cl_word;
0209 }
0210 }
0211 }