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 auto epos = std::max_element(ecalScalePhiBins.begin(), ecalScalePhiBins.end());
74 auto numEcalPhiBins = ecalScalePhiBins[
std::distance(ecalScalePhiBins.begin(), epos)]+1;
75 auto ecalSF = caloParams.layer1ECalScaleFactors();
76 if ( ecalSF.size() != ecalScaleETBins.size()*numEcalPhiBins*28 ) {
77 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1ECalScaleFactors().size() != caloParams.layer1ECalScaleETBins().size()*numEcalPhiBins*28 !!";
80 auto hcalScaleETBins = caloParams.layer1HCalScaleETBins();
81 auto hcalScalePhiBins = caloParams.layer1HCalScalePhiBins();
82 auto hpos = std::max_element(hcalScalePhiBins.begin(), hcalScalePhiBins.end());
83 auto numHcalPhiBins = hcalScalePhiBins[
std::distance(hcalScalePhiBins.begin(), hpos)]+1;
84 auto hcalSF = caloParams.layer1HCalScaleFactors();
85 if ( hcalSF.size() != hcalScaleETBins.size()*numHcalPhiBins*28 ) {
86 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HCalScaleFactors().size() != caloParams.layer1HCalScaleETBins().size()*numHcalPhiBins*28 !!";
95 auto hfScaleETBins = caloParams.layer1HFScaleETBins();
96 auto hfScalePhiBins = caloParams.layer1HFScalePhiBins();
97 auto hfpos = std::max_element(hfScalePhiBins.begin(), hfScalePhiBins.end());
98 auto numHFPhiBins = hfScalePhiBins[
std::distance(hfScalePhiBins.begin(), hfpos)]+1;
99 auto hfSF = caloParams.layer1HFScaleFactors();
100 if ( hfSF.size() != hfScaleETBins.size()*numHFPhiBins*12 ) {
101 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HFScaleFactors().size() != caloParams.layer1HFScaleETBins().size()*numHFPhiBins*12 !!";
106 if ( useCalib && (ecalSF.size()==0 || hcalSF.size()==0 || hfSF.size()==0) ) {
107 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Layer 1 calibrations requested (useCalib = True) but there are missing scale factors in CaloParams! Please check conditions setup.";
111 const double ecalLSB = 0.5;
117 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Missing CaloTPGTranscoder object! Check Global Tag, etc.";
123 auto decodeHcalEt = [&decoder](
int iEta, uint32_t compressedEt, uint32_t iPhi=3) ->
double {
135 std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> phiLUT;
136 eLUT.push_back(phiLUT);
138 for(uint32_t
fb = 0;
fb < nCalSideBins;
fb++) {
139 for(uint32_t ecalInput = 0; ecalInput <= 0xFF; ecalInput++) {
140 uint32_t
value = ecalInput;
142 double linearizedECalInput = ecalInput*ecalLSB;
145 for(; etBin < ecalScaleETBins.size(); etBin++) {
146 if(linearizedECalInput < ecalScaleETBins[etBin])
break;
148 if ( etBin >= ecalScaleETBins.size() ) etBin = ecalScaleETBins.size()-1;
150 double calibratedECalInput = linearizedECalInput;
151 if (useCalib) calibratedECalInput *= ecalSF.at(
phiBin*ecalScaleETBins.size()*28 + etBin*28 +
etaBin);
152 if (useLSB) calibratedECalInput /= caloLSB;
154 value = calibratedECalInput;
163 uint32_t et_log2 = ((uint32_t) log2(value)) & 0x7;
164 value |= (et_log2 << 12);
175 std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> phiLUT;
176 hLUT.push_back(phiLUT);
181 if (
pos!=hcalScalePhiBins.end()) {
189 iPhi = (
index-18)*4+1;
192 for(uint32_t
fb = 0;
fb < nCalSideBins;
fb++) {
193 for(uint32_t hcalInput = 0; hcalInput <= 0xFF; hcalInput++) {
194 uint32_t value = hcalInput;
197 double linearizedHcalInput = decodeHcalEt(caloEta, hcalInput, iPhi);
200 for(; etBin < hcalScaleETBins.size(); etBin++) {
201 if(linearizedHcalInput < hcalScaleETBins[etBin])
break;
203 if ( etBin >= hcalScaleETBins.size() ) etBin = hcalScaleETBins.size()-1;
205 double calibratedHcalInput = linearizedHcalInput;
206 if(useCalib) calibratedHcalInput *= hcalSF.at(
phiBin*hcalScaleETBins.size()*28 + etBin*28 +
etaBin);
207 if(useLSB) calibratedHcalInput /= caloLSB;
209 value = calibratedHcalInput;
218 uint32_t et_log2 = ((uint32_t) log2(value)) & 0x7;
219 value |= (et_log2 << 12);
230 std::array< std::array<uint32_t, nEtBins>, nHfEtaBins> phiLUT;
231 hfLUT.push_back(phiLUT);
236 if (
pos!=hfScalePhiBins.end()) {
243 iPhi = (
index-18)*4+1;
245 if (
std::abs(caloEta) == 41 && iPhi<3) iPhi = 3;
247 for(uint32_t etCode = 0; etCode < nEtBins; etCode++) {
248 uint32_t value = etCode;
251 double linearizedHFInput = 0;
253 linearizedHFInput = decodeHcalEt(caloEta, value, iPhi);
257 for(; etBin < hfScaleETBins.size(); etBin++) {
258 if(linearizedHFInput < hfScaleETBins[etBin])
break;
260 if ( etBin >= hfScaleETBins.size() ) etBin = hfScaleETBins.size()-1;
262 double calibratedHFInput = linearizedHFInput;
263 if(useCalib) calibratedHFInput *= hfSF.at(
phiBin*hfScalePhiBins.size()*12+etBin*12+
etaBin);
264 if(useLSB) calibratedHFInput /= caloLSB;
266 value = calibratedHFInput;
277 for(uint32_t isPos=0; isPos<2; isPos++) {
278 for(uint32_t iPhi=1; iPhi<=72; iPhi++) {
279 uint32_t card = floor((iPhi+1)/4);
280 if (card>17) card-=18;
281 ePhiMap[isPos*72+iPhi-1] = ecalScalePhiBins[isPos*18+card];
282 hPhiMap[isPos*72+iPhi-1] = hcalScalePhiBins[isPos*18+card];
283 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