CMS 3D CMS Logo

MEtXYcorrectParameters.h
Go to the documentation of this file.
1 //
2 #ifndef MEtXYcorrectParameters_h
3 #define MEtXYcorrectParameters_h
4 
6 
7 #include <string>
8 #include <vector>
9 #include <algorithm>
10 #include <iostream>
13 
15 {
16  //---------------- MEtParameters class ----------------
17  //-- Encapsulates all the information of the parametrization ---
18  public:
19  //---------------- Definitions class ---------------------------
20  //-- Global iformation about the parametrization is kept here --
21  class Definitions
22  {
23  public:
24  //-------- Constructors --------------
26  Definitions(const std::vector<std::string>& fVar, const std::vector<std::string>& fParVar, const std::string& fFormula);
27  Definitions(const std::string& fLine);
28  //-------- Member functions ----------
29  unsigned nBinVar() const {return mBinVar.size(); }
30  unsigned nParVar() const {return mParVar.size(); }
31  int PtclType() const {return ptclType; }
32  std::vector<unsigned> parVar() const {return mParVar; } // parameterized Variable
33  std::vector<std::string> binVar() const {return mBinVar; }
34  unsigned parVar(unsigned fIndex) const {return mParVar[fIndex];}
35  std::string binVar(unsigned fIndex) const {return mBinVar[fIndex];}
36  std::string formula() const {return mFormula; }
37  private:
38  //-------- Member variables ----------
39  int ptclType;
41  std::vector<unsigned> mParVar;
42  std::vector<std::string> mBinVar;
43 
45  };
46  //---------------- Record class --------------------------------
47  //-- Each Record holds the properties of a bin -----------------
48  class Record
49  {
50  public:
51  //-------- Constructors --------------
52  Record() : mNvar(0),mMin(0),mMax(0), mParameters(0) {}
53  Record(unsigned fNvar, const std::vector<float>& fXMin, const std::vector<float>& fXMax, const std::vector<float>& fParameters) : mNvar(fNvar),mMin(fXMin),mMax(fXMax),mParameters(fParameters) {}
54  Record(const std::string& fLine, unsigned fNvar);
55  //-------- Member functions ----------
56  float xMin(unsigned fVar) const {return mMin[fVar]; }
57  float xMax(unsigned fVar) const {return mMax[fVar]; }
58  float xMiddle(unsigned fVar) const {return 0.5*(xMin(fVar)+xMax(fVar));}
59  float parameter(unsigned fIndex) const {return mParameters[fIndex]; }
60  std::vector<float> parameters() const {return mParameters; }
61  unsigned nParameters() const {return mParameters.size(); }
62  std::string MetAxis() const {return mMetAxis; }
63  int operator< (const Record& other) const {return xMin(0) < other.xMin(0); }
64  private:
65  //-------- Member variables ----------
66  unsigned mNvar;
67  std::vector<float> mMin;
68  std::vector<float> mMax;
69  std::vector<float> mParameters;
71 
73  };
74 
75  //-------- Constructors --------------
77  MEtXYcorrectParameters(const std::string& fFile, const std::string& fSection = "");
79  const std::vector<MEtXYcorrectParameters::Record>& fRecords)
80  : mDefinitions(fDefinitions),mRecords(fRecords) { valid_ = true;}
81  //-------- Member functions ----------
82  const Record& record(unsigned fBin) const {return mRecords[fBin]; }
83  const Definitions& definitions() const {return mDefinitions; }
84  unsigned size() const {return mRecords.size();}
85  unsigned size(unsigned fVar) const;
86  int binIndex(const std::vector<float>& fX) const;
87  int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const;
88  std::vector<float> binCenters(unsigned fVar) const;
89  void printScreen() const;
90  void printScreen(const std::string& Section) const;
91  void printFile(const std::string& fFileName) const;
92  void printFile(const std::string& fFileName, const std::string& Section)const;
93  bool isValid() const { return valid_; }
94 
95  private:
96  //-------- Member variables ----------
98  std::vector<MEtXYcorrectParameters::Record> mRecords;
99  bool valid_;
100 
102 };
103 
104 
106  public:
107  enum Level_t { shiftMC=0,
108  shiftDY=1,
109  shiftTTJets=2,
110  shiftWJets=3,
111  shiftData=4,
112  N_LEVELS=5
113  };
114 
115  typedef int key_type;
118  typedef std::pair<key_type,value_type> pair_type;
119  typedef std::vector<pair_type> collection_type;
120 
121  // Constructor... initialize all three vectors to zero
123  correctionsShift_.clear();
124  }
125 
126  // Add a MEtXYshiftParameter object, for each source
127  void push_back( key_type i, value_type const & j, label_type const & flav = "" );
128 
129  // Access the MEtXYshiftParameter via the key k.
130  // key_type is hashed to deal with the three collections
131  MEtXYcorrectParameters const & operator[]( key_type k ) const;
132 
133  // Access the MEtXYshiftParameter via a string.
134  // Will find the hashed value for the label, and call via that
135  // operator.
137  return operator[]( findKey(label) );
138  }
139 
140  // Get a list of valid keys. These will contain hashed keys
141  // that are aware of all three collections.
142  void validKeys(std::vector<key_type> & keys ) const;
143 
144 
145  // Helper method to find all of the sections in a given
146  // parameters file
147  void getSections( std::string inputFile,
148  std::vector<std::string> & outputs );
149 
150  key_type getShiftMcFlavBin( std::string const & Flav );
151  key_type getShiftDyFlavBin( std::string const & Flav );
152  key_type getShiftTTJetsFlavBin( std::string const & Flav );
153  key_type getShiftWJetsFlavBin( std::string const & Flav );
154  key_type getShiftDataFlavBin( std::string const & Flav );
155 
156  static bool isShiftMC( key_type k);
157  static bool isShiftDY( key_type k);
158  static bool isShiftTTJets( key_type k);
159  static bool isShiftWJets( key_type k);
160  static bool isShiftData( key_type k);
161 
162  static std::string findLabel( key_type k );
163  static std::string levelName( key_type k );
164 
165 
166  static std::string findShiftMCflavor( key_type k );
167  static std::string findShiftDYflavor( key_type k );
168  static std::string findShiftTTJetsFlavor( key_type k );
169  static std::string findShiftWJetsFlavor( key_type k );
170  static std::string findShiftDataFlavor( key_type k );
171 
172  protected:
173 
174  // Find the key corresponding to each label
175  key_type findKey( std::string const & label ) const; // Not used
176 
177  collection_type correctionsShift_;
178 
180 };
181 
182 
183 #endif
std::string binVar(unsigned fIndex) const
int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const
float parameter(unsigned fIndex) const
std::vector< pair_type > collection_type
std::vector< MEtXYcorrectParameters::Record > mRecords
std::pair< key_type, value_type > pair_type
const Definitions & definitions() const
float xMax(unsigned fVar) const
int binIndex(const std::vector< float > &fX) const
float xMiddle(unsigned fVar) const
void printFile(const std::string &fFileName) const
MEtXYcorrectParameters const & operator[](std::string const &label) const
const Record & record(unsigned fBin) const
char const * label
T operator[](int i) const
unsigned parVar(unsigned fIndex) const
const char * levelName(LogLevel)
Definition: fwLog.cc:34
int k[5][pyjets_maxn]
MEtXYcorrectParameters::Definitions mDefinitions
std::vector< std::string > binVar() const
#define COND_SERIALIZABLE
Definition: Serializable.h:38
Record(unsigned fNvar, const std::vector< float > &fXMin, const std::vector< float > &fXMax, const std::vector< float > &fParameters)
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:73
float xMin(unsigned fVar) const
MEtXYcorrectParameters(const MEtXYcorrectParameters::Definitions &fDefinitions, const std::vector< MEtXYcorrectParameters::Record > &fRecords)
std::vector< float > parameters() const
std::vector< unsigned > parVar() const
std::vector< float > binCenters(unsigned fVar) const