17 : ncfebs_(tmbHeader->NCFEBs()), ntbins_(tmbHeader->NTBins()) {
18 if (tmbHeader !=
nullptr)
27 : ncfebs_(ncfebs), ntbins_(ntbins), theFirmwareVersion(firmware_version) {
33 : ncfebs_(ncfebs), ntbins_(ntbins), theFirmwareVersion(firmware_version) {
42 for (
int ifeb = 0; ifeb <
ncfebs_; ++ifeb) {
43 for (
int tbin = 0; tbin <
ntbins_; ++tbin) {
44 for (
int layer = 1; layer <= 6; ++layer) {
52 static const bool doStripSwapping =
true;
60 std::vector<CSCComparatorDigi>
result;
61 assert(layer > 0 && layer <= 6);
65 for (
int distrip = 0; distrip < 8; ++distrip) {
66 uint16_t tbinbitsS0HS0 = 0;
67 uint16_t tbinbitsS0HS1 = 0;
68 uint16_t tbinbitsS1HS0 = 0;
69 uint16_t tbinbitsS1HS1 = 0;
70 for (
int tbin = 0; tbin <
ntbins_ - 2; ++tbin) {
71 if (
bitValue(cfeb, tbin, layer, distrip)) {
78 int bit2 =
bitValue(cfeb, tbin + 1, layer, distrip);
79 int bit3 =
bitValue(cfeb, tbin + 2, layer, distrip);
81 int chamberDistrip = distrip + cfeb * 8;
82 int HalfStrip = 4 * chamberDistrip + bit2 * 2 + bit3;
83 int output = 4 + bit2 * 2 + bit3;
95 LogTrace(
"CSCComparatorData|CSCRawToDigi")
96 <<
"fillComparatorOutputs: layer = " << layer <<
" timebin = " << tbin <<
" cfeb = " << cfeb
97 <<
" distrip = " << chamberDistrip <<
" HalfStrip = " << HalfStrip <<
" Output " <<
output << std::endl;
102 tbinbitsS0HS0 = tbinbitsS0HS0 + (1 << tbin);
104 tbinbitsS0HS1 = tbinbitsS0HS1 + (1 << tbin);
106 tbinbitsS1HS0 = tbinbitsS1HS0 + (1 << tbin);
108 tbinbitsS1HS1 = tbinbitsS1HS1 + (1 << tbin);
117 if (tbinbitsS0HS0 || tbinbitsS0HS1 || tbinbitsS1HS0 || tbinbitsS1HS1) {
118 unsigned int cfeb_corr = cfeb;
119 unsigned int distrip_corr = distrip;
121 if (doStripSwapping) {
128 distrip_corr = 7 - distrip;
129 cfeb_corr = 10 - cfeb;
131 if (me1b && !
zplus) {
132 distrip_corr = 7 - distrip;
133 cfeb_corr = 3 - cfeb;
138 distrip_corr = 7 - distrip;
140 if (me1b && !
zplus) {
141 distrip_corr = 7 - distrip;
142 cfeb_corr = 3 - cfeb;
147 int strip = 16 * cfeb_corr + 2 * distrip_corr + 1;
150 LogTrace(
"CSCComparatorData|CSCRawToDigi") <<
"fillComparatorOutputs: cfeb_corr = " << cfeb_corr
151 <<
" distrip_corr = " << distrip_corr <<
" strip = " <<
strip;
153 if (doStripSwapping && ((me1a &&
zplus) || (me1b && !
zplus))) {
181 std::vector<CSCComparatorDigi>
result;
182 assert(layer > 0 && layer <= 6);
184 for (
int cfeb = 0; cfeb <
ncfebs_; ++cfeb) {
185 std::vector<CSCComparatorDigi> oneCfebDigi =
comparatorDigis(layer, cfeb);
186 result.insert(
result.end(), oneCfebDigi.begin(), oneCfebDigi.end());
196 int cfeb = (
strip - 1) / 16;
197 int distrip = ((
strip - 1) % 16) / 2;
201 assert(distrip < 8 && cfeb < 8 && halfStrip < 225);
204 for (std::vector<int>::const_iterator tbinItr = timeBinsOn.begin(); tbinItr != timeBinsOn.end(); ++tbinItr) {
206 if (tbin >= 0 && tbin <
ntbins_ - 2) {
211 dataWord(cfeb, tbin + 1, layer).
set(distrip,
true);
215 dataWord(cfeb, tbin + 2, layer).
set(distrip,
true);
224 static const bool doStripSwapping =
true;
225 bool me1a = (cid.
station() == 1) && (cid.
ring() == 4);
227 bool me1b = (cid.
station() == 1) && (cid.
ring() == 1);
230 unsigned layer = cid.
layer();
234 int cfeb = (
strip - 1) / 16;
235 int distrip = ((
strip - 1) % 16) / 2;
236 int bit2 = (
strip - 1) % 2;
242 assert(distrip < 8 && cfeb < 8 && halfstrip < 225);
244 assert(distrip < 8 && cfeb < 6 && halfstrip < 161);
248 if (doStripSwapping) {
250 if ((me1a || (me1b && (cfeb > 3))) &&
zplus) {
251 distrip = 7 - distrip;
253 bit2 = ((31 - (halfstrip % 32)) % 4) / 2;
254 bit3 = ((31 - (halfstrip % 32)) % 4) % 2;
256 if (me1b && !
zplus && (cfeb < 4)) {
257 distrip = 7 - distrip;
259 bit2 = ((31 - (halfstrip % 32)) % 4) / 2;
260 bit3 = ((31 - (halfstrip % 32)) % 4) % 2;
264 if ((me1a || (me1b && (cfeb > 3))) &&
zplus) {
265 distrip = 7 - distrip;
266 bit2 = ((31 - (halfstrip % 32)) % 4) / 2;
267 bit3 = ((31 - (halfstrip % 32)) % 4) % 2;
269 if (me1b && !
zplus && (cfeb < 4)) {
270 distrip = 7 - distrip;
272 bit2 = ((31 - (halfstrip % 32)) % 4) / 2;
273 bit3 = ((31 - (halfstrip % 32)) % 4) % 2;
279 for (std::vector<int>::const_iterator tbinItr = timeBinsOn.begin(); tbinItr != timeBinsOn.end(); ++tbinItr) {
281 if (tbin >= 0 && tbin <
ntbins_ - 2) {
287 dataWord(cfeb, tbin + 1, layer).
set(distrip,
true);
292 dataWord(cfeb, tbin + 2, layer).
set(distrip,
true);
299 for (
int cfeb = 0; cfeb <
ncfebs_; ++cfeb) {
300 for (
int tbin = 0; tbin <
ntbins_; ++tbin) {
301 for (
int layer = 1; layer <= 6; ++layer) {
304 bool wordIsGood = (
word.tbin_ == tbin) && (
word.cfeb_ == cfeb);
306 if (!wordIsGood &&
debug) {
307 LogTrace(
"CSCComparatorData|CSCRawToDigi")
308 <<
"Bad CLCT data in layer " << layer <<
" expect CFEB " << cfeb <<
" tbin " << tbin;
309 LogTrace(
"CSCComparatorData|CSCRawToDigi") <<
" See " <<
word.cfeb_ <<
" " <<
word.tbin_;
315 LogTrace(
"CSCComparatorData|CSCRawToDigi") <<
"++ Bad CLCT Data ++ ";
335 comparatorData.
add(comparatorDigi1, 1);
336 comparatorData.
add(comparatorDigi2, 4);
337 comparatorData.
add(comparatorDigi3, 6);
343 std::vector<CSCComparatorDigi> digis1 = comparatorData.
comparatorDigis(1);
344 std::vector<CSCComparatorDigi> digis2 = comparatorData.
comparatorDigis(4);
345 std::vector<CSCComparatorDigi> digis3 = comparatorData.
comparatorDigis(6);
347 assert(digis1.size() == 1);
348 assert(digis2.size() == 1);
349 assert(digis3.size() == 1);
351 assert(digis1[0].getStrip() == 1);
352 assert(digis1[0].getComparator() == 0);
353 assert(digis1[0].getTimeBin() == 4);
355 assert(digis2[0].getStrip() == 39);
356 assert(digis2[0].getComparator() == 1);
357 assert(digis2[0].getTimeBin() == 5);
359 assert(digis3[0].getStrip() == 80);
360 assert(digis3[0].getComparator() == 1);
361 assert(digis3[0].getTimeBin() == 6);