48 <<
"Using Stage2-Layer1 but HCAL Geometry has use1x1 = 0! HF will be suppressed. Check Global Tag, etc.";
54 if (not paramsHandle.
isValid()) {
55 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Missing CaloParams object! Check Global Tag, etc.";
64 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloLSB (caloParams.towerLsbSum()) != 0.5, actually = " << caloLSB;
72 auto ecalScaleETBins =
caloParams.layer1ECalScaleETBins();
73 auto ecalScalePhiBins =
caloParams.layer1ECalScalePhiBins();
74 if (ecalScalePhiBins.empty()) {
76 ecalScalePhiBins.resize(36, 0);
77 }
else if (ecalScalePhiBins.size() % 36 != 0) {
78 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1ECalScaleETBins().size() is not multiple of 36 !!";
81 size_t numEcalPhiBins = (*std::max_element(ecalScalePhiBins.begin(), ecalScalePhiBins.end())) + 1;
82 auto ecalSF =
caloParams.layer1ECalScaleFactors();
83 if (ecalSF.size() != ecalScaleETBins.size() * numEcalPhiBins * 28) {
84 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1ECalScaleFactors().size() != " 85 "caloParams.layer1ECalScaleETBins().size()*numEcalPhiBins*28 !!";
88 auto hcalScaleETBins =
caloParams.layer1HCalScaleETBins();
89 auto hcalScalePhiBins =
caloParams.layer1HCalScalePhiBins();
90 if (hcalScalePhiBins.empty()) {
91 hcalScalePhiBins.resize(36, 0);
92 }
else if (hcalScalePhiBins.size() % 36 != 0) {
93 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HCalScaleETBins().size() is not multiple of 36 !!";
96 size_t numHcalPhiBins = (*std::max_element(hcalScalePhiBins.begin(), hcalScalePhiBins.end())) + 1;
97 auto hcalSF =
caloParams.layer1HCalScaleFactors();
98 if (hcalSF.size() != hcalScaleETBins.size() * numHcalPhiBins * 28) {
99 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HCalScaleFactors().size() != " 100 "caloParams.layer1HCalScaleETBins().size()*numHcalPhiBins*28 !!";
109 auto hfScaleETBins =
caloParams.layer1HFScaleETBins();
110 auto hfScalePhiBins =
caloParams.layer1HFScalePhiBins();
111 if (hfScalePhiBins.empty()) {
112 hfScalePhiBins.resize(36, 0);
113 }
else if (hfScalePhiBins.size() % 36 != 0) {
114 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HFScaleETBins().size() is not multiple of 36 !!";
117 size_t numHFPhiBins = (*std::max_element(hfScalePhiBins.begin(), hfScalePhiBins.end())) + 1;
119 if (
hfSF.size() != hfScaleETBins.size() * numHFPhiBins * 12) {
121 <<
"caloParams.layer1HFScaleFactors().size() != caloParams.layer1HFScaleETBins().size()*numHFPhiBins*12 !!";
126 if (
useCalib && (ecalSF.empty() || hcalSF.empty() ||
hfSF.empty())) {
127 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Layer 1 calibrations requested (useCalib = True) but there are missing " 128 "scale factors in CaloParams! Please check conditions setup.";
132 const double ecalLSB = 0.5;
137 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Missing CaloTPGTranscoder object! Check Global Tag, etc.";
143 auto decodeHcalEt = [&decoder](
int iEta, uint32_t compressedEt, uint32_t iPhi = 3) ->
double {
154 std::array<std::array<std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> phiLUT;
155 eLUT.push_back(phiLUT);
157 for (uint32_t fb = 0; fb < nCalSideBins; fb++) {
158 for (uint32_t ecalInput = 0; ecalInput <= 0xFF; ecalInput++) {
159 uint32_t
value = ecalInput;
161 double linearizedECalInput = ecalInput * ecalLSB;
164 for (;
etBin < ecalScaleETBins.size();
etBin++) {
165 if (linearizedECalInput < ecalScaleETBins[
etBin])
168 if (
etBin >= ecalScaleETBins.size())
169 etBin = ecalScaleETBins.size() - 1;
171 double calibratedECalInput = linearizedECalInput;
173 calibratedECalInput *= ecalSF.at(
phiBin * ecalScaleETBins.size() * 28 +
etBin * 28 +
etaBin);
175 calibratedECalInput /= caloLSB;
177 value = calibratedECalInput;
181 if (
value > 0xFF || ecalInput == 0xFF) {
193 uint32_t et_log2 = ((uint32_t)log2(
value)) & 0x7;
194 value |= (et_log2 << 12);
205 std::array<std::array<std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> phiLUT;
206 hLUT.push_back(phiLUT);
211 if (
pos != hcalScalePhiBins.end()) {
216 iPhi =
index * 4 + 1;
218 iPhi = (
index - 18) * 4 + 1;
221 for (uint32_t fb = 0; fb < nCalSideBins; fb++) {
222 for (uint32_t hcalInput = 0; hcalInput <= 0xFF; hcalInput++) {
223 uint32_t
value = hcalInput;
226 double linearizedHcalInput = decodeHcalEt(caloEta, hcalInput, iPhi);
229 for (;
etBin < hcalScaleETBins.size();
etBin++) {
230 if (linearizedHcalInput < hcalScaleETBins[
etBin])
233 if (
etBin >= hcalScaleETBins.size())
234 etBin = hcalScaleETBins.size() - 1;
236 double calibratedHcalInput = linearizedHcalInput;
238 calibratedHcalInput *= hcalSF.at(
phiBin * hcalScaleETBins.size() * 28 +
etBin * 28 +
etaBin);
240 calibratedHcalInput /= caloLSB;
242 value = calibratedHcalInput;
245 if (
value > 0xFF || hcalInput == 0xFF) {
257 uint32_t et_log2 = ((uint32_t)log2(
value)) & 0x7;
258 value |= (et_log2 << 12);
269 std::array<std::array<uint32_t, nEtBins>, nHfEtaBins> phiLUT;
270 hfLUT.push_back(phiLUT);
272 int caloEta =
etaBin + 30;
275 if (
pos != hfScalePhiBins.end()) {
279 iPhi =
index * 4 - 1;
281 iPhi = (
index - 18) * 4 - 1;
286 for (uint32_t etCode = 0; etCode < nEtBins; etCode++) {
287 uint32_t
value = etCode;
289 double linearizedHFInput = 0;
291 linearizedHFInput = decodeHcalEt(caloEta,
value, iPhi);
295 for (;
etBin < hfScaleETBins.size();
etBin++) {
296 if (linearizedHFInput < hfScaleETBins[
etBin])
299 if (
etBin >= hfScaleETBins.size())
300 etBin = hfScaleETBins.size() - 1;
302 double calibratedHFInput = linearizedHFInput;
306 calibratedHFInput /= caloLSB;
309 uint32_t absCaloEta =
std::abs(caloEta);
310 if (absCaloEta > 29 && absCaloEta < 40) {
312 calibratedHFInput *= 0.5;
313 }
else if (absCaloEta == 40 || absCaloEta == 41) {
315 calibratedHFInput *= 0.25;
317 value = calibratedHFInput;
319 if (
value >= 0xFF || etCode == 0xFF) {
323 value = calibratedHFInput;
335 for (uint32_t isPos = 0; isPos < 2; isPos++) {
336 for (uint32_t iPhi = 1; iPhi <= 72; iPhi++) {
337 uint32_t card = floor((iPhi + 1) / 4);
340 ePhiMap[isPos * 72 + iPhi - 1] = ecalScalePhiBins[isPos * 18 + card];
341 hPhiMap[isPos * 72 + iPhi - 1] = hcalScalePhiBins[isPos * 18 + card];
342 hfPhiMap[isPos * 72 + iPhi - 1] = hfScalePhiBins[isPos * 18 + card];
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)
bool getData(T &iHolder) const
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
virtual double hcaletValue(const int &ieta, const int &iphi, const int &version, const int &compressedValue) const =0