CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetCorrectorParameters.h
Go to the documentation of this file.
1 //
2 // Original Author: Fedor Ratnikov Nov 9, 2007
3 // $Id: JetCorrectorParameters.h,v 1.15 2012/03/01 18:24:52 srappocc Exp $
4 //
5 // Generic parameters for Jet corrections
6 //
7 #ifndef JetCorrectorParameters_h
8 #define JetCorrectorParameters_h
9 
10 #include <string>
11 #include <vector>
12 #include <algorithm>
13 #include <iostream>
15 
17 {
18  //---------------- JetCorrectorParameters class ----------------
19  //-- Encapsulates all the information of the parametrization ---
20  public:
21  //---------------- Definitions class ---------------------------
22  //-- Global iformation about the parametrization is kept here --
23  class Definitions
24  {
25  public:
26  //-------- Constructors --------------
28  Definitions(const std::vector<std::string>& fBinVar, const std::vector<std::string>& fParVar, const std::string& fFormula, bool fIsResponse);
29  Definitions(const std::string& fLine);
30  //-------- Member functions ----------
31  unsigned nBinVar() const {return mBinVar.size(); }
32  unsigned nParVar() const {return mParVar.size(); }
33  std::vector<std::string> parVar() const {return mParVar; }
34  std::vector<std::string> binVar() const {return mBinVar; }
35  std::string parVar(unsigned fIndex) const {return mParVar[fIndex];}
36  std::string binVar(unsigned fIndex) const {return mBinVar[fIndex];}
37  std::string formula() const {return mFormula; }
38  std::string level() const {return mLevel; }
39  bool isResponse() const {return mIsResponse; }
40  private:
41  //-------- Member variables ----------
42  bool mIsResponse;
43  std::string mLevel;
44  std::string mFormula;
45  std::vector<std::string> mParVar;
46  std::vector<std::string> mBinVar;
47  };
48  //---------------- Record class --------------------------------
49  //-- Each Record holds the properties of a bin -----------------
50  class Record
51  {
52  public:
53  //-------- Constructors --------------
54  Record() : mNvar(0),mMin(0),mMax(0) {}
55  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) {}
56  Record(const std::string& fLine, unsigned fNvar);
57  //-------- Member functions ----------
58  float xMin(unsigned fVar) const {return mMin[fVar]; }
59  float xMax(unsigned fVar) const {return mMax[fVar]; }
60  float xMiddle(unsigned fVar) const {return 0.5*(xMin(fVar)+xMax(fVar));}
61  float parameter(unsigned fIndex) const {return mParameters[fIndex]; }
62  std::vector<float> parameters() const {return mParameters; }
63  unsigned nParameters() const {return mParameters.size(); }
64  int operator< (const Record& other) const {return xMin(0) < other.xMin(0); }
65  private:
66  //-------- Member variables ----------
67  unsigned mNvar;
68  std::vector<float> mMin;
69  std::vector<float> mMax;
70  std::vector<float> mParameters;
71  };
72 
73  //-------- Constructors --------------
75  JetCorrectorParameters(const std::string& fFile, const std::string& fSection = "");
77  const std::vector<JetCorrectorParameters::Record>& fRecords)
78  : mDefinitions(fDefinitions),mRecords(fRecords) { valid_ = true;}
79  //-------- Member functions ----------
80  const Record& record(unsigned fBin) const {return mRecords[fBin]; }
81  const Definitions& definitions() const {return mDefinitions; }
82  unsigned size() const {return mRecords.size();}
83  unsigned size(unsigned fVar) const;
84  int binIndex(const std::vector<float>& fX) const;
85  int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const;
86  std::vector<float> binCenters(unsigned fVar) const;
87  void printScreen() const;
88  void printFile(const std::string& fFileName) const;
89  bool isValid() const { return valid_; }
90 
91  private:
92  //-------- Member variables ----------
94  std::vector<JetCorrectorParameters::Record> mRecords;
95  bool valid_;
96 };
97 
98 
99 
101  //---------------- JetCorrectorParametersCollection class ----------------
102  //-- Adds several JetCorrectorParameters together by algorithm type ---
103  //-- to reduce the number of payloads in the Database ---
104  public:
105  enum Level_t { L1Offset=0,
107  L1FastJet = 10,
111  L4EMF=3,
113  L6UE=5,
133  };
134 
135 
138  typedef int key_type;
139  typedef std::string label_type;
141  typedef std::pair<key_type,value_type> pair_type;
142  typedef std::vector<pair_type> collection_type;
143 
144 
145  // Constructor... initialize all three vectors to zero
147 
148  // Add a JetCorrectorParameter object, possibly with flavor.
149  void push_back( key_type i, value_type const & j, label_type const & flav = "" );
150 
151  // Access the JetCorrectorParameter via the key k.
152  // key_type is hashed to deal with the three collections
153  JetCorrectorParameters const & operator[]( key_type k ) const;
154 
155  // Access the JetCorrectorParameter via a string.
156  // Will find the hashed value for the label, and call via that
157  // operator.
158  JetCorrectorParameters const & operator[]( std::string const & label ) const {
159  return operator[]( findKey(label) );
160  }
161 
162  // Get a list of valid keys. These will contain hashed keys
163  // that are aware of all three collections.
164  void validKeys(std::vector<key_type> & keys ) const;
165 
166 
167 
168  // Helper method to find all of the sections in a given
169  // parameters file
170  static void getSections( std::string inputFile,
171  std::vector<std::string> & outputs );
172 
173  // Find the L5 bin for hashing
174  static key_type getL5Bin( std::string const & flav );
175  // Find the L7 bin for hashing
176  static key_type getL7Bin( std::string const & flav );
177  // Check if this is an L5 hashed value
178  static bool isL5( key_type k );
179  // Check if this is an L7 hashed value
180  static bool isL7( key_type k );
181 
182  static std::string findLabel( key_type k ){
183  if ( isL5(k) ) return findL5Flavor(k);
184  else if ( isL7(k) ) return findL7Parton(k);
185  else return labels_[k];
186  }
187 
188  static std::string findL5Flavor( key_type k ){
189  if ( k == L5Flavor ) return labels_[L5Flavor];
190  else
191  return l5Flavors_[k / 100 - 1];
192  }
193 
194  static std::string findL7Parton( key_type k ){
195  if ( k == L7Parton ) return labels_[L7Parton];
196  else
197  return l7Partons_[k / 1000 - 1];
198  }
199 
200  protected:
201 
202  // Find the key corresponding to each label
203  key_type findKey( std::string const & label ) const;
204 
208  static const char * labelsArray_[N_LEVELS];
209  static std::vector<std::string> labels_;
210 
211  static const char * l5FlavorArray_[N_L5_SPECIES];
212  static std::vector<std::string> l5Flavors_;
213 
214  static const char * l7PartonArray_[N_L7_SPECIES];
215  static std::vector<std::string> l7Partons_;
216 };
217 
218 
219 
220 #endif
float xMin(unsigned fVar) const
static std::string findLabel(key_type k)
int i
Definition: DBlmapReader.cc:9
static std::vector< std::string > labels_
JetCorrectorParameters const & operator[](std::string const &label) const
void push_back(key_type i, value_type const &j, label_type const &flav="")
std::pair< key_type, value_type > pair_type
std::string parVar(unsigned fIndex) const
static std::string findL7Parton(key_type k)
std::vector< float > parameters() const
std::string binVar(unsigned fIndex) const
const Definitions & definitions() const
std::vector< pair_type > collection_type
static key_type getL5Bin(std::string const &flav)
static const char * l5FlavorArray_[N_L5_SPECIES]
static const char * labelsArray_[N_LEVELS]
std::vector< JetCorrectorParameters::Record > mRecords
const Record & record(unsigned fBin) const
std::vector< std::string > parVar() const
float parameter(unsigned fIndex) const
static std::string findL5Flavor(key_type k)
void printFile(const std::string &fFileName) const
int binIndex(const std::vector< float > &fX) const
std::vector< float > binCenters(unsigned fVar) const
Record(unsigned fNvar, const std::vector< float > &fXMin, const std::vector< float > &fXMax, const std::vector< float > &fParameters)
int j
Definition: DBlmapReader.cc:9
float xMiddle(unsigned fVar) const
static const char * l7PartonArray_[N_L7_SPECIES]
static std::vector< std::string > l7Partons_
key_type findKey(std::string const &label) const
float xMax(unsigned fVar) const
int k[5][pyjets_maxn]
int operator<(const Record &other) const
static key_type getL7Bin(std::string const &flav)
static std::vector< std::string > l5Flavors_
static void getSections(std::string inputFile, std::vector< std::string > &outputs)
void validKeys(std::vector< key_type > &keys) const
std::vector< std::string > binVar() const
JetCorrectorParameters::Definitions mDefinitions
int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const
JetCorrectorParameters const & operator[](key_type k) const
JetCorrectorParameters(const JetCorrectorParameters::Definitions &fDefinitions, const std::vector< JetCorrectorParameters::Record > &fRecords)