File indexing completed on 2024-04-06 12:19:54
0001 #include "L1Trigger/GlobalCaloTrigger/test/gctTestHfEtSums.h"
0002
0003 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
0004
0005 #include "DataFormats/L1CaloTrigger/interface/L1CaloRegion.h"
0006
0007 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalHfSumAlgos.h"
0008 #include "L1Trigger/GlobalCaloTrigger/interface/L1GlobalCaloTrigger.h"
0009
0010 #include <math.h>
0011 #include <iostream>
0012 #include <cassert>
0013
0014 using namespace std;
0015
0016
0017
0018
0019
0020 gctTestHfEtSums::gctTestHfEtSums()
0021 : m_etScale(),
0022 m_expectedRing0EtSumPositiveEta(),
0023 m_expectedRing0EtSumNegativeEta(),
0024 m_expectedRing1EtSumPositiveEta(),
0025 m_expectedRing1EtSumNegativeEta(),
0026 m_expectedRing0BitCountPositiveEta(),
0027 m_expectedRing0BitCountNegativeEta(),
0028 m_expectedRing1BitCountPositiveEta(),
0029 m_expectedRing1BitCountNegativeEta() {}
0030
0031 gctTestHfEtSums::~gctTestHfEtSums() {}
0032
0033
0034
0035
0036
0037 void gctTestHfEtSums::configure(const L1CaloEtScale* scale) { m_etScale = scale; }
0038
0039 bool gctTestHfEtSums::setupOk() const { return (m_etScale != 0); }
0040
0041
0042
0043 void gctTestHfEtSums::reset() {
0044 m_expectedRing0EtSumPositiveEta.clear();
0045 m_expectedRing0EtSumNegativeEta.clear();
0046 m_expectedRing1EtSumPositiveEta.clear();
0047 m_expectedRing1EtSumNegativeEta.clear();
0048 m_expectedRing0BitCountPositiveEta.clear();
0049 m_expectedRing0BitCountNegativeEta.clear();
0050 m_expectedRing1BitCountPositiveEta.clear();
0051 m_expectedRing1BitCountNegativeEta.clear();
0052 }
0053
0054
0055
0056
0057 void gctTestHfEtSums::fillExpectedHfSums(const std::vector<RegionsVector>& inputRegions) {
0058
0059
0060
0061 static const unsigned NUMBER_OF_INNER_RINGS = 2;
0062 static const unsigned NUMBER_OF_RINGS_PER_WHEEL = L1CaloRegionDetId::N_ETA / 2;
0063
0064 static const unsigned MIN_ETA_HF_SUMS = NUMBER_OF_RINGS_PER_WHEEL - NUMBER_OF_INNER_RINGS;
0065
0066 static const unsigned MAX_ETSUM_VALUE = (1 << 8) - 1;
0067 static const unsigned MAX_TOWER_COUNT = (1 << 5) - 1;
0068
0069 unsigned numOfBx = inputRegions.size();
0070 m_expectedRing0EtSumPositiveEta.resize(numOfBx);
0071 m_expectedRing0EtSumNegativeEta.resize(numOfBx);
0072 m_expectedRing1EtSumPositiveEta.resize(numOfBx);
0073 m_expectedRing1EtSumNegativeEta.resize(numOfBx);
0074 m_expectedRing0BitCountPositiveEta.resize(numOfBx);
0075 m_expectedRing0BitCountNegativeEta.resize(numOfBx);
0076 m_expectedRing1BitCountPositiveEta.resize(numOfBx);
0077 m_expectedRing1BitCountNegativeEta.resize(numOfBx);
0078
0079 for (unsigned bx = 0; bx < inputRegions.size(); bx++) {
0080 std::vector<unsigned> etNegativeEta(NUMBER_OF_INNER_RINGS, 0);
0081 std::vector<unsigned> etPositiveEta(NUMBER_OF_INNER_RINGS, 0);
0082 std::vector<bool> ofNegativeEta(NUMBER_OF_INNER_RINGS, false);
0083 std::vector<bool> ofPositiveEta(NUMBER_OF_INNER_RINGS, false);
0084 std::vector<unsigned> bcNegativeEta(NUMBER_OF_INNER_RINGS, 0);
0085 std::vector<unsigned> bcPositiveEta(NUMBER_OF_INNER_RINGS, 0);
0086
0087 for (RegionsVector::const_iterator region = inputRegions.at(bx).begin(); region != inputRegions.at(bx).end();
0088 region++) {
0089 if (region->id().rctEta() >= MIN_ETA_HF_SUMS) {
0090 unsigned ring = NUMBER_OF_RINGS_PER_WHEEL - region->id().rctEta() - 1;
0091
0092 if (region->id().ieta() < NUMBER_OF_RINGS_PER_WHEEL) {
0093 etNegativeEta.at(ring) += region->et();
0094 ofNegativeEta.at(ring) = ofNegativeEta.at(ring) || region->overFlow();
0095 if (region->fineGrain())
0096 ++bcNegativeEta.at(ring);
0097 } else {
0098 etPositiveEta.at(ring) += region->et();
0099 ofPositiveEta.at(ring) = ofPositiveEta.at(ring) || region->overFlow();
0100 if (region->fineGrain())
0101 ++bcPositiveEta.at(ring);
0102 }
0103 }
0104 }
0105 m_expectedRing0EtSumNegativeEta.at(bx) =
0106 ((etNegativeEta.at(0) > MAX_ETSUM_VALUE) || ofNegativeEta.at(0) ? MAX_ETSUM_VALUE : etNegativeEta.at(0));
0107 m_expectedRing0EtSumPositiveEta.at(bx) =
0108 ((etPositiveEta.at(0) > MAX_ETSUM_VALUE) || ofPositiveEta.at(0) ? MAX_ETSUM_VALUE : etPositiveEta.at(0));
0109 m_expectedRing1EtSumNegativeEta.at(bx) =
0110 ((etNegativeEta.at(1) > MAX_ETSUM_VALUE) || ofNegativeEta.at(1) ? MAX_ETSUM_VALUE : etNegativeEta.at(1));
0111 m_expectedRing1EtSumPositiveEta.at(bx) =
0112 ((etPositiveEta.at(1) > MAX_ETSUM_VALUE) || ofPositiveEta.at(1) ? MAX_ETSUM_VALUE : etPositiveEta.at(1));
0113 m_expectedRing0BitCountNegativeEta.at(bx) = bcNegativeEta.at(0);
0114 m_expectedRing0BitCountPositiveEta.at(bx) = bcPositiveEta.at(0);
0115 m_expectedRing1BitCountNegativeEta.at(bx) = bcNegativeEta.at(1);
0116 m_expectedRing1BitCountPositiveEta.at(bx) = bcPositiveEta.at(1);
0117 if (m_expectedRing0BitCountNegativeEta.at(bx) > MAX_TOWER_COUNT)
0118 m_expectedRing0BitCountNegativeEta.at(bx) = MAX_TOWER_COUNT;
0119 if (m_expectedRing0BitCountPositiveEta.at(bx) > MAX_TOWER_COUNT)
0120 m_expectedRing0BitCountPositiveEta.at(bx) = MAX_TOWER_COUNT;
0121 if (m_expectedRing1BitCountNegativeEta.at(bx) > MAX_TOWER_COUNT)
0122 m_expectedRing1BitCountNegativeEta.at(bx) = MAX_TOWER_COUNT;
0123 if (m_expectedRing1BitCountPositiveEta.at(bx) > MAX_TOWER_COUNT)
0124 m_expectedRing1BitCountPositiveEta.at(bx) = MAX_TOWER_COUNT;
0125 }
0126 }
0127
0128
0129
0130
0131 bool gctTestHfEtSums::checkHfEtSums(const L1GlobalCaloTrigger* gct, const int numOfBx) const {
0132 if (!setupOk()) {
0133 cout << "checkHfEtSums setup check failed" << endl;
0134 return false;
0135 }
0136
0137 bool testPass = true;
0138
0139 for (int bx = 0; bx < numOfBx; bx++) {
0140 unsigned bitCountRing0PositiveEta =
0141 gct->getHfSumProcessor()->hfSumsOutput(L1GctHfEtSumsLut::bitCountPosEtaRing1).at(bx);
0142 unsigned bitCountRing0NegativeEta =
0143 gct->getHfSumProcessor()->hfSumsOutput(L1GctHfEtSumsLut::bitCountNegEtaRing1).at(bx);
0144 unsigned bitCountRing1PositiveEta =
0145 gct->getHfSumProcessor()->hfSumsOutput(L1GctHfEtSumsLut::bitCountPosEtaRing2).at(bx);
0146 unsigned bitCountRing1NegativeEta =
0147 gct->getHfSumProcessor()->hfSumsOutput(L1GctHfEtSumsLut::bitCountNegEtaRing2).at(bx);
0148 unsigned etSumRing0PositiveEta = gct->getHfSumProcessor()->hfSumsOutput(L1GctHfEtSumsLut::etSumPosEtaRing1).at(bx);
0149 unsigned etSumRing0NegativeEta = gct->getHfSumProcessor()->hfSumsOutput(L1GctHfEtSumsLut::etSumNegEtaRing1).at(bx);
0150 unsigned etSumRing1PositiveEta = gct->getHfSumProcessor()->hfSumsOutput(L1GctHfEtSumsLut::etSumPosEtaRing2).at(bx);
0151 unsigned etSumRing1NegativeEta = gct->getHfSumProcessor()->hfSumsOutput(L1GctHfEtSumsLut::etSumNegEtaRing2).at(bx);
0152
0153 if (etSumRing0PositiveEta != etSumLut(m_expectedRing0EtSumPositiveEta.at(bx))) {
0154 cout << "Hf Et Sum Positive Eta, expected " << etSumLut(m_expectedRing0EtSumPositiveEta.at(bx)) << ", found "
0155 << etSumRing0PositiveEta << endl;
0156 testPass = false;
0157 }
0158 if (etSumRing0NegativeEta != etSumLut(m_expectedRing0EtSumNegativeEta.at(bx))) {
0159 cout << "Hf Et Sum Negative Eta, expected " << etSumLut(m_expectedRing0EtSumNegativeEta.at(bx)) << ", found "
0160 << etSumRing0NegativeEta << endl;
0161 testPass = false;
0162 }
0163 if (etSumRing1PositiveEta != etSumLut(m_expectedRing1EtSumPositiveEta.at(bx))) {
0164 cout << "Hf Et Sum Positive Eta, expected " << etSumLut(m_expectedRing1EtSumPositiveEta.at(bx)) << ", found "
0165 << etSumRing1PositiveEta << endl;
0166 testPass = false;
0167 }
0168 if (etSumRing1NegativeEta != etSumLut(m_expectedRing1EtSumNegativeEta.at(bx))) {
0169 cout << "Hf Et Sum Negative Eta, expected " << etSumLut(m_expectedRing1EtSumNegativeEta.at(bx)) << ", found "
0170 << etSumRing1NegativeEta << endl;
0171 testPass = false;
0172 }
0173 if (bitCountRing0PositiveEta != countLut(m_expectedRing0BitCountPositiveEta.at(bx))) {
0174 cout << "000Hf Tower Count Positive Eta, expected " << countLut(m_expectedRing0BitCountPositiveEta.at(bx))
0175 << ", found " << bitCountRing0PositiveEta << endl;
0176 testPass = false;
0177 }
0178 if (bitCountRing0NegativeEta != countLut(m_expectedRing0BitCountNegativeEta.at(bx))) {
0179 cout << "111Hf Tower Count Negative Eta, expected " << countLut(m_expectedRing0BitCountNegativeEta.at(bx))
0180 << ", found " << bitCountRing0NegativeEta << endl;
0181 testPass = false;
0182 }
0183 if (bitCountRing1PositiveEta != countLut(m_expectedRing1BitCountPositiveEta.at(bx))) {
0184 cout << "222Hf Tower Count Positive Eta, expected " << countLut(m_expectedRing1BitCountPositiveEta.at(bx))
0185 << ", found " << bitCountRing1PositiveEta << endl;
0186 testPass = false;
0187 }
0188 if (bitCountRing1NegativeEta != countLut(m_expectedRing1BitCountNegativeEta.at(bx))) {
0189 cout << "333Hf Tower Count Negative Eta, expected " << countLut(m_expectedRing1BitCountNegativeEta.at(bx))
0190 << ", found " << bitCountRing1NegativeEta << endl;
0191 testPass = false;
0192 }
0193
0194
0195 }
0196 return testPass;
0197 }
0198
0199 unsigned gctTestHfEtSums::etSumLut(const unsigned expectedValue) const {
0200
0201 return m_etScale->rank((uint16_t)expectedValue);
0202 }
0203
0204 unsigned gctTestHfEtSums::countLut(const unsigned expectedValue) const {
0205
0206
0207 static const unsigned maxLut = (1 << 3) - 1;
0208 unsigned result = maxLut;
0209 unsigned bitCount = expectedValue;
0210 if (bitCount < maxLut)
0211 result = bitCount;
0212 return result;
0213 }