Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport to 14_0_X (#44337)]: Add Veto Threshold to HCAL TP Emulator #44556

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CalibCalorimetry/HcalTPGAlgos/interface/LutXml.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class LutXml : public XMLDOMBlock {
std::string targetfirmware;
int generalizedindex;
int weight;
int codedvetothreshold;
std::vector<unsigned int> lut;
std::vector<uint64_t> mask;
} Config;
Expand Down
14 changes: 14 additions & 0 deletions CalibCalorimetry/HcalTPGAlgos/src/LutXml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion CaloOnlineTools/HcalOnlineDb/src/HcalLutManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,10 @@ std::map<int, std::shared_ptr<LutXml>> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -142,6 +144,7 @@ class HcalTriggerPrimitiveAlgo {
bool peakfind_;
std::vector<double> weights_;
std::array<std::array<int, 2>, 29> weightsQIE11_;
std::array<int, 29> codedVetoThresholds_;
int latency_;
uint32_t FG_threshold_;
std::vector<uint32_t> FG_HF_thresholds_;
Expand Down
62 changes: 53 additions & 9 deletions SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -580,12 +599,22 @@ void HcalTriggerPrimitiveAlgo::analyzeQIE11(IntegerCaloSamples& samples,
output[ibin] = 0;
}
} else {
output[ibin] = std::min<unsigned int>(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<unsigned int>(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)
Expand Down Expand Up @@ -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<std::string> 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<int>(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class HcalTrigPrimDigiProducer : public edm::stream::EDProducer<> {
edm::EDGetTokenT<HBHEDigiCollection> tok_hbhe_;
edm::EDGetTokenT<HFDigiCollection> tok_hf_;

bool overrideDBvetoThresholdsHE_;
bool overrideDBvetoThresholdsHB_;

bool overrideDBweightsAndFilterHE_;
bool overrideDBweightsAndFilterHB_;

Expand Down Expand Up @@ -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<bool>("overrideDBvetoThresholdsHE");
overrideDBvetoThresholdsHB_ = ps.getParameter<bool>("overrideDBvetoThresholdsHB");

overrideDBweightsAndFilterHE_ = ps.getParameter<bool>("overrideDBweightsAndFilterHE");
overrideDBweightsAndFilterHB_ = ps.getParameter<bool>("overrideDBweightsAndFilterHB");

theAlgo_.setWeightsQIE11(ps.getParameter<edm::ParameterSet>("weightsQIE11"));
theAlgo_.setCodedVetoThresholds(ps.getParameter<edm::ParameterSet>("codedVetoThresholds"));

if (ps.exists("parameters")) {
auto pset = ps.getUntrackedParameter<edm::ParameterSet>("parameters");
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down