CMS 3D CMS Logo

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