File indexing completed on 2024-04-06 12:04:17
0001 #include "DataFormats/HcalDetId/interface/HcalFrontEndId.h"
0002 #include <iomanip>
0003 #include <sstream>
0004 #include <iostream>
0005 #include <cstdlib>
0006
0007 HcalFrontEndId::HcalFrontEndId(
0008 const std::string& rbx, int rm, int pixel, int rmfiber, int fiberchannel, int qie, int adc) {
0009 hcalFrontEndId_ = 0;
0010
0011 if (rbx.size() < 5)
0012 return;
0013 if (rm < 1 || rm > 5)
0014 return;
0015 if (pixel < 0 || pixel > 19)
0016 return;
0017 if (rmfiber < 1 || rmfiber > 8)
0018 return;
0019 if (fiberchannel < 0 || fiberchannel > 2)
0020 return;
0021 if (qie < 1 || qie > 4)
0022 return;
0023 if (adc < 0 || adc > 5)
0024 return;
0025
0026 int num = -1;
0027 if (!rbx.compare(0, 3, "HBM")) {
0028 num = 0 + atoi(rbx.substr(3, 2).c_str()) - 1;
0029 } else if (!rbx.compare(0, 3, "HBP")) {
0030 num = 18 + atoi(rbx.substr(3, 2).c_str()) - 1;
0031 } else if (!rbx.compare(0, 3, "HEM")) {
0032 num = 18 * 2 + atoi(rbx.substr(3, 2).c_str()) - 1;
0033 } else if (!rbx.compare(0, 3, "HEP")) {
0034 num = 18 * 3 + atoi(rbx.substr(3, 2).c_str()) - 1;
0035 } else if (!rbx.compare(0, 4, "HO2M")) {
0036 num = 18 * 4 + atoi(rbx.substr(4, 2).c_str()) - 1;
0037 } else if (!rbx.compare(0, 4, "HO1M")) {
0038 num = 18 * 4 + 12 + atoi(rbx.substr(4, 2).c_str()) - 1;
0039 } else if (!rbx.compare(0, 3, "HO0")) {
0040 num = 18 * 4 + 12 * 2 + atoi(rbx.substr(3, 2).c_str()) - 1;
0041 } else if (!rbx.compare(0, 4, "HO1P")) {
0042 num = 18 * 4 + 12 * 3 + atoi(rbx.substr(4, 2).c_str()) - 1;
0043 } else if (!rbx.compare(0, 4, "HO2P")) {
0044 num = 18 * 4 + 12 * 4 + atoi(rbx.substr(4, 2).c_str()) - 1;
0045 } else if (!rbx.compare(0, 3, "HFM")) {
0046 num = 18 * 4 + 12 * 5 + atoi(rbx.substr(3, 2).c_str()) - 1;
0047 } else if (!rbx.compare(0, 3, "HFP")) {
0048 num = 18 * 4 + 12 * 6 + atoi(rbx.substr(3, 2).c_str()) - 1;
0049 } else
0050 return;
0051
0052 hcalFrontEndId_ |= ((adc + 1) & 0x7);
0053 hcalFrontEndId_ |= ((qie - 1) & 0x3) << 3;
0054 hcalFrontEndId_ |= (fiberchannel & 0x3) << 5;
0055 hcalFrontEndId_ |= ((rmfiber - 1) & 0x7) << 7;
0056 hcalFrontEndId_ |= (pixel & 0x1F) << 10;
0057 hcalFrontEndId_ |= ((rm - 1) & 0x7) << 15;
0058 hcalFrontEndId_ |= (num & 0xFF) << 18;
0059 }
0060
0061 HcalFrontEndId::~HcalFrontEndId() {}
0062
0063 std::string HcalFrontEndId::rbx() const {
0064 std::string subdets[11] = {"HBM", "HBP", "HEM", "HEP", "HO2M", "HO1M", "HO0", "HO1P", "HO2P", "HFM", "HFP"};
0065
0066 int box = hcalFrontEndId_ >> 18;
0067 int num = -1;
0068 int subdet_index = -1;
0069 if (box < 18 * 4) {
0070 num = box % 18;
0071 subdet_index = (box - num) / 18;
0072 } else {
0073 num = (box - 18 * 4) % 12;
0074 subdet_index = 4 + (box - 18 * 4 - num) / 12;
0075 }
0076 std::stringstream tempss;
0077 tempss << std::setw(2) << std::setfill('0') << num + 1;
0078 return subdets[subdet_index] + tempss.str();
0079 }
0080
0081 std::ostream& operator<<(std::ostream& s, const HcalFrontEndId& id) {
0082 return s << id.rbx() << id.rm() << '[' << id.rmFiber() << '/' << id.fiberChannel() << "] pix=" << id.pixel()
0083 << " qiecard=" << id.qieCard() << " adc=" << id.adc();
0084 }