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 for jet flavour clustering #3994

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 15 additions & 15 deletions PhysicsTools/JetExamples/test/printJetFlavourInfo.cc
Expand Up @@ -58,30 +58,30 @@ void printJetFlavourInfo::analyze(const edm::Event& iEvent, const edm::EventSetu

for(size_t gj=0; gj<groomedJets->size(); ++gj)
{
double matchedDR = 1e9;
double matchedDR2 = 1e9;
int matchedIdx = -1;

for(reco::JetFlavourInfoMatchingCollection::const_iterator j = theJetFlavourInfos->begin();
j != theJetFlavourInfos->end();
++j)
if( groomedJets->at(gj).pt()>0. ) // skips pathological cases of groomed jets with Pt=0
{
if( jetLocks.at(j - theJetFlavourInfos->begin()) ) continue; // skip jets that have already been matched

double tempDR = reco::deltaR( j->first->rapidity(), j->first->phi(), groomedJets->at(gj).rapidity(), groomedJets->at(gj).phi() );
if( tempDR < matchedDR )
for(reco::JetFlavourInfoMatchingCollection::const_iterator j = theJetFlavourInfos->begin();
j != theJetFlavourInfos->end();
++j)
{
matchedDR = tempDR;
matchedIdx = (j - theJetFlavourInfos->begin());
if( jetLocks.at(j - theJetFlavourInfos->begin()) ) continue; // skip jets that have already been matched

double tempDR2 = reco::deltaR2( j->first->rapidity(), j->first->phi(), groomedJets->at(gj).rapidity(), groomedJets->at(gj).phi() );
if( tempDR2 < matchedDR2 )
{
matchedDR2 = tempDR2;
matchedIdx = (j - theJetFlavourInfos->begin());
}
}
}

if( matchedIdx>=0 ) jetLocks.at(matchedIdx) = true;
jetIndices.push_back(matchedIdx);
}

if( std::find( jetIndices.begin(), jetIndices.end(), -1 ) != jetIndices.end() )
throw cms::Exception("Jet matching failed") << "Matching groomed to original jets failed. Please check that the jet algorithm, jet size, and Pt threshold match for the two jet collections.";

for(size_t j=0; j<theJetFlavourInfos->size(); ++j)
{
std::vector<int>::iterator matchedIndex = std::find( jetIndices.begin(), jetIndices.end(), j );
Expand All @@ -101,7 +101,7 @@ void printJetFlavourInfo::analyze(const edm::Event& iEvent, const edm::EventSetu
<< "[printJetFlavourInfo] Jet " << (j - theJetFlavourInfos->begin()) << " pt, eta, rapidity, phi = " << aJet->pt() << ", "
<< aJet->eta() << ", "
<< aJet->rapidity() << ", "
<< aJet->phi() << ", "
<< aJet->phi()
<< std::endl;
// ----------------------- Hadrons -------------------------------
std::cout << " Hadron-based flavour: " << aInfo.getHadronFlavour() << std::endl;
Expand Down Expand Up @@ -205,7 +205,7 @@ void printJetFlavourInfo::analyze(const edm::Event& iEvent, const edm::EventSetu
<< aSubjet->rapidity() << ", "
<< aSubjet->phi() << ", "
<< reco::deltaR( aSubjet->eta(), aSubjet->phi(), aJet->eta(), aJet->phi() ) << ", "
<< reco::deltaR( aSubjet->rapidity(), aSubjet->phi(), aJet->rapidity(), aJet->phi() ) << ", "
<< reco::deltaR( aSubjet->rapidity(), aSubjet->phi(), aJet->rapidity(), aJet->phi() )
<< std::endl;
// ----------------------- Hadrons -------------------------------
std::cout << " Hadron-based flavour: " << aInfo.getHadronFlavour() << std::endl;
Expand Down
44 changes: 27 additions & 17 deletions PhysicsTools/JetMCAlgos/plugins/JetFlavourClustering.cc
Expand Up @@ -473,22 +473,27 @@ JetFlavourClustering::matchReclusteredJets(const edm::Handle<edm::View<reco::Jet

for(size_t j=0; j<jets->size(); ++j)
{
double matchedDR = 1e9;
double matchedDR2 = 1e9;
int matchedIdx = -1;

for(size_t rj=0; rj<reclusteredJets.size(); ++rj)
{
if( matchedLocks.at(rj) ) continue; // skip jets that have already been matched

double tempDR = reco::deltaR( jets->at(j).rapidity(), jets->at(j).phi(), reclusteredJets.at(rj).rapidity(), reclusteredJets.at(rj).phi_std() );
if( tempDR < matchedDR )
double tempDR2 = reco::deltaR2( jets->at(j).rapidity(), jets->at(j).phi(), reclusteredJets.at(rj).rapidity(), reclusteredJets.at(rj).phi_std() );
if( tempDR2 < matchedDR2 )
{
matchedDR = tempDR;
matchedDR2 = tempDR2;
matchedIdx = rj;
}
}

if( matchedIdx>=0 ) matchedLocks.at(matchedIdx) = true;
if( matchedIdx>=0 )
{
matchedLocks.at(matchedIdx) = true;
if ( matchedDR2 > rParam_*rParam_ )
Copy link

Choose a reason for hiding this comment

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

matchedLocks remains true in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vadler With this condition met, something was not configured properly and the final results should not be used until the problem is fixed. So in that sense, one could argue that it doesn't matter much to what value matchedLocks was set since the results probably don't make much sense anyways. However, I do agree that it is probably better not to set matchedLocks to true if this condition is met. The same is true for https://github.com/cms-sw/cmssw/pull/3994/files#r13046815 I will commit a fix soon. Thanks for spotting this.

Copy link

Choose a reason for hiding this comment

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

Thanx!
Please also propagate the fix to the other release cycles, so that I can sign all four of them right away ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. Working on it right now.

edm::LogError("JetMatchingFailed") << "Matched reclustered jet " << matchedIdx << " and original jet " << j <<" are separated by dR=" << sqrt(matchedDR2) << " which is greater than the jet size R=" << rParam_ << ". This is not expected so please check that the jet algorithm and jet size match those used for the original jet collection.";
}
matchedIndices.push_back(matchedIdx);
}

Expand All @@ -507,28 +512,33 @@ JetFlavourClustering::matchGroomedJets(const edm::Handle<edm::View<reco::Jet> >&

for(size_t gj=0; gj<groomedJets->size(); ++gj)
{
double matchedDR = 1e9;
double matchedDR2 = 1e9;
int matchedIdx = -1;

for(size_t j=0; j<jets->size(); ++j)
if( groomedJets->at(gj).pt()>0. ) // skips pathological cases of groomed jets with Pt=0
{
if( jetLocks.at(j) ) continue; // skip jets that have already been matched

double tempDR = reco::deltaR( jets->at(j).rapidity(), jets->at(j).phi(), groomedJets->at(gj).rapidity(), groomedJets->at(gj).phi() );
if( tempDR < matchedDR )
for(size_t j=0; j<jets->size(); ++j)
{
matchedDR = tempDR;
matchedIdx = j;
if( jetLocks.at(j) ) continue; // skip jets that have already been matched

double tempDR2 = reco::deltaR2( jets->at(j).rapidity(), jets->at(j).phi(), groomedJets->at(gj).rapidity(), groomedJets->at(gj).phi() );
if( tempDR2 < matchedDR2 )
{
matchedDR2 = tempDR2;
matchedIdx = j;
}
}
}

if( matchedIdx>=0 ) jetLocks.at(matchedIdx) = true;
if( matchedIdx>=0 )
{
jetLocks.at(matchedIdx) = true;
if ( matchedDR2 > rParam_*rParam_ )
Copy link

Choose a reason for hiding this comment

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

edm::LogWarning("MatchedJetsFarApart") << "Matched groomed jet " << gj << " and original jet " << matchedIdx <<" are separated by dR=" << sqrt(matchedDR2) << " which is greater than the jet size R=" << rParam_ << ". This is not expected so please check that the two jet collections belong to each other.";
}
jetIndices.push_back(matchedIdx);
}

if( std::find( jetIndices.begin(), jetIndices.end(), -1 ) != jetIndices.end() )
edm::LogError("JetMatchingFailed") << "Matching groomed to original jets failed. Please check that the two jet collections belong to each other.";

for(size_t j=0; j<jets->size(); ++j)
{
std::vector<int>::iterator matchedIndex = std::find( jetIndices.begin(), jetIndices.end(), j );
Expand Down