diff --git a/CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h b/CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h index f71d2132ca276..ffb3467adc171 100644 --- a/CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h +++ b/CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h @@ -82,6 +82,10 @@ class HcaluLUTTPGCoder : public HcalTPGCoder { void setOverrideDBweightsAndFilterHE(bool overrideDBweightsAndFilterHE) { overrideDBweightsAndFilterHE_ = overrideDBweightsAndFilterHE; } + void setNpedWidthsForZS(float nPedWidthsForZS) { nPedWidthsForZS_ = nPedWidthsForZS; } + void setOverrideDBnPedWidthsForZS(bool overrideDBnPedWidthsForZS) { + overrideDBnPedWidthsForZS_ = overrideDBnPedWidthsForZS; + } void lookupMSB(const HBHEDataFrame& df, std::vector& msb) const; void lookupMSB(const QIE10DataFrame& df, std::vector>& msb) const; void lookupMSB(const QIE11DataFrame& df, std::vector>& msb) const; @@ -141,6 +145,8 @@ class HcaluLUTTPGCoder : public HcalTPGCoder { std::unique_ptr pulseCorr_; bool overrideDBweightsAndFilterHB_ = false; bool overrideDBweightsAndFilterHE_ = false; + float nPedWidthsForZS_ = 0.0; + bool overrideDBnPedWidthsForZS_ = false; }; #endif diff --git a/CalibCalorimetry/HcalTPGAlgos/src/HcaluLUTTPGCoder.cc b/CalibCalorimetry/HcalTPGAlgos/src/HcaluLUTTPGCoder.cc index 0e2bc91030afc..67526ccc6fefc 100644 --- a/CalibCalorimetry/HcalTPGAlgos/src/HcaluLUTTPGCoder.cc +++ b/CalibCalorimetry/HcalTPGAlgos/src/HcaluLUTTPGCoder.cc @@ -464,6 +464,16 @@ void HcaluLUTTPGCoder::update(const HcalDbService& conditions) { bool is2018OrLater = topo_->triggerMode() >= HcalTopologyMode::TriggerMode_2018 or topo_->triggerMode() == HcalTopologyMode::TriggerMode_2018legacy; + // The number of pedestal widths for ZS is packed into the third byte + // of the 32 bit auxi1 variable from HcalTPParameters + // Assume a fixed-point SF of 1 / 16 to convert to final number of widths + float nPedWidthsForZSfromDB = ((aux1 & 0xFF0000u) >> 16) / 16.0; + + // If overriding with corresponding param in python or the extracted value from third byte of HcalTPParameters auxi1 is 0, + // use the param from python. Otherwise, take the value as extracted from DB + float nPedWidthsForZSfinal = + (overrideDBnPedWidthsForZS_ or nPedWidthsForZSfromDB == 0) ? nPedWidthsForZS_ : nPedWidthsForZSfromDB; + for (const auto& id : metadata->getAllChannels()) { if (id.det() == DetId::Hcal and topo_->valid(id)) { HcalDetId cell(id); @@ -479,9 +489,16 @@ void HcaluLUTTPGCoder::update(const HcalDbService& conditions) { int lutId = getLUTId(cell); Lut& lut = inputLUT_[lutId]; float ped = 0; + float pedwidth = 0; float gain = 0; uint32_t status = 0; + const HcalCalibrationWidths& calibrationWidths = conditions.getHcalCalibrationWidths(cell); + for (auto capId : {0, 1, 2, 3}) { + pedwidth += calibrationWidths.effpedestal(capId); + } + pedwidth /= 4.0; + if (LUTGenerationMode_) { const HcalCalibrations& calibrations = conditions.getHcalCalibrations(cell); for (auto capId : {0, 1, 2, 3}) { @@ -574,17 +591,22 @@ void HcaluLUTTPGCoder::update(const HcalDbService& conditions) { } } if (allLinear_) - lut[adc] = (LutElement)std::min( - std::max(0, - int((adc2fC(adc) - ped) * gain * rcalib * nonlinearityCorrection * containmentCorrection / - linearLSB / cosh_ieta(cell.ietaAbs(), cell.depth(), HcalEndcap))), - MASK); + lut[adc] = + adc2fC(adc) - (ped + nPedWidthsForZSfinal * pedwidth) <= 0 + ? 0 + : (LutElement)std::min(std::max(0, + int((adc2fC(adc) - ped) * gain * rcalib * nonlinearityCorrection * + containmentCorrection / linearLSB / + cosh_ieta(cell.ietaAbs(), cell.depth(), HcalEndcap))), + MASK); else lut[adc] = - (LutElement)std::min(std::max(0, - int((adc2fC(adc) - ped) * gain * rcalib * nonlinearityCorrection * - containmentCorrection / nominalgain_ / granularity)), - MASK); + adc2fC(adc) - (ped + nPedWidthsForZSfinal * pedwidth) <= 0 + ? 0 + : (LutElement)std::min(std::max(0, + int((adc2fC(adc) - ped) * gain * rcalib * nonlinearityCorrection * + containmentCorrection / nominalgain_ / granularity)), + MASK); unsigned int linearizedADC = lut[adc]; // used for bits 12, 13, 14, 15 for Group 0 LUT for LLP time and depth bits that rely on linearized energies diff --git a/CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc b/CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc index 08abd5cf408ba..c502dc1e1d49e 100644 --- a/CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc +++ b/CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc @@ -62,6 +62,8 @@ class HcalTPGCoderULUT : public edm::ESProducer { double containPhaseNSHB_, containPhaseNSHE_; bool applyFixPCC_; bool overrideDBweightsAndFilterHB_, overrideDBweightsAndFilterHE_; + double nPedWidthsForZS_; + bool overrideDBnPedWidthsForZS_; double linearLSB_QIE8_, linearLSB_QIE11Overlap_, linearLSB_QIE11_; int maskBit_; bool overrideFGHF_; @@ -93,6 +95,8 @@ HcalTPGCoderULUT::HcalTPGCoderULUT(const edm::ParameterSet& iConfig) { containPhaseNSHE_ = iConfig.getParameter("containPhaseNSHE"); overrideDBweightsAndFilterHB_ = iConfig.getParameter("overrideDBweightsAndFilterHB"); overrideDBweightsAndFilterHE_ = iConfig.getParameter("overrideDBweightsAndFilterHE"); + nPedWidthsForZS_ = iConfig.getParameter("nPedWidthsForZS"); + overrideDBnPedWidthsForZS_ = iConfig.getParameter("overrideDBnPedWidthsForZS"); applyFixPCC_ = iConfig.getParameter("applyFixPCC"); //the following line is needed to tell the framework what @@ -135,6 +139,9 @@ void HcalTPGCoderULUT::buildCoder(const HcalTopology* topo, theCoder->setContainPhaseHB(containPhaseNSHB_); theCoder->setContainPhaseHE(containPhaseNSHE_); + theCoder->setNpedWidthsForZS(nPedWidthsForZS_); + theCoder->setOverrideDBnPedWidthsForZS(overrideDBnPedWidthsForZS_); + theCoder->setApplyFixPCC(applyFixPCC_); if (read_Ascii_ || read_XML_) { diff --git a/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cff.py b/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cff.py index 672d2b036cf95..5c03b75f288c5 100644 --- a/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cff.py +++ b/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cff.py @@ -22,6 +22,8 @@ applyFixPCC = PCCUpdate.applyFixPCC, overrideDBweightsAndFilterHB = cms.bool(False), overrideDBweightsAndFilterHE = cms.bool(False), + nPedWidthsForZS = cms.double(0.0), + overrideDBnPedWidthsForZS = cms.bool(False), tpScales = tpScales, MaskBit = cms.int32(0x8000), overrideFGHF = cms.bool(False),