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 
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  //specific deep response tune case
198  std::vector<MET::METCorrectionType> tmpDeepResponse;
199  tmpDeepResponse.push_back(MET::DeepResponseTune);
200  corMap_[MET::RawDeepResponseTune] = tmpDeepResponse;
201 
202  //specific deep resolution tune case
203  std::vector<MET::METCorrectionType> tmpDeepResolution;
204  tmpDeepResolution.push_back(MET::DeepResolutionTune);
205  corMap_[MET::RawDeepResolutionTune] = tmpDeepResolution;
206 }
207 
209  //find corrections shifts =============================
210  std::map<MET::METCorrectionLevel, std::vector<MET::METCorrectionType> >::const_iterator itCor_ = corMap_.find(cor);
211  if (itCor_ == corMap_.end())
212  throw cms::Exception("Unsupported", "Specified MET correction scheme does not exist");
213 
214  bool isSmeared = false;
215  MET::PackedMETUncertainty totShift;
216  unsigned int scor = itCor_->second.size();
217  for (unsigned int i = 0; i < scor; i++) {
218  totShift.add(corrections_[itCor_->second[i]].dpx(),
219  corrections_[itCor_->second[i]].dpy(),
220  corrections_[itCor_->second[i]].dsumEt());
221 
222  if (itCor_->first >= MET::Type1Smear)
223  isSmeared = true;
224  }
225 
226  //find uncertainty shift =============================
227 
228  if (uncertainties_.empty())
229  return totShift;
230 
231  if (shift >= MET::METUncertaintySize)
232  throw cms::Exception("Unsupported", "MET uncertainty does not exist");
233  if (isSmeared && shift <= MET::JetResDown)
234  shift = (MET::METUncertainty)(MET::METUncertaintySize + shift + 1);
235 
236  totShift.add(uncertainties_[shift].dpx(), uncertainties_[shift].dpy(), uncertainties_[shift].dsumEt());
237 
238  return totShift;
239 }
240 
242  Vector2 vo;
243 
244  //backward compatibility with 74X samples -> the only one
245  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
246  //will be removed once 74X is not used anymore
247  if (!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
248  if (cor != MET::METCorrectionLevel::RawCalo) {
249  vo = shiftedP2_74x(shift, cor);
250  } else {
252  vo = ret;
253  }
254  } else {
255  const MET::PackedMETUncertainty &v = findMETTotalShift(cor, shift);
256  Vector2 ret{(px() + v.dpx()), (py() + v.dpy())};
257  //return ret;
258  vo = ret;
259  }
260  return vo;
261 }
263  Vector vo;
264 
265  //backward compatibility with 74X samples -> the only one
266  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
267  //will be removed once 74X is not used anymore
268  if (!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
269  if (cor != MET::METCorrectionLevel::RawCalo) {
270  vo = shiftedP3_74x(shift, cor);
271  } else {
273  vo = tmp;
274  }
275  } else {
276  const MET::PackedMETUncertainty &v = findMETTotalShift(cor, shift);
277  //return Vector(px() + v.dpx(), py() + v.dpy(), 0);
278  Vector tmp(px() + v.dpx(), py() + v.dpy(), 0);
279  vo = tmp;
280  }
281  return vo;
282 }
284  LorentzVector vo;
285 
286  //backward compatibility with 74X samples -> the only one
287  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
288  //will be removed once 74X is not used anymore
289  if (!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
290  if (cor != MET::METCorrectionLevel::RawCalo) {
291  vo = shiftedP4_74x(shift, cor);
292  } else {
293  double x = caloPackedMet_.dpx(), y = caloPackedMet_.dpy();
294  LorentzVector tmp(x, y, 0, std::hypot(x, y));
295  vo = tmp;
296  }
297  } else {
298  const MET::PackedMETUncertainty &v = findMETTotalShift(cor, shift);
299  double x = px() + v.dpx(), y = py() + v.dpy();
300  //return LorentzVector(x, y, 0, std::hypot(x,y));
301  LorentzVector tmp(x, y, 0, std::hypot(x, y));
302  vo = tmp;
303  }
304  return vo;
305 }
307  double sumEto;
308 
309  //backward compatibility with 74X samples -> the only one
310  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
311  //will be removed once 74X is not used anymore
312  if (!uncertaintiesType1_.empty() || !uncertaintiesRaw_.empty()) {
313  if (cor != MET::METCorrectionLevel::RawCalo) {
314  sumEto = shiftedSumEt_74x(shift, cor);
315  } else {
316  sumEto = caloPackedMet_.dsumEt();
317  }
318  } else {
319  const MET::PackedMETUncertainty &v = findMETTotalShift(cor, shift);
320  //return sumEt() + v.dsumEt();
321  sumEto = sumEt() + v.dsumEt();
322  }
323  return sumEto;
324 }
325 
330 
334 double MET::uncorSumEt() const { return shiftedSumEt(MET::NoShift, MET::Raw); }
335 
336 void MET::setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared) {
337  if (uncertainties_.empty()) {
338  uncertainties_.resize(METUncertainty::METFullUncertaintySize);
339  }
340 
341  if (isSmeared && shift <= MET::JetResDown) {
342  //changing reference to only get the uncertainty shift and not the smeared one
343  // which is performed independently
344  shift = (MET::METUncertainty)(METUncertainty::METUncertaintySize + shift + 1);
345  const PackedMETUncertainty &ref = uncertainties_[METUncertainty::NoShift];
346  uncertainties_[shift].set(
347  px + ref.dpx() - this->px(), py + ref.dpy() - this->py(), sumEt + ref.dsumEt() - this->sumEt());
348  } else
349  uncertainties_[shift].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
350 }
351 
352 void MET::setCorShift(double px, double py, double sumEt, MET::METCorrectionType level) {
353  if (corrections_.empty()) {
354  corrections_.resize(MET::METCorrectionType::METCorrectionTypeSize);
355  }
356 
357  corrections_[level].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
358 }
359 
361  return shiftedP2(MET::METUncertainty::NoShift, MET::METCorrectionLevel::RawCalo);
362 }
363 
364 double MET::caloMETPt() const { return caloMETP2().pt(); }
365 
366 double MET::caloMETPhi() const { return caloMETP2().phi(); }
367 
369 
370 // functions to access to 74X samples ========================================================
372  if (level != Type1 && level != Raw)
373  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
374  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
375  if (v.empty())
376  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
377  if (v.size() == 1) {
378  if (shift != MET::METUncertainty::NoShift)
379  throw cms::Exception(
380  "Unsupported",
381  "MET uncertainties not available for the specified correction type (only central value available)\n");
382  return Vector2{(px() + v.front().dpx()), (py() + v.front().dpy())};
383  }
384  Vector2 ret{(px() + v[shift].dpx()), (py() + v[shift].dpy())};
385  return ret;
386 }
387 
389  if (level != Type1 && level != Raw)
390  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
391  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
392  if (v.empty())
393  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
394  if (v.size() == 1) {
395  if (shift != MET::METUncertainty::NoShift)
396  throw cms::Exception(
397  "Unsupported",
398  "MET uncertainties not available for the specified correction type (only central value available)\n");
399  return Vector(px() + v.front().dpx(), py() + v.front().dpy(), 0);
400  }
401  return Vector(px() + v[shift].dpx(), py() + v[shift].dpy(), 0);
402 }
403 
405  if (level != Type1 && level != Raw)
406  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
407  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
408  if (v.empty())
409  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
410  if (v.size() == 1) {
411  if (shift != MET::METUncertainty::NoShift)
412  throw cms::Exception(
413  "Unsupported",
414  "MET uncertainties not available for the specified correction type (only central value available)\n");
415  double x = px() + v.front().dpx(), y = py() + v.front().dpy();
416  return LorentzVector(x, y, 0, std::hypot(x, y));
417  }
418  double x = px() + v[shift].dpx(), y = py() + v[shift].dpy();
419  return LorentzVector(x, y, 0, std::hypot(x, y));
420 }
421 
423  if (level != Type1 && level != Raw)
424  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
425  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
426  if (v.empty())
427  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
428  if (v.size() == 1) {
429  if (shift != MET::METUncertainty::NoShift)
430  throw cms::Exception(
431  "Unsupported",
432  "MET uncertainties not available for the specified correction type (only central value available)\n");
433  return sumEt() + v.front().dsumEt();
434  }
435  return sumEt() + v[shift].dsumEt();
436 }
437 
439 
441  packedDpx_ = MiniFloatConverter::float32to16(dpx_);
442  packedDpy_ = MiniFloatConverter::float32to16(dpy_);
443  packedDSumEt_ = MiniFloatConverter::float32to16(dsumEt_);
444 }
446  unpacked_ = true;
447  dpx_ = MiniFloatConverter::float16to32(packedDpx_);
448  dpy_ = MiniFloatConverter::float16to32(packedDpy_);
449  dsumEt_ = MiniFloatConverter::float16to32(packedDSumEt_);
450 }
Analysis-level MET class.
Definition: MET.h:40
std::vector< double > dsumEt() const
Definition: MET.cc:126
value_type const * get() const
Definition: RefToBase.h:234
std::vector< PackedMETUncertainty > uncertaintiesRaw_
Definition: MET.h:339
Vector2 shiftedP2_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:371
const PackedMETUncertainty findMETTotalShift(MET::METCorrectionLevel cor, MET::METUncertainty shift) const
Definition: MET.cc:208
MET()
default constructor
Definition: MET.cc:9
SpecificPFMETData getSpecific() const
Definition: PFMET.h:72
double dpy() const
Definition: MET.h:287
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
double metSig_
Definition: MET.h:327
Vector2 caloMETP2() const
Definition: MET.cc:360
std::vector< PackedMETUncertainty > uncertaintiesType1p2_
Definition: MET.h:339
Vector2 corP2(METCorrectionLevel level=Type1) const
Definition: MET.cc:326
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
std::vector< PackedMETUncertainty > uncertainties_
Definition: MET.h:341
double px() const final
x coordinate of momentum vector
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
Definition: MET.cc:157
double y() const final
rapidity
LorentzVector shiftedP4(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:283
void setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared=false)
Definition: MET.cc:336
double dsumEt() const
Definition: MET.h:292
~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:331
Vector corP3(METCorrectionLevel level=Type1) const
Definition: MET.cc:327
static float float16to32(uint16_t h)
Definition: libminifloat.h:12
double caloMETSumEt() const
Definition: MET.cc:368
Definition: HeavyIon.h:7
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:329
void add(float dpx, float dpy, float dsumEt)
Definition: MET.h:304
SpecificCaloMETData getSpecific() const
Definition: CaloMET.h:79
double sumEt() const
Definition: MET.h:56
Definition: MET.h:42
PackedMETUncertainty caloPackedMet_
Definition: MET.h:344
static uint16_t float32to16(float x)
Definition: libminifloat.h:17
LorentzVector corP4(METCorrectionLevel level=Type1) const
Definition: MET.cc:328
double dpx() const
Definition: MET.h:282
Vector2 shiftedP2(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:241
double caloMETPhi() const
Definition: MET.cc:366
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:306
double phi() const
Definition: MET.h:212
std::vector< reco::GenMET > genMET_
Definition: MET.h:320
LorentzVector shiftedP4_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:404
void initCorMap()
Definition: MET.cc:132
double shiftedSumEt_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:422
double uncorSumEt() const
Definition: MET.cc:334
double pt() const
Definition: MET.h:211
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:333
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:322
this below should be private but Reflex doesn&#39;t like it
Definition: MET.h:270
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
METCorrectionLevel
Definition: MET.h:173
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::vector< PackedMETUncertainty > uncertaintiesType1_
Definition: MET.h:339
fixed size matrix
METCorrectionType
Definition: MET.h:191
std::vector< PackedMETUncertainty > corrections_
Definition: MET.h:342
math::XYZVector Vector
point in the space
Definition: LeafCandidate.h:29
static unsigned int const shift
LorentzVector uncorP4() const
Definition: MET.cc:333
Templated PAT object container.
Definition: PATObject.h:49
void setCorShift(double px, double py, double sumEt, METCorrectionType level)
Definition: MET.cc:352
sumPtUnclustered
Definition: met_cff.py:20
void setGenMET(const reco::GenMET &gm)
set the associated GenMET
Definition: MET.cc:118
std::vector< SpecificPFMETData > pfMET_
Definition: MET.h:324
double metSumPtUnclustered() const
Definition: MET.cc:130
double sumPtUnclustered_
Definition: MET.h:329
double caloMETPt() const
Definition: MET.cc:364
Vector uncorP3() const
Definition: MET.cc:332
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
void unpack() const
Definition: MET.cc:445
void setMETSignificance(const double &metSig)
Definition: MET.cc:124
Vector shiftedP3_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:388
reco::METCovMatrix getSignificanceMatrix(void) const
Definition: MET.cc:139
Vector shiftedP3(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:262