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

Remove a dead assignment of accChargeForToA in the HGCDigitizer #39622

Merged
merged 2 commits into from
Jan 21, 2023
Merged
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
28 changes: 13 additions & 15 deletions SimCalorimetry/HGCalSimProducers/plugins/HGCDigitizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
#include "DataFormats/Math/interface/liblogintpack.h"
#include <algorithm>
#include <boost/foreach.hpp>
#include "FWCore/Utilities/interface/transform.h"

//#define EDM_ML_DEBUG
Expand Down Expand Up @@ -201,25 +200,24 @@ namespace {
int waferThickness = getCellThickness(geom, detectorId);
float cell_threshold = tdcForToAOnset[waferThickness - 1];
const auto& hitRec = hitmapIterator.second;
float accChargeForToA(0.f), fireTDC(0.f);
float fireTDC(0.f);
const auto aboveThrPos = std::upper_bound(
hitRec.begin(), hitRec.end(), std::make_pair(cell_threshold, 0.f), [](const auto& i, const auto& j) {
return i.first < j.first;
});

if (aboveThrPos == hitRec.end()) {
accChargeForToA = hitRec.back().first;
fireTDC = 0.f;
} else if (hitRec.end() - aboveThrPos > 0 || orderChanged) {
accChargeForToA = aboveThrPos->first;
fireTDC = aboveThrPos->second;
if (aboveThrPos - hitRec.begin() >= 1) {
const auto& belowThrPos = aboveThrPos - 1;
float chargeBeforeThr = belowThrPos->first;
float timeBeforeThr = belowThrPos->second;
float deltaQ = accChargeForToA - chargeBeforeThr;
float deltaTOF = fireTDC - timeBeforeThr;
fireTDC = (cell_threshold - chargeBeforeThr) * deltaTOF / deltaQ + timeBeforeThr;
if (aboveThrPos != hitRec.end()) {
if (hitRec.end() - aboveThrPos > 0 || orderChanged) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rovere, if I am not wrong aboveThrPos can never be larger than hitRec.end(), it being bound between hitRec.begin() and hitRec.end(), see https://github.com/cms-sw/cmssw/pull/39622/files#diff-563eece7ae99b29c2501955e163a955bd6940d6fa39094e919eee33975bdb1f2R204-R207

Therefore, given the L209 the check of orderChanged can never be done.

Please notice that this was the same already in the original code: my fix simply reproduces the original logic but avoiding the dead assignment. If this observation of mine is correct, the original code was already bugged, and the dead assignment reported by the static analyzer helped to spot the bug. (And if so, of course, this PR has to be updated with a more proper fix that I'd suggest either you or some other HGCal code developer take care of).

fireTDC = aboveThrPos->second;
if (aboveThrPos - hitRec.begin() >= 1) {
float accChargeForToA = aboveThrPos->first;
const auto& belowThrPos = aboveThrPos - 1;
float chargeBeforeThr = belowThrPos->first;
float timeBeforeThr = belowThrPos->second;
float deltaQ = accChargeForToA - chargeBeforeThr;
float deltaTOF = fireTDC - timeBeforeThr;
fireTDC = (cell_threshold - chargeBeforeThr) * deltaTOF / deltaQ + timeBeforeThr;
}
}
}
(simIt->second).hit_info[1][9] = fireTDC;
Expand Down