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 charged and neutral candidate converters for reco::Jets #35922
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,20 +53,22 @@ namespace btagbtvdeep { | |
|
||
// subjet related | ||
const auto* patJet = dynamic_cast<const pat::Jet*>(&jet); | ||
if (!patJet) { | ||
throw edm::Exception(edm::errors::InvalidReference) << "Input is not a pat::Jet."; | ||
} | ||
|
||
if (patJet->nSubjetCollections() > 0) { | ||
auto subjets = patJet->subjets(); | ||
// sort by pt | ||
std::sort(subjets.begin(), subjets.end(), [](const edm::Ptr<pat::Jet>& p1, const edm::Ptr<pat::Jet>& p2) { | ||
return p1->pt() > p2->pt(); | ||
}); | ||
c_pf_features.drsubjet1 = !subjets.empty() ? reco::deltaR(*c_pf, *subjets.at(0)) : -1; | ||
c_pf_features.drsubjet2 = subjets.size() > 1 ? reco::deltaR(*c_pf, *subjets.at(1)) : -1; | ||
if (patJet) { | ||
if (patJet->nSubjetCollections() > 0) { | ||
auto subjets = patJet->subjets(); | ||
// sort by pt | ||
std::sort(subjets.begin(), subjets.end(), [](const edm::Ptr<pat::Jet>& p1, const edm::Ptr<pat::Jet>& p2) { | ||
return p1->pt() > p2->pt(); | ||
}); | ||
c_pf_features.drsubjet1 = !subjets.empty() ? reco::deltaR(*c_pf, *subjets.at(0)) : -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
c_pf_features.drsubjet2 = subjets.size() > 1 ? reco::deltaR(*c_pf, *subjets.at(1)) : -1; | ||
} else { | ||
// AK4 jets don't have subjets | ||
c_pf_features.drsubjet1 = -1; | ||
c_pf_features.drsubjet2 = -1; | ||
} | ||
} else { | ||
// AK4 jets don't have subjets | ||
c_pf_features.drsubjet1 = -1; | ||
c_pf_features.drsubjet2 = -1; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,18 +32,20 @@ namespace btagbtvdeep { | |
NeutralCandidateFeatures& n_pf_features) { | ||
const auto* patJet = dynamic_cast<const pat::Jet*>(&jet); | ||
|
||
if (!patJet) { | ||
throw edm::Exception(edm::errors::InvalidReference) << "Input is not a pat::Jet."; | ||
} | ||
// Do Subjets | ||
if (patJet->nSubjetCollections() > 0) { | ||
auto subjets = patJet->subjets(); | ||
// sort by pt | ||
std::sort(subjets.begin(), subjets.end(), [](const edm::Ptr<pat::Jet>& p1, const edm::Ptr<pat::Jet>& p2) { | ||
return p1->pt() > p2->pt(); | ||
}); | ||
n_pf_features.drsubjet1 = !subjets.empty() ? reco::deltaR(*n_pf, *subjets.at(0)) : -1; | ||
n_pf_features.drsubjet2 = subjets.size() > 1 ? reco::deltaR(*n_pf, *subjets.at(1)) : -1; | ||
if (patJet) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why all this code duplication? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please clarify the comment about what code exactly is duplicated in this file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code in this file looks identical to the one in the previous one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SWuchterl for clarification, the duplication is between ChargedCandidateConverter.h and NeutralCandidateConverter.h. The new code could be a simple utility function defined once, and called from both files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first file is about Charged candidates and this one is about the Neutral ones. Some elements look similar indeed but they define 2 different inputs used by the neural network. |
||
if (patJet->nSubjetCollections() > 0) { | ||
auto subjets = patJet->subjets(); | ||
// sort by pt | ||
std::sort(subjets.begin(), subjets.end(), [](const edm::Ptr<pat::Jet>& p1, const edm::Ptr<pat::Jet>& p2) { | ||
return p1->pt() > p2->pt(); | ||
}); | ||
n_pf_features.drsubjet1 = !subjets.empty() ? reco::deltaR(*n_pf, *subjets.at(0)) : -1; | ||
n_pf_features.drsubjet2 = subjets.size() > 1 ? reco::deltaR(*n_pf, *subjets.at(1)) : -1; | ||
} else { | ||
n_pf_features.drsubjet1 = -1; | ||
n_pf_features.drsubjet2 = -1; | ||
} | ||
} else { | ||
n_pf_features.drsubjet1 = -1; | ||
n_pf_features.drsubjet2 = -1; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for a full sorting here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those pieces of the code were already there, I just inverted the logic of the if statement in the beginning. From the diff it seems different, I know. But of course, I can change it as suggested.
(Also applies for the second comment below)
Just for clarification, do you suggest removing the line entirely because the collection should already be sorted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stil this code is very sub-optimal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SWuchterl I understand you only need the first and second jet by pt, so you don't need to do a full sorting. This could be a straightforward improvement for both the new and original code. I'm not sure you can safely assume that the collection is sorted.
We can also run a profiling on this PR to check if this is a measurable/detectable issue.