From 3629240e6bf8e22a5fbb9bfa47e2057995b75164 Mon Sep 17 00:00:00 2001 From: Michael David Krohn Date: Tue, 23 Jan 2024 15:38:24 -0600 Subject: [PATCH] squash latest commits and address perrotta comment --- .../HcalTPGAlgos/interface/LutXml.h | 1 + CalibCalorimetry/HcalTPGAlgos/src/LutXml.cc | 14 +++++ .../HcalOnlineDb/src/HcalLutManager.cc | 4 +- .../interface/HcalTriggerPrimitiveAlgo.h | 3 + .../src/HcalTriggerPrimitiveAlgo.cc | 62 ++++++++++++++++--- .../plugins/HcalTrigPrimDigiProducer.cc | 53 ++++++++++------ .../python/hcaltpdigi_cfi.py | 37 +++++++++++ 7 files changed, 144 insertions(+), 30 deletions(-) diff --git a/CalibCalorimetry/HcalTPGAlgos/interface/LutXml.h b/CalibCalorimetry/HcalTPGAlgos/interface/LutXml.h index 76e2a72b424d9..7b418c411e6f7 100644 --- a/CalibCalorimetry/HcalTPGAlgos/interface/LutXml.h +++ b/CalibCalorimetry/HcalTPGAlgos/interface/LutXml.h @@ -36,6 +36,7 @@ class LutXml : public XMLDOMBlock { std::string targetfirmware; int generalizedindex; int weight; + int codedvetothreshold; std::vector lut; std::vector mask; } Config; diff --git a/CalibCalorimetry/HcalTPGAlgos/src/LutXml.cc b/CalibCalorimetry/HcalTPGAlgos/src/LutXml.cc index 6c61eb85580c2..a5216186dc42a 100644 --- a/CalibCalorimetry/HcalTPGAlgos/src/LutXml.cc +++ b/CalibCalorimetry/HcalTPGAlgos/src/LutXml.cc @@ -50,6 +50,8 @@ LutXml::Config::_Config() { targetfirmware = "default_revision"; generalizedindex = -1; weight = -1; + // Default to keeping veto disabled + codedvetothreshold = 0; } LutXml::LutXml() : XMLDOMBlock("CFGBrickSet", 1) { init(); } @@ -113,6 +115,18 @@ void LutXml::addLut(LutXml::Config &_config, XMLDOMBlock *checksums_xml) { addParameter("SLB", "int", _config.fiber); addParameter("SLBCHAN", "int", _config.fiberchan); addParameter("WEIGHT", "int", _config.weight); + // Special coded veto threshold value of zero disables vetoing in PFA1' + if (_config.codedvetothreshold > 0) { + // A valid coded value here is in the range (1, 2048) inclusive + if (_config.codedvetothreshold <= 2048) { + // The coded value of 2048 means to do vetoing with no threshold + int actualvetothreshold = _config.codedvetothreshold == 2048 ? 0 : _config.codedvetothreshold; + addParameter("PREFIRE_VETO_THRESHOLD", "int", actualvetothreshold); + } else { + edm::LogWarning("LutXml") << "Positive veto threshold of " << _config.codedvetothreshold + << " is not in range (1, 2048) ! Vetoing will not be done in PFA1' !"; + } + } addData(to_string(_config.lut.size()), "hex", _config.lut); } else if (_config.lut_type == 5) { // channel masks addParameter("MASK_TYPE", "string", "TRIGGERCHANMASK"); diff --git a/CaloOnlineTools/HcalOnlineDb/src/HcalLutManager.cc b/CaloOnlineTools/HcalOnlineDb/src/HcalLutManager.cc index d3697365576d4..c15d8e27e7df5 100644 --- a/CaloOnlineTools/HcalOnlineDb/src/HcalLutManager.cc +++ b/CaloOnlineTools/HcalOnlineDb/src/HcalLutManager.cc @@ -979,8 +979,10 @@ std::map> HcalLutManager::getCompressionLutXmlFromC _cfg.lut = _coder.getCompressionLUT(_detid); auto pWeight = conditions->getHcalTPChannelParameter(_detid, false); - if (pWeight) + if (pWeight) { _cfg.weight = pWeight->getauxi1(); + _cfg.codedvetothreshold = pWeight->getauxi2(); + } int crot = 100 * row->crate + row->slot; unsigned int size = _cfg.lut.size(); diff --git a/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalTriggerPrimitiveAlgo.h b/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalTriggerPrimitiveAlgo.h index 11f6a00d654a4..456183cd11f4c 100644 --- a/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalTriggerPrimitiveAlgo.h +++ b/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalTriggerPrimitiveAlgo.h @@ -83,6 +83,8 @@ class HcalTriggerPrimitiveAlgo { void setPeakFinderAlgorithm(int algo); void setWeightsQIE11(const edm::ParameterSet& weightsQIE11); void setWeightQIE11(int aieta, int weight); + void setCodedVetoThresholds(const edm::ParameterSet& codedVetoThresholds); + void setCodedVetoThreshold(int aieta, int codedVetoThreshold); void setNCTScaleShift(int); void setRCTScaleShift(int); @@ -142,6 +144,7 @@ class HcalTriggerPrimitiveAlgo { bool peakfind_; std::vector weights_; std::array, 29> weightsQIE11_; + std::array codedVetoThresholds_; int latency_; uint32_t FG_threshold_; std::vector FG_HF_thresholds_; diff --git a/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc b/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc index 45611ff5a0079..7b91781fec82a 100644 --- a/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc +++ b/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc @@ -516,13 +516,12 @@ void HcalTriggerPrimitiveAlgo::analyzeQIE11(IntegerCaloSamples& samples, int sampleTSminus1 = samples[ibin]; if (fix_saturation_ && (sample_saturation.size() > ibin + 1)) - check_sat = (sample_saturation[ibin + 1] || (sampleTS >= QIE11_MAX_LINEARIZATION_ET) || - sample_saturation[ibin] || (sampleTSminus1 >= QIE11_MAX_LINEARIZATION_ET)); + check_sat |= sample_saturation[ibin + 1] | (sampleTS >= QIE11_MAX_LINEARIZATION_ET); if (sampleTS > QIE11_MAX_LINEARIZATION_ET) sampleTS = QIE11_MAX_LINEARIZATION_ET; - if (sampleTSminus1 > QIE11_MAX_LINEARIZATION_ET) + if (sampleTSminus1 > QIE11_MAX_LINEARIZATION_ET || sample_saturation[ibin]) sampleTSminus1 = QIE11_MAX_LINEARIZATION_ET; // Usually use a segmentation factor of 1.0 but for ieta >= 21 use 2 @@ -553,6 +552,26 @@ void HcalTriggerPrimitiveAlgo::analyzeQIE11(IntegerCaloSamples& samples, IntegerCaloSamples output(samples.id(), tpSamples); output.setPresamples(tpPresamples); + // Based on the |ieta| of the sample, retrieve the correct region "coded" veto threshold + // where two of the possible values have special meaning + unsigned int codedVetoThreshold = codedVetoThresholds_[theIeta]; + + // Anything in range (1, 2048) inclusive shall activate the veto + unsigned int actualVetoThreshold = codedVetoThreshold; + bool applyVetoThreshold = codedVetoThreshold > 0 && codedVetoThreshold <= 2048; + + // Special value to disable vetoing in the PFA1' algo is 0 + if (codedVetoThreshold > 0) { + if (codedVetoThreshold <= 2048) { + // Special value to run the veto in PFA1' with no threshold + if (codedVetoThreshold == 2048) + actualVetoThreshold = 0; + } else { + edm::LogWarning("HcalTPAlgo") << "Specified veto threshold value " << codedVetoThreshold + << " is not in range (1, 2048) ! Vetoing in PFA1' will not be enabled !"; + } + } + for (unsigned int ibin = 0; ibin < tpSamples; ++ibin) { // ibin - index for output TP // idx - index for samples + shift - filterPresamples @@ -580,12 +599,22 @@ void HcalTriggerPrimitiveAlgo::analyzeQIE11(IntegerCaloSamples& samples, output[ibin] = 0; } } else { - output[ibin] = std::min(sum[idx], QIE11_MAX_LINEARIZATION_ET); - - if (fix_saturation_ && force_saturation[idx] && ids.size() == 2) - output[ibin] = QIE11_MAX_LINEARIZATION_ET / 2; - else if (fix_saturation_ && force_saturation[idx]) - output[ibin] = QIE11_MAX_LINEARIZATION_ET; + // Only if the sum for the future time sample is above the veto + // threshold and the now sum is not a peak and the now sum is not + // saturated does the current sum get zeroed + if (applyVetoThreshold && sum[idx + 1] >= actualVetoThreshold && + (sum[idx] < sum[idx + 1] || force_saturation[idx + 1]) && !force_saturation[idx]) + output[ibin] = 0; + else { + // Here, either the "now" sum is a peak or the vetoing criteria are not satisfied + // so assign the appropriate sum to the output + output[ibin] = std::min(sum[idx], QIE11_MAX_LINEARIZATION_ET); + if (fix_saturation_ && force_saturation[idx]) { + output[ibin] = QIE11_MAX_LINEARIZATION_ET; + if (ids.size() == 2) + output[ibin] /= 2; + } + } } // peak-finding is not applied for FG bits // compute(msb) returns two bits (MIP). compute(timingTDC,ids) returns 6 bits (1 depth, 1 prompt, 1 delayed 01, 1 delayed 10, 2 reserved) @@ -1067,6 +1096,21 @@ void HcalTriggerPrimitiveAlgo::setWeightQIE11(int aieta, int weight) { weightsQIE11_[aieta] = {{weight, 255}}; } +void HcalTriggerPrimitiveAlgo::setCodedVetoThresholds(const edm::ParameterSet& codedVetoThresholds) { + // Names are just abs(ieta) for HBHE + std::vector ietaStrs = codedVetoThresholds.getParameterNames(); + for (auto& ietaStr : ietaStrs) { + // Strip off "ieta" part of key and just use integer value in map + auto const& v = codedVetoThresholds.getParameter(ietaStr); + codedVetoThresholds_[std::stoi(ietaStr.substr(4))] = {v}; + } +} + +void HcalTriggerPrimitiveAlgo::setCodedVetoThreshold(int aieta, int codedVetoThreshold) { + // Simple map of |ieta| in HBHE to veto threshold + codedVetoThresholds_[aieta] = {codedVetoThreshold}; +} + void HcalTriggerPrimitiveAlgo::setPeakFinderAlgorithm(int algo) { if (algo <= 0 || algo > 2) throw cms::Exception("ERROR: Only algo 1 & 2 are supported.") << std::endl; diff --git a/SimCalorimetry/HcalTrigPrimProducers/plugins/HcalTrigPrimDigiProducer.cc b/SimCalorimetry/HcalTrigPrimProducers/plugins/HcalTrigPrimDigiProducer.cc index 7a6f069385816..3fddb13fd68e5 100644 --- a/SimCalorimetry/HcalTrigPrimProducers/plugins/HcalTrigPrimDigiProducer.cc +++ b/SimCalorimetry/HcalTrigPrimProducers/plugins/HcalTrigPrimDigiProducer.cc @@ -52,6 +52,9 @@ class HcalTrigPrimDigiProducer : public edm::stream::EDProducer<> { edm::EDGetTokenT tok_hbhe_; edm::EDGetTokenT tok_hf_; + bool overrideDBvetoThresholdsHE_; + bool overrideDBvetoThresholdsHB_; + bool overrideDBweightsAndFilterHE_; bool overrideDBweightsAndFilterHB_; @@ -104,10 +107,14 @@ HcalTrigPrimDigiProducer::HcalTrigPrimDigiProducer(const edm::ParameterSet& ps) upgrade_ = std::any_of(std::begin(upgrades), std::end(upgrades), [](bool a) { return a; }); legacy_ = std::any_of(std::begin(upgrades), std::end(upgrades), [](bool a) { return !a; }); + overrideDBvetoThresholdsHE_ = ps.getParameter("overrideDBvetoThresholdsHE"); + overrideDBvetoThresholdsHB_ = ps.getParameter("overrideDBvetoThresholdsHB"); + overrideDBweightsAndFilterHE_ = ps.getParameter("overrideDBweightsAndFilterHE"); overrideDBweightsAndFilterHB_ = ps.getParameter("overrideDBweightsAndFilterHB"); theAlgo_.setWeightsQIE11(ps.getParameter("weightsQIE11")); + theAlgo_.setCodedVetoThresholds(ps.getParameter("codedVetoThresholds")); if (ps.exists("parameters")) { auto pset = ps.getUntrackedParameter("parameters"); @@ -173,40 +180,46 @@ void HcalTrigPrimDigiProducer::beginRun(const edm::Run& run, const edm::EventSet continue; int aieta = abs(hcalTTDetId.ieta()); + // Do not let ieta 29 in the map + if (aieta >= lastHERing) + continue; // Filter weight represented in fixed point 8 bit - int fixedPointWeight = -1; + int fixedPointWeight = 255; + // Coded veto threshold in range (0, 2048) + // Default, special value of 0 will disable vetoing + int codedVetoThreshold = 0; + // Number of filter presamples + int presamples = 0; // The absence of TT channels in the HcalTPChannelParameters // is intepreted as to not use the new filter auto tpParam = db->getHcalTPChannelParameter(hcalTTDetId, false); - if (tpParam) + if (tpParam) { + // Fix number of filter presamples to one if we are using DB weights + // Size of filter is already known when using DB weights + // Weight from DB represented as 8-bit integer fixedPointWeight = tpParam->getauxi1(); + codedVetoThreshold = tpParam->getauxi2(); + presamples = 1; + } - // Do not let ieta 29 in the map // If the aieta already has a weight in the map, then move on if (aieta <= lastHBRing) { - // Fix number of filter presamples to one if we are using DB weights - // Size of filter is already known when using DB weights - // Weight from DB represented as 8-bit integer + if (!overrideDBvetoThresholdsHB_) { + theAlgo_.setCodedVetoThreshold(aieta, codedVetoThreshold); + } if (!overrideDBweightsAndFilterHB_) { - if (fixedPointWeight != -1) { - theAlgo_.setNumFilterPresamplesHBQIE11(1); - theAlgo_.setWeightQIE11(aieta, fixedPointWeight); - } else { - theAlgo_.setNumFilterPresamplesHBQIE11(0); - theAlgo_.setWeightQIE11(aieta, 255); - } + theAlgo_.setNumFilterPresamplesHBQIE11(presamples); + theAlgo_.setWeightQIE11(aieta, fixedPointWeight); } } else if (aieta < lastHERing) { + if (!overrideDBvetoThresholdsHE_) { + theAlgo_.setCodedVetoThreshold(aieta, codedVetoThreshold); + } if (!overrideDBweightsAndFilterHE_) { - if (fixedPointWeight != -1) { - theAlgo_.setNumFilterPresamplesHEQIE11(1); - theAlgo_.setWeightQIE11(aieta, fixedPointWeight); - } else { - theAlgo_.setNumFilterPresamplesHEQIE11(0); - theAlgo_.setWeightQIE11(aieta, 255); - } + theAlgo_.setNumFilterPresamplesHEQIE11(presamples); + theAlgo_.setWeightQIE11(aieta, fixedPointWeight); } } } diff --git a/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py b/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py index 04b4dc44ef486..18cdfe6d0c270 100644 --- a/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py +++ b/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py @@ -48,6 +48,43 @@ FG_threshold = cms.uint32(12), ## threshold for setting fine grain bit FG_HF_thresholds = cms.vuint32(17, 255), ## thresholds for setting fine grain bit ZS_threshold = cms.uint32(1), ## threshold for setting TP zero suppression + + # To be used when overriding the CondDB, default is with vetoing off ("coded" threshold = 0) + # To run PFA1' + vetoing with no threshold, use 2048 + # All other values (1, 2047) are interpreted literally as the PFA1' veto threshold + codedVetoThresholds = cms.PSet( + ieta1 = cms.int32(0), + ieta2 = cms.int32(0), + ieta3 = cms.int32(0), + ieta4 = cms.int32(0), + ieta5 = cms.int32(0), + ieta6 = cms.int32(0), + ieta7 = cms.int32(0), + ieta8 = cms.int32(0), + ieta9 = cms.int32(0), + ieta10 = cms.int32(0), + ieta11 = cms.int32(0), + ieta12 = cms.int32(0), + ieta13 = cms.int32(0), + ieta14 = cms.int32(0), + ieta15 = cms.int32(0), + ieta16 = cms.int32(0), + ieta17 = cms.int32(0), + ieta18 = cms.int32(0), + ieta19 = cms.int32(0), + ieta20 = cms.int32(0), + ieta21 = cms.int32(0), + ieta22 = cms.int32(0), + ieta23 = cms.int32(0), + ieta24 = cms.int32(0), + ieta25 = cms.int32(0), + ieta26 = cms.int32(0), + ieta27 = cms.int32(0), + ieta28 = cms.int32(0) + ), + + overrideDBvetoThresholdsHB = cms.bool(False), + overrideDBvetoThresholdsHE = cms.bool(False), numberOfSamples = cms.int32(4), numberOfPresamples = cms.int32(2), numberOfSamplesHF = cms.int32(4),