Skip to content

Commit

Permalink
Adding an accessor for groomed jet mass for convenience, particularly…
Browse files Browse the repository at this point in the history
… nanoaod
  • Loading branch information
rappoccio committed Jan 19, 2018
1 parent 2ca73ae commit 253d636
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 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,33 @@ 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{
return nSubjetCollections() > 0 && !subjets(index).empty() ?
std::accumulate( subjets(index).begin(), subjets(index).end(),
reco::Candidate::LorentzVector(), [] (reco::Candidate::LorentzVector a, reco::CandidatePtr const & b){return a + b->p4();}).mass() :
-1.0;
}
double groomedMass(std::string const & label) const{
return hasSubjets(label) && !subjets(label).empty() ?
std::accumulate( subjets(label).begin(), subjets(label).end(),
reco::Candidate::LorentzVector(), [] (reco::Candidate::LorentzVector 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 253d636

Please sign in to comment.