-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJetCorrectionUncertainty.cc
274 lines (272 loc) · 8.99 KB
/
JetCorrectionUncertainty.cc
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include "JetCorrectionUncertainty.h"
#include "SimpleJetCorrectionUncertainty.h"
#include "JetCorrectorParameters.h"
//#include "FWCore/Utilities/interface/Exception.h"
#include "Utilities.cc"
#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;
mUncertainty = new SimpleJetCorrectionUncertainty();
}
/////////////////////////////////////////////////////////////////////////
JetCorrectionUncertainty::JetCorrectionUncertainty(const std::string& 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;
mUncertainty = new SimpleJetCorrectionUncertainty(fDataFile);
}
/////////////////////////////////////////////////////////////////////////
JetCorrectionUncertainty::JetCorrectionUncertainty(const JetCorrectorParameters& 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;
mUncertainty = new SimpleJetCorrectionUncertainty(fParameters);
}
/////////////////////////////////////////////////////////////////////////
JetCorrectionUncertainty::~JetCorrectionUncertainty ()
{
delete mUncertainty;
}
/////////////////////////////////////////////////////////////////////////
void JetCorrectionUncertainty::setParameters(const std::string& fDataFile)
{
//---- delete the mParameters pointer before setting the new address ---
delete mUncertainty;
mUncertainty = new 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){
//throw cms::Exception("JetCorrectionUncertainty::")<<" jet eta is not set";
handleError("JetCorrectionUncertainty"," jet eta is not set");
}
result.push_back(mJetEta);
}
else if (fNames[i] == "JetPt")
{
if (!mIsJetPtset){
//throw cms::Exception("JetCorrectionUncertainty::")<<" jet pt is not set";
handleError("JetCorrectionUncertainty"," jet pt is not set");
}
result.push_back(mJetPt);
}
else if (fNames[i] == "JetPhi")
{
if (!mIsJetPhiset){
//throw cms::Exception("JetCorrectionUncertainty::")<<" jet phi is not set";
handleError("JetCorrectionUncertainty"," jet phi is not set");
}
result.push_back(mJetPt);
}
else if (fNames[i] == "JetE")
{
if (!mIsJetEset){
//throw cms::Exception("JetCorrectionUncertainty::")<<" jet energy is not set";
handleError("JetCorrectionUncertainty"," jet energy is not set");
}
result.push_back(mJetE);
}
else if (fNames[i] == "JetEMF")
{
if (!mIsJetEMFset){
//throw cms::Exception("JetCorrectionUncertainty::")<<" jet emf is not set";
handleError("JetCorrectionUncertainty"," jet emf is not set");
}
result.push_back(mJetEMF);
}
else if (fNames[i] == "LepPx")
{
if (!mIsLepPxset){
//throw cms::Exception("JetCorrectionUncertainty::")<<" lepton px is not set";
handleError("JetCorrectionUncertainty"," lepton px is not set");
}
result.push_back(mLepPx);
}
else if (fNames[i] == "LepPy")
{
if (!mIsLepPyset){
//throw cms::Exception("JetCorrectionUncertainty::")<<" lepton py is not set";
handleError("JetCorrectionUncertainty"," lepton py is not set");
}
result.push_back(mLepPy);
}
else if (fNames[i] == "LepPz")
{
if (!mIsLepPzset){
//throw cms::Exception("JetCorrectionUncertainty::")<<" lepton pz is not set";
handleError("JetCorrectionUncertainty"," lepton pz is not set");
}
result.push_back(mLepPz);
}
else{
//throw cms::Exception("JetCorrectionUncertainty::")<<" unknown parameter "<<fNames[i];
std::stringstream sserr;
sserr<<" ERROR: unknown paramter "<<fNames[i];
handleError("JetCorrectionUncertainty",sserr.str());
}
}
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;
if (!(lj2 > 0)){
//throw cms::Exception("JetCorrectionUncertainty")<<" not positive lepton-jet momentum: "<<lj2;
std::stringstream sserr;
sserr<<" ERROR: not positive lepton-jet momentum "<<lj2;
handleError("JetCorrectionUncertainty",sserr.str());
}
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
float pTrel2 = lep2-pLrel2;
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;
}
//------------------------------------------------------------------------