50 <<
"Using Stage2-Layer1 but HCAL Geometry has use1x1 = 0! HF will be suppressed. Check Global Tag, etc.";
56 if (not paramsHandle.
isValid()) {
57 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Missing CaloParams object! Check Global Tag, etc.";
66 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloLSB (caloParams.towerLsbSum()) != 0.5, actually = " << caloLSB;
74 auto ecalScaleETBins =
caloParams.layer1ECalScaleETBins();
75 auto ecalScalePhiBins =
caloParams.layer1ECalScalePhiBins();
76 if (ecalScalePhiBins.empty()) {
78 ecalScalePhiBins.resize(36, 0);
79 }
else if (ecalScalePhiBins.size() % 36 != 0) {
80 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1ECalScaleETBins().size() is not multiple of 36 !!";
83 size_t numEcalPhiBins = (*std::max_element(ecalScalePhiBins.begin(), ecalScalePhiBins.end())) + 1;
84 auto ecalSF =
caloParams.layer1ECalScaleFactors();
85 if (ecalSF.size() != ecalScaleETBins.size() * numEcalPhiBins * 28) {
86 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1ECalScaleFactors().size() != " 87 "caloParams.layer1ECalScaleETBins().size()*numEcalPhiBins*28 !!";
90 auto hcalScaleETBins =
caloParams.layer1HCalScaleETBins();
91 auto hcalScalePhiBins =
caloParams.layer1HCalScalePhiBins();
92 if (hcalScalePhiBins.empty()) {
93 hcalScalePhiBins.resize(36, 0);
94 }
else if (hcalScalePhiBins.size() % 36 != 0) {
95 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HCalScaleETBins().size() is not multiple of 36 !!";
98 size_t numHcalPhiBins = (*std::max_element(hcalScalePhiBins.begin(), hcalScalePhiBins.end())) + 1;
99 auto hcalSF =
caloParams.layer1HCalScaleFactors();
100 if (hcalSF.size() != hcalScaleETBins.size() * numHcalPhiBins * 28) {
101 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HCalScaleFactors().size() != " 102 "caloParams.layer1HCalScaleETBins().size()*numHcalPhiBins*28 !!";
111 auto hfScaleETBins =
caloParams.layer1HFScaleETBins();
112 auto hfScalePhiBins =
caloParams.layer1HFScalePhiBins();
113 if (hfScalePhiBins.empty()) {
114 hfScalePhiBins.resize(36, 0);
115 }
else if (hfScalePhiBins.size() % 36 != 0) {
116 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HFScaleETBins().size() is not multiple of 36 !!";
119 size_t numHFPhiBins = (*std::max_element(hfScalePhiBins.begin(), hfScalePhiBins.end())) + 1;
121 if (
hfSF.size() != hfScaleETBins.size() * numHFPhiBins * 12) {
123 <<
"caloParams.layer1HFScaleFactors().size() != caloParams.layer1HFScaleETBins().size()*numHFPhiBins*12 !!";
128 if (
useCalib && (ecalSF.empty() || hcalSF.empty() ||
hfSF.empty())) {
129 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Layer 1 calibrations requested (useCalib = True) but there are missing " 130 "scale factors in CaloParams! Please check conditions setup.";
137 auto fbLUTUpper =
caloParams.layer1HCalFBLUTUpper();
138 auto fbLUTLower =
caloParams.layer1HCalFBLUTLower();
141 if (fbLUTUpper.size() != nCalEtaBins) {
143 <<
"caloParams.layer1HCalFBLUTUpper().size() " << fbLUTUpper.size() <<
" != " << nCalEtaBins <<
" !!";
146 if (fbLUTLower.size() != nCalEtaBins) {
148 <<
"caloParams.layer1HCalFBLUTLower().size() " << fbLUTLower.size() <<
" != " << nCalEtaBins <<
" !!";
154 const double ecalLSB = 0.5;
159 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Missing CaloTPGTranscoder object! Check Global Tag, etc.";
165 auto decodeHcalEt = [&decoder](
int iEta, uint32_t compressedEt, uint32_t iPhi = 3) ->
double {
171 return decoder->hcaletValue(
id,
sample);
176 std::array<std::array<std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> phiLUT;
179 for (uint32_t fb = 0; fb < nCalSideBins; fb++) {
180 for (uint32_t ecalInput = 0; ecalInput <= 0xFF; ecalInput++) {
181 uint32_t
value = ecalInput;
183 double linearizedECalInput = ecalInput * ecalLSB;
186 for (;
etBin < ecalScaleETBins.size();
etBin++) {
187 if (linearizedECalInput < ecalScaleETBins[
etBin])
190 if (
etBin >= ecalScaleETBins.size())
191 etBin = ecalScaleETBins.size() - 1;
193 double calibratedECalInput = linearizedECalInput;
195 calibratedECalInput *= ecalSF.at(
phiBin * ecalScaleETBins.size() * 28 +
etBin * 28 +
etaBin);
197 calibratedECalInput /= caloLSB;
199 value = calibratedECalInput;
203 if (
value > 0xFF || ecalInput == 0xFF) {
215 uint32_t et_log2 = ((uint32_t)log2(
value)) & 0x7;
216 value |= (et_log2 << 12);
224 eLUT.push_back(phiLUT);
229 std::array<std::array<std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> phiLUT;
234 if (
pos != hcalScalePhiBins.end()) {
239 iPhi =
index * 4 + 1;
241 iPhi = (
index - 18) * 4 + 1;
244 for (uint32_t fb = 0; fb < nCalSideBins; fb++) {
245 for (uint32_t hcalInput = 0; hcalInput <= 0xFF; hcalInput++) {
246 uint32_t
value = hcalInput;
249 double linearizedHcalInput = decodeHcalEt(caloEta, hcalInput, iPhi);
252 for (;
etBin < hcalScaleETBins.size();
etBin++) {
253 if (linearizedHcalInput < hcalScaleETBins[
etBin])
256 if (
etBin >= hcalScaleETBins.size())
257 etBin = hcalScaleETBins.size() - 1;
259 double calibratedHcalInput = linearizedHcalInput;
261 calibratedHcalInput *= hcalSF.at(
phiBin * hcalScaleETBins.size() * 28 +
etBin * 28 +
etaBin);
263 calibratedHcalInput /= caloLSB;
265 value = calibratedHcalInput;
268 if (
value > 0xFF || hcalInput == 0xFF) {
280 uint32_t et_log2 = ((uint32_t)log2(
value)) & 0x7;
281 value |= (et_log2 << 12);
289 hLUT.push_back(phiLUT);
294 std::array<std::array<uint32_t, nEtBins>, nHfEtaBins> phiLUT;
297 int caloEta =
etaBin + 30;
300 if (
pos != hfScalePhiBins.end()) {
304 iPhi =
index * 4 - 1;
306 iPhi = (
index - 18) * 4 - 1;
311 for (uint32_t etCode = 0; etCode < nEtBins; etCode++) {
312 uint32_t
value = etCode;
314 double linearizedHFInput = 0;
316 linearizedHFInput = decodeHcalEt(caloEta,
value, iPhi);
320 for (;
etBin < hfScaleETBins.size();
etBin++) {
321 if (linearizedHFInput < hfScaleETBins[
etBin])
324 if (
etBin >= hfScaleETBins.size())
325 etBin = hfScaleETBins.size() - 1;
327 double calibratedHFInput = linearizedHFInput;
331 calibratedHFInput /= caloLSB;
334 uint32_t absCaloEta =
std::abs(caloEta);
335 if (absCaloEta > 29 && absCaloEta < 40) {
337 calibratedHFInput *= 0.5;
338 }
else if (absCaloEta == 40 || absCaloEta == 41) {
340 calibratedHFInput *= 0.25;
342 value = calibratedHFInput;
344 if (
value >= 0xFF || etCode == 0xFF) {
348 value = calibratedHFInput;
357 hfLUT.push_back(phiLUT);
366 hcalFBLUT.push_back(
value);
370 for (uint32_t isPos = 0; isPos < 2; isPos++) {
371 for (uint32_t iPhi = 1; iPhi <= 72; iPhi++) {
372 uint32_t card = floor((iPhi + 1) / 4);
375 ePhiMap[isPos * 72 + iPhi - 1] = ecalScalePhiBins[isPos * 18 + card];
376 hPhiMap[isPos * 72 + iPhi - 1] = hcalScalePhiBins[isPos * 18 + card];
377 hfPhiMap[isPos * 72 + iPhi - 1] = hfScalePhiBins[isPos * 18 + card];
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
T const * product() const
Abs< T >::type abs(const T &t)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
unsigned long long uint64_t