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 
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  tmpType1SmearXY.push_back(MET::Smear);
162  tmpType01SmearXY.push_back(MET::Smear);
163 
164  tmpTypeXY.push_back(MET::TXYForRaw);
165  tmpType1XY.push_back(MET::TXY);
166  tmpType01XY.push_back(MET::TXYForT01);
167  tmpType1SmearXY.push_back(MET::TXYForT1Smear);
168  tmpType01SmearXY.push_back(MET::TXYForT01Smear);
169 
170  corMap_[MET::Raw] = tmpRaw;
171  corMap_[MET::Type1] = tmpType1;
172  corMap_[MET::Type01] = tmpType01;
173  corMap_[MET::TypeXY] = tmpTypeXY;
174  corMap_[MET::Type1XY] = tmpType1XY;
175  corMap_[MET::Type01XY] = tmpType01XY;
176  corMap_[MET::Type1Smear] = tmpType1Smear;
177  corMap_[MET::Type01Smear] = tmpType01Smear;
178  corMap_[MET::Type1SmearXY] = tmpType1SmearXY;
179  corMap_[MET::Type01SmearXY] = tmpType01SmearXY;
180 
181  //specific calo case
182  std::vector<MET::METCorrectionType> tmpRawCalo;
183  tmpRawCalo.push_back(MET::Calo);
184  corMap_[MET::RawCalo] = tmpRawCalo;
185 }
186 
189 
190  //find corrections shifts =============================
191  std::map<MET::METCorrectionLevel, std::vector<MET::METCorrectionType> >::const_iterator itCor_ = corMap_.find(cor);
192  if(itCor_==corMap_.end() ) throw cms::Exception("Unsupported", "Specified MET correction scheme does not exist");
193 
194  bool isSmeared=false;
195  MET::PackedMETUncertainty totShift;
196  unsigned int scor=itCor_->second.size();
197  for(unsigned int i=0; i<scor;i++) {
198  totShift.add( corrections_[ itCor_->second[i] ].dpx(),
199  corrections_[ itCor_->second[i] ].dpy(),
200  corrections_[ itCor_->second[i] ].dsumEt() );
201 
202  if(itCor_->first>=MET::Type1Smear)
203  isSmeared=true;
204  }
205 
206 
207 
208  //find uncertainty shift =============================
209 
210  if (uncertainties_.empty())
211  return totShift;
212 
213  if(shift>=MET::METUncertaintySize) throw cms::Exception("Unsupported", "MET uncertainty does not exist");
214  if(isSmeared && shift<=MET::JetResDown) shift = (MET::METUncertainty)(MET::METUncertaintySize+shift+1);
215 
216  totShift.add( uncertainties_[ shift ].dpx(),
217  uncertainties_[ shift ].dpy(),
218  uncertainties_[ shift ].dsumEt() );
219 
220  return totShift;
221 }
222 
223 
225 
226  Vector2 vo;
227 
228  //backward compatibility with 74X samples -> the only one
229  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
230  //will be removed once 74X is not used anymore
231  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
232  if(cor!=MET::METCorrectionLevel::RawCalo) {
233  vo = shiftedP2_74x(shift, cor);
234  } else {
236  vo = ret;
237  }
238  }
239  else {
240  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
241  Vector2 ret{ (px() + v.dpx()), (py() + v.dpy()) };
242  //return ret;
243  vo = ret;
244  }
245  return vo;
246 }
248 
249  Vector vo;
250 
251  //backward compatibility with 74X samples -> the only one
252  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
253  //will be removed once 74X is not used anymore
254  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
255  if(cor!=MET::METCorrectionLevel::RawCalo) {
256  vo = shiftedP3_74x(shift, cor);
257  } else {
259  vo = tmp;
260  }
261  }
262  else {
263  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
264  //return Vector(px() + v.dpx(), py() + v.dpy(), 0);
265  Vector tmp(px() + v.dpx(), py() + v.dpy(), 0);
266  vo = tmp;
267  }
268  return vo;
269 }
271 
272  LorentzVector vo;
273 
274  //backward compatibility with 74X samples -> the only one
275  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
276  //will be removed once 74X is not used anymore
277  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
278  if(cor!=MET::METCorrectionLevel::RawCalo) {
279  vo = shiftedP4_74x(shift, cor);
280  } else {
281  double x = caloPackedMet_.dpx(), y = caloPackedMet_.dpy();
282  LorentzVector tmp(x, y, 0, std::hypot(x,y));
283  vo = tmp;
284  }
285  }
286  else {
287  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
288  double x = px() + v.dpx(), y = py() + v.dpy();
289  //return LorentzVector(x, y, 0, std::hypot(x,y));
290  LorentzVector tmp(x, y, 0, std::hypot(x,y));
291  vo = tmp;
292  }
293  return vo;
294 }
296 
297  double sumEto;
298 
299  //backward compatibility with 74X samples -> the only one
300  // with uncertaintiesType1_/uncertaintiesRaw_ not empty
301  //will be removed once 74X is not used anymore
302  if(uncertaintiesType1_.size()!=0 || uncertaintiesRaw_.size()!=0) {
303  if(cor!=MET::METCorrectionLevel::RawCalo) {
304  sumEto = shiftedSumEt_74x(shift, cor);
305  } else {
306  sumEto = caloPackedMet_.dsumEt();
307  }
308  }
309  else {
310  const MET::PackedMETUncertainty& v = findMETTotalShift(cor,shift);
311  //return sumEt() + v.dsumEt();
312  sumEto = sumEt() + v.dsumEt();
313  }
314  return sumEto;
315 }
316 
318  return shiftedP2(MET::NoShift, cor );
319 }
321  return shiftedP3(MET::NoShift, cor );
322 }
324  return shiftedP4(MET::NoShift, cor );
325 }
327  return shiftedSumEt(MET::NoShift, cor );
328 }
329 
331  return shiftedP2(MET::NoShift, MET::Raw );
332 }
334  return shiftedP3(MET::NoShift, MET::Raw );
335 }
337  return shiftedP4(MET::NoShift, MET::Raw );
338 }
339 double MET::uncorSumEt() const {
341 }
342 
343 
344 void MET::setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared) {
345  if (uncertainties_.empty()) {
346  uncertainties_.resize(METUncertainty::METFullUncertaintySize);
347  }
348 
349  if(isSmeared && shift<=MET::JetResDown) {
350  //changing reference to only get the uncertainty shift and not the smeared one
351  // which is performed independently
352  shift = (MET::METUncertainty)(METUncertainty::METUncertaintySize+shift+1);
353  const PackedMETUncertainty& ref = uncertainties_[METUncertainty::NoShift];
354  uncertainties_[shift].set(px + ref.dpx() - this->px(), py + ref.dpy() - this->py(), sumEt + ref.dsumEt() - this->sumEt() );
355  }
356  else
357  uncertainties_[shift].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
358 
359 }
360 
361 void MET::setCorShift(double px, double py, double sumEt, MET::METCorrectionType level) {
362  if (corrections_.empty()) {
363  corrections_.resize(MET::METCorrectionType::METCorrectionTypeSize);
364  }
365 
366  corrections_[level].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
367 }
368 
369 
371  return shiftedP2(MET::METUncertainty::NoShift, MET::METCorrectionLevel::RawCalo );
372 }
373 
374 double MET::caloMETPt() const {
375  return caloMETP2().pt();
376 }
377 
378 double MET::caloMETPhi() const {
379  return caloMETP2().phi();
380 }
381 
382 double MET::caloMETSumEt() const {
384 }
385 
386 // functions to access to 74X samples ========================================================
388  if (level != Type1 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
389  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
390  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
391  if (v.size() == 1) {
392  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
393  return Vector2{ (px() + v.front().dpx()), (py() + v.front().dpy()) };
394  }
395  Vector2 ret{ (px() + v[shift].dpx()), (py() + v[shift].dpy()) };
396  return ret;
397 }
398 
400  if (level != Type1 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples \n");
401  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
402  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
403  if (v.size() == 1) {
404  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
405  return Vector(px() + v.front().dpx(), py() + v.front().dpy(), 0);
406  }
407  return Vector(px() + v[shift].dpx(), py() + v[shift].dpy(), 0);
408 }
409 
411  if (level != Type1 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
412  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
413  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
414  if (v.size() == 1) {
415  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
416  double x = px() + v.front().dpx(), y = py() + v.front().dpy();
417  return LorentzVector(x, y, 0, std::hypot(x,y));
418  }
419  double x = px() + v[shift].dpx(), y = py() + v[shift].dpy();
420  return LorentzVector(x, y, 0, std::hypot(x,y));
421 }
422 
424  if (level != Type1 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw and Type1 in 74X samples\n");
425  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : uncertaintiesRaw_);
426  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type\n");
427  if (v.size() == 1) {
428  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)\n");
429  return sumEt() + v.front().dsumEt();
430  }
431  return sumEt() + v[shift].dsumEt();
432 }
433 
434 
435 
436 
438 
440  packedDpx_ = MiniFloatConverter::float32to16(dpx_);
441  packedDpy_ = MiniFloatConverter::float32to16(dpy_);
442  packedDSumEt_ = MiniFloatConverter::float32to16(dsumEt_);
443 }
445  unpacked_=true;
446  dpx_=MiniFloatConverter::float16to32(packedDpx_);
447  dpy_=MiniFloatConverter::float16to32(packedDpy_);
448  dsumEt_=MiniFloatConverter::float16to32(packedDSumEt_);
449 }
450 
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:387
const PackedMETUncertainty findMETTotalShift(MET::METCorrectionLevel cor, MET::METUncertainty shift) const
Definition: MET.cc:188
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:370
std::vector< PackedMETUncertainty > uncertaintiesType1p2_
Definition: MET.h:266
Vector2 corP2(METCorrectionLevel level=Type1) const
Definition: MET.cc:317
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
virtual double y() const final
rapidity
LorentzVector shiftedP4(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:270
void setUncShift(double px, double py, double sumEt, METUncertainty shift, bool isSmeared=false)
Definition: MET.cc:344
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:330
Vector corP3(METCorrectionLevel level=Type1) const
Definition: MET.cc:320
static float float16to32(uint16_t h)
Definition: libminifloat.h:10
double caloMETSumEt() const
Definition: MET.cc:382
double corSumEt(METCorrectionLevel level=Type1) const
Definition: MET.cc:326
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:323
double dpx() const
Definition: MET.h:230
Vector2 shiftedP2(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:224
double caloMETPhi() const
Definition: MET.cc:378
double shiftedSumEt(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:295
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:410
void initCorMap()
Definition: MET.cc:132
double shiftedSumEt_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:423
double uncorSumEt() const
Definition: MET.cc:339
double pt() const
Definition: MET.h:172
MET & operator=(MET const &)
Definition: MET.cc:93
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
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:336
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:361
tuple level
Definition: testEve_cfg.py:34
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:374
Vector uncorP3() const
Definition: MET.cc:333
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
void unpack() const
Definition: MET.cc:444
void setMETSignificance(const double &metSig)
Definition: MET.cc:122
Vector shiftedP3_74x(METUncertainty shift, METCorrectionLevel level) const
Definition: MET.cc:399
reco::METCovMatrix getSignificanceMatrix(void) const
Definition: MET.cc:139
Vector shiftedP3(METUncertainty shift, METCorrectionLevel level=Type1) const
Definition: MET.cc:247