24 #include "L1TCaloLayer1FetchLUTs.hh"
25 #include "UCTLogging.hh"
28 std::vector< std::vector< std::vector < uint32_t > > > &eLUT,
29 std::vector< std::vector< std::vector < uint32_t > > > &hLUT,
30 std::vector< std::vector< uint32_t > > &hfLUT,
41 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Using Stage2-Layer1 but HCAL Geometry has use1x1 = 0! HF will be suppressed. Check Global Tag, etc.";
49 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Missing CaloParams object! Check Global Tag, etc.";
56 if ( caloLSB != 0.5 ) {
58 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloLSB (caloParams.towerLsbSum()) != 0.5, actually = " << caloLSB;
65 auto ecalScaleETBins =
caloParams.layer1ECalScaleETBins();
66 auto ecalSF =
caloParams.layer1ECalScaleFactors();
67 if ( ecalSF.size() != ecalScaleETBins.size()*28 ) {
68 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1ECalScaleFactors().size() != caloParams.layer1ECalScaleETBins().size()*28 !!";
71 auto hcalScaleETBins =
caloParams.layer1HCalScaleETBins();
72 auto hcalSF =
caloParams.layer1HCalScaleFactors();
73 if ( hcalSF.size() != hcalScaleETBins.size()*28 ) {
74 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HCalScaleFactors().size() != caloParams.layer1HCalScaleETBins().size()*28 !!";
82 auto hfScaleETBins =
caloParams.layer1HFScaleETBins();
84 if ( hfSF.size() != hfScaleETBins.size()*12 ) {
85 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"caloParams.layer1HFScaleFactors().size() != caloParams.layer1HFScaleETBins().size()*12 !!";
90 if ( useCalib && (ecalSF.size()==0 || hcalSF.size()==0 || hfSF.size()==0) ) {
91 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Layer 1 calibrations requested (useCalib = True) but there are missing scale factors in CaloParams! Please check conditions setup.";
95 const double ecalLSB = 0.5;
101 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"Missing CaloTPGTranscoder object! Check Global Tag, etc.";
107 auto decodeHcalEt = [&decoder](
int iEta, uint32_t compressedEt, uint32_t iPhi=3) ->
double {
113 return decoder->hcaletValue(
id, sample);
118 for(
int absCaloEta = 1; absCaloEta <= 28; absCaloEta++) {
119 uint32_t iEta = absCaloEta - 1;
120 for(uint32_t
fb = 0;
fb < 2;
fb++) {
121 for(uint32_t ecalInput = 0; ecalInput <= 0xFF; ecalInput++) {
122 uint32_t
value = ecalInput;
124 double linearizedECalInput = ecalInput*ecalLSB;
127 for(; etBin < ecalScaleETBins.size(); etBin++) {
128 if(linearizedECalInput < ecalScaleETBins[etBin])
break;
130 if ( etBin >= ecalScaleETBins.size() ) etBin = ecalScaleETBins.size()-1;
132 double calibratedECalInput = linearizedECalInput;
133 if (useCalib) calibratedECalInput *= ecalSF.at(etBin*28 + iEta);
134 if (useLSB) calibratedECalInput /= caloLSB;
136 value = calibratedECalInput;
145 uint32_t et_log2 = ((uint32_t) log2(value)) & 0x7;
146 value |= (et_log2 << 12);
149 eLUT[iEta][
fb][ecalInput] =
value;
155 for(
int absCaloEta = 1; absCaloEta <= 28; absCaloEta++) {
156 uint32_t iEta = absCaloEta - 1;
157 for(uint32_t
fb = 0;
fb < 2;
fb++) {
158 for(uint32_t hcalInput = 0; hcalInput <= 0xFF; hcalInput++) {
159 uint32_t
value = hcalInput;
162 double linearizedHcalInput = decodeHcalEt(absCaloEta, hcalInput);
163 if(linearizedHcalInput != decodeHcalEt(-absCaloEta, hcalInput)) {
164 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"L1TCaloLayer1FetchLUTs - hcal scale factors are different for positive and negative eta ! :(" << std::endl;
168 for(; etBin < hcalScaleETBins.size(); etBin++) {
169 if(linearizedHcalInput < hcalScaleETBins[etBin])
break;
171 if ( etBin >= hcalScaleETBins.size() ) etBin = hcalScaleETBins.size()-1;
173 double calibratedHcalInput = linearizedHcalInput;
174 if(useCalib) calibratedHcalInput *= hcalSF.at(etBin*28 + iEta);
175 if(useLSB) calibratedHcalInput /= caloLSB;
177 value = calibratedHcalInput;
186 uint32_t et_log2 = ((uint32_t) log2(value)) & 0x7;
187 value |= (et_log2 << 12);
190 hLUT[iEta][
fb][hcalInput] =
value;
196 for(uint32_t etaBin = 0; etaBin < 12; etaBin++) {
197 for(uint32_t etCode = 0; etCode < 256; etCode++) {
198 uint32_t
value = etCode;
201 double linearizedHFInput = 0;
203 linearizedHFInput = decodeHcalEt(30+etaBin, value);
204 if(linearizedHFInput != decodeHcalEt(-30-etaBin, value)) {
205 edm::LogError(
"L1TCaloLayer1FetchLUTs") <<
"L1TCaloLayer1FetchLUTs - HF scale factors are different for positive and negative eta ! :(" << std::endl;
210 for(; etBin < hfScaleETBins.size(); etBin++) {
211 if(linearizedHFInput < hfScaleETBins[etBin])
break;
213 if ( etBin >= hfScaleETBins.size() ) etBin = hfScaleETBins.size()-1;
215 double calibratedHFInput = linearizedHFInput;
216 if(useCalib) calibratedHFInput *= hfSF.at(etBin*12+etaBin);
217 if(useLSB) calibratedHFInput /= caloLSB;
219 value = calibratedHFInput;
224 hfLUT[etaBin][etCode] =
value;
Abs< T >::type abs(const T &t)
T const * product() const
bool L1TCaloLayer1FetchLUTs(const edm::EventSetup &iSetup, std::vector< std::vector< std::vector< uint32_t > > > &eLUT, std::vector< std::vector< std::vector< uint32_t > > > &hLUT, std::vector< std::vector< uint32_t > > &hfLUT, bool useLSB, bool useCalib, bool useECALLUT, bool useHCALLUT, bool useHFLUT)