24 #include "L1TCaloLayer1FetchLUTs.hh" 25 #include "UCTLogging.hh" 30 std::vector<
std::array<
std::array< std::array<uint32_t, nEtBins>, nCalSideBins >, nCalEtaBins> > &eLUT,
31 std::vector<
std::array<
std::array< std::array<uint32_t, nEtBins>, nCalSideBins >, nCalEtaBins> > &hLUT,
32 std::vector<
std::array< std::array<uint32_t, nEtBins>, nHfEtaBins > > &hfLUT,
33 std::vector<unsigned int> &ePhiMap,
34 std::vector<unsigned int> &hPhiMap,
35 std::vector<unsigned int> &hfPhiMap,
47 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Using Stage2-Layer1 but HCAL Geometry has use1x1 = 0! HF will be suppressed. Check Global Tag, etc.";
55 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Missing CaloParams object! Check Global Tag, etc.";
62 if ( caloLSB != 0.5 ) {
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);
78 else if ( ecalScalePhiBins.size() % 36 != 0 ) {
79 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1ECalScaleETBins().size() is not multiple of 36 !!";
82 size_t numEcalPhiBins = (*std::max_element(ecalScalePhiBins.begin(), ecalScalePhiBins.end())) + 1;
83 auto ecalSF = caloParams.layer1ECalScaleFactors();
84 if ( ecalSF.size() != ecalScaleETBins.size()*numEcalPhiBins*28 ) {
85 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1ECalScaleFactors().size() != caloParams.layer1ECalScaleETBins().size()*numEcalPhiBins*28 !!";
88 auto hcalScaleETBins = caloParams.layer1HCalScaleETBins();
89 auto hcalScalePhiBins = caloParams.layer1HCalScalePhiBins();
90 if ( hcalScalePhiBins.empty() ) {
91 hcalScalePhiBins.resize(36, 0);
93 else if ( hcalScalePhiBins.size() % 36 != 0 ) {
94 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HCalScaleETBins().size() is not multiple of 36 !!";
97 size_t numHcalPhiBins = (*std::max_element(hcalScalePhiBins.begin(), hcalScalePhiBins.end())) + 1;
98 auto hcalSF = caloParams.layer1HCalScaleFactors();
99 if ( hcalSF.size() != hcalScaleETBins.size()*numHcalPhiBins*28 ) {
100 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HCalScaleFactors().size() != caloParams.layer1HCalScaleETBins().size()*numHcalPhiBins*28 !!";
109 auto hfScaleETBins = caloParams.layer1HFScaleETBins();
110 auto hfScalePhiBins = caloParams.layer1HFScalePhiBins();
111 if ( hfScalePhiBins.empty() ) {
112 hfScalePhiBins.resize(36, 0);
114 else if ( hfScalePhiBins.size() % 36 != 0 ) {
115 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HFScaleETBins().size() is not multiple of 36 !!";
118 size_t numHFPhiBins = (*std::max_element(hfScalePhiBins.begin(), hfScalePhiBins.end())) + 1;
119 auto hfSF = caloParams.layer1HFScaleFactors();
120 if ( hfSF.size() != hfScaleETBins.size()*numHFPhiBins*12 ) {
121 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"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 scale factors in CaloParams! Please check conditions setup.";
131 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 {
155 std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> phiLUT;
156 eLUT.push_back(phiLUT);
158 for(uint32_t
fb = 0;
fb < nCalSideBins;
fb++) {
159 for(uint32_t ecalInput = 0; ecalInput <= 0xFF; ecalInput++) {
160 uint32_t
value = ecalInput;
162 double linearizedECalInput = ecalInput*ecalLSB;
165 for(; etBin < ecalScaleETBins.size(); etBin++) {
166 if(linearizedECalInput < ecalScaleETBins[etBin])
break;
168 if ( etBin >= ecalScaleETBins.size() ) etBin = ecalScaleETBins.size()-1;
170 double calibratedECalInput = linearizedECalInput;
171 if (useCalib) calibratedECalInput *= ecalSF.at(
phiBin*ecalScaleETBins.size()*28 + etBin*28 +
etaBin);
172 if (useLSB) calibratedECalInput /= caloLSB;
174 value = calibratedECalInput;
175 if ( fwVersion > 2 ) {
178 if(value > 0xFF || ecalInput == 0xFF) {
192 uint32_t et_log2 = ((uint32_t) log2(value)) & 0x7;
193 value |= (et_log2 << 12);
204 std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> phiLUT;
205 hLUT.push_back(phiLUT);
210 if (
pos!=hcalScalePhiBins.end()) {
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])
break;
232 if ( etBin >= hcalScaleETBins.size() ) etBin = hcalScaleETBins.size()-1;
234 double calibratedHcalInput = linearizedHcalInput;
235 if(useCalib) calibratedHcalInput *= hcalSF.at(
phiBin*hcalScaleETBins.size()*28 + etBin*28 +
etaBin);
236 if(useLSB) calibratedHcalInput /= caloLSB;
238 value = calibratedHcalInput;
239 if ( fwVersion > 2 ) {
241 if(value > 0xFF || hcalInput == 0xFF) {
255 uint32_t et_log2 = ((uint32_t) log2(value)) & 0x7;
256 value |= (et_log2 << 12);
267 std::array< std::array<uint32_t, nEtBins>, nHfEtaBins> phiLUT;
268 hfLUT.push_back(phiLUT);
273 if (
pos!=hfScalePhiBins.end()) {
280 iPhi = (
index-18)*4-1;
282 if (iPhi < 0) iPhi = 71;
284 for(uint32_t etCode = 0; etCode < nEtBins; etCode++) {
285 uint32_t
value = etCode;
288 double linearizedHFInput = 0;
290 linearizedHFInput = decodeHcalEt(caloEta, value, iPhi);
294 for(; etBin < hfScaleETBins.size(); etBin++) {
295 if(linearizedHFInput < hfScaleETBins[etBin])
break;
297 if ( etBin >= hfScaleETBins.size() ) etBin = hfScaleETBins.size()-1;
299 double calibratedHFInput = linearizedHFInput;
300 if(useCalib) calibratedHFInput *= hfSF.at(
phiBin*hfScalePhiBins.size()*12+etBin*12+
etaBin);
301 if(useLSB) calibratedHFInput /= caloLSB;
303 if ( fwVersion > 2 ) {
304 uint32_t absCaloEta =
std::abs(caloEta);
305 if(absCaloEta > 29 && absCaloEta < 40) {
307 calibratedHFInput *= 0.5;
309 else if(absCaloEta == 40 || absCaloEta == 41) {
311 calibratedHFInput *= 0.25;
313 value = calibratedHFInput;
315 if(value >= 0xFF || etCode == 0xFF) {
320 value = calibratedHFInput;
332 for(uint32_t isPos=0; isPos<2; isPos++) {
333 for(uint32_t iPhi=1; iPhi<=72; iPhi++) {
334 uint32_t card = floor((iPhi+1)/4);
335 if (card>17) card-=18;
336 ePhiMap[isPos*72+iPhi-1] = ecalScalePhiBins[isPos*18+card];
337 hPhiMap[isPos*72+iPhi-1] = hcalScalePhiBins[isPos*18+card];
338 hfPhiMap[isPos*72+iPhi-1] = hfScalePhiBins[isPos*18+card];
bool L1TCaloLayer1FetchLUTs(const edm::EventSetup &iSetup, std::vector< std::array< std::array< std::array< uint32_t, nEtBins >, nCalSideBins >, nCalEtaBins > > &eLUT, std::vector< std::array< std::array< std::array< uint32_t, nEtBins >, nCalSideBins >, nCalEtaBins > > &hLUT, std::vector< std::array< std::array< uint32_t, nEtBins >, nHfEtaBins > > &hfLUT, std::vector< unsigned int > &ePhiMap, std::vector< unsigned int > &hPhiMap, std::vector< unsigned int > &hfPhiMap, bool useLSB, bool useCalib, bool useECALLUT, bool useHCALLUT, bool useHFLUT, int fwVersion)
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