Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:54

0001 #ifndef DataFormats_PatCandidates_JetCorrFactors_h
0002 #define DataFormats_PatCandidates_JetCorrFactors_h
0003 
0004 /**
0005    \class    pat::JetCorrFactors JetCorrFactors.h "DataFormats/PatCandidates/interface/JetCorrFactors.h"
0006    \brief    Class for the storage of jet correction factors
0007    
0008    Class for the storage of jet correction factors that have been calculated during pat tuple production. 
0009    The class is created to deal with a flexible number and order of the JES correction factors, which are 
0010    expected to be nested. I.e. each correction level implies that all previous correction have been applied 
0011    in advance. This scheme corresponds to the jet energy correction scheme propagated by the JetMET PAG.
0012    In dividual levels of JEC are safed as CorrectionFactor, which is a 
0013 
0014    std::pair<std::string, std::vector<float> >. 
0015 
0016    The std::string contains a human readable label indicating the corection level, the std::vector<float> 
0017    contains the JEC factors, which are expected to have a length of 1 or 5. In this scheme the vector of 
0018    length 1 is reserved for flavor independent CorrectionFactors, while the vector of length 5 corresponds 
0019    to flavor dependent CorrectionFactors. The individual positions within the vector are expected to be 
0020    distributed according to the Flavor enumerator of the class as: 
0021 
0022    GLUON, UDS, CHARM, BOTTOM, NONE
0023 
0024    The structure is checked in the constructor of the class. The function _correction_ returns potentially 
0025    flavor dependent correction factor of the JES relative to an uncorrected jet. To move from one correction 
0026    level to another correction level the initial correction level of the jet need to be uncorrected before
0027    applying the final correction factor. The class is expected to be used from within the pat::Jet only, 
0028    this is taken care of automatically. 
0029 */
0030 
0031 #include <vector>
0032 #include <string>
0033 #include <cmath>
0034 
0035 namespace pat {
0036 
0037   class JetCorrFactors {
0038   public:
0039     // jet energy correction factor. For flavor independent jet energy corrections the
0040     // std::vector<float> holds just a single entry. From the first flavor dependent entry
0041     // in the chain on it holds five floats corresponding to the flavors: none, gluon, uds,
0042     // charm, bottom; in this case the entry for none will be set to -1; the std::string
0043     // indicates the correction level according to jetMET definitions.
0044     typedef std::pair<std::string, std::vector<float> > CorrectionFactor;
0045     // order of flavor dependent CorrectionFactors
0046     enum Flavor { GLUON, UDS, CHARM, BOTTOM, NONE };
0047     // number of maximally available flavor types
0048     static const unsigned int MAX_FLAVORS = 4;
0049 
0050   public:
0051     // default Constructor
0052     JetCorrFactors(){};
0053     // constructor by value
0054     JetCorrFactors(const std::string& label, const std::vector<CorrectionFactor>& jec);
0055     // add correction factor
0056     void insertFactor(const unsigned int& position, const CorrectionFactor& factor);
0057 
0058     // instance label of the jet energy corrections set
0059     std::string jecSet() const { return label_; }
0060     // correction level from unsigned int
0061     std::string jecLevel(const unsigned int& level) const { return jec_.at(level).first; };
0062     // correction level from std::string
0063     int jecLevel(const std::string& level) const;
0064     // jet energy correction flavor from enum
0065     std::string jecFlavor(const Flavor& flavor) const;
0066     // jet energy correction flavor from std::string
0067     Flavor jecFlavor(std::string flavor) const;
0068 
0069     // correction factor up to a given level and flavor (per default the flavor is NONE)
0070     float correction(unsigned int level, Flavor flavor = NONE) const;
0071     // a list of the labels of all correction levels according to jetMET definitions, separated by '\n'
0072     std::string correctionLabelString() const;
0073     // a vector of the labels of all correction levels according to jetMET definitions
0074     std::vector<std::string> correctionLabels() const;
0075     // label of a specific correction factor according to jetMET definitions; for overflow a string ERROR is returned
0076     std::string correctionLabel(unsigned int level) const {
0077       return (level < jec_.size() ? jec_.at(level).first : std::string("ERROR"));
0078     };
0079     // check whether CorrectionFactor is flavor independent or not
0080     bool flavorDependent(unsigned int level) const {
0081       return (level < jec_.size() ? jec_.at(level).second.size() == MAX_FLAVORS : false);
0082     };
0083     // number of available correction factors
0084     unsigned int numberOfCorrectionLevels() const { return jec_.size(); };
0085     // print function for debugging
0086     void print() const;
0087 
0088   private:
0089     // check consistency of input vector
0090     bool flavorDependent(const CorrectionFactor& jec) const { return (jec.second.size() == MAX_FLAVORS); }
0091     // check consistency of input vector
0092     bool flavorIndependent(const CorrectionFactor& jec) const { return (jec.second.size() == 1); }
0093     // check consistency of input vector
0094     bool isValid(const CorrectionFactor& jec) const { return (flavorDependent(jec) || flavorIndependent(jec)); }
0095     void invalidFactor() const;
0096 
0097   private:
0098     // instance label of jet energy correction factors
0099     std::string label_;
0100     // vector of CorrectionFactors. NOTE: the correction factors are expected to appear
0101     // nested; they may appear in arbitary number and order according to the configuration
0102     // of the jetCorrFactors module. CorrectionFactors appear in two versions: as a single
0103     // float (for flavor independent corrections) or as a std::vector of four floats (for
0104     // flavor dependent corrections). Due to the nested structure of the CorrectionFactors
0105     // from the first flavor dependent CorrectionFactor in the chain on each correction is
0106     // flavor dependent.
0107     std::vector<CorrectionFactor> jec_;
0108   };
0109 }  // namespace pat
0110 
0111 #endif