// // Original Author: Fedor Ratnikov Nov 9, 2007 // $Id: JetCorrectorParameters.h,v 1.2 2011/06/12 21:50:39 dmytro Exp $ // // Generic parameters for Jet corrections // #ifndef JetCorrectorParameters_h #define JetCorrectorParameters_h #include #include #include #include // #include "FWCore/Utilities/interface/Exception.h" class JetCorrectorParameters { //---------------- JetCorrectorParameters class ---------------- //-- Encapsulates all the information of the parametrization --- public: //---------------- Definitions class --------------------------- //-- Global iformation about the parametrization is kept here -- class Definitions { public: //-------- Constructors -------------- Definitions() {} Definitions(const std::vector& fBinVar, const std::vector& fParVar, const std::string& fFormula, bool fIsResponse); Definitions(const std::string& fLine); //-------- Member functions ---------- unsigned nBinVar() const {return mBinVar.size(); } unsigned nParVar() const {return mParVar.size(); } std::vector parVar() const {return mParVar; } std::vector binVar() const {return mBinVar; } std::string parVar(unsigned fIndex) const {return mParVar[fIndex];} std::string binVar(unsigned fIndex) const {return mBinVar[fIndex];} std::string formula() const {return mFormula; } std::string level() const {return mLevel; } bool isResponse() const {return mIsResponse; } private: //-------- Member variables ---------- bool mIsResponse; std::string mLevel; std::string mFormula; std::vector mParVar; std::vector mBinVar; }; //---------------- Record class -------------------------------- //-- Each Record holds the properties of a bin ----------------- class Record { public: //-------- Constructors -------------- Record() : mNvar(0),mMin(0),mMax(0) {} Record(unsigned fNvar, const std::vector& fXMin, const std::vector& fXMax, const std::vector& fParameters) : mNvar(fNvar),mMin(fXMin),mMax(fXMax),mParameters(fParameters) {} Record(const std::string& fLine, unsigned fNvar); //-------- Member functions ---------- unsigned nVar() const {return mNvar; } float xMin(unsigned fVar) const {return mMin[fVar]; } float xMax(unsigned fVar) const {return mMax[fVar]; } float xMiddle(unsigned fVar) const {return 0.5*(xMin(fVar)+xMax(fVar));} float parameter(unsigned fIndex) const {return mParameters[fIndex]; } std::vector parameters() const {return mParameters; } unsigned nParameters() const {return mParameters.size(); } bool operator< (const Record& other) const { if (xMin(0) < other.xMin(0)) return true; if (xMin(0) > other.xMin(0)) return false; if ((mNvar > 1) && (xMin(1) < other.xMin(1))) return true; if ((mNvar > 1) && (xMin(1) > other.xMin(1))) return false; return ((mNvar > 2) && (xMin(2) < other.xMin(2))); } bool operator< (const std::vector fX) const { if (mNvar == 1) { return xMin(0) < fX[0]; } else { if ((xMin(0) < fX[0]) && (xMax(0) < fX[0])) return true; if ((xMin(0) > fX[0]) && (xMax(0) > fX[0])) return false; // now we must be in the correct eta bin, so just look at one pt edge return (xMin(1) < fX[1]); } } private: //-------- Member variables ---------- unsigned mNvar; std::vector mMin; std::vector mMax; std::vector mParameters; }; //-------- Constructors -------------- JetCorrectorParameters() { valid_ = false;} JetCorrectorParameters(const std::string& fFile, const std::string& fSection = ""); JetCorrectorParameters(const JetCorrectorParameters::Definitions& fDefinitions, const std::vector& fRecords) : mDefinitions(fDefinitions),mRecords(fRecords) { valid_ = true;} //-------- Member functions ---------- const Record& record(unsigned fBin) const {return mRecords[fBin]; } const Definitions& definitions() const {return mDefinitions; } unsigned size() const {return mRecords.size();} unsigned size(unsigned fVar) const; int binIndex(const std::vector& fX) const; int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const; std::vector binCenters(unsigned fVar) const; void printScreen() const; void printFile(const std::string& fFileName) const; bool isValid() const { return valid_; } private: //-------- Member variables ---------- JetCorrectorParameters::Definitions mDefinitions; std::vector mRecords; bool valid_; /// is this a valid set? }; class JetCorrectorParametersCollection { //---------------- JetCorrectorParametersCollection class ---------------- //-- Adds several JetCorrectorParameters together by algorithm type --- //-- to reduce the number of payloads in the Database --- public: enum Level_t { L1Offset=0, L1JPTOffset=7, L1FastJet = 10, L2Relative=1, L3Absolute=2, L2L3Residual=8, L4EMF=3, L5Flavor=4, L6UE=5, L7Parton=6, Uncertainty=9, N_LEVELS=11 }; enum L5_Species_t {L5_bJ=0,L5_cJ,L5_qJ,L5_gJ,L5_bT,L5_cT,L5_qT,L5_gT,N_L5_SPECIES}; enum L7_Species_t {L7_gJ=0,L7_qJ,L7_cJ,L7_bJ,L7_jJ,L7_qT,L7_cT,L7_bT,L7_jT,N_L7_SPECIES}; typedef int key_type; typedef std::string label_type; typedef JetCorrectorParameters value_type; typedef std::pair pair_type; typedef std::vector collection_type; // Constructor... initialize all three vectors to zero JetCorrectorParametersCollection() { corrections_.clear(); correctionsL5_.clear(); correctionsL7_.clear(); } // Add a JetCorrectorParameter object, possibly with flavor. void push_back( key_type i, value_type const & j, label_type const & flav = "" ); // Access the JetCorrectorParameter via the key k. // key_type is hashed to deal with the three collections JetCorrectorParameters const & operator[]( key_type k ) const; // Access the JetCorrectorParameter via a string. // Will find the hashed value for the label, and call via that // operator. JetCorrectorParameters const & operator[]( std::string const & label ) const { return operator[]( findKey(label) ); } // Get a list of valid keys. These will contain hashed keys // that are aware of all three collections. void validKeys(std::vector & keys ) const; // Helper method to find all of the sections in a given // parameters file static void getSections( std::string inputFile, std::vector & outputs ); // Find the L5 bin for hashing static key_type getL5Bin( std::string const & flav ); // Find the L7 bin for hashing static key_type getL7Bin( std::string const & flav ); // Check if this is an L5 hashed value static bool isL5( key_type k ); // Check if this is an L7 hashed value static bool isL7( key_type k ); static std::string findLabel( key_type k ){ if ( isL5(k) ) return findL5Flavor(k); else if ( isL7(k) ) return findL7Parton(k); else return labels_[k]; } static std::string findL5Flavor( key_type k ){ if ( k == L5Flavor ) return labels_[L5Flavor]; else return l5Flavors_[k / 100 - 1]; } static std::string findL7Parton( key_type k ){ if ( k == L7Parton ) return labels_[L7Parton]; else return l7Partons_[k / 1000 - 1]; } protected: // Find the key corresponding to each label key_type findKey( std::string const & label ) const; collection_type corrections_; collection_type correctionsL5_; collection_type correctionsL7_; static const char * labelsArray_[N_LEVELS]; static std::vector labels_; static const char * l5FlavorArray_[N_L5_SPECIES]; static std::vector l5Flavors_; static const char * l7PartonArray_[N_L7_SPECIES]; static std::vector l7Partons_; }; #endif