File indexing completed on 2024-04-06 12:21:41
0001
0002
0003
0004
0005
0006
0007
0008 #include <cmath>
0009 #include <bitset>
0010 #include "L1Trigger/RPCTrigger/interface/RPCPacData.h"
0011 #include "L1Trigger/RPCTrigger/interface/RPCConst.h"
0012
0013 #include "L1Trigger/RPCTrigger/interface/RPCException.h"
0014
0015 #include <iostream>
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 RPCPacData::RPCPacData(std::string patFilesDir, int tower, int logSector, int logSegment) {
0030
0031 m_MaxQuality = 0;
0032 std::string patFileName;
0033
0034 RPCConst rpcconst;
0035
0036 patFileName = patFilesDir + "pacPat_t" + rpcconst.intToString(tower) + "sc" + rpcconst.intToString(logSector) + "sg" +
0037 rpcconst.intToString(logSegment) + ".xml";
0038
0039 RPCConst::l1RpcConeCrdnts coneCrds;
0040 coneCrds.m_Tower = tower;
0041 coneCrds.m_LogSector = logSector;
0042 coneCrds.m_LogSegment = logSegment;
0043
0044 RPCPatternsParser parser;
0045 parser.parse(patFileName);
0046 init(parser, coneCrds);
0047
0048 m_TrackPatternsGroup.setGroupDescription("Track PatternsGroup");
0049 }
0050
0051
0052
0053
0054
0055 RPCPacData::RPCPacData(const RPCPattern::RPCPatVec& patVec, const RPCPattern::TQualityVec& qualVec) : m_MaxQuality(0) {
0056 for (unsigned int i = 0; i < qualVec.size(); ++i) {
0057 RPCPattern::TQuality quality = qualVec[i];
0058 std::bitset<RPCConst::m_LOGPLANES_COUNT> qualBits(quality.m_FiredPlanes);
0059 unsigned short firedPlanes = qualBits.to_ulong();
0060
0061 insertQualityRecord(quality.m_QualityTabNumber, firedPlanes, quality.m_QualityValue);
0062 }
0063
0064 insertPatterns(patVec);
0065 }
0066
0067 RPCPacData::RPCPacData(const L1RPCConfig* rpcconf, const int tower, const int sector, const int segment)
0068 : m_MaxQuality(0) {
0069 for (unsigned int iqual = 0; iqual < rpcconf->m_quals.size(); iqual++) {
0070 if (rpcconf->m_quals[iqual].m_tower != tower || rpcconf->m_quals[iqual].m_logsector != sector ||
0071 rpcconf->m_quals[iqual].m_logsegment != segment)
0072 continue;
0073
0074 RPCPattern::TQuality quality = rpcconf->m_quals[iqual];
0075 std::bitset<RPCConst::m_LOGPLANES_COUNT> qualBits(quality.m_FiredPlanes);
0076 unsigned short firedPlanes = qualBits.to_ulong();
0077 insertQualityRecord(quality.m_QualityTabNumber, firedPlanes, quality.m_QualityValue);
0078 }
0079
0080 insertPatterns(rpcconf->m_pats, tower, sector, segment);
0081 }
0082
0083
0084
0085
0086
0087
0088 int RPCPacData::getPatternsGroupCount() {
0089 return (1 + m_EnergeticPatternsGroupList.size());
0090 }
0091
0092
0093
0094
0095
0096
0097 RPCPattern RPCPacData::getPattern(int patNum) const {
0098 if (m_PatternsVec.empty()) {
0099 throw RPCException("GetPattren(): Patterns vec is empty, mayby it was not filled!");
0100
0101 }
0102 return m_PatternsVec[patNum];
0103 }
0104
0105
0106
0107
0108
0109 int RPCPacData::getPatternsCount() { return m_PatternsVec.size(); }
0110
0111
0112
0113
0114
0115
0116 bool RPCPacData::getTPatternsGroupShape(int logPlane, int logStripNum) {
0117 return m_TrackPatternsGroup.m_GroupShape.getLogStripState(logPlane, logStripNum);
0118 }
0119
0120
0121
0122
0123
0124
0125 bool RPCPacData::getEPatternsGroupShape(int groupNum, int logPlane, int bitNum) {
0126 TEPatternsGroupList::const_iterator iEGroup = m_EnergeticPatternsGroupList.begin();
0127 int i = 0;
0128 for (; iEGroup != m_EnergeticPatternsGroupList.end(); iEGroup++, i++) {
0129 if (i == groupNum)
0130 return iEGroup->m_GroupShape.getLogStripState(logPlane, bitNum);
0131 }
0132 throw RPCException("getEPatternsGroupShape(): groupNum to big!");
0133
0134 return false;
0135 }
0136
0137 std::string RPCPacData::getPatternsGroupDescription(int patternGroupNum) {
0138 RPCConst rpcconst;
0139
0140 std::string ret;
0141 if (patternGroupNum == -1)
0142 ret = m_TrackPatternsGroup.getGroupDescription();
0143 else {
0144 TEPatternsGroupList::iterator iEGroup = m_EnergeticPatternsGroupList.begin();
0145 int i = 0;
0146 for (; iEGroup != m_EnergeticPatternsGroupList.end(); iEGroup++, i++) {
0147 if (i == patternGroupNum)
0148 ret = "EGroup #" + rpcconst.intToString(i) + iEGroup->getGroupDescription();
0149 }
0150 }
0151
0152 if (ret.empty()) {
0153 throw RPCException("getEPatternsGroupShape(): groupNum to big!");
0154
0155 }
0156
0157 return ret;
0158 }
0159
0160 void RPCPacData::insertQualityRecord(unsigned int qualityTabNumber, unsigned short firedPlanes, short quality) {
0161 if (quality > m_MaxQuality)
0162 m_MaxQuality = quality;
0163 if (qualityTabNumber < m_QualityTabsVec.size()) {
0164 m_QualityTabsVec[qualityTabNumber][firedPlanes] = quality;
0165 } else if (qualityTabNumber == m_QualityTabsVec.size()) {
0166
0167
0168
0169 RPCConst::TQualityTab qualityTab((int)std::pow(2.0, RPCConst::m_LOGPLANES_COUNT), -1);
0170 m_QualityTabsVec.push_back(qualityTab);
0171 m_QualityTabsVec[qualityTabNumber][firedPlanes] = quality;
0172 } else
0173 throw RPCException("insertQualityRecord(): wrong qualityTabNumber");
0174
0175 }
0176
0177 void RPCPacData::insertPatterns(const RPCPattern::RPCPatVec& patternsVec,
0178 const int tower,
0179 const int sector,
0180 const int segment) {
0181 bool ignorePos = false;
0182 if (tower == 99 || sector == 99 || segment == 99)
0183 ignorePos = true;
0184
0185 RPCConst rpcconst;
0186
0187 for (RPCPattern::RPCPatVec::const_iterator patIt = patternsVec.begin(); patIt != patternsVec.end(); patIt++) {
0188 if (!ignorePos &&
0189 (patIt->getTower() != tower || patIt->getLogSector() != sector || patIt->getLogSegment() != segment))
0190 continue;
0191
0192 if (patIt->getPatternType() == RPCPattern::PAT_TYPE_T)
0193 m_TrackPatternsGroup.addPattern(patIt);
0194 else if (patIt->getPatternType() == RPCPattern::PAT_TYPE_E) {
0195 TEPatternsGroupList::iterator iEGroup;
0196 for (iEGroup = m_EnergeticPatternsGroupList.begin(); iEGroup != m_EnergeticPatternsGroupList.end(); iEGroup++)
0197 if (iEGroup->check(patIt))
0198 break;
0199 if (iEGroup == m_EnergeticPatternsGroupList.end()) {
0200 TEPatternsGroup newEGroup(patIt);
0201 newEGroup.setGroupDescription(
0202
0203 ", code: " + rpcconst.intToString(patIt->getCode()) + ", dir: " + rpcconst.intToString(patIt->getSign()) +
0204 ", refGroup: " + rpcconst.intToString(patIt->getRefGroup()) +
0205 ", qualityTabNumber: " + rpcconst.intToString(patIt->getQualityTabNumber()));
0206 m_EnergeticPatternsGroupList.push_back(newEGroup);
0207 } else
0208 iEGroup->addPattern(patIt);
0209 } else
0210 throw RPCException("InsertPattern(): unsupported pattern type");
0211
0212 }
0213
0214 if (!m_EnergeticPatternsGroupList.empty()) {
0215 m_EnergeticPatternsGroupList.sort();
0216
0217
0218 m_EnergeticPatternsGroupList.reverse();
0219 }
0220 }
0221
0222 void RPCPacData::init(const RPCPatternsParser& parser, const RPCConst::l1RpcConeCrdnts& coneCrdnts) {
0223 for (unsigned int i = 0; i < parser.getQualityVec().size(); i++) {
0224 RPCPattern::TQuality quality = parser.getQualityVec()[i];
0225 std::bitset<RPCConst::m_LOGPLANES_COUNT> qualBits(quality.m_FiredPlanes);
0226 unsigned short firedPlanes = qualBits.to_ulong();
0227
0228 insertQualityRecord(quality.m_QualityTabNumber, firedPlanes, quality.m_QualityValue);
0229 }
0230
0231 m_PatternsVec = parser.getPatternsVec(coneCrdnts);
0232 insertPatterns(m_PatternsVec);
0233 }