CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
66 uncertainties_(iOther.uncertainties_),
67 corrections_(iOther.corrections_),
68 caloPackedMet_(iOther.caloPackedMet_) {
69 
70  metSig_ =0.;
71  initCorMap();
72 }
73 
75 // old uncertainties discarded on purpose to avoid confusion
76 MET::MET(const reco::MET & corMET, const MET& srcMET ):
77 PATObject<reco::MET>(corMET),
78 genMET_(srcMET.genMET_),
79 caloMET_(srcMET.caloMET_),
80 pfMET_(srcMET.pfMET_),
81 metSig_(srcMET.metSig_),
82 caloPackedMet_(srcMET.caloPackedMet_) {
83 
84  initCorMap();
85 }
86 
89 
90 }
91 
92 MET& MET::operator=(MET const& iOther) {
94  genMET_ = iOther.genMET_;
95  caloMET_ =iOther.caloMET_;
96  pfMET_ =iOther.pfMET_;
97  uncertaintiesRaw_ = iOther.uncertaintiesRaw_; //74X compatibility
101  corrections_ = iOther.corrections_;
102  metSig_ = iOther.metSig_;
104 
105  return *this;
106 }
107 
109 const reco::GenMET * MET::genMET() const {
110  return (genMET_.size() > 0 ? &genMET_.front() : 0 );
111 }
112 
114 void MET::setGenMET(const reco::GenMET & gm) {
115  genMET_.clear();
116  genMET_.push_back(gm);
117 }
118 
119 
120 //Method to set the MET significance
121 void MET::setMETSignificance(const double& metSig) {
122  metSig_ = metSig;
123 }
124 
125 double MET::metSignificance() const {
126  return metSig_;
127 }
128 
129 
130 void
132 
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  tmpType1SmearXY.push_back(MET::Smear);
161  tmpType01SmearXY.push_back(MET::Smear);
162 
163  tmpTypeXY.push_back(MET::TXYForRaw);
164  tmpType1XY.push_back(MET::TXY);
165  tmpType01XY.push_back(MET::TXYForT01);
166  tmpType1SmearXY.push_back(MET::TXYForT1Smear);
167  tmpType01SmearXY.push_back(MET::TXYForT01Smear);
168 
169  corMap_[MET::Raw] = tmpRaw;
170  corMap_[MET::Type1] = tmpType1;
171  corMap_[MET::Type01] = tmpType01;
172  corMap_[MET::TypeXY] = tmpTypeXY;
173  corMap_[MET::Type1XY] = tmpType1XY;
174  corMap_[MET::Type01XY] = tmpType01XY;
175  corMap_[MET::Type1Smear] = tmpType1Smear;
176  corMap_[MET::Type01Smear] = tmpType01Smear;
177  corMap_[MET::Type1SmearXY] = tmpType1SmearXY;
178  corMap_[MET::Type01SmearXY] = tmpType01SmearXY;
179 
180  //specific calo case
181  std::vector<MET::METCorrectionType> tmpRawCalo;
182  tmpRawCalo.push_back(MET::Calo);
183  corMap_[MET::RawCalo] = tmpRawCalo;
184 }
185 
188 
189  //find corrections shifts =============================
190  std::map<MET::METCorrectionLevel, std::vector<MET::METCorrectionType> >::const_iterator itCor_ = corMap_.find(cor);
191  if(itCor_==corMap_.end() ) throw cms::Exception("Unsupported", "Specified MET correction scheme does not exist");
192 
193  bool isSmeared=false;
194  MET::PackedMETUncertainty totShift;
195  unsigned int scor=itCor_->second.size();
196  for(unsigned int i=0; i<scor;i++) {
197  totShift.add( corrections_[ itCor_->second[i] ].dpx(),
198  corrections_[ itCor_->second[i] ].dpy(),
199  corrections_[ itCor_->second[i] ].dsumEt() );
200 
201  if(itCor_->first>=MET::Type1Smear)
202  isSmeared=true;
203  }
204 
205 
206 
207  //find uncertainty shift =============================
208 
209  if (uncertainties_.empty())
210  return totShift;
211 
212  if(shift>=MET::METUncertaintySize) throw cms::Exception("Unsupported", "MET uncertainty does not exist");
213  if(isSmeared && shift<=MET::JetResDown) shift = (MET::METUncertainty)(MET::METUncertaintySize+shift+1);
214 
215  totShift.add( uncertainties_[ shift ].dpx(),
216  uncertainties_[ shift ].dpy(),
217  uncertainties_[ shift ].dsumEt() );
218 
219  return totShift;
220 }
221 
222 
224 
225  Vector2 vo;
226 
227  //backward compatibility with 74X samples -> the only one
228  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
229  //will be removed once 74X is not used anymore
230  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
231  if(cor!=MET::METCorrectionLevel::RawCalo) {
232  vo = shiftedP2_74x(shift, cor);
233  } else {
235  vo = ret;
236  }
237  }
238  else {
239  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
240  Vector2 ret{ (px() + v.dpx()), (py() + v.dpy()) };
241  //return ret;
242  vo = ret;
243  }
244  return vo;
245 }
247 
248  Vector vo;
249 
250  //backward compatibility with 74X samples -> the only one
251  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
252  //will be removed once 74X is not used anymore
253  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
254  if(cor!=MET::METCorrectionLevel::RawCalo) {
255  vo = shiftedP3_74x(shift, cor);
256  } else {
258  vo = tmp;
259  }
260  }
261  else {
262  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
263  //return Vector(px() + v.dpx(), py() + v.dpy(), 0);
264  Vector tmp(px() + v.dpx(), py() + v.dpy(), 0);
265  vo = tmp;
266  }
267  return vo;
268 }
270 
271  LorentzVector vo;
272 
273  //backward compatibility with 74X samples -> the only one
274  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
275  //will be removed once 74X is not used anymore
276  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
277  if(cor!=MET::METCorrectionLevel::RawCalo) {
278  vo = shiftedP4_74x(shift, cor);
279  } else {
280  double x = caloPackedMet_.dpx(), y = caloPackedMet_.dpy();
281  LorentzVector tmp(x, y, 0, std::hypot(x,y));
282  vo = tmp;
283  }
284  }
285  else {
286  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
287  double x = px() + v.dpx(), y = py() + v.dpy();
288  //return LorentzVector(x, y, 0, std::hypot(x,y));
289  LorentzVector tmp(x, y, 0, std::hypot(x,y));
290  vo = tmp;
291  }
292  return vo;
293 }
295 
296  double sumEto;
297 
298  //backward compatibility with 74X samples -> the only one
299  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
300  //will be removed once 74X is not used anymore
301  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
302  if(cor!=MET::METCorrectionLevel::RawCalo) {
303  sumEto = shiftedSumEt_74x(shift, cor);
304  } else {
305  sumEto = caloPackedMet_.dsumEt();
306  }
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 
317  return shiftedP2(MET::NoShift, cor );
318 }
320  return shiftedP3(MET::NoShift, cor );
321 }
323  return shiftedP4(MET::NoShift, cor );
324 }
326  return shiftedSumEt(MET::NoShift, cor );
327 }
328 
330  return shiftedP2(MET::NoShift, MET::Raw );
331 }
333  return shiftedP3(MET::NoShift, MET::Raw );
334 }
336  return shiftedP4(MET::NoShift, MET::Raw );
337 }
338 double MET::uncorSumEt() const {
340 }
341 
342 
343 void MET::setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared) {
344  if (uncertainties_.empty()) {
345  uncertainties_.resize(METUncertainty::METFullUncertaintySize);
346  }
347 
348  if(isSmeared && shift<=MET::JetResDown) {
349  //changing reference to only get the uncertainty shift and not the smeared one
350  // which is performed independently
351  shift = (MET::METUncertainty)(METUncertainty::METUncertaintySize+shift+1);
352  const PackedMETUncertainty& ref = uncertainties_[METUncertainty::NoShift];
353  uncertainties_[shift].set(px + ref.dpx() - this->px(), py + ref.dpy() - this->py(), sumEt + ref.dsumEt() - this->sumEt() );
354  }
355  else
356  uncertainties_[shift].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
357 
358 }
359 
360 void MET::setCorShift(double px, double py, double sumEt, MET::METCorrectionType level) {
361  if (corrections_.empty()) {
362  corrections_.resize(MET::METCorrectionType::METCorrectionTypeSize);
363  }
364 
365  corrections_[level].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
366 }
367 
368 
370  return shiftedP2(MET::METUncertainty::NoShift, MET::METCorrectionLevel::RawCalo );
371 }
372 
373 double MET::caloMETPt() const {
374  return caloMETP2().pt();
375 }
376 
377 double MET::caloMETPhi() const {
378  return caloMETP2().phi();
379 }
380 
381 double MET::caloMETSumEt() const {
383 }
384 
385 // functions to access to 74X samples ========================================================
387  if (level != Type1 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
388  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
389  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
390  if (v.size() == 1) {
391  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
392  return Vector2{ (px() + v.front().dpx()), (py() + v.front().dpy()) };
393  }
394  Vector2 ret{ (px() + v[shift].dpx()), (py() + v[shift].dpy()) };
395  return ret;
396 }
397 
399  if (level != Type1 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
400  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
401  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
402  if (v.size() == 1) {
403  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
404  return Vector(px() + v.front().dpx(), py() + v.front().dpy(), 0);
405  }
406  return Vector(px() + v[shift].dpx(), py() + v[shift].dpy(), 0);
407 }
408 
410  if (level != Type1 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
411  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
412  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
413  if (v.size() == 1) {
414  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "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) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
424  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
425  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
426  if (v.size() == 1) {
427  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
428  return sumEt() + v.front().dsumEt();
429  }
430  return sumEt() + v[shift].dsumEt();
431 }
432 
433 
434 
435 
437 
439  packedDpx_ = MiniFloatConverter::float32to16(dpx_);
440  packedDpy_ = MiniFloatConverter::float32to16(dpy_);
441  packedDSumEt_ = MiniFloatConverter::float32to16(dsumEt_);
442 }
444  unpacked_=true;
445  dpx_=MiniFloatConverter::float16to32(packedDpx_);
446  dpy_=MiniFloatConverter::float16to32(packedDpy_);
447  dsumEt_=MiniFloatConverter::float16to32(packedDSumEt_);
448 }
449 
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:225
int i
Definition: DBlmapReader.cc:9
std::vector< PackedMETUncertainty > uncertaintiesRaw_
Definition: MET.h:266
Vector2 shiftedP2_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:386
const PackedMETUncertainty findMETTotalShift(MET::METCorrectionLevel cor, MET::METUncertainty shift) const
Definition: MET.cc:187
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:369
std::vector< PackedMETUncertainty > uncertaintiesType1p2_
Definition: MET.h:266
Vector2 corP2(METCorrectionLevel level=Type1) const
Definition: MET.cc:316
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:160
std::vector< PackedMETUncertainty > uncertainties_
Definition: MET.h:268
virtual double y() const
rapidity
LorentzVector shiftedP4(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:269
void setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared=false)
Definition: MET.cc:343
double dsumEt() const
Definition: MET.h:232
double metSignificance() const
Definition: MET.cc:125
METUncertainty
Definition: MET.h:152
Vector2 uncorP2() const
Definition: MET.cc:329
Vector corP3(METCorrectionLevel level=Type1) const
Definition: MET.cc:319
static float float16to32(uint16_t h)
Definition: libminifloat.h:10
double caloMETSumEt() const
Definition: MET.cc:381
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:325
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
static uint16_t float32to16(float x)
Definition: libminifloat.h:15
LorentzVector corP4(METCorrectionLevel level=Type1) const
Definition: MET.cc:322
double dpx() const
Definition: MET.h:230
Vector2 shiftedP2(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:223
double caloMETPhi() const
Definition: MET.cc:377
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:294
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:409
void initCorMap()
Definition: MET.cc:131
double shiftedSumEt_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:422
double uncorSumEt() const
Definition: MET.cc:338
double pt() const
Definition: MET.h:172
MET & operator=(MET const &)
Definition: MET.cc:92
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:109
virtual double px() const
x coordinate of momentum vector
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
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:335
Templated PAT object container.
Definition: PATObject.h:49
void setCorShift(double px, double py, double sumEt, METCorrectionType level)
Definition: MET.cc:360
tuple level
Definition: testEve_cfg.py:34
void setGenMET(const reco::GenMET &gm)
set the associated GenMET
Definition: MET.cc:114
std::vector< SpecificPFMETData > pfMET_
Definition: MET.h:250
virtual ~MET()
destructor
Definition: MET.cc:88
double caloMETPt() const
Definition: MET.cc:373
Vector uncorP3() const
Definition: MET.cc:332
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
virtual double py() const
y coordinate of momentum vector
void unpack() const
Definition: MET.cc:443
void setMETSignificance(const double &metSig)
Definition: MET.cc:121
Vector shiftedP3_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:398
Vector shiftedP3(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:246