CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetCorrectionUncertainty.cc
Go to the documentation of this file.
5 #include "Math/PtEtaPhiE4D.h"
6 #include "Math/Vector3D.h"
7 #include "Math/LorentzVector.h"
8 #include <vector>
9 #include <string>
10 
13 {
14  mJetEta = -9999;
15  mJetPt = -9999;
16  mJetPhi = -9999;
17  mJetE = -9999;
18  mJetEMF = -9999;
19  mLepPx = -9999;
20  mLepPy = -9999;
21  mLepPz = -9999;
22  mIsJetEset = false;
23  mIsJetPtset = false;
24  mIsJetPhiset = false;
25  mIsJetEtaset = false;
26  mIsJetEMFset = false;
27  mIsLepPxset = false;
28  mIsLepPyset = false;
29  mIsLepPzset = false;
30  mAddLepToJet = false;
32 }
35 {
36  mJetEta = -9999;
37  mJetPt = -9999;
38  mJetPhi = -9999;
39  mJetE = -9999;
40  mJetEMF = -9999;
41  mLepPx = -9999;
42  mLepPy = -9999;
43  mLepPz = -9999;
44  mIsJetEset = false;
45  mIsJetPtset = false;
46  mIsJetPhiset = false;
47  mIsJetEtaset = false;
48  mIsJetEMFset = false;
49  mIsLepPxset = false;
50  mIsLepPyset = false;
51  mIsLepPzset = false;
52  mAddLepToJet = false;
54 }
57 {
58  mJetEta = -9999;
59  mJetPt = -9999;
60  mJetPhi = -9999;
61  mJetE = -9999;
62  mJetEMF = -9999;
63  mLepPx = -9999;
64  mLepPy = -9999;
65  mLepPz = -9999;
66  mIsJetEset = false;
67  mIsJetPtset = false;
68  mIsJetPhiset = false;
69  mIsJetEtaset = false;
70  mIsJetEMFset = false;
71  mIsLepPxset = false;
72  mIsLepPyset = false;
73  mIsLepPzset = false;
74  mAddLepToJet = false;
76 }
79 {
80  delete mUncertainty;
81 }
83 void JetCorrectionUncertainty::setParameters(const std::string& fDataFile)
84 {
85  //---- delete the mParameters pointer before setting the new address ---
86  delete mUncertainty;
88 }
91 {
92  float result;
93  std::vector<float> vx,vy;
96  result = mUncertainty->uncertainty(vx,vy[0],fDirection);
97  mIsJetEset = false;
98  mIsJetPtset = false;
99  mIsJetPhiset = false;
100  mIsJetEtaset = false;
101  mIsJetEMFset = false;
102  mIsLepPxset = false;
103  mIsLepPyset = false;
104  mIsLepPzset = false;
105  return result;
106 }
107 //------------------------------------------------------------------------
108 //--- Reads the parameter names and fills a vector of floats -------------
109 //------------------------------------------------------------------------
110 std::vector<float> JetCorrectionUncertainty::fillVector(const std::vector<std::string>& fNames)
111 {
112  std::vector<float> result;
113  for(unsigned i=0;i<fNames.size();i++)
114  {
115  if (fNames[i] == "JetEta")
116  {
117  if (!mIsJetEtaset)
118  throw cms::Exception("JetCorrectionUncertainty::")<<" jet eta is not set";
119  result.push_back(mJetEta);
120  }
121  else if (fNames[i] == "JetPt")
122  {
123  if (!mIsJetPtset)
124  throw cms::Exception("JetCorrectionUncertainty::")<<" jet pt is not set";
125  result.push_back(mJetPt);
126  }
127  else if (fNames[i] == "JetPhi")
128  {
129  if (!mIsJetPhiset)
130  throw cms::Exception("JetCorrectionUncertainty::")<<" jet phi is not set";
131  result.push_back(mJetPt);
132  }
133  else if (fNames[i] == "JetE")
134  {
135  if (!mIsJetEset)
136  throw cms::Exception("JetCorrectionUncertainty::")<<" jet energy is not set";
137  result.push_back(mJetE);
138  }
139  else if (fNames[i] == "JetEMF")
140  {
141  if (!mIsJetEMFset)
142  throw cms::Exception("JetCorrectionUncertainty::")<<" jet emf is not set";
143  result.push_back(mJetEMF);
144  }
145  else if (fNames[i] == "LepPx")
146  {
147  if (!mIsLepPxset)
148  throw cms::Exception("JetCorrectionUncertainty::")<<" lepton px is not set";
149  result.push_back(mLepPx);
150  }
151  else if (fNames[i] == "LepPy")
152  {
153  if (!mIsLepPyset)
154  throw cms::Exception("JetCorrectionUncertainty::")<<" lepton py is not set";
155  result.push_back(mLepPy);
156  }
157  else if (fNames[i] == "LepPz")
158  {
159  if (!mIsLepPzset)
160  throw cms::Exception("JetCorrectionUncertainty::")<<" lepton pz is not set";
161  result.push_back(mLepPz);
162  }
163  else
164  throw cms::Exception("JetCorrectionUncertainty::")<<" unknown parameter "<<fNames[i];
165  }
166  return result;
167 }
168 //------------------------------------------------------------------------
169 //--- Calculate the PtRel (needed for the SLB) ---------------------------
170 //------------------------------------------------------------------------
172 {
173  typedef ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiE4D<float> > PtEtaPhiELorentzVector;
174  typedef ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<float> > XYZVector;
175  PtEtaPhiELorentzVector jet;
176  XYZVector lep;
177  jet.SetPt(mJetPt);
178  jet.SetEta(mJetEta);
179  jet.SetPhi(mJetPhi);
180  jet.SetE(mJetE);
181  lep.SetXYZ(mLepPx,mLepPy,mLepPz);
182  float lj_x = (mAddLepToJet) ? lep.X()+jet.Px() : jet.Px();
183  float lj_y = (mAddLepToJet) ? lep.Y()+jet.Py() : jet.Py();
184  float lj_z = (mAddLepToJet) ? lep.Z()+jet.Pz() : jet.Pz();
185  // absolute values squared
186  float lj2 = lj_x*lj_x+lj_y*lj_y+lj_z*lj_z;
187  if (!(lj2 > 0))
188  throw cms::Exception("JetCorrectionUncertainty")<<" not positive lepton-jet momentum: "<<lj2;
189  float lep2 = lep.X()*lep.X()+lep.Y()*lep.Y()+lep.Z()*lep.Z();
190  // projection vec(mu) to lepjet axis
191  float lepXlj = lep.X()*lj_x+lep.Y()*lj_y+lep.Z()*lj_z;
192  // absolute value squared and normalized
193  float pLrel2 = lepXlj*lepXlj/lj2;
194  // lep2 = pTrel2 + pLrel2
195  float pTrel2 = lep2-pLrel2;
196  return (pTrel2 > 0) ? std::sqrt(pTrel2) : 0.0;
197 }
198 //------------------------------------------------------------------------
199 //--- Setters ------------------------------------------------------------
200 //------------------------------------------------------------------------
202 {
203  mJetEta = fEta;
204  mIsJetEtaset = true;
205 }
206 //------------------------------------------------------------------------
208 {
209  mJetPt = fPt;
210  mIsJetPtset = true;
211 }
212 //------------------------------------------------------------------------
214 {
215  mJetPhi = fPhi;
216  mIsJetPhiset = true;
217 }
218 //------------------------------------------------------------------------
220 {
221  mJetE = fE;
222  mIsJetEset = true;
223 }
224 //------------------------------------------------------------------------
226 {
227  mJetEMF = fEMF;
228  mIsJetEMFset = true;
229 }
230 //------------------------------------------------------------------------
232 {
233  mLepPx = fPx;
234  mIsLepPxset = true;
235 }
236 //------------------------------------------------------------------------
238 {
239  mLepPy = fPy;
240  mIsLepPyset = true;
241 }
242 //------------------------------------------------------------------------
244 {
245  mLepPz = fPz;
246  mIsLepPzset = true;
247 }
248 //------------------------------------------------------------------------
int i
Definition: DBlmapReader.cc:9
SimpleJetCorrectionUncertainty * mUncertainty
const Definitions & definitions() const
std::vector< std::string > parVar() const
T sqrt(T t)
Definition: SSEVec.h:46
tuple result
Definition: query.py:137
PtEtaPhiELorentzVectorD PtEtaPhiELorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:28
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
void setParameters(const std::string &fDataFile)
float uncertainty(std::vector< float > fX, float fY, bool fDirection) const
float getUncertainty(bool fDirection)
std::vector< float > fillVector(const std::vector< std::string > &fNames)
std::vector< std::string > binVar() const
const JetCorrectorParameters & parameters() const