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

Fix undefined behavior in EgammaTowerIsolation #31170

Merged
merged 1 commit into from Aug 20, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h
Expand Up @@ -53,13 +53,13 @@ class EgammaTowerIsolationNew {

~EgammaTowerIsolationNew() { delete[] mem; }

void compute(
bool et, Sum& sum, reco::Candidate const& cand, CaloTowerDetId const* first, CaloTowerDetId const* last) const {
template <typename I>
void compute(bool et, Sum& sum, reco::Candidate const& cand, I first, I last) const {
reco::SuperCluster const& sc = *cand.get<reco::SuperClusterRef>().get();
return compute(et, sum, sc, first, last);
}
void compute(
bool et, Sum& sum, reco::SuperCluster const& sc, CaloTowerDetId const* first, CaloTowerDetId const* last) const;
template <typename I>
void compute(bool et, Sum& sum, reco::SuperCluster const& sc, I first, I last) const;

void setRadius(float const extRadius[NC], float const intRadius[NC]) {
for (std::size_t i = 0; i != NCuts; ++i) {
Expand Down Expand Up @@ -153,8 +153,9 @@ inline EgammaTowerIsolationNew<NC>::EgammaTowerIsolationNew(float extRadius[NC],
}

template <unsigned int NC>
template <typename I>
inline void EgammaTowerIsolationNew<NC>::compute(
bool et, Sum& sum, reco::SuperCluster const& sc, CaloTowerDetId const* first, CaloTowerDetId const* last) const {
bool et, Sum& sum, reco::SuperCluster const& sc, I first, I last) const {
if (nt == 0)
return;

Expand Down
11 changes: 6 additions & 5 deletions RecoEgamma/EgammaIsolationAlgos/src/EgammaTowerIsolation.cc
Expand Up @@ -58,11 +58,12 @@ double EgammaTowerIsolation::getSum(bool et,
tls.newAlgo->setRadius(&extRadius, &intRadius);

EgammaTowerIsolationNew<1>::Sum sum;
tls.newAlgo->compute(et,
sum,
sc,
(detIdToExclude == nullptr) ? nullptr : &((*detIdToExclude).front()),
(detIdToExclude == nullptr) ? nullptr : (&(*detIdToExclude).back()) + 1);
if (detIdToExclude == nullptr) {
tls.newAlgo->compute(
et, sum, sc, static_cast<CaloTowerDetId const*>(nullptr), static_cast<CaloTowerDetId const*>(nullptr));
} else {
tls.newAlgo->compute(et, sum, sc, detIdToExclude->cbegin(), detIdToExclude->cend());
}

switch (depth_) {
case AllDepths:
Expand Down
3 changes: 2 additions & 1 deletion RecoEgamma/EgammaIsolationAlgos/test/EgammaTowerIso_t.cpp
Expand Up @@ -9,7 +9,8 @@ int main() {

CaloTower cand;
EgammaTowerIsolationNew<2>::Sum sum;
iso.compute(true, sum, cand, nullptr, nullptr);
iso.compute(
true, sum, cand, static_cast<CaloTowerDetId const*>(nullptr), static_cast<CaloTowerDetId const*>(nullptr));

return 0;
}