Skip to content

Commit

Permalink
Merge pull request #38753 from Michael-Krohn/integer-math-hcal-tps
Browse files Browse the repository at this point in the history
HCAL: Bugfix of PFA1' Trigger Primitive algo by switching to integer based math
  • Loading branch information
cmsbuild committed Jul 22, 2022
2 parents 89e207c + 8414339 commit bb439bc
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 63 deletions.
Expand Up @@ -80,7 +80,7 @@ class HcalTriggerPrimitiveAlgo {
HcalTrigPrimDigiCollection& result);
void setPeakFinderAlgorithm(int algo);
void setWeightsQIE11(const edm::ParameterSet& weightsQIE11);
void setWeightQIE11(int aieta, double weight);
void setWeightQIE11(int aieta, int weight);
void setNCTScaleShift(int);
void setRCTScaleShift(int);

Expand Down Expand Up @@ -136,7 +136,7 @@ class HcalTriggerPrimitiveAlgo {
double theThreshold;
bool peakfind_;
std::vector<double> weights_;
std::array<std::array<double, 2>, 29> weightsQIE11_;
std::array<std::array<int, 2>, 29> weightsQIE11_;
int latency_;
uint32_t FG_threshold_;
std::vector<uint32_t> FG_HF_thresholds_;
Expand Down
90 changes: 64 additions & 26 deletions SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc
Expand Up @@ -439,38 +439,76 @@ void HcalTriggerPrimitiveAlgo::analyzeQIE11(IntegerCaloSamples& samples,
for (unsigned int ibin = 0; ibin < dgSamples - shrink; ++ibin) {
int algosumvalue = 0;
bool check_sat = false;
for (unsigned int i = 0; i < filterSamples; i++) {
//TP energy calculation for PFA2
if (weightsQIE11_[theIeta][0] == 255) {
for (unsigned int i = 0; i < filterSamples; i++) {
//add up value * scale factor
// In addition, divide by two in the 10 degree phi segmentation region
// to mimic 5 degree segmentation for the trigger
unsigned int sample = samples[ibin + i];

if (fix_saturation_ && (sample_saturation.size() > ibin + i))
check_sat = (check_sat | sample_saturation[ibin + i] | (sample > QIE11_MAX_LINEARIZATION_ET));

if (sample > QIE11_MAX_LINEARIZATION_ET)
sample = QIE11_MAX_LINEARIZATION_ET;

// Usually use a segmentation factor of 1.0 but for ieta >= 21 use 2
int segmentationFactor = 1;
if (ids.size() == 2) {
segmentationFactor = 2;
}

algosumvalue += int(sample / segmentationFactor);
}
if (algosumvalue < 0)
sum[ibin] = 0; // low-side
//high-side
//else if (algosumvalue>QIE11_LINEARIZATION_ET) sum[ibin]=QIE11_LINEARIZATION_ET;
else
sum[ibin] = algosumvalue; //assign value to sum[]

if (check_sat)
force_saturation[ibin] = true;
//TP energy calculation for PFA1' and PFA1
} else {
//add up value * scale factor
// In addition, divide by two in the 10 degree phi segmentation region
// to mimic 5 degree segmentation for the trigger
unsigned int sample = samples[ibin + i];
int sampleTS = samples[ibin + 1];
int sampleTSminus1 = samples[ibin];

if (fix_saturation_ && (sample_saturation.size() > ibin + i))
check_sat = (check_sat | sample_saturation[ibin + i] | (sample > QIE11_MAX_LINEARIZATION_ET));
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));

if (sample > QIE11_MAX_LINEARIZATION_ET)
sample = QIE11_MAX_LINEARIZATION_ET;
if (sampleTS > QIE11_MAX_LINEARIZATION_ET)
sampleTS = QIE11_MAX_LINEARIZATION_ET;

// Usually use a segmentation factor of 1.0 but for ieta >= 21 use 0.5
double segmentationFactor = 1.0;
if (sampleTSminus1 > QIE11_MAX_LINEARIZATION_ET)
sampleTSminus1 = QIE11_MAX_LINEARIZATION_ET;

// Usually use a segmentation factor of 1.0 but for ieta >= 21 use 2
int segmentationFactor = 1;
if (ids.size() == 2) {
segmentationFactor = 0.5;
segmentationFactor = 2;
}

// Based on the |ieta| of the sample, retrieve the correct region weight
double theWeight = weightsQIE11_[theIeta][i];
int theWeight = weightsQIE11_[theIeta][0];

algosumvalue += int(sample * segmentationFactor * theWeight);
}
if (algosumvalue < 0)
sum[ibin] = 0; // low-side
//high-side
//else if (algosumvalue>QIE11_LINEARIZATION_ET) sum[ibin]=QIE11_LINEARIZATION_ET;
else
sum[ibin] = algosumvalue; //assign value to sum[]
algosumvalue = ((sampleTS << 8) - (sampleTSminus1 * theWeight)) / 256 / segmentationFactor;

if (algosumvalue < 0)
sum[ibin] = 0; // low-side
//high-side
//else if (algosumvalue>QIE11_LINEARIZATION_ET) sum[ibin]=QIE11_LINEARIZATION_ET;
else
sum[ibin] = algosumvalue; //assign value to sum[]

if (check_sat)
force_saturation[ibin] = true;
if (check_sat)
force_saturation[ibin] = true;
}
}

std::vector<int> finegrain(tpSamples, false);
Expand All @@ -490,13 +528,13 @@ void HcalTriggerPrimitiveAlgo::analyzeQIE11(IntegerCaloSamples& samples,
}

//Only run the peak-finder when the PFA2 FIR filter is running, which corresponds to weights = 1
if (weightsQIE11_[theIeta][0] == 1) {
if (weightsQIE11_[theIeta][0] == 255) {
bool isPeak = (sum[idx] > sum[idx - 1] && sum[idx] >= sum[idx + 1] && sum[idx] > theThreshold);
if (isPeak) {
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 * 0.5;
output[ibin] = QIE11_MAX_LINEARIZATION_ET / 2;
else if (fix_saturation_ && force_saturation[idx])
output[ibin] = QIE11_MAX_LINEARIZATION_ET;

Expand All @@ -508,7 +546,7 @@ void HcalTriggerPrimitiveAlgo::analyzeQIE11(IntegerCaloSamples& samples,
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 * 0.5;
output[ibin] = QIE11_MAX_LINEARIZATION_ET / 2;
else if (fix_saturation_ && force_saturation[idx])
output[ibin] = QIE11_MAX_LINEARIZATION_ET;
}
Expand Down Expand Up @@ -957,15 +995,15 @@ void HcalTriggerPrimitiveAlgo::setWeightsQIE11(const edm::ParameterSet& weightsQ
std::vector<std::string> ietaStrs = weightsQIE11.getParameterNames();
for (auto& ietaStr : ietaStrs) {
// Strip off "ieta" part of key and just use integer value in map
auto const& v = weightsQIE11.getParameter<std::vector<double>>(ietaStr);
auto const& v = weightsQIE11.getParameter<std::vector<int>>(ietaStr);
weightsQIE11_[std::stoi(ietaStr.substr(4))] = {{v[0], v[1]}};
}
}

void HcalTriggerPrimitiveAlgo::setWeightQIE11(int aieta, double weight) {
void HcalTriggerPrimitiveAlgo::setWeightQIE11(int aieta, int weight) {
// Simple map of |ieta| in HBHE to weight
// Only one weight for SOI-1 TS
weightsQIE11_[aieta] = {{weight, 1.0}};
weightsQIE11_[aieta] = {{weight, 255}};
}

void HcalTriggerPrimitiveAlgo::setPeakFinderAlgorithm(int algo) {
Expand Down
Expand Up @@ -175,7 +175,7 @@ void HcalTrigPrimDigiProducer::beginRun(const edm::Run& run, const edm::EventSet
int aieta = abs(hcalTTDetId.ieta());

// Filter weight represented in fixed point 8 bit
int fixedPointWeight = -1.0;
int fixedPointWeight = -1;

// The absence of TT channels in the HcalTPChannelParameters
// is intepreted as to not use the new filter
Expand All @@ -190,22 +190,22 @@ void HcalTrigPrimDigiProducer::beginRun(const edm::Run& run, const edm::EventSet
// Size of filter is already known when using DB weights
// Weight from DB represented as 8-bit integer
if (!overrideDBweightsAndFilterHB_) {
if (fixedPointWeight != -1.0) {
if (fixedPointWeight != -1) {
theAlgo_.setNumFilterPresamplesHBQIE11(1);
theAlgo_.setWeightQIE11(aieta, -static_cast<double>(fixedPointWeight) / 256.0);
theAlgo_.setWeightQIE11(aieta, fixedPointWeight);
} else {
theAlgo_.setNumFilterPresamplesHBQIE11(0);
theAlgo_.setWeightQIE11(aieta, 1.0);
theAlgo_.setWeightQIE11(aieta, 255);
}
}
} else if (aieta < lastHERing) {
if (!overrideDBweightsAndFilterHE_) {
if (fixedPointWeight != -1.0) {
if (fixedPointWeight != -1) {
theAlgo_.setNumFilterPresamplesHEQIE11(1);
theAlgo_.setWeightQIE11(aieta, -static_cast<double>(fixedPointWeight) / 256.0);
theAlgo_.setWeightQIE11(aieta, fixedPointWeight);
} else {
theAlgo_.setNumFilterPresamplesHEQIE11(0);
theAlgo_.setWeightQIE11(aieta, 1.0);
theAlgo_.setWeightQIE11(aieta, 255);
}
}
}
Expand Down
56 changes: 28 additions & 28 deletions SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py
Expand Up @@ -18,34 +18,34 @@
peakFilter = cms.bool(True),
weights = cms.vdouble(1.0, 1.0), ##hardware algo
weightsQIE11 = cms.PSet(
ieta1 = cms.vdouble(1.0, 1.0),
ieta2 = cms.vdouble(1.0, 1.0),
ieta3 = cms.vdouble(1.0, 1.0),
ieta4 = cms.vdouble(1.0, 1.0),
ieta5 = cms.vdouble(1.0, 1.0),
ieta6 = cms.vdouble(1.0, 1.0),
ieta7 = cms.vdouble(1.0, 1.0),
ieta8 = cms.vdouble(1.0, 1.0),
ieta9 = cms.vdouble(1.0, 1.0),
ieta10 = cms.vdouble(1.0, 1.0),
ieta11 = cms.vdouble(1.0, 1.0),
ieta12 = cms.vdouble(1.0, 1.0),
ieta13 = cms.vdouble(1.0, 1.0),
ieta14 = cms.vdouble(1.0, 1.0),
ieta15 = cms.vdouble(1.0, 1.0),
ieta16 = cms.vdouble(1.0, 1.0),
ieta17 = cms.vdouble(1.0, 1.0),
ieta18 = cms.vdouble(1.0, 1.0),
ieta19 = cms.vdouble(1.0, 1.0),
ieta20 = cms.vdouble(1.0, 1.0),
ieta21 = cms.vdouble(1.0, 1.0),
ieta22 = cms.vdouble(1.0, 1.0),
ieta23 = cms.vdouble(1.0, 1.0),
ieta24 = cms.vdouble(1.0, 1.0),
ieta25 = cms.vdouble(1.0, 1.0),
ieta26 = cms.vdouble(1.0, 1.0),
ieta27 = cms.vdouble(1.0, 1.0),
ieta28 = cms.vdouble(1.0, 1.0)
ieta1 = cms.vint32(255, 255),
ieta2 = cms.vint32(255, 255),
ieta3 = cms.vint32(255, 255),
ieta4 = cms.vint32(255, 255),
ieta5 = cms.vint32(255, 255),
ieta6 = cms.vint32(255, 255),
ieta7 = cms.vint32(255, 255),
ieta8 = cms.vint32(255, 255),
ieta9 = cms.vint32(255, 255),
ieta10 = cms.vint32(255, 255),
ieta11 = cms.vint32(255, 255),
ieta12 = cms.vint32(255, 255),
ieta13 = cms.vint32(255, 255),
ieta14 = cms.vint32(255, 255),
ieta15 = cms.vint32(255, 255),
ieta16 = cms.vint32(255, 255),
ieta17 = cms.vint32(255, 255),
ieta18 = cms.vint32(255, 255),
ieta19 = cms.vint32(255, 255),
ieta20 = cms.vint32(255, 255),
ieta21 = cms.vint32(255, 255),
ieta22 = cms.vint32(255, 255),
ieta23 = cms.vint32(255, 255),
ieta24 = cms.vint32(255, 255),
ieta25 = cms.vint32(255, 255),
ieta26 = cms.vint32(255, 255),
ieta27 = cms.vint32(255, 255),
ieta28 = cms.vint32(255, 255)
),

latency = cms.int32(1),
Expand Down

0 comments on commit bb439bc

Please sign in to comment.