CMS 3D CMS Logo

METCorrectorParameters.h
Go to the documentation of this file.
1 //
2 #ifndef METCorrectorParameters_h
3 #define METCorrectorParameters_h
4 
6 
7 #include <string>
8 #include <vector>
9 #include <algorithm>
10 #include <iostream>
13 
15 {
16  //---------------- METCorrectorParameters 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  std::vector<std::string> parVar() const {return mParVar; }
32  std::vector<std::string> binVar() const {return mBinVar; }
33  std::string parVar(unsigned fIndex) const {return mParVar[fIndex];}
34  std::string binVar(unsigned fIndex) const {return mBinVar[fIndex];}
35  std::string formula() const {return mFormula; }
36  private:
37  //-------- Member variables ----------
38  int ptclType;
40  std::vector<std::string> mParVar;
41  std::vector<std::string> mBinVar;
42 
44  };
45  //---------------- Record class --------------------------------
46  //-- Each Record holds the properties of a bin -----------------
47  class Record
48  {
49  public:
50  //-------- Constructors --------------
51  Record() : mNvar(0),mMin(0),mMax(0), mParameters(0) {}
52  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) {}
53  Record(const std::string& fLine, unsigned fNvar);
54  //-------- Member functions ----------
55  float xMin(unsigned fVar) const {return mMin[fVar]; }
56  float xMax(unsigned fVar) const {return mMax[fVar]; }
57  float xMiddle(unsigned fVar) const {return 0.5*(xMin(fVar)+xMax(fVar));}
58  float parameter(unsigned fIndex) const {return mParameters[fIndex]; }
59  std::vector<float> parameters() const {return mParameters; }
60  unsigned nParameters() const {return mParameters.size(); }
61  int operator< (const Record& other) const {return xMin(0) < other.xMin(0); }
62  private:
63  //-------- Member variables ----------
64  unsigned mNvar;
65  std::vector<float> mMin;
66  std::vector<float> mMax;
67  std::vector<float> mParameters;
68 
70  };
71 
72  //-------- Constructors --------------
74  METCorrectorParameters(const std::string& fFile, const std::string& fSection = "");
76  const std::vector<METCorrectorParameters::Record>& fRecords)
77  : mDefinitions(fDefinitions),mRecords(fRecords) { valid_ = true;}
78  //-------- Member functions ----------
79  const Record& record(unsigned fBin) const {return mRecords[fBin]; }
80  const Definitions& definitions() const {return mDefinitions; }
81  unsigned size() const {return mRecords.size();}
82  unsigned size(unsigned fVar) const;
83  int binIndex(const std::vector<float>& fX) const;
84  int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const;
85  std::vector<float> binCenters(unsigned fVar) const;
86  void printScreen() const;
87  void printFile(const std::string& fFileName) const;
88  bool isValid() const { return valid_; }
89 
90  private:
91  //-------- Member variables ----------
93  std::vector<METCorrectorParameters::Record> mRecords;
94  bool valid_;
95 
97 };
98 
99 
101  public:
102  enum Level_t { MiniAod=0,
103  N_LEVELS=1
104  };
105 
106  typedef int key_type;
109  typedef std::pair<key_type,value_type> pair_type;
110  typedef std::vector<pair_type> collection_type;
111 
112  // Constructor... initialize all three vectors to zero
113  METCorrectorParametersCollection() { correctionsMiniAod_.clear();}
114 
115  // Add a METCorrectorParameter object, for each source
116  void push_back( key_type i, value_type const & j, label_type const & source = "" );
117 
118  // Access the METCorrectorParameter via the key k.
119  // key_type is hashed to deal with the three collections
120  METCorrectorParameters const & operator[]( key_type k ) const;
121 
122  // Access the METCorrectorParameter via a string.
123  // Will find the hashed value for the label, and call via that
124  // operator.
126  return operator[]( findKey(label) );
127  }
128 
129  // Get a list of valid keys. These will contain hashed keys
130  // that are aware of all three collections.
131  void validKeys(std::vector<key_type> & keys ) const;
132 
133 
134  // Helper method to find all of the sections in a given
135  // parameters file
136  static void getSections( std::string inputFile,
137  std::vector<std::string> & outputs );
138  // Find the MiniAod bin for hashing
139  static key_type getMiniAodBin( std::string const & source );
140 
141  static bool isMiniAod( key_type k);
142 
143  static std::string findLabel( key_type k );
144  static std::string findMiniAodSource( key_type k );
145 
146  protected:
147 
148  // Find the key corresponding to each label
149  key_type findKey( std::string const & label ) const;
150 
151  collection_type correctionsMiniAod_;
152 
154 };
155 
156 
157 #endif
std::vector< std::string > parVar() const
METCorrectorParameters(const METCorrectorParameters::Definitions &fDefinitions, const std::vector< METCorrectorParameters::Record > &fRecords)
const Record & record(unsigned fBin) const
std::vector< float > binCenters(unsigned fVar) const
std::vector< METCorrectorParameters::Record > mRecords
std::vector< float > parameters() const
const Definitions & definitions() const
char const * label
int binIndex(const std::vector< float > &fX) const
float xMax(unsigned fVar) const
Record(unsigned fNvar, const std::vector< float > &fXMin, const std::vector< float > &fXMax, const std::vector< float > &fParameters)
std::vector< pair_type > collection_type
T operator[](int i) const
std::string binVar(unsigned fIndex) const
std::vector< std::string > binVar() const
METCorrectorParameters const & operator[](std::string const &label) const
void printFile(const std::string &fFileName) const
METCorrectorParameters::Definitions mDefinitions
int k[5][pyjets_maxn]
float xMin(unsigned fVar) const
std::string parVar(unsigned fIndex) const
#define COND_SERIALIZABLE
Definition: Serializable.h:38
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:73
float parameter(unsigned fIndex) const
int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const
std::pair< key_type, value_type > pair_type
static std::string const source
Definition: EdmProvDump.cc:47
float xMiddle(unsigned fVar) const