CMS 3D CMS Logo

MET.cc
Go to the documentation of this file.
1 //
2 //
3 
5 
6 using namespace pat;
7 
10 
12 MET::MET(const reco::MET &aMET) : PATObject<reco::MET>(aMET) {
13  const reco::CaloMET *calo = dynamic_cast<const reco::CaloMET *>(&aMET);
14  if (calo != nullptr)
15  caloMET_.push_back(calo->getSpecific());
16  const reco::PFMET *pf = dynamic_cast<const reco::PFMET *>(&aMET);
17  if (pf != nullptr)
18  pfMET_.push_back(pf->getSpecific());
19  const pat::MET *pm = dynamic_cast<const pat::MET *>(&aMET);
20  if (pm != nullptr)
21  this->operator=(*pm);
22 
23  metSig_ = 0.;
24  sumPtUnclustered_ = 0.;
25  initCorMap();
26 }
27 
29 MET::MET(const edm::RefToBase<reco::MET> &aMETRef) : PATObject<reco::MET>(aMETRef) {
30  const reco::CaloMET *calo = dynamic_cast<const reco::CaloMET *>(aMETRef.get());
31  if (calo != nullptr)
32  caloMET_.push_back(calo->getSpecific());
33  const reco::PFMET *pf = dynamic_cast<const reco::PFMET *>(aMETRef.get());
34  if (pf != nullptr)
35  pfMET_.push_back(pf->getSpecific());
36  const pat::MET *pm = dynamic_cast<const pat::MET *>(aMETRef.get());
37  if (pm != nullptr)
38  this->operator=(*pm);
39 
40  metSig_ = 0.;
41  sumPtUnclustered_ = 0.;
42  initCorMap();
43 }
44 
46 MET::MET(const edm::Ptr<reco::MET> &aMETRef) : PATObject<reco::MET>(aMETRef) {
47  const reco::CaloMET *calo = dynamic_cast<const reco::CaloMET *>(aMETRef.get());
48  if (calo != nullptr)
49  caloMET_.push_back(calo->getSpecific());
50  const reco::PFMET *pf = dynamic_cast<const reco::PFMET *>(aMETRef.get());
51  if (pf != nullptr)
52  pfMET_.push_back(pf->getSpecific());
53  const pat::MET *pm = dynamic_cast<const pat::MET *>(aMETRef.get());
54  if (pm != nullptr)
55  this->operator=(*pm);
56 
57  metSig_ = 0.;
58  sumPtUnclustered_ = 0.;
59  initCorMap();
60 }
61 
63 MET::MET(MET const &iOther)
64  : PATObject<reco::MET>(iOther),
65  genMET_(iOther.genMET_),
66  caloMET_(iOther.caloMET_),
67  pfMET_(iOther.pfMET_),
68  metSig_(iOther.metSig_),
70  uncertaintiesRaw_(iOther.uncertaintiesRaw_), //74X reading compatibility
71  uncertaintiesType1_(iOther.uncertaintiesType1_), //74X compatibility
72  uncertaintiesType1p2_(iOther.uncertaintiesType1p2_), //74X compatibility
74  corrections_(iOther.corrections_),
76  initCorMap();
77 }
78 
80 // old uncertainties discarded on purpose to avoid confusion
81 MET::MET(const reco::MET &corMET, const MET &srcMET)
82  : PATObject<reco::MET>(corMET),
83  genMET_(srcMET.genMET_),
84  caloMET_(srcMET.caloMET_),
85  pfMET_(srcMET.pfMET_),
86  metSig_(srcMET.metSig_),
90 
91  initCorMap();
92 }
93 
96 
97 MET &MET::operator=(MET const &iOther) {
99  genMET_ = iOther.genMET_;
100  caloMET_ = iOther.caloMET_;
101  pfMET_ = iOther.pfMET_;
102  uncertaintiesRaw_ = iOther.uncertaintiesRaw_; //74X compatibility
106  corrections_ = iOther.corrections_;
107  metSig_ = iOther.metSig_;
110 
111  return *this;
112 }
113 
115 const reco::GenMET *MET::genMET() const { return (!genMET_.empty() ? &genMET_.front() : nullptr); }
116 
118 void MET::setGenMET(const reco::GenMET &gm) {
119  genMET_.clear();
120  genMET_.push_back(gm);
121 }
122 
123 //Method to set the MET significance
124 void MET::setMETSignificance(const double &metSig) { metSig_ = metSig; }
125 
126 double MET::metSignificance() const { return metSig_; }
127 
128 void MET::setMETSumPtUnclustered(const double &sumPtUnclustered) { sumPtUnclustered_ = sumPtUnclustered; }
129 
130 double MET::metSumPtUnclustered() const { return sumPtUnclustered_; }
131 
133  std::vector<MET::METCorrectionType> tmpRaw;
134  std::vector<MET::METCorrectionType> tmpType1;
135  std::vector<MET::METCorrectionType> tmpType01;
136  std::vector<MET::METCorrectionType> tmpTypeXY;
137  std::vector<MET::METCorrectionType> tmpType1XY;
138  std::vector<MET::METCorrectionType> tmpType01XY;
139  std::vector<MET::METCorrectionType> tmpType1Smear;
140  std::vector<MET::METCorrectionType> tmpType01Smear;
141  std::vector<MET::METCorrectionType> tmpType1SmearXY;
142  std::vector<MET::METCorrectionType> tmpType01SmearXY;
143 
144  tmpRaw.push_back(MET::None);
145 
146  tmpType1.push_back(MET::T1);
147  tmpType01.push_back(MET::T1);
148  tmpType1XY.push_back(MET::T1);
149  tmpType01XY.push_back(MET::T1);
150  tmpType1Smear.push_back(MET::T1);
151  tmpType01Smear.push_back(MET::T1);
152  tmpType1SmearXY.push_back(MET::T1);
153  tmpType01SmearXY.push_back(MET::T1);
154 
155  tmpType01.push_back(MET::T0);
156  tmpType01XY.push_back(MET::T0);
157  tmpType01Smear.push_back(MET::T0);
158  tmpType01SmearXY.push_back(MET::T0);
159 
160  tmpType1Smear.push_back(MET::Smear);
161  tmpType01Smear.push_back(MET::Smear);
162  tmpType1SmearXY.push_back(MET::Smear);
163  tmpType01SmearXY.push_back(MET::Smear);
164 
165  tmpTypeXY.push_back(MET::TXYForRaw);
166  tmpType1XY.push_back(MET::TXY);
167  tmpType01XY.push_back(MET::TXYForT01);
168  tmpType1SmearXY.push_back(MET::TXYForT1Smear);
169  tmpType01SmearXY.push_back(MET::TXYForT01Smear);
170 
171  corMap_[MET::Raw] = tmpRaw;
172  corMap_[MET::Type1] = tmpType1;
173  corMap_[MET::Type01] = tmpType01;
174  corMap_[MET::TypeXY] = tmpTypeXY;
175  corMap_[MET::Type1XY] = tmpType1XY;
176  corMap_[MET::Type01XY] = tmpType01XY;
177  corMap_[MET::Type1Smear] = tmpType1Smear;
178  corMap_[MET::Type01Smear] = tmpType01Smear;
179  corMap_[MET::Type1SmearXY] = tmpType1SmearXY;
180  corMap_[MET::Type01SmearXY] = tmpType01SmearXY;
181 
182  //specific calo case
183  std::vector<MET::METCorrectionType> tmpRawCalo;
184  tmpRawCalo.push_back(MET::Calo);
185  corMap_[MET::RawCalo] = tmpRawCalo;
186 
187  //specific chs case
188  std::vector<MET::METCorrectionType> tmpRawChs;
189  tmpRawChs.push_back(MET::Chs);
190  corMap_[MET::RawChs] = tmpRawChs;
191 
192  //specific trk case
193  std::vector<MET::METCorrectionType> tmpRawTrk;
194  tmpRawTrk.push_back(MET::Trk);
195  corMap_[MET::RawTrk] = tmpRawTrk;
196 }
197 
199  //find corrections shifts =============================
200  std::map<MET::METCorrectionLevel, std::vector<MET::METCorrectionType> >::const_iterator itCor_ = corMap_.find(cor);
201  if (itCor_ == corMap_.end())
202  throw cms::Exception("Unsupported", "Specified MET correction scheme does not exist");
203 
204  bool isSmeared = false;
205  MET::PackedMETUncertainty totShift;
206  unsigned int scor = itCor_->second.size();
207  for (unsigned int i = 0; i < scor; i++) {
208  totShift.add(corrections_[itCor_->second[i]].dpx(),
209  corrections_[itCor_->second[i]].dpy(),
210  corrections_[itCor_->second[i]].dsumEt());
211 
212  if (itCor_->first >= MET::Type1Smear)
213  isSmeared = true;
214  }
215 
216  //find uncertainty shift =============================
217 
218  if (uncertainties_.empty())
219  return totShift;
220 
221  if (shift >= MET::METUncertaintySize)
222  throw cms::Exception("Unsupported", "MET uncertainty does not exist");
223  if (isSmeared && shift <= MET::JetResDown)
224  shift = (MET::METUncertainty)(MET::METUncertaintySize + shift + 1);
225 
226  totShift.add(uncertainties_[shift].dpx(), uncertainties_[shift].dpy(), uncertainties_[shift].dsumEt());
227 
228  return totShift;
229 }
230 
232  Vector2 vo;
233 
234  //backward compatibility with 74X samples -> the only one
235  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
236  //will be removed once 74X is not used anymore
237  if (!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
238  if (cor != MET::METCorrectionLevel::RawCalo) {
239  vo = shiftedP2_74x(shift, cor);
240  } else {
242  vo = ret;
243  }
244  } else {
245  const MET::PackedMETUncertainty &v = findMETTotalShift(cor, shift);
246  Vector2 ret{(px() + v.dpx()), (py() + v.dpy())};
247  //return ret;
248  vo = ret;
249  }
250  return vo;
251 }
253  Vector vo;
254 
255  //backward compatibility with 74X samples -> the only one
256  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
257  //will be removed once 74X is not used anymore
258  if (!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
259  if (cor != MET::METCorrectionLevel::RawCalo) {
260  vo = shiftedP3_74x(shift, cor);
261  } else {
263  vo = tmp;
264  }
265  } else {
266  const MET::PackedMETUncertainty &v = findMETTotalShift(cor, shift);
267  //return Vector(px() + v.dpx(), py() + v.dpy(), 0);
268  Vector tmp(px() + v.dpx(), py() + v.dpy(), 0);
269  vo = tmp;
270  }
271  return vo;
272 }
274  LorentzVector vo;
275 
276  //backward compatibility with 74X samples -> the only one
277  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
278  //will be removed once 74X is not used anymore
279  if (!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
280  if (cor != MET::METCorrectionLevel::RawCalo) {
281  vo = shiftedP4_74x(shift, cor);
282  } else {
283  double x = caloPackedMet_.dpx(), y = caloPackedMet_.dpy();
284  LorentzVector tmp(x, y, 0, std::hypot(x, y));
285  vo = tmp;
286  }
287  } else {
288  const MET::PackedMETUncertainty &v = findMETTotalShift(cor, shift);
289  double x = px() + v.dpx(), y = py() + v.dpy();
290  //return LorentzVector(x, y, 0, std::hypot(x,y));
291  LorentzVector tmp(x, y, 0, std::hypot(x, y));
292  vo = tmp;
293  }
294  return vo;
295 }
297  double sumEto;
298 
299  //backward compatibility with 74X samples -> the only one
300  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
301  //will be removed once 74X is not used anymore
302  if (!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
303  if (cor != MET::METCorrectionLevel::RawCalo) {
304  sumEto = shiftedSumEt_74x(shift, cor);
305  } else {
306  sumEto = caloPackedMet_.dsumEt();
307  }
308  } else {
309  const MET::PackedMETUncertainty &v = findMETTotalShift(cor, shift);
310  //return sumEt() + v.dsumEt();
311  sumEto = sumEt() + v.dsumEt();
312  }
313  return sumEto;
314 }
315 
320 
324 double MET::uncorSumEt() const { return shiftedSumEt(MET::NoShift, MET::Raw); }
325 
326 void MET::setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared) {
327  if (uncertainties_.empty()) {
328  uncertainties_.resize(METUncertainty::METFullUncertaintySize);
329  }
330 
331  if (isSmeared && shift <= MET::JetResDown) {
332  //changing reference to only get the uncertainty shift and not the smeared one
333  // which is performed independently
334  shift = (MET::METUncertainty)(METUncertainty::METUncertaintySize + shift + 1);
335  const PackedMETUncertainty &ref = uncertainties_[METUncertainty::NoShift];
336  uncertainties_[shift].set(
337  px + ref.dpx() - this->px(), py + ref.dpy() - this->py(), sumEt + ref.dsumEt() - this->sumEt());
338  } else
339  uncertainties_[shift].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
340 }
341 
342 void MET::setCorShift(double px, double py, double sumEt, MET::METCorrectionType level) {
343  if (corrections_.empty()) {
344  corrections_.resize(MET::METCorrectionType::METCorrectionTypeSize);
345  }
346 
347  corrections_[level].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
348 }
349 
351  return shiftedP2(MET::METUncertainty::NoShift, MET::METCorrectionLevel::RawCalo);
352 }
353 
354 double MET::caloMETPt() const { return caloMETP2().pt(); }
355 
356 double MET::caloMETPhi() const { return caloMETP2().phi(); }
357 
359 
360 // functions to access to 74X samples ========================================================
362  if (level != Type1 && level != Raw)
363  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
364  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
365  if (v.empty())
366  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
367  if (v.size() == 1) {
368  if (shift != MET::METUncertainty::NoShift)
369  throw cms::Exception(
370  "Unsupported",
371  "MET uncertainties not available for the specified correction type (only central value available)\n");
372  return Vector2{(px() + v.front().dpx()), (py() + v.front().dpy())};
373  }
374  Vector2 ret{(px() + v[shift].dpx()), (py() + v[shift].dpy())};
375  return ret;
376 }
377 
379  if (level != Type1 && level != Raw)
380  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
381  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
382  if (v.empty())
383  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
384  if (v.size() == 1) {
385  if (shift != MET::METUncertainty::NoShift)
386  throw cms::Exception(
387  "Unsupported",
388  "MET uncertainties not available for the specified correction type (only central value available)\n");
389  return Vector(px() + v.front().dpx(), py() + v.front().dpy(), 0);
390  }
391  return Vector(px() + v[shift].dpx(), py() + v[shift].dpy(), 0);
392 }
393 
395  if (level != Type1 && level != Raw)
396  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
397  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
398  if (v.empty())
399  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
400  if (v.size() == 1) {
401  if (shift != MET::METUncertainty::NoShift)
402  throw cms::Exception(
403  "Unsupported",
404  "MET uncertainties not available for the specified correction type (only central value available)\n");
405  double x = px() + v.front().dpx(), y = py() + v.front().dpy();
406  return LorentzVector(x, y, 0, std::hypot(x, y));
407  }
408  double x = px() + v[shift].dpx(), y = py() + v[shift].dpy();
409  return LorentzVector(x, y, 0, std::hypot(x, y));
410 }
411 
413  if (level != Type1 && level != Raw)
414  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
415  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
416  if (v.empty())
417  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
418  if (v.size() == 1) {
419  if (shift != MET::METUncertainty::NoShift)
420  throw cms::Exception(
421  "Unsupported",
422  "MET uncertainties not available for the specified correction type (only central value available)\n");
423  return sumEt() + v.front().dsumEt();
424  }
425  return sumEt() + v[shift].dsumEt();
426 }
427 
429 
431  packedDpx_ = MiniFloatConverter::float32to16(dpx_);
432  packedDpy_ = MiniFloatConverter::float32to16(dpy_);
433  packedDSumEt_ = MiniFloatConverter::float32to16(dsumEt_);
434 }
436  unpacked_ = true;
437  dpx_ = MiniFloatConverter::float16to32(packedDpx_);
438  dpy_ = MiniFloatConverter::float16to32(packedDpy_);
439  dsumEt_ = MiniFloatConverter::float16to32(packedDSumEt_);
440 }
Analysis-level MET class.
Definition: MET.h:40
std::vector< double > dsumEt() const
Definition: MET.cc:112
value_type const * get() const
Definition: RefToBase.h:209
std::vector< PackedMETUncertainty > uncertaintiesRaw_
Definition: MET.h:335
Vector2 shiftedP2_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:361
const PackedMETUncertainty findMETTotalShift(MET::METCorrectionLevel cor, MET::METUncertainty shift) const
Definition: MET.cc:198
MET()
default constructor
Definition: MET.cc:9
SpecificPFMETData getSpecific() const
Definition: PFMET.h:70
double dpy() const
Definition: MET.h:283
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
double metSig_
Definition: MET.h:323
Vector2 caloMETP2() const
Definition: MET.cc:350
std::vector< PackedMETUncertainty > uncertaintiesType1p2_
Definition: MET.h:335
ret
prodAgent to be discontinued
Vector2 corP2(METCorrectionLevel level=Type1) const
Definition: MET.cc:316
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
std::vector< PackedMETUncertainty > uncertainties_
Definition: MET.h:337
double px() const final
x coordinate of momentum vector
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
Definition: MET.cc:137
double y() const final
rapidity
LorentzVector shiftedP4(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:273
void setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared=false)
Definition: MET.cc:326
double dsumEt() const
Definition: MET.h:288
~MET() override
destructor
Definition: MET.cc:95
double metSignificance() const
Definition: MET.cc:126
METUncertainty
Definition: MET.h:152
Vector2 uncorP2() const
Definition: MET.cc:321
Vector corP3(METCorrectionLevel level=Type1) const
Definition: MET.cc:317
static float float16to32(uint16_t h)
Definition: libminifloat.h:12
double caloMETSumEt() const
Definition: MET.cc:358
Definition: HeavyIon.h:7
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:319
void add(float dpx, float dpy, float dsumEt)
Definition: MET.h:300
SpecificCaloMETData getSpecific() const
Definition: CaloMET.h:77
double sumEt() const
Definition: MET.h:52
Definition: MET.h:41
PackedMETUncertainty caloPackedMet_
Definition: MET.h:340
static uint16_t float32to16(float x)
Definition: libminifloat.h:20
LorentzVector corP4(METCorrectionLevel level=Type1) const
Definition: MET.cc:318
double dpx() const
Definition: MET.h:278
Vector2 shiftedP2(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:231
double caloMETPhi() const
Definition: MET.cc:356
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:296
double phi() const
Definition: MET.h:208
std::vector< reco::GenMET > genMET_
Definition: MET.h:316
LorentzVector shiftedP4_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:394
void initCorMap()
Definition: MET.cc:132
double shiftedSumEt_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:412
double uncorSumEt() const
Definition: MET.cc:324
double pt() const
Definition: MET.h:207
MET & operator=(MET const &)
Definition: MET.cc:97
void setMETSumPtUnclustered(const double &sumPtUnclustered)
Definition: MET.cc:128
std::map< MET::METCorrectionLevel, std::vector< MET::METCorrectionType > > corMap_
Definition: MET.h:329
const reco::GenMET * genMET() const
return the associated GenMET
Definition: MET.cc:115
double py() const final
y coordinate of momentum vector
std::vector< SpecificCaloMETData > caloMET_
Definition: MET.h:318
this below should be private but Reflex doesn&#39;t like it
Definition: MET.h:266
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
METCorrectionLevel
Definition: MET.h:173
std::vector< PackedMETUncertainty > uncertaintiesType1_
Definition: MET.h:335
fixed size matrix
METCorrectionType
Definition: MET.h:189
std::vector< PackedMETUncertainty > corrections_
Definition: MET.h:338
math::XYZVector Vector
point in the space
Definition: LeafCandidate.h:29
static unsigned int const shift
LorentzVector uncorP4() const
Definition: MET.cc:323
Templated PAT object container.
Definition: PATObject.h:48
void setCorShift(double px, double py, double sumEt, METCorrectionType level)
Definition: MET.cc:342
void setGenMET(const reco::GenMET &gm)
set the associated GenMET
Definition: MET.cc:118
std::vector< SpecificPFMETData > pfMET_
Definition: MET.h:320
double metSumPtUnclustered() const
Definition: MET.cc:130
double sumPtUnclustered_
Definition: MET.h:325
tmp
align.sh
Definition: createJobs.py:716
double caloMETPt() const
Definition: MET.cc:354
Vector uncorP3() const
Definition: MET.cc:322
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
void unpack() const
Definition: MET.cc:435
void setMETSignificance(const double &metSig)
Definition: MET.cc:124
Vector shiftedP3_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:378
reco::METCovMatrix getSignificanceMatrix(void) const
Definition: MET.cc:123
Vector shiftedP3(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:252