diff --git a/CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h b/CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h index 97766c441a3f6..b935b6cd64118 100644 --- a/CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h +++ b/CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h @@ -60,6 +60,7 @@ class HcaluLUTTPGCoder : public HcalTPGCoder { void update(const char* filename, bool appendMSB = false); void updateXML(const char* filename); void setLUTGenerationMode(bool gen) { LUTGenerationMode_ = gen; }; + void setOverrideFGHF(bool overrideFGHF) { overrideFGHF_ = overrideFGHF; }; void setFGHFthresholds(const std::vector& fgthresholds) { FG_HF_thresholds_ = fgthresholds; }; void setMaskBit(int bit) { bitToMask_ = bit; }; void setAllLinear(bool linear, double lsb8, double lsb11, double lsb11overlap) { @@ -114,6 +115,7 @@ class HcaluLUTTPGCoder : public HcalTPGCoder { const HcalElectronicsMap* emap_; const HcalTimeSlew* delay_; bool LUTGenerationMode_; + bool overrideFGHF_ = false; std::vector FG_HF_thresholds_; int bitToMask_; int firstHBEta_, lastHBEta_, nHBEta_, maxDepthHB_, sizeHB_; diff --git a/CalibCalorimetry/HcalTPGAlgos/src/HcaluLUTTPGCoder.cc b/CalibCalorimetry/HcalTPGAlgos/src/HcaluLUTTPGCoder.cc index 582098ffd0dd5..9b1594f6118e8 100644 --- a/CalibCalorimetry/HcalTPGAlgos/src/HcaluLUTTPGCoder.cc +++ b/CalibCalorimetry/HcalTPGAlgos/src/HcaluLUTTPGCoder.cc @@ -43,6 +43,7 @@ HcaluLUTTPGCoder::HcaluLUTTPGCoder() emap_{}, delay_{}, LUTGenerationMode_{}, + overrideFGHF_{}, FG_HF_thresholds_{}, bitToMask_{}, firstHBEta_{}, @@ -81,6 +82,7 @@ void HcaluLUTTPGCoder::init(const HcalTopology* top, const HcalElectronicsMap* e emap_ = emap; delay_ = delay; LUTGenerationMode_ = true; + overrideFGHF_ = false; FG_HF_thresholds_ = {0, 0}; bitToMask_ = 0; allLinear_ = false; @@ -381,6 +383,34 @@ void HcaluLUTTPGCoder::update(const HcalDbService& conditions) { bool newHBtp = false; bool newHEtp = false; std::vector vIds = emap_->allElectronicsIdTrigger(); + + // Access TPParameters to get HF fine-grain thresholds + const HcalTPParameters* tpparameters = conditions.getHcalTPParameters(); + + // Read thresholds from auxi1 field + // aux1: 32-bit auxiliary word. Currently, only the low 16 bits are used (HF MinBias FG thresholds). The high 16 bits are reserved for future use. + const uint32_t aux1 = tpparameters->getAuxi1(); + unsigned fg_hf_lo, fg_hf_hi; + + // The first 16 bits of auxi1 are empty OR the switch is open: Read from configuration parameters + const bool zerothresFGHF = (aux1 & 0xFFFFu) == 0u; + if (overrideFGHF_ || zerothresFGHF) { + fg_hf_lo = FG_HF_thresholds_[0]; + fg_hf_hi = FG_HF_thresholds_[1]; + } else { + // First 8-bits: low threshold + // Second 8-bits: high threshold + fg_hf_lo = aux1 & 0xFFu; + fg_hf_hi = (aux1 >> 8) & 0xFFu; + } + + // Sanity check: low less than high + if (fg_hf_hi < fg_hf_lo) { + edm::LogError("HcaluLUTTPGCoder") + << "ERROR: HF fine-grain thresholds, taken from auxi1 field of HcalTPParameters, are possibly mis-ordered: " + << "lower threshold (" << fg_hf_lo << ") > high threshold (" << fg_hf_hi << ")."; + } + for (std::vector::const_iterator eId = vIds.begin(); eId != vIds.end(); eId++) { // The first HB or HE id is enough to tell whether to use new scheme in HB or HE if (foundHB and foundHE) @@ -577,9 +607,9 @@ void HcaluLUTTPGCoder::update(const HcalDbService& conditions) { else { lut[adc] = std::min( std::max(0, int((adc2fC(adc) - ped) * gain * rcalib / lsb_ / cosh_ieta_[cell.ietaAbs()])), MASK); - if (adc > FG_HF_thresholds_[0]) + if (adc > fg_hf_lo) lut[adc] |= QIE10_LUT_MSB0; - if (adc > FG_HF_thresholds_[1]) + if (adc > fg_hf_hi) lut[adc] |= QIE10_LUT_MSB1; } } diff --git a/CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc b/CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc index 811976266a9a0..17cae15954051 100644 --- a/CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc +++ b/CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc @@ -64,6 +64,7 @@ class HcalTPGCoderULUT : public edm::ESProducer { bool overrideDBweightsAndFilterHB_, overrideDBweightsAndFilterHE_; double linearLSB_QIE8_, linearLSB_QIE11Overlap_, linearLSB_QIE11_; int maskBit_; + bool overrideFGHF_; std::vector FG_HF_thresholds_; edm::FileInPath fgfile_, ifilename_; }; @@ -107,6 +108,7 @@ HcalTPGCoderULUT::HcalTPGCoderULUT(const edm::ParameterSet& iConfig) { linearLSB_QIE11_ = scales.getParameter("LSBQIE11"); linearLSB_QIE11Overlap_ = scales.getParameter("LSBQIE11Overlap"); maskBit_ = iConfig.getParameter("MaskBit"); + overrideFGHF_ = iConfig.getParameter("overrideFGHF"); FG_HF_thresholds_ = iConfig.getParameter >("FG_HF_thresholds"); } else { ifilename_ = iConfig.getParameter("inputLUTs"); @@ -146,6 +148,7 @@ void HcalTPGCoderULUT::buildCoder(const HcalTopology* topo, theCoder->setAllLinear(linearLUTs_, linearLSB_QIE8_, linearLSB_QIE11_, linearLSB_QIE11Overlap_); theCoder->setLUTGenerationMode(LUTGenerationMode_); theCoder->setMaskBit(maskBit_); + theCoder->setOverrideFGHF(overrideFGHF_); theCoder->setFGHFthresholds(FG_HF_thresholds_); } } diff --git a/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cff.py b/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cff.py index cd2ad5300abfd..553b6a2808411 100644 --- a/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cff.py +++ b/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cff.py @@ -24,6 +24,7 @@ overrideDBweightsAndFilterHE = cms.bool(False), tpScales = tpScales, MaskBit = cms.int32(0x8000), + overrideFGHF = cms.bool(False), FG_HF_thresholds = cms.vuint32(17, 255), inputLUTs = cms.FileInPath('CalibCalorimetry/HcalTPGAlgos/data/inputLUTcoder_physics.dat'), FGLUTs = cms.FileInPath('CalibCalorimetry/HcalTPGAlgos/data/HBHE_FG_LUT.dat'), diff --git a/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py b/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py index 18cdfe6d0c270..dc06706992cb3 100644 --- a/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py +++ b/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py @@ -46,6 +46,7 @@ latency = cms.int32(1), FG_threshold = cms.uint32(12), ## threshold for setting fine grain bit + overrideFGHF = cms.bool(False), ## switch: False = read thresholds from TPParameters (default), True = override with FG_HF_thresholds FG_HF_thresholds = cms.vuint32(17, 255), ## thresholds for setting fine grain bit ZS_threshold = cms.uint32(1), ## threshold for setting TP zero suppression