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