Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:14

0001 //
0002 #ifndef MEtXYcorrectParameters_h
0003 #define MEtXYcorrectParameters_h
0004 
0005 #include "CondFormats/Serialization/interface/Serializable.h"
0006 
0007 #include <string>
0008 #include <vector>
0009 #include <algorithm>
0010 #include <iostream>
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 class MEtXYcorrectParameters {
0015   //---------------- MEtParameters class ----------------
0016   //-- Encapsulates all the information of the parametrization ---
0017 public:
0018   //---------------- Definitions class ---------------------------
0019   //-- Global iformation about the parametrization is kept here --
0020   class Definitions {
0021   public:
0022     //-------- Constructors --------------
0023     Definitions() {}
0024     Definitions(const std::vector<std::string>& fVar,
0025                 const std::vector<std::string>& fParVar,
0026                 const std::string& fFormula);
0027     Definitions(const std::string& fLine);
0028     //-------- Member functions ----------
0029     unsigned nBinVar() const { return mBinVar.size(); }
0030     unsigned nParVar() const { return mParVar.size(); }
0031     int PtclType() const { return ptclType; }
0032     std::vector<unsigned> parVar() const { return mParVar; }  // parameterized Variable
0033     std::vector<std::string> binVar() const { return mBinVar; }
0034     unsigned parVar(unsigned fIndex) const { return mParVar[fIndex]; }
0035     std::string binVar(unsigned fIndex) const { return mBinVar[fIndex]; }
0036     std::string formula() const { return mFormula; }
0037 
0038   private:
0039     //-------- Member variables ----------
0040     int ptclType;
0041     std::string mFormula;
0042     std::vector<unsigned> mParVar;
0043     std::vector<std::string> mBinVar;
0044 
0045     COND_SERIALIZABLE;
0046   };
0047   //---------------- Record class --------------------------------
0048   //-- Each Record holds the properties of a bin -----------------
0049   class Record {
0050   public:
0051     //-------- Constructors --------------
0052     Record() : mNvar(0), mMin(0), mMax(0), mParameters(0) {}
0053     Record(unsigned fNvar,
0054            const std::vector<float>& fXMin,
0055            const std::vector<float>& fXMax,
0056            const std::vector<float>& fParameters)
0057         : mNvar(fNvar), mMin(fXMin), mMax(fXMax), mParameters(fParameters) {}
0058     Record(const std::string& fLine, unsigned fNvar);
0059     //-------- Member functions ----------
0060     float xMin(unsigned fVar) const { return mMin[fVar]; }
0061     float xMax(unsigned fVar) const { return mMax[fVar]; }
0062     float xMiddle(unsigned fVar) const { return 0.5 * (xMin(fVar) + xMax(fVar)); }
0063     float parameter(unsigned fIndex) const { return mParameters[fIndex]; }
0064     std::vector<float> parameters() const { return mParameters; }
0065     unsigned nParameters() const { return mParameters.size(); }
0066     std::string MetAxis() const { return mMetAxis; }
0067     int operator<(const Record& other) const { return xMin(0) < other.xMin(0); }
0068 
0069   private:
0070     //-------- Member variables ----------
0071     unsigned mNvar;
0072     std::vector<float> mMin;
0073     std::vector<float> mMax;
0074     std::vector<float> mParameters;
0075     std::string mMetAxis;
0076 
0077     COND_SERIALIZABLE;
0078   };
0079 
0080   //-------- Constructors --------------
0081   MEtXYcorrectParameters() { valid_ = false; }
0082   MEtXYcorrectParameters(const std::string& fFile, const std::string& fSection = "");
0083   MEtXYcorrectParameters(const MEtXYcorrectParameters::Definitions& fDefinitions,
0084                          const std::vector<MEtXYcorrectParameters::Record>& fRecords)
0085       : mDefinitions(fDefinitions), mRecords(fRecords) {
0086     valid_ = true;
0087   }
0088   //-------- Member functions ----------
0089   const Record& record(unsigned fBin) const { return mRecords[fBin]; }
0090   const Definitions& definitions() const { return mDefinitions; }
0091   unsigned size() const { return mRecords.size(); }
0092   unsigned size(unsigned fVar) const;
0093   int binIndex(const std::vector<float>& fX) const;
0094   int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const;
0095   std::vector<float> binCenters(unsigned fVar) const;
0096   void printScreen() const;
0097   void printScreen(const std::string& Section) const;
0098   void printFile(const std::string& fFileName) const;
0099   void printFile(const std::string& fFileName, const std::string& Section) const;
0100   bool isValid() const { return valid_; }
0101 
0102 private:
0103   //-------- Member variables ----------
0104   MEtXYcorrectParameters::Definitions mDefinitions;
0105   std::vector<MEtXYcorrectParameters::Record> mRecords;
0106   bool valid_;  /// is this a valid set?
0107 
0108   COND_SERIALIZABLE;
0109 };
0110 
0111 class MEtXYcorrectParametersCollection {
0112 public:
0113   enum Level_t { shiftMC = 0, shiftDY = 1, shiftTTJets = 2, shiftWJets = 3, shiftData = 4, N_LEVELS = 5 };
0114 
0115   typedef int key_type;
0116   typedef std::string label_type;
0117   typedef MEtXYcorrectParameters value_type;
0118   typedef std::pair<key_type, value_type> pair_type;
0119   typedef std::vector<pair_type> collection_type;
0120 
0121   // Constructor... initialize all three vectors to zero
0122   MEtXYcorrectParametersCollection() { correctionsShift_.clear(); }
0123 
0124   // Add a MEtXYshiftParameter object, for each source
0125   void push_back(key_type i, value_type const& j, label_type const& flav = "");
0126 
0127   // Access the MEtXYshiftParameter via the key k.
0128   // key_type is hashed to deal with the three collections
0129   MEtXYcorrectParameters const& operator[](key_type k) const;
0130 
0131   // Access the MEtXYshiftParameter via a string.
0132   // Will find the hashed value for the label, and call via that
0133   // operator.
0134   MEtXYcorrectParameters const& operator[](std::string const& label) const { return operator[](findKey(label)); }
0135 
0136   // Get a list of valid keys. These will contain hashed keys
0137   // that are aware of all three collections.
0138   void validKeys(std::vector<key_type>& keys) const;
0139 
0140   // Helper method to find all of the sections in a given
0141   // parameters file
0142   void getSections(std::string inputFile, std::vector<std::string>& outputs);
0143 
0144   key_type getShiftMcFlavBin(std::string const& Flav);
0145   key_type getShiftDyFlavBin(std::string const& Flav);
0146   key_type getShiftTTJetsFlavBin(std::string const& Flav);
0147   key_type getShiftWJetsFlavBin(std::string const& Flav);
0148   key_type getShiftDataFlavBin(std::string const& Flav);
0149 
0150   static bool isShiftMC(key_type k);
0151   static bool isShiftDY(key_type k);
0152   static bool isShiftTTJets(key_type k);
0153   static bool isShiftWJets(key_type k);
0154   static bool isShiftData(key_type k);
0155 
0156   static std::string findLabel(key_type k);
0157   static std::string levelName(key_type k);
0158 
0159   static std::string findShiftMCflavor(key_type k);
0160   static std::string findShiftDYflavor(key_type k);
0161   static std::string findShiftTTJetsFlavor(key_type k);
0162   static std::string findShiftWJetsFlavor(key_type k);
0163   static std::string findShiftDataFlavor(key_type k);
0164 
0165 protected:
0166   // Find the key corresponding to each label
0167   key_type findKey(std::string const& label) const;  // Not used
0168 
0169   collection_type correctionsShift_;
0170 
0171   COND_SERIALIZABLE;
0172 };
0173 
0174 #endif