Skip to content

Commit

Permalink
Merge pull request #21902 from rappoccio/patjet_groomedmass_10x
Browse files Browse the repository at this point in the history
Adding an accessor for groomed jet mass in 10.x
  • Loading branch information
cmsbuild authored Jan 26, 2018
2 parents 375030f + 0e39d13 commit 33c63be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 22 additions & 4 deletions DataFormats/PatCandidates/interface/Jet.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include "DataFormats/Common/interface/OwnVector.h"
#include "DataFormats/Common/interface/AtomicPtrCache.h"

#include <numeric>


// Define typedefs for convenience
namespace pat {
Expand Down Expand Up @@ -498,21 +500,37 @@ namespace pat {


/// String access to subjet list
pat::JetPtrCollection const & subjets( std::string label ) const ;
pat::JetPtrCollection const & subjets( std::string const & label ) const ;

/// Add new set of subjets
void addSubjets( pat::JetPtrCollection const & pieces, std::string label = "" );
void addSubjets( pat::JetPtrCollection const & pieces, std::string const & label = "" );

/// Check to see if the subjet collection exists
bool hasSubjets( std::string label ) const { return find( subjetLabels_.begin(), subjetLabels_.end(), label) != subjetLabels_.end(); }
bool hasSubjets( std::string const & label ) const { return find( subjetLabels_.begin(), subjetLabels_.end(), label) != subjetLabels_.end(); }

/// Number of subjet collections
unsigned int nSubjetCollections( ) const { return subjetCollections_.size(); }

/// Subjet collection names
std::vector<std::string> const & subjetCollectionNames() const { return subjetLabels_; }


/// Access to mass of subjets
double groomedMass(unsigned int index = 0) const{
auto const& sub = subjets(index);
return nSubjetCollections() > index && !sub.empty() ?
std::accumulate( sub.begin(), sub.end(),
reco::Candidate::LorentzVector(),
[] (reco::Candidate::LorentzVector const & a, reco::CandidatePtr const & b){return a + b->p4();}).mass() :
-1.0;
}
double groomedMass(std::string const & label) const{
auto const& sub = subjets(label);
return hasSubjets(label) && !sub.empty() ?
std::accumulate( sub.begin(), sub.end(),
reco::Candidate::LorentzVector(),
[] (reco::Candidate::LorentzVector const & a, reco::CandidatePtr const & b){return a + b->p4();}).mass() :
-1.0;
}

protected:

Expand Down
4 changes: 2 additions & 2 deletions DataFormats/PatCandidates/src/Jet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ pat::JetPtrCollection const & Jet::subjets( unsigned int index) const {


/// String access to subjet list
pat::JetPtrCollection const & Jet::subjets( std::string label ) const {
pat::JetPtrCollection const & Jet::subjets( std::string const & label ) const {
auto found = find( subjetLabels_.begin(), subjetLabels_.end(), label );
if ( found != subjetLabels_.end() ){
auto index = std::distance( subjetLabels_.begin(), found );
Expand All @@ -611,7 +611,7 @@ pat::JetPtrCollection const & Jet::subjets( std::string label ) const {
}

/// Add new set of subjets
void Jet::addSubjets( pat::JetPtrCollection const & pieces, std::string label ) {
void Jet::addSubjets( pat::JetPtrCollection const & pieces, std::string const & label ) {
subjetCollections_.push_back( pieces );
subjetLabels_.push_back( label );
}

0 comments on commit 33c63be

Please sign in to comment.