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_),
69  sumPtUnclustered_(iOther.sumPtUnclustered_),
70  uncertaintiesRaw_(iOther.uncertaintiesRaw_), //74X reading compatibility
71  uncertaintiesType1_(iOther.uncertaintiesType1_), //74X compatibility
72  uncertaintiesType1p2_(iOther.uncertaintiesType1p2_), //74X compatibility
73  uncertainties_(iOther.uncertainties_),
74  corrections_(iOther.corrections_),
75  caloPackedMet_(iOther.caloPackedMet_) {
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_),
87  sumPtUnclustered_(srcMET.sumPtUnclustered_),
88  caloPackedMet_(srcMET.caloPackedMet_) {
89  setSignificanceMatrix(srcMET.getSignificanceMatrix());
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;
216  unsigned int scor = itCor_->second.size();
217  for (unsigned int i = 0; i < scor; i++) {
218  auto up = corrections_[itCor_->second[i]].unpack();
219  totShift.add(up.dpx(), up.dpy(), up.dsumEt());
220 
221  if (itCor_->first >= MET::Type1Smear)
222  isSmeared = true;
223  }
224 
225  //find uncertainty shift =============================
226 
227  if (uncertainties_.empty())
228  return totShift;
229 
231  throw cms::Exception("Unsupported", "MET uncertainty does not exist");
232  if (isSmeared && shift <= MET::JetResDown)
234 
235  auto up = uncertainties_[shift].unpack();
236  totShift.add(up.dpx(), up.dpy(), up.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  auto 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 {
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 {
294  LorentzVector tmp(x, y, 0, std::hypot(x, y));
295  vo = tmp;
296  }
297  } else {
298  const auto 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_.unpackDSumEt();
317  }
318  } else {
319  const auto 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 = corrections_[METCorrectionType::Smear];
346  uncertainties_[shift].set(px - ref.unpackDpx() - this->px(),
347  py - ref.unpackDpy() - this->py(),
348  sumEt - ref.unpackDSumEt() - this->sumEt());
349  } else
350  uncertainties_[shift].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
351 }
352 
353 void MET::setCorShift(double px, double py, double sumEt, MET::METCorrectionType level) {
354  if (corrections_.empty()) {
355  corrections_.resize(MET::METCorrectionType::METCorrectionTypeSize);
356  }
357 
358  corrections_[level].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
359 }
360 
362  return shiftedP2(MET::METUncertainty::NoShift, MET::METCorrectionLevel::RawCalo);
363 }
364 
365 double MET::caloMETPt() const { return caloMETP2().pt(); }
366 
367 double MET::caloMETPhi() const { return caloMETP2().phi(); }
368 
370 
371 // functions to access to 74X samples ========================================================
373  if (level != Type1 && level != Raw)
374  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
375  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
376  if (v.empty())
377  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
378  if (v.size() == 1) {
379  if (shift != MET::METUncertainty::NoShift)
380  throw cms::Exception(
381  "Unsupported",
382  "MET uncertainties not available for the specified correction type (only central value available)\n");
383  auto const &p = v.front();
384  return Vector2{(px() + p.unpackDpx()), (py() + p.unpackDpy())};
385  }
386  auto const &p = v[shift];
387  Vector2 ret{(px() + p.unpackDpx()), (py() + p.unpackDpy())};
388  return ret;
389 }
390 
392  if (level != Type1 && level != Raw)
393  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
394  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
395  if (v.empty())
396  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
397  if (v.size() == 1) {
398  if (shift != MET::METUncertainty::NoShift)
399  throw cms::Exception(
400  "Unsupported",
401  "MET uncertainties not available for the specified correction type (only central value available)\n");
402  auto const &p = v.front();
403  return Vector(px() + p.unpackDpx(), py() + p.unpackDpy(), 0);
404  }
405  auto const &p = v[shift];
406  return Vector(px() + p.unpackDpx(), py() + p.unpackDpy(), 0);
407 }
408 
410  if (level != Type1 && level != Raw)
411  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
412  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
413  if (v.empty())
414  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
415  if (v.size() == 1) {
416  if (shift != MET::METUncertainty::NoShift)
417  throw cms::Exception(
418  "Unsupported",
419  "MET uncertainties not available for the specified correction type (only central value available)\n");
420  auto const &p = v.front();
421  double x = px() + p.unpackDpx(), y = py() + p.unpackDpy();
422  return LorentzVector(x, y, 0, std::hypot(x, y));
423  }
424  auto const &p = v[shift];
425  double x = px() + p.unpackDpx(), y = py() + p.unpackDpy();
426  return LorentzVector(x, y, 0, std::hypot(x, y));
427 }
428 
430  if (level != Type1 && level != Raw)
431  throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
432  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
433  if (v.empty())
434  throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
435  if (v.size() == 1) {
436  if (shift != MET::METUncertainty::NoShift)
437  throw cms::Exception(
438  "Unsupported",
439  "MET uncertainties not available for the specified correction type (only central value available)\n");
440  return sumEt() + v.front().unpackDSumEt();
441  }
442  return sumEt() + v[shift].unpackDSumEt();
443 }
444 
446 
451  return UnpackedMETUncertainty(dpx, dpy, dsumEt);
452 }
453 
455 
457 
459 
460 void MET::PackedMETUncertainty::pack(float dpx, float dpy, float dsumEt) {
461  packedDpx_ = MiniFloatConverter::float32to16(dpx);
462  packedDpy_ = MiniFloatConverter::float32to16(dpy);
463  packedDSumEt_ = MiniFloatConverter::float32to16(dsumEt);
464 }
Definition: BitonicSort.h:7
Analysis-level MET class.
Definition: MET.h:40
LorentzVector uncorP4() const
Definition: MET.cc:333
std::vector< double > dsumEt() const
Definition: MET.cc:117
UnpackedMETUncertainty unpack() const
Definition: MET.cc:447
std::vector< PackedMETUncertainty > uncertaintiesRaw_
Definition: MET.h:333
Basic3DVector & operator=(const Basic3DVector &)=default
Assignment operator.
MPlex< T, D1, D2, N > hypot(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b)
Definition: Matriplex.h:436
MET()
default constructor
Definition: MET.cc:9
LorentzVector shiftedP4_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:409
double y() const final
rapidity
math::XYZVector Vector
point in the space
Definition: Candidate.h:42
double metSig_
Definition: MET.h:321
std::vector< PackedMETUncertainty > uncertaintiesType1p2_
Definition: MET.h:333
LorentzVector shiftedP4(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:283
Vector shiftedP3_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:391
ret
prodAgent to be discontinued
std::vector< PackedMETUncertainty > uncertainties_
Definition: MET.h:335
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
Definition: MET.cc:142
Vector uncorP3() const
Definition: MET.cc:332
UnpackedMETUncertainty findMETTotalShift(MET::METCorrectionLevel cor, MET::METUncertainty shift) const
Definition: MET.cc:208
double caloMETPhi() const
Definition: MET.cc:367
Vector2 corP2(METCorrectionLevel level=Type1) const
Definition: MET.cc:326
void setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared=false)
Definition: MET.cc:336
double sumEt() const
Definition: MET.h:56
~MET() override
destructor
Definition: MET.cc:95
Vector2 caloMETP2() const
Definition: MET.cc:361
METUncertainty
Definition: MET.h:152
static float float16to32(uint16_t h)
Definition: libminifloat.h:13
const reco::GenMET * genMET() const
return the associated GenMET
Definition: MET.cc:115
Definition: HeavyIon.h:7
float unpackDpx() const
Definition: MET.cc:454
float unpackDSumEt() const
Definition: MET.cc:458
double px() const final
x coordinate of momentum vector
double p() const final
magnitude of momentum vector
double caloMETPt() const
Definition: MET.cc:365
double metSumPtUnclustered() const
Definition: MET.cc:130
Definition: MET.h:41
PackedMETUncertainty caloPackedMet_
Definition: MET.h:338
void add(float dpx, float dpy, float dsumEt)
Definition: MET.h:283
static uint16_t float32to16(float x)
Definition: libminifloat.h:17
LorentzVector corP4(METCorrectionLevel level=Type1) const
Definition: MET.cc:328
Vector corP3(METCorrectionLevel level=Type1) const
Definition: MET.cc:327
std::vector< reco::GenMET > genMET_
Definition: MET.h:314
double py() const final
y coordinate of momentum vector
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:306
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
void initCorMap()
Definition: MET.cc:132
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:327
float unpackDpy() const
Definition: MET.cc:456
Vector2 uncorP2() const
Definition: MET.cc:331
std::vector< SpecificCaloMETData > caloMET_
Definition: MET.h:316
this below should be private but Reflex doesn&#39;t like it
Definition: MET.h:294
Vector2 shiftedP2(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:241
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
METCorrectionLevel
Definition: MET.h:173
Vector2 shiftedP2_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:372
std::vector< PackedMETUncertainty > uncertaintiesType1_
Definition: MET.h:333
fixed size matrix
METCorrectionType
Definition: MET.h:191
std::vector< PackedMETUncertainty > corrections_
Definition: MET.h:336
double caloMETSumEt() const
Definition: MET.cc:369
double shiftedSumEt_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:429
math::XYZVector Vector
point in the space
Definition: LeafCandidate.h:29
static unsigned int const shift
float x
Templated PAT object container.
Definition: PATObject.h:43
void setCorShift(double px, double py, double sumEt, METCorrectionType level)
Definition: MET.cc:353
sumPtUnclustered
Definition: met_cff.py:22
Vector shiftedP3(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:262
void pack(float dpx, float dpy, float dsumEt)
Definition: MET.cc:460
void setGenMET(const reco::GenMET &gm)
set the associated GenMET
Definition: MET.cc:118
std::vector< SpecificPFMETData > pfMET_
Definition: MET.h:318
double sumPtUnclustered_
Definition: MET.h:323
double uncorSumEt() const
Definition: MET.cc:334
tmp
align.sh
Definition: createJobs.py:716
double pt() const
Definition: MET.h:211
value_type const * get() const
Definition: RefToBase.h:211
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
void setMETSignificance(const double &metSig)
Definition: MET.cc:124
Definition: Common.h:9
double phi() const
Definition: MET.h:212
double metSignificance() const
Definition: MET.cc:126
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:329