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