Skip to content

Commit

Permalink
Merge pull request #3994 from cms-btv-pog/JetFlavourClusteringFix_fro…
Browse files Browse the repository at this point in the history
…m-CMSSW_7_1_0_pre8

Fix for  jet flavour clustering
  • Loading branch information
davidlange6 committed Jun 3, 2014
2 parents 84e5a0f + 76e79d8 commit 45e7d5a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 35 deletions.
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
59 changes: 39 additions & 20 deletions PhysicsTools/JetMCAlgos/plugins/JetFlavourClustering.cc
Expand Up @@ -473,27 +473,36 @@ 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 )
{
if ( matchedDR2 > rParam_*rParam_ )
{
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_ << ".\n"
<< "This is not expected so please check that the jet algorithm and jet size match those used for the original jet collection.";
}
else
matchedLocks.at(matchedIdx) = true;
}
else
edm::LogError("JetMatchingFailed") << "Matching reclustered to original jets failed. Please check that the jet algorithm and jet size match those used for the original jet collection.";

matchedIndices.push_back(matchedIdx);
}

if( std::find( matchedIndices.begin(), matchedIndices.end(), -1 ) != matchedIndices.end() )
edm::LogError("JetMatchingFailed") << "Matching reclustered to original jets failed. Please check that the jet algorithm and jet size match those used for the original jet collection.";
}

// ------------ method that matches groomed and original jets based on minimum dR ------------
Expand All @@ -507,28 +516,38 @@ 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 )
{
if ( matchedDR2 > rParam_*rParam_ )
{
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_ << ".\n"
<< "This is not expected so the matching of these two jets has been discarded. Please check that the two jet collections belong to each other.";
matchedIdx = -1;
}
else
jetLocks.at(matchedIdx) = true;
}
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

0 comments on commit 45e7d5a

Please sign in to comment.