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  if(shift>=MET::METUncertaintySize) throw cms::Exception("Unsupported", "MET uncertainty does not exist");
209  if(isSmeared && shift<=MET::JetResDown) shift = (MET::METUncertainty)(MET::METUncertaintySize+shift+1);
210 
211  totShift.add( uncertainties_[ shift ].dpx(),
212  uncertainties_[ shift ].dpy(),
213  uncertainties_[ shift ].dsumEt() );
214 
215  return totShift;
216 }
217 
218 
220 
221  Vector2 vo;
222 
223  //backward compatibility with 74X samples -> the only one
224  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
225  //will be removed once 74X is not used anymore
226  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
227  if(cor!=MET::METCorrectionLevel::RawCalo) {
228  vo = shiftedP2_74x(shift, cor);
229  } else {
231  vo = ret;
232  }
233  }
234  else {
235  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
236  Vector2 ret{ (px() + v.dpx()), (py() + v.dpy()) };
237  //return ret;
238  vo = ret;
239  }
240  return vo;
241 }
243 
244  Vector vo;
245 
246  //backward compatibility with 74X samples -> the only one
247  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
248  //will be removed once 74X is not used anymore
249  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
250  if(cor!=MET::METCorrectionLevel::RawCalo) {
251  vo = shiftedP3_74x(shift, cor);
252  } else {
254  vo = tmp;
255  }
256  }
257  else {
258  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
259  //return Vector(px() + v.dpx(), py() + v.dpy(), 0);
260  Vector tmp(px() + v.dpx(), py() + v.dpy(), 0);
261  vo = tmp;
262  }
263  return vo;
264 }
266 
267  LorentzVector vo;
268 
269  //backward compatibility with 74X samples -> the only one
270  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
271  //will be removed once 74X is not used anymore
272  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
273  if(cor!=MET::METCorrectionLevel::RawCalo) {
274  vo = shiftedP4_74x(shift, cor);
275  } else {
276  double x = caloPackedMet_.dpx(), y = caloPackedMet_.dpy();
277  LorentzVector tmp(x, y, 0, std::hypot(x,y));
278  vo = tmp;
279  }
280  }
281  else {
282  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
283  double x = px() + v.dpx(), y = py() + v.dpy();
284  //return LorentzVector(x, y, 0, std::hypot(x,y));
285  LorentzVector tmp(x, y, 0, std::hypot(x,y));
286  vo = tmp;
287  }
288  return vo;
289 }
291 
292  double sumEto;
293 
294  //backward compatibility with 74X samples -> the only one
295  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
296  //will be removed once 74X is not used anymore
297  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
298  if(cor!=MET::METCorrectionLevel::RawCalo) {
299  sumEto = shiftedSumEt_74x(shift, cor);
300  } else {
301  sumEto = caloPackedMet_.dsumEt();
302  }
303  }
304  else {
305  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
306  //return sumEt() + v.dsumEt();
307  sumEto = sumEt() + v.dsumEt();
308  }
309  return sumEto;
310 }
311 
313  return shiftedP2(MET::NoShift, cor );
314 }
316  return shiftedP3(MET::NoShift, cor );
317 }
319  return shiftedP4(MET::NoShift, cor );
320 }
322  return shiftedSumEt(MET::NoShift, cor );
323 }
324 
326  return shiftedP2(MET::NoShift, MET::Raw );
327 }
329  return shiftedP3(MET::NoShift, MET::Raw );
330 }
332  return shiftedP4(MET::NoShift, MET::Raw );
333 }
334 double MET::uncorSumEt() const {
336 }
337 
338 
339 void MET::setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared) {
340  if (uncertainties_.empty()) {
341  uncertainties_.resize(METUncertainty::METFullUncertaintySize);
342  }
343 
344  if(isSmeared && shift<=MET::JetResDown) {
345  //changing reference to only get the uncertainty shift and not the smeared one
346  // which is performed independently
347  shift = (MET::METUncertainty)(METUncertainty::METUncertaintySize+shift+1);
348  const PackedMETUncertainty& ref = uncertainties_[METUncertainty::NoShift];
349  uncertainties_[shift].set(px + ref.dpx() - this->px(), py + ref.dpy() - this->py(), sumEt + ref.dsumEt() - this->sumEt() );
350  }
351  else
352  uncertainties_[shift].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
353 
354 }
355 
356 void MET::setCorShift(double px, double py, double sumEt, MET::METCorrectionType level) {
357  if (corrections_.empty()) {
358  corrections_.resize(MET::METCorrectionType::METCorrectionTypeSize);
359  }
360 
361  corrections_[level].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
362 }
363 
364 
366  return shiftedP2(MET::METUncertainty::NoShift, MET::METCorrectionLevel::RawCalo );
367 }
368 
369 double MET::caloMETPt() const {
370  return caloMETP2().pt();
371 }
372 
373 double MET::caloMETPhi() const {
374  return caloMETP2().phi();
375 }
376 
377 double MET::caloMETSumEt() const {
379 }
380 
381 // functions to access to 74X samples ========================================================
383  if (level != Type1 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
384  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
385  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
386  if (v.size() == 1) {
387  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
388  return Vector2{ (px() + v.front().dpx()), (py() + v.front().dpy()) };
389  }
390  Vector2 ret{ (px() + v[shift].dpx()), (py() + v[shift].dpy()) };
391  return ret;
392 }
393 
395  if (level != Type1 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
396  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
397  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
398  if (v.size() == 1) {
399  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
400  return Vector(px() + v.front().dpx(), py() + v.front().dpy(), 0);
401  }
402  return Vector(px() + v[shift].dpx(), py() + v[shift].dpy(), 0);
403 }
404 
406  if (level != Type1 && level != Raw) 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()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
409  if (v.size() == 1) {
410  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
411  double x = px() + v.front().dpx(), y = py() + v.front().dpy();
412  return LorentzVector(x, y, 0, std::hypot(x,y));
413  }
414  double x = px() + v[shift].dpx(), y = py() + v[shift].dpy();
415  return LorentzVector(x, y, 0, std::hypot(x,y));
416 }
417 
419  if (level != Type1 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
420  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
421  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
422  if (v.size() == 1) {
423  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
424  return sumEt() + v.front().dsumEt();
425  }
426  return sumEt() + v[shift].dsumEt();
427 }
428 
429 
430 
431 
433 
435  packedDpx_ = MiniFloatConverter::float32to16(dpx_);
436  packedDpy_ = MiniFloatConverter::float32to16(dpy_);
437  packedDSumEt_ = MiniFloatConverter::float32to16(dsumEt_);
438 }
440  unpacked_=true;
441  dpx_=MiniFloatConverter::float16to32(packedDpx_);
442  dpy_=MiniFloatConverter::float16to32(packedDpy_);
443  dsumEt_=MiniFloatConverter::float16to32(packedDSumEt_);
444 }
445 
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:382
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:365
std::vector< PackedMETUncertainty > uncertaintiesType1p2_
Definition: MET.h:266
Vector2 corP2(METCorrectionLevel level=Type1) const
Definition: MET.cc:312
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:265
void setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared=false)
Definition: MET.cc:339
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:325
Vector corP3(METCorrectionLevel level=Type1) const
Definition: MET.cc:315
static float float16to32(uint16_t h)
Definition: libminifloat.h:10
double caloMETSumEt() const
Definition: MET.cc:377
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:321
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:318
double dpx() const
Definition: MET.h:230
Vector2 shiftedP2(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:219
double caloMETPhi() const
Definition: MET.cc:373
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:290
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:405
void initCorMap()
Definition: MET.cc:131
double shiftedSumEt_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:418
double uncorSumEt() const
Definition: MET.cc:334
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:331
Templated PAT object container.
Definition: PATObject.h:41
void setCorShift(double px, double py, double sumEt, METCorrectionType level)
Definition: MET.cc:356
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:369
Vector uncorP3() const
Definition: MET.cc:328
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
virtual double py() const
y coordinate of momentum vector
void unpack() const
Definition: MET.cc:439
void setMETSignificance(const double &metSig)
Definition: MET.cc:121
Vector shiftedP3_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:394
Vector shiftedP3(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:242