46 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Using Stage2-Layer1 but HCAL Geometry has use1x1 = 0! HF will be suppressed. Check Global Tag, etc.";
54 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Missing CaloParams object! Check Global Tag, etc.";
61 if ( caloLSB != 0.5 ) {
63 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloLSB (caloParams.towerLsbSum()) != 0.5, actually = " << caloLSB;
71 auto ecalScaleETBins = caloParams.layer1ECalScaleETBins();
72 auto ecalScalePhiBins = caloParams.layer1ECalScalePhiBins();
73 if ( ecalScalePhiBins.empty() ) {
75 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() != caloParams.layer1ECalScaleETBins().size()*numEcalPhiBins*28 !!";
87 auto hcalScaleETBins = caloParams.layer1HCalScaleETBins();
88 auto hcalScalePhiBins = caloParams.layer1HCalScalePhiBins();
89 if ( hcalScalePhiBins.empty() ) {
90 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() != caloParams.layer1HCalScaleETBins().size()*numHcalPhiBins*28 !!";
108 auto hfScaleETBins = caloParams.layer1HFScaleETBins();
109 auto hfScalePhiBins = caloParams.layer1HFScalePhiBins();
110 if ( hfScalePhiBins.empty() ) {
111 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;
118 auto hfSF = caloParams.layer1HFScaleFactors();
119 if ( hfSF.size() != hfScaleETBins.size()*numHFPhiBins*12 ) {
120 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HFScaleFactors().size() != caloParams.layer1HFScaleETBins().size()*numHFPhiBins*12 !!";
125 if ( useCalib && (ecalSF.size()==0 || hcalSF.size()==0 || hfSF.size()==0) ) {
126 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Layer 1 calibrations requested (useCalib = True) but there are missing scale factors in CaloParams! Please check conditions setup.";
130 const double ecalLSB = 0.5;
136 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Missing CaloTPGTranscoder object! Check Global Tag, etc.";
142 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])
break;
167 if ( etBin >= ecalScaleETBins.size() ) etBin = ecalScaleETBins.size()-1;
169 double calibratedECalInput = linearizedECalInput;
170 if (useCalib) calibratedECalInput *= ecalSF.at(
phiBin*ecalScaleETBins.size()*28 + etBin*28 +
etaBin);
171 if (useLSB) calibratedECalInput /= caloLSB;
173 value = calibratedECalInput;
182 uint32_t et_log2 = ((uint32_t) log2(value)) & 0x7;
183 value |= (et_log2 << 12);
194 std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> phiLUT;
195 hLUT.push_back(phiLUT);
200 if (
pos!=hcalScalePhiBins.end()) {
208 iPhi = (
index-18)*4+1;
211 for(uint32_t
fb = 0;
fb < nCalSideBins;
fb++) {
212 for(uint32_t hcalInput = 0; hcalInput <= 0xFF; hcalInput++) {
213 uint32_t value = hcalInput;
216 double linearizedHcalInput = decodeHcalEt(caloEta, hcalInput, iPhi);
219 for(; etBin < hcalScaleETBins.size(); etBin++) {
220 if(linearizedHcalInput < hcalScaleETBins[etBin])
break;
222 if ( etBin >= hcalScaleETBins.size() ) etBin = hcalScaleETBins.size()-1;
224 double calibratedHcalInput = linearizedHcalInput;
225 if(useCalib) calibratedHcalInput *= hcalSF.at(
phiBin*hcalScaleETBins.size()*28 + etBin*28 +
etaBin);
226 if(useLSB) calibratedHcalInput /= caloLSB;
228 value = calibratedHcalInput;
237 uint32_t et_log2 = ((uint32_t) log2(value)) & 0x7;
238 value |= (et_log2 << 12);
249 std::array< std::array<uint32_t, nEtBins>, nHfEtaBins> phiLUT;
250 hfLUT.push_back(phiLUT);
255 if (
pos!=hfScalePhiBins.end()) {
262 iPhi = (
index-18)*4-1;
264 if (iPhi < 0) iPhi = 71;
266 for(uint32_t etCode = 0; etCode < nEtBins; etCode++) {
267 uint32_t value = etCode;
270 double linearizedHFInput = 0;
272 linearizedHFInput = decodeHcalEt(caloEta, value, iPhi);
276 for(; etBin < hfScaleETBins.size(); etBin++) {
277 if(linearizedHFInput < hfScaleETBins[etBin])
break;
279 if ( etBin >= hfScaleETBins.size() ) etBin = hfScaleETBins.size()-1;
281 double calibratedHFInput = linearizedHFInput;
282 if(useCalib) calibratedHFInput *= hfSF.at(
phiBin*hfScalePhiBins.size()*12+etBin*12+
etaBin);
283 if(useLSB) calibratedHFInput /= caloLSB;
285 value = calibratedHFInput;
296 for(uint32_t isPos=0; isPos<2; isPos++) {
297 for(uint32_t iPhi=1; iPhi<=72; iPhi++) {
298 uint32_t card = floor((iPhi+1)/4);
299 if (card>17) card-=18;
300 ePhiMap[isPos*72+iPhi-1] = ecalScalePhiBins[isPos*18+card];
301 hPhiMap[isPos*72+iPhi-1] = hcalScalePhiBins[isPos*18+card];
302 hfPhiMap[isPos*72+iPhi-1] = hfScalePhiBins[isPos*18+card];
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Abs< T >::type abs(const T &t)
double towerLsbSum() const
virtual double hcaletValue(const int &ieta, const int &iphi, const int &version, const int &compressedValue) const =0
T const * product() const