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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
#include "CondFormats/JetMETObjects/interface/JetCorrectionUncertainty.h"
#include "CondFormats/JetMETObjects/interface/SimpleJetCorrectionUncertainty.h"
#include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "Math/PtEtaPhiE4D.h"
#include "Math/Vector3D.h"
#include "Math/LorentzVector.h"
#include <vector>
#include <string>
/////////////////////////////////////////////////////////////////////////
JetCorrectionUncertainty::JetCorrectionUncertainty() {
mJetEta = -9999;
mJetPt = -9999;
mJetPhi = -9999;
mJetE = -9999;
mJetEMF = -9999;
mLepPx = -9999;
mLepPy = -9999;
mLepPz = -9999;
mIsJetEset = false;
mIsJetPtset = false;
mIsJetPhiset = false;
mIsJetEtaset = false;
mIsJetEMFset = false;
mIsLepPxset = false;
mIsLepPyset = false;
mIsLepPzset = false;
mAddLepToJet = false;
}
/////////////////////////////////////////////////////////////////////////
JetCorrectionUncertainty::JetCorrectionUncertainty(const std::string& fDataFile) : mUncertainty{fDataFile} {
mJetEta = -9999;
mJetPt = -9999;
mJetPhi = -9999;
mJetE = -9999;
mJetEMF = -9999;
mLepPx = -9999;
mLepPy = -9999;
mLepPz = -9999;
mIsJetEset = false;
mIsJetPtset = false;
mIsJetPhiset = false;
mIsJetEtaset = false;
mIsJetEMFset = false;
mIsLepPxset = false;
mIsLepPyset = false;
mIsLepPzset = false;
mAddLepToJet = false;
}
/////////////////////////////////////////////////////////////////////////
JetCorrectionUncertainty::JetCorrectionUncertainty(const JetCorrectorParameters& fParameters)
: mUncertainty{fParameters} {
mJetEta = -9999;
mJetPt = -9999;
mJetPhi = -9999;
mJetE = -9999;
mJetEMF = -9999;
mLepPx = -9999;
mLepPy = -9999;
mLepPz = -9999;
mIsJetEset = false;
mIsJetPtset = false;
mIsJetPhiset = false;
mIsJetEtaset = false;
mIsJetEMFset = false;
mIsLepPxset = false;
mIsLepPyset = false;
mIsLepPzset = false;
mAddLepToJet = false;
}
/////////////////////////////////////////////////////////////////////////
void JetCorrectionUncertainty::setParameters(const std::string& fDataFile) {
mUncertainty = SimpleJetCorrectionUncertainty(fDataFile);
}
/////////////////////////////////////////////////////////////////////////
float JetCorrectionUncertainty::getUncertainty(bool fDirection) {
float result;
std::vector<float> vx, vy;
vx = fillVector(mUncertainty.parameters().definitions().binVar());
vy = fillVector(mUncertainty.parameters().definitions().parVar());
result = mUncertainty.uncertainty(vx, vy[0], fDirection);
mIsJetEset = false;
mIsJetPtset = false;
mIsJetPhiset = false;
mIsJetEtaset = false;
mIsJetEMFset = false;
mIsLepPxset = false;
mIsLepPyset = false;
mIsLepPzset = false;
return result;
}
//------------------------------------------------------------------------
//--- Reads the parameter names and fills a vector of floats -------------
//------------------------------------------------------------------------
std::vector<float> JetCorrectionUncertainty::fillVector(const std::vector<std::string>& fNames) {
std::vector<float> result;
for (unsigned i = 0; i < fNames.size(); i++) {
if (fNames[i] == "JetEta") {
if (!mIsJetEtaset) {
edm::LogError("JetCorrectionUncertainty::") << " jet eta is not set";
result.push_back(-999.0);
} else {
result.push_back(mJetEta);
}
} else if (fNames[i] == "JetPt") {
if (!mIsJetPtset) {
edm::LogError("JetCorrectionUncertainty::") << " jet pt is not set";
result.push_back(-999.0);
} else {
result.push_back(mJetPt);
}
} else if (fNames[i] == "JetPhi") {
if (!mIsJetPhiset) {
edm::LogError("JetCorrectionUncertainty::") << " jet phi is not set";
result.push_back(-999.0);
} else {
result.push_back(mJetPhi);
}
} else if (fNames[i] == "JetE") {
if (!mIsJetEset) {
edm::LogError("JetCorrectionUncertainty::") << " jet energy is not set";
result.push_back(-999.0);
} else {
result.push_back(mJetE);
}
} else if (fNames[i] == "JetEMF") {
if (!mIsJetEMFset) {
edm::LogError("JetCorrectionUncertainty::") << " jet emf is not set";
result.push_back(-999.0);
} else {
result.push_back(mJetEMF);
}
} else if (fNames[i] == "LepPx") {
if (!mIsLepPxset) {
edm::LogError("JetCorrectionUncertainty::") << " lepton px is not set";
result.push_back(-999.0);
} else {
result.push_back(mLepPx);
}
} else if (fNames[i] == "LepPy") {
if (!mIsLepPyset) {
edm::LogError("JetCorrectionUncertainty::") << " lepton py is not set";
result.push_back(-999.0);
} else {
result.push_back(mLepPy);
}
} else if (fNames[i] == "LepPz") {
if (!mIsLepPzset) {
edm::LogError("JetCorrectionUncertainty::") << " lepton pz is not set";
result.push_back(-999.0);
} else {
result.push_back(mLepPz);
}
}
else {
edm::LogError("JetCorrectionUncertainty::") << " unknown parameter " << fNames[i];
result.push_back(-999.0);
}
}
return result;
}
//------------------------------------------------------------------------
//--- Calculate the PtRel (needed for the SLB) ---------------------------
//------------------------------------------------------------------------
float JetCorrectionUncertainty::getPtRel() {
typedef ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiE4D<float> > PtEtaPhiELorentzVector;
typedef ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<float> > XYZVector;
PtEtaPhiELorentzVector jet;
XYZVector lep;
jet.SetPt(mJetPt);
jet.SetEta(mJetEta);
jet.SetPhi(mJetPhi);
jet.SetE(mJetE);
lep.SetXYZ(mLepPx, mLepPy, mLepPz);
float lj_x = (mAddLepToJet) ? lep.X() + jet.Px() : jet.Px();
float lj_y = (mAddLepToJet) ? lep.Y() + jet.Py() : jet.Py();
float lj_z = (mAddLepToJet) ? lep.Z() + jet.Pz() : jet.Pz();
// absolute values squared
float lj2 = lj_x * lj_x + lj_y * lj_y + lj_z * lj_z;
float pTrel2 = -999.0;
if (lj2 > 0) {
float lep2 = lep.X() * lep.X() + lep.Y() * lep.Y() + lep.Z() * lep.Z();
// projection vec(mu) to lepjet axis
float lepXlj = lep.X() * lj_x + lep.Y() * lj_y + lep.Z() * lj_z;
// absolute value squared and normalized
float pLrel2 = lepXlj * lepXlj / lj2;
// lep2 = pTrel2 + pLrel2
pTrel2 = lep2 - pLrel2;
} else
edm::LogError("JetCorrectionUncertainty") << " not positive lepton-jet momentum: " << lj2;
return (pTrel2 > 0) ? std::sqrt(pTrel2) : 0.0;
}
//------------------------------------------------------------------------
//--- Setters ------------------------------------------------------------
//------------------------------------------------------------------------
void JetCorrectionUncertainty::setJetEta(float fEta) {
mJetEta = fEta;
mIsJetEtaset = true;
}
//------------------------------------------------------------------------
void JetCorrectionUncertainty::setJetPt(float fPt) {
mJetPt = fPt;
mIsJetPtset = true;
}
//------------------------------------------------------------------------
void JetCorrectionUncertainty::setJetPhi(float fPhi) {
mJetPhi = fPhi;
mIsJetPhiset = true;
}
//------------------------------------------------------------------------
void JetCorrectionUncertainty::setJetE(float fE) {
mJetE = fE;
mIsJetEset = true;
}
//------------------------------------------------------------------------
void JetCorrectionUncertainty::setJetEMF(float fEMF) {
mJetEMF = fEMF;
mIsJetEMFset = true;
}
//------------------------------------------------------------------------
void JetCorrectionUncertainty::setLepPx(float fPx) {
mLepPx = fPx;
mIsLepPxset = true;
}
//------------------------------------------------------------------------
void JetCorrectionUncertainty::setLepPy(float fPy) {
mLepPy = fPy;
mIsLepPyset = true;
}
//------------------------------------------------------------------------
void JetCorrectionUncertainty::setLepPz(float fPz) {
mLepPz = fPz;
mIsLepPzset = true;
}
//------------------------------------------------------------------------
|