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

13_1 backport: Fix numeric issues in PFCand scaling, add some debug output #41608

Merged
merged 1 commit into from
May 16, 2023
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
6 changes: 4 additions & 2 deletions DataFormats/ParticleFlowCandidate/src/PFCandidate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,10 @@ void PFCandidate::rescaleMomentum(double rescaleFactor) {
throw cms::Exception(
"NegativeScaling",
"Scale factor " + std::to_string(rescaleFactor) + " is < 0. Cannot rescale momentum by this value");
float rescaleE = std::sqrt(p() * p() * (rescaleFactor * rescaleFactor - 1) / (energy() * energy()) + 1);
LorentzVector rescaledp4(rescaleFactor * px(), rescaleFactor * py(), rescaleFactor * pz(), rescaleE * energy());

float e = std::sqrt(p() * p() * rescaleFactor * rescaleFactor + mass() * mass());

LorentzVector rescaledp4(rescaleFactor * px(), rescaleFactor * py(), rescaleFactor * pz(), e);
setP4(rescaledp4);
}

Expand Down
3 changes: 0 additions & 3 deletions RecoParticleFlow/PFProducer/plugins/PFLinker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ void PFLinker::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Ptr<reco::PFCandidate> candPtr(pfCandidates, i);
reco::PFCandidate cand(candPtr);

if (!(cand.energy() > 0))
continue;

bool isphoton = cand.particleId() == reco::PFCandidate::gamma && cand.mva_nothing_gamma() > 0.;
bool iselectron = cand.particleId() == reco::PFCandidate::e;
// PFCandidates may have a valid MuonRef though they are not muons.
Expand Down
20 changes: 18 additions & 2 deletions RecoParticleFlow/PFProducer/src/PFAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2425,7 +2425,15 @@ void PFAlgo::createCandidatesHCAL(const reco::PFBlock& block,
if (iTrack == corrTrack) {
if (corrFact < 0.)
corrFact = 0.; // protect against negative scaling
(*pfCandidates_)[tmpi].rescaleMomentum(corrFact);
auto& candRescale = (*pfCandidates_)[tmpi];
LogTrace("PFAlgo|createCandidatesHCAL")
<< "\tBefore rescaling: momentum " << candRescale.p() << " pT " << candRescale.pt() << " energy "
<< candRescale.energy() << " mass " << candRescale.mass() << std::endl
<< "\tTo rescale by " << corrFact << std::endl;
candRescale.rescaleMomentum(corrFact);
LogTrace("PFAlgo|createCandidatesHCAL")
<< "\tRescaled candidate momentum " << candRescale.p() << " pT " << candRescale.pt() << " energy "
<< candRescale.energy() << " mass " << candRescale.mass() << std::endl;
trackMomentum *= corrFact;
}
chargedHadronsIndices.push_back(tmpi);
Expand Down Expand Up @@ -2508,7 +2516,15 @@ void PFAlgo::createCandidatesHCAL(const reco::PFBlock& block,
double rescaleFactor = x(i) / hcalP[i];
if (rescaleFactor < 0.)
rescaleFactor = 0.; // protect against negative scaling
(*pfCandidates_)[ich].rescaleMomentum(rescaleFactor);
auto& candRescale = (*pfCandidates_)[ich];
LogTrace("PFAlgo|createCandidatesHCAL")
<< "\tBefore rescaling: momentum " << candRescale.p() << " pT " << candRescale.pt() << " energy "
<< candRescale.energy() << " mass " << candRescale.mass() << std::endl
<< "\tTo rescale by " << rescaleFactor << std::endl;
candRescale.rescaleMomentum(rescaleFactor);
LogTrace("PFAlgo|createCandidatesHCAL")
<< "\tRescaled candidate momentum " << candRescale.p() << " pT " << candRescale.pt() << " energy "
<< candRescale.energy() << " mass " << candRescale.mass() << std::endl;

LogTrace("PFAlgo|createCandidatesHCAL")
<< "\t\t\told p " << hcalP[i] << " new p " << x(i) << " rescale " << rescaleFactor;
Expand Down