1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
//
#ifndef METCorrectorParameters_h
#define METCorrectorParameters_h
#include "CondFormats/Serialization/interface/Serializable.h"
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
class METCorrectorParameters {
//---------------- METCorrectorParameters 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<std::string>& fVar,
const std::vector<std::string>& fParVar,
const std::string& fFormula);
Definitions(const std::string& fLine);
//-------- Member functions ----------
unsigned nBinVar() const { return mBinVar.size(); }
unsigned nParVar() const { return mParVar.size(); }
std::vector<std::string> parVar() const { return mParVar; }
std::vector<std::string> 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; }
private:
//-------- Member variables ----------
int ptclType;
std::string mFormula;
std::vector<std::string> mParVar;
std::vector<std::string> mBinVar;
COND_SERIALIZABLE;
};
//---------------- Record class --------------------------------
//-- Each Record holds the properties of a bin -----------------
class Record {
public:
//-------- Constructors --------------
Record() : mNvar(0), mMin(0), mMax(0), mParameters(0) {}
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) {}
Record(const std::string& fLine, unsigned fNvar);
//-------- Member functions ----------
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<float> parameters() const { return mParameters; }
unsigned nParameters() const { return mParameters.size(); }
int operator<(const Record& other) const { return xMin(0) < other.xMin(0); }
private:
//-------- Member variables ----------
unsigned mNvar;
std::vector<float> mMin;
std::vector<float> mMax;
std::vector<float> mParameters;
COND_SERIALIZABLE;
};
//-------- Constructors --------------
METCorrectorParameters() { valid_ = false; }
METCorrectorParameters(const std::string& fFile, const std::string& fSection = "");
METCorrectorParameters(const METCorrectorParameters::Definitions& fDefinitions,
const std::vector<METCorrectorParameters::Record>& 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<float>& fX) const;
int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const;
std::vector<float> binCenters(unsigned fVar) const;
void printScreen() const;
void printFile(const std::string& fFileName) const;
bool isValid() const { return valid_; }
private:
//-------- Member variables ----------
METCorrectorParameters::Definitions mDefinitions;
std::vector<METCorrectorParameters::Record> mRecords;
bool valid_; /// is this a valid set?
COND_SERIALIZABLE;
};
class METCorrectorParametersCollection {
public:
enum Level_t { MiniAod = 0, N_LEVELS = 1 };
typedef int key_type;
typedef std::string label_type;
typedef METCorrectorParameters value_type;
typedef std::pair<key_type, value_type> pair_type;
typedef std::vector<pair_type> collection_type;
// Constructor... initialize all three vectors to zero
METCorrectorParametersCollection() { correctionsMiniAod_.clear(); }
// Add a METCorrectorParameter object, for each source
void push_back(key_type i, value_type const& j, label_type const& source = "");
// Access the METCorrectorParameter via the key k.
// key_type is hashed to deal with the three collections
METCorrectorParameters const& operator[](key_type k) const;
// Access the METCorrectorParameter via a string.
// Will find the hashed value for the label, and call via that
// operator.
METCorrectorParameters 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<key_type>& keys) const;
// Helper method to find all of the sections in a given
// parameters file
static void getSections(std::string inputFile, std::vector<std::string>& outputs);
// Find the MiniAod bin for hashing
static key_type getMiniAodBin(std::string const& source);
static bool isMiniAod(key_type k);
static std::string findLabel(key_type k);
static std::string findMiniAodSource(key_type k);
protected:
// Find the key corresponding to each label
key_type findKey(std::string const& label) const;
collection_type correctionsMiniAod_;
COND_SERIALIZABLE;
};
#endif
|