CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
pat::JetCorrFactors Class Reference

Class for the storage of jet correction factors. More...

#include "DataFormats/PatCandidates/interface/JetCorrFactors.h"

Public Types

typedef std::pair< std::string, std::vector< float > > CorrectionFactor
 
enum  Flavor {
  GLUON, UDS, CHARM, BOTTOM,
  NONE
}
 

Public Member Functions

float correction (unsigned int level, Flavor flavor=NONE) const
 
std::string correctionLabel (unsigned int level) const
 
std::vector< std::string > correctionLabels () const
 
std::string correctionLabelString () const
 
bool flavorDependent (unsigned int level) const
 
void insertFactor (const unsigned int &position, const CorrectionFactor &factor)
 
std::string jecFlavor (const Flavor &flavor) const
 
Flavor jecFlavor (std::string flavor) const
 
std::string jecLevel (const unsigned int &level) const
 
int jecLevel (const std::string &level) const
 
std::string jecSet () const
 
 JetCorrFactors ()
 
 JetCorrFactors (const std::string &label, const std::vector< CorrectionFactor > &jec)
 
unsigned int numberOfCorrectionLevels () const
 
void print () const
 

Static Public Attributes

static const unsigned int MAX_FLAVORS = 4
 

Private Member Functions

bool flavorDependent (const CorrectionFactor &jec) const
 
bool flavorIndependent (const CorrectionFactor &jec) const
 
void invalidFactor () const
 
bool isValid (const CorrectionFactor &jec) const
 

Private Attributes

std::vector< CorrectionFactorjec_
 
std::string label_
 

Detailed Description

Class for the storage of jet correction factors.

Class for the storage of jet correction factors that have been calculated during pat tuple production. The class is created to deal with a flexible number and order of the JES correction factors, which are expected to be nested. I.e. each correction level implies that all previous correction have been applied in advance. This scheme corresponds to the jet energy correction scheme propagated by the JetMET PAG. In dividual levels of JEC are safed as CorrectionFactor, which is a

std::pair<std::string, std::vector<float> >.

The std::string contains a human readable label indicating the corection level, the std::vector<float> contains the JEC factors, which are expected to have a length of 1 or 5. In this scheme the vector of length 1 is reserved for flavor independent CorrectionFactors, while the vector of length 5 corresponds to flavor dependent CorrectionFactors. The individual positions within the vector are expected to be distributed according to the Flavor enumerator of the class as:

GLUON, UDS, CHARM, BOTTOM, NONE

The structure is checked in the constructor of the class. The function correction returns potentially flavor dependent correction factor of the JES relative to an uncorrected jet. To move from one correction level to another correction level the initial correction level of the jet need to be uncorrected before applying the final correction factor. The class is expected to be used from within the pat::Jet only, this is taken care of automatically.

Definition at line 37 of file JetCorrFactors.h.

Member Typedef Documentation

typedef std::pair<std::string, std::vector<float> > pat::JetCorrFactors::CorrectionFactor

Definition at line 45 of file JetCorrFactors.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

pat::JetCorrFactors::JetCorrFactors ( )
inline
JetCorrFactors::JetCorrFactors ( const std::string &  label,
const std::vector< CorrectionFactor > &  jec 
)

Definition at line 14 of file JetCorrFactors.cc.

References invalidFactor(), and isValid().

14  : label_(label), jec_(jec)
15 {
16  for(std::vector<CorrectionFactor>::const_iterator corrFactor=jec.begin(); corrFactor!=jec.end(); ++corrFactor){
17  if (!isValid(*corrFactor))
18  invalidFactor();
19  }
20 }
std::vector< CorrectionFactor > jec_
char const * label
bool isValid(const CorrectionFactor &jec) const
void invalidFactor() const

Member Function Documentation

float JetCorrFactors::correction ( unsigned int  level,
Flavor  flavor = NONE 
) const

Definition at line 59 of file JetCorrFactors.cc.

References correctionLabelString(), Exception, flavorDependent(), jec_, NONE, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by jecLevel(), and print().

60 {
61  if(!(level<jec_.size())){
62  throw cms::Exception("InvalidRequest") << "You try to call a jet energy correction level wich does not exist. \n"
63  << "Available jet energy correction levels are: \n"
65  }
66  if(flavorDependent(jec_.at(level)) && flavor==NONE){
67  throw cms::Exception("InvalidRequest") << "You try to call a flavor dependent jet energy correction level: \n"
68  << "level : " << level << " label: " << jec_.at(level).first << " \n"
69  << "You need to specify one of the following flavors: GLUON, UDS, \n"
70  << "CHARM, BOTTOM. \n";
71  }
72  return flavorDependent(jec_.at(level)) ? jec_.at(level).second.at(flavor) : jec_.at(level).second.at(0);
73 }
std::vector< CorrectionFactor > jec_
std::string correctionLabelString() const
bool flavorDependent(unsigned int level) const
std::string pat::JetCorrFactors::correctionLabel ( unsigned int  level) const
inline

Definition at line 77 of file JetCorrFactors.h.

References jec_, and AlCaHLTBitMon_QueryRunRegistry::string.

77 { return (level<jec_.size() ? jec_.at(level).first : std::string("ERROR")); };
std::vector< CorrectionFactor > jec_
std::vector< std::string > JetCorrFactors::correctionLabels ( ) const

Definition at line 87 of file JetCorrFactors.cc.

References jec_, and tablePrinter::labels.

Referenced by jecLevel().

88 {
89  std::vector<std::string> labels;
90  for(std::vector<CorrectionFactor>::const_iterator corrFactor=jec_.begin(); corrFactor!=jec_.end(); ++corrFactor){
91  labels.push_back(corrFactor->first);
92  }
93  return labels;
94 }
std::vector< CorrectionFactor > jec_
std::string JetCorrFactors::correctionLabelString ( ) const

Definition at line 76 of file JetCorrFactors.cc.

References mps_setup::append, training_settings::idx, jec_, tablePrinter::labels, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by correction(), and jecLevel().

77 {
79  for(std::vector<CorrectionFactor>::const_iterator corrFactor=jec_.begin(); corrFactor!=jec_.end(); ++corrFactor){
80  std::stringstream idx; idx << (corrFactor-jec_.begin());
81  labels.append(idx.str()).append(" ").append(corrFactor->first).append("\n");
82  }
83  return labels;
84 }
std::vector< CorrectionFactor > jec_
bool pat::JetCorrFactors::flavorDependent ( unsigned int  level) const
inline

Definition at line 79 of file JetCorrFactors.h.

References jec_.

Referenced by correction(), isValid(), and print().

79 { return (level<jec_.size() ? jec_.at(level).second.size()==MAX_FLAVORS : false); };
std::vector< CorrectionFactor > jec_
static const unsigned int MAX_FLAVORS
bool pat::JetCorrFactors::flavorDependent ( const CorrectionFactor jec) const
inlineprivate

Definition at line 87 of file JetCorrFactors.h.

References MAX_FLAVORS.

87 { return (jec.second.size()==MAX_FLAVORS); }
static const unsigned int MAX_FLAVORS
bool pat::JetCorrFactors::flavorIndependent ( const CorrectionFactor jec) const
inlineprivate

Definition at line 89 of file JetCorrFactors.h.

Referenced by isValid().

89 { return (jec.second.size()==1); }
void JetCorrFactors::insertFactor ( const unsigned int &  position,
const CorrectionFactor factor 
)

Definition at line 22 of file JetCorrFactors.cc.

References invalidFactor(), isValid(), jec_, position, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by JetCorrFactors().

22  {
23  if (!isValid(corrFactor))
24  invalidFactor();
25  jec_.insert(jec_.begin() + position, corrFactor);
26 }
std::vector< CorrectionFactor > jec_
bool isValid(const CorrectionFactor &jec) const
void invalidFactor() const
static int position[264][3]
Definition: ReadPGInfo.cc:509
void JetCorrFactors::invalidFactor ( ) const
private

Definition at line 116 of file JetCorrFactors.cc.

References Exception.

Referenced by insertFactor(), isValid(), and JetCorrFactors().

116  {
117  throw cms::Exception("InvalidRequest")
118  << "You try to create a CorrectionFactor which is neither flavor dependent nor \n"
119  << "flavor independent. The CorrectionFactor should obey the following rules: \n"
120  << "\n"
121  << " * CorrectionFactor is a std::pair<std::string, std::vector<float> >. \n"
122  << " * The std::string holds the label of the correction level (following the \n"
123  << " conventions of JetMET. \n"
124  << " * The std::vector<float> holds the correction factors, these factors are \n"
125  << " up to the given level. They include all previous correction steps. \n"
126  << " * The vector has the length *1* for flavor independent correction factors \n"
127  << " or *5* for flavor dependent correction factors. \n"
128  << " * The expected order of flavor dependent correction factors is: NONE, \n"
129  << " GLUON, UDS, CHARM, BOTTOM. If follows the JetMET conventions and is \n"
130  << " in the Flavor enumerator of the JetCorrFactos class. \n"
131  << " * For flavor depdendent correction factors the first entry in the vector \n"
132  << " (corresponding to NONE) is invalid and should be set to -1. It will not \n"
133  << " be considered by the class structure though. \n"
134  << "\n"
135  << "Make sure that all elements of the argument vector to this contructor are \n"
136  << "in accordance with these rules.\n";
137 }
bool pat::JetCorrFactors::isValid ( const CorrectionFactor jec) const
inlineprivate

Definition at line 91 of file JetCorrFactors.h.

References flavorDependent(), flavorIndependent(), and invalidFactor().

Referenced by ntupleDataFormat._Object::_checkIsValid(), insertFactor(), JetCorrFactors(), and core.AutoHandle.AutoHandle::ReallyLoad().

91 { return (flavorDependent(jec) || flavorIndependent(jec)); }
bool flavorIndependent(const CorrectionFactor &jec) const
bool flavorDependent(unsigned int level) const
std::string JetCorrFactors::jecFlavor ( const Flavor flavor) const

Definition at line 29 of file JetCorrFactors.cc.

References BOTTOM, CHARM, GLUON, NONE, and UDS.

Referenced by jecLevel().

30 {
31  std::map<Flavor, std::string> flavors;
32  flavors[UDS]="uds"; flavors[CHARM]="charm"; flavors[BOTTOM]="bottom"; flavors[GLUON]="gluon"; flavors[NONE]="none";
33  return flavors.find(flavor)->second;
34 }
JetCorrFactors::Flavor JetCorrFactors::jecFlavor ( std::string  flavor) const

Definition at line 37 of file JetCorrFactors.cc.

References BOTTOM, EnergyCorrector::c, CHARM, Exception, GLUON, NONE, create_public_lumi_plots::transform, and UDS.

38 {
39  std::map<std::string, Flavor> flavors;
40  std::transform(flavor.begin(), flavor.end(), flavor.begin(), [&](int c){ return std::tolower(c);} );
41  flavors["uds"]=UDS; flavors["charm"]=CHARM; flavors["bottom"]=BOTTOM; flavors["gluon"]=GLUON; flavors["none"]=NONE;
42  if(flavors.find(flavor)==flavors.end()){
43  throw cms::Exception("InvalidRequest") << "You ask for a flavor, which does not exist. Available flavors are: \n"
44  << "'uds', 'charm', 'bottom', 'gluon', 'none', (not case sensitive). \n";
45  }
46  return flavors.find(flavor)->second;
47 }
std::string pat::JetCorrFactors::jecLevel ( const unsigned int &  level) const
inline
int JetCorrFactors::jecLevel ( const std::string &  level) const

Definition at line 50 of file JetCorrFactors.cc.

References jec_.

51 {
52  for(std::vector<CorrectionFactor>::const_iterator corrFactor=jec_.begin(); corrFactor!=jec_.end(); ++corrFactor){
53  if(corrFactor->first==level) return (corrFactor-jec_.begin());
54  }
55  return -1;
56 }
std::vector< CorrectionFactor > jec_
std::string pat::JetCorrFactors::jecSet ( ) const
inline

Definition at line 60 of file JetCorrFactors.h.

References label_.

60 { return label_; }
unsigned int pat::JetCorrFactors::numberOfCorrectionLevels ( ) const
inline

Definition at line 81 of file JetCorrFactors.h.

References jec_, and print().

81 { return jec_.size(); };
std::vector< CorrectionFactor > jec_
void JetCorrFactors::print ( void  ) const

Definition at line 97 of file JetCorrFactors.cc.

References correction(), flavorDependent(), jec_, and NONE.

Referenced by numberOfCorrectionLevels().

98 {
99  edm::LogInfo message( "JetCorrFactors" );
100  for(std::vector<CorrectionFactor>::const_iterator corrFactor=jec_.begin(); corrFactor!=jec_.end(); ++corrFactor){
101  unsigned int corrFactorIdx=corrFactor-jec_.begin();
102  message << std::setw(3) << corrFactorIdx << " " << corrFactor->first;
103  if( flavorDependent(*corrFactor) ){
104  for(std::vector<float>::const_iterator flavor=corrFactor->second.begin(); flavor!=corrFactor->second.end(); ++flavor){
105  unsigned int flavorIdx=flavor-corrFactor->second.begin();
106  message << std::setw(10) << correction(corrFactorIdx, (Flavor)flavorIdx);
107  }
108  }
109  else{
110  message << std::setw(10) << correction (corrFactor-jec_.begin(), NONE);
111  }
112  message << "\n";
113  }
114 }
float correction(unsigned int level, Flavor flavor=NONE) const
std::vector< CorrectionFactor > jec_
bool flavorDependent(unsigned int level) const

Member Data Documentation

std::vector<CorrectionFactor> pat::JetCorrFactors::jec_
private
std::string pat::JetCorrFactors::label_
private
const unsigned int pat::JetCorrFactors::MAX_FLAVORS = 4
static

Definition at line 49 of file JetCorrFactors.h.

Referenced by flavorDependent().