Skip to content

Commit

Permalink
Merge pull request #35955 from slava77/CMSSW_12_1_0_pre5/sign1128/hca…
Browse files Browse the repository at this point in the history
…lSum

mitigate high CPU cost of HBHE hit position calculation in EgammaHcalIsolation
  • Loading branch information
cmsbuild authored Nov 3, 2021
2 parents 0b448d0 + f33bdaa commit 69ae98c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ class EgammaHcalIsolation {
}

private:
double goodHitEnergy(const GlobalPoint &pclu,
double goodHitEnergy(float pcluEta,
float pcluPhi,
const HBHERecHit &hit,
int depth,
int ieta,
Expand Down
48 changes: 29 additions & 19 deletions RecoEgamma/EgammaIsolationAlgos/src/EgammaHcalIsolation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,52 +118,60 @@ EgammaHcalIsolation::EgammaHcalIsolation(InclusionRule extIncRule,
}
}

double EgammaHcalIsolation::goodHitEnergy(const GlobalPoint &pclu,
double EgammaHcalIsolation::goodHitEnergy(float pcluEta,
float pcluPhi,
const HBHERecHit &hit,
int depth,
int ieta,
int iphi,
int include_or_exclude,
double (*scale)(const double &)) const {
const auto phit = caloGeometry_.getPosition(hit.detid());

if ((extIncRule_ == InclusionRule::withinConeAroundCluster and deltaR2(pclu, phit) > extRadius_) or
(intIncRule_ == InclusionRule::withinConeAroundCluster and deltaR2(pclu, phit) < intRadius_))
return 0.;

const HcalDetId hid(hit.detid());
const int hd = hid.depth(), he = hid.ieta(), hp = hid.iphi();
const int h1 = hd - 1;

if ((hid.subdet() == HcalBarrel and (hd < 1 or hd > int(eThresHB_.size()))) or
(hid.subdet() == HcalEndcap and (hd < 1 or hd > int(eThresHE_.size()))))
edm::LogWarning("EgammaHcalIsolation")
<< " hit in subdet " << hid.subdet() << " has an unaccounted for depth of " << hd << "!!";

if (include_or_exclude == -1 and (he != ieta or hp != iphi))
return 0.;

if (include_or_exclude == 1 and (he == ieta and hp == iphi))
return 0.;

if ((hid.subdet() == HcalBarrel and (hd < 1 or hd > int(eThresHB_.size()))) or
(hid.subdet() == HcalEndcap and (hd < 1 or hd > int(eThresHE_.size()))))
edm::LogWarning("EgammaHcalIsolation")
<< " hit in subdet " << hid.subdet() << " has an unaccounted for depth of " << hd << "!!";

const bool right_depth = (depth == 0 or hd == depth);
if (!right_depth)
return 0.;

const bool goodHBe = hid.subdet() == HcalBarrel and hit.energy() > eThresHB_[h1];
const bool goodHEe = hid.subdet() == HcalEndcap and hit.energy() > eThresHE_[h1];
if (!(goodHBe or goodHEe))
return 0.;

const auto phit = caloGeometry_.getPosition(hit.detid());
const float phitEta = phit.eta();

if (extIncRule_ == InclusionRule::withinConeAroundCluster or intIncRule_ == InclusionRule::withinConeAroundCluster) {
auto const dR2 = deltaR2(pcluEta, pcluPhi, phitEta, phit.phi());
if ((extIncRule_ == InclusionRule::withinConeAroundCluster and dR2 > extRadius_) or
(intIncRule_ == InclusionRule::withinConeAroundCluster and dR2 < intRadius_))
return 0.;
}

DetId did = hcalTopology_.idFront(hid);
const uint32_t flag = hit.flags();
const uint32_t dbflag = hcalChStatus_.getValues(did)->getValue();
int severity = hcalSevLvlComputer_.getSeverityLevel(did, flag, dbflag);
bool recovered = hcalSevLvlComputer_.recoveredRecHit(did, flag);

const double het = hit.energy() * scaleToEt(phit.eta());
const bool goodHB = hid.subdet() == HcalBarrel and (severity <= maxSeverityHB_ or recovered) and
hit.energy() > eThresHB_[h1] and het > etThresHB_[h1];
const bool goodHE = hid.subdet() == HcalEndcap and (severity <= maxSeverityHE_ or recovered) and
hit.energy() > eThresHE_[h1] and het > etThresHE_[h1];
const double het = hit.energy() * scaleToEt(phitEta);
const bool goodHB = goodHBe and (severity <= maxSeverityHB_ or recovered) and het > etThresHB_[h1];
const bool goodHE = goodHEe and (severity <= maxSeverityHE_ or recovered) and het > etThresHE_[h1];

if (goodHB or goodHE)
return hit.energy() * scale(phit.eta());
return hit.energy() * scale(phitEta);

return 0.;
}
Expand All @@ -175,8 +183,10 @@ double EgammaHcalIsolation::getHcalSum(const GlobalPoint &pclu,
int include_or_exclude,
double (*scale)(const double &)) const {
double sum = 0.;
const float pcluEta = pclu.eta();
const float pcluPhi = pclu.phi();
for (const auto &hit : mhbhe_)
sum += goodHitEnergy(pclu, hit, depth, ieta, iphi, include_or_exclude, scale);
sum += goodHitEnergy(pcluEta, pcluPhi, hit, depth, ieta, iphi, include_or_exclude, scale);

return sum;
}

0 comments on commit 69ae98c

Please sign in to comment.