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 }
13 
14 
16 MET::MET(const reco::MET & aMET) : PATObject<reco::MET>(aMET) {
17  const reco::CaloMET * calo = dynamic_cast<const reco::CaloMET *>(&aMET);
18  if (calo != 0) caloMET_.push_back(calo->getSpecific());
19  const reco::PFMET * pf = dynamic_cast<const reco::PFMET *>(&aMET);
20  if (pf != 0) pfMET_.push_back(pf->getSpecific());
21  const pat::MET * pm = dynamic_cast<const pat::MET *>(&aMET);
22  if (pm != 0) this->operator=(*pm);
23 }
24 
25 
27 MET::MET(const edm::RefToBase<reco::MET> & aMETRef) : PATObject<reco::MET>(aMETRef) {
28  const reco::CaloMET * calo = dynamic_cast<const reco::CaloMET *>(aMETRef.get());
29  if (calo != 0) caloMET_.push_back(calo->getSpecific());
30  const reco::PFMET * pf = dynamic_cast<const reco::PFMET *>(aMETRef.get());
31  if (pf != 0) pfMET_.push_back(pf->getSpecific());
32  const pat::MET * pm = dynamic_cast<const pat::MET *>(aMETRef.get());
33  if (pm != 0) this->operator=(*pm);
34 }
35 
37 MET::MET(const edm::Ptr<reco::MET> & aMETRef) : PATObject<reco::MET>(aMETRef) {
38  const reco::CaloMET * calo = dynamic_cast<const reco::CaloMET *>(aMETRef.get());
39  if (calo != 0) caloMET_.push_back(calo->getSpecific());
40  const reco::PFMET * pf = dynamic_cast<const reco::PFMET *>(aMETRef.get());
41  if (pf != 0) pfMET_.push_back(pf->getSpecific());
42  const pat::MET * pm = dynamic_cast<const pat::MET *>(aMETRef.get());
43  if (pm != 0) this->operator=(*pm);
44 }
45 
47 MET::MET(MET const& iOther):
48 PATObject<reco::MET>(iOther),
49 genMET_(iOther.genMET_),
50 caloMET_(iOther.caloMET_),
51 pfMET_(iOther.pfMET_),
52 uncertaintiesRaw_(iOther.uncertaintiesRaw_),
53 uncertaintiesType1_(iOther.uncertaintiesType1_),
54 uncertaintiesType1p2_(iOther.uncertaintiesType1p2_),
55 caloPackedMet_(iOther.caloPackedMet_) {
56 }
57 
60 
61 }
62 
63 MET& MET::operator=(MET const& iOther) {
65  genMET_ = iOther.genMET_;
66  caloMET_ =iOther.caloMET_;
67  pfMET_ =iOther.pfMET_;
72 
73  return *this;
74 }
75 
77 const reco::GenMET * MET::genMET() const {
78  return (genMET_.size() > 0 ? &genMET_.front() : 0 );
79 }
80 
82 void MET::setGenMET(const reco::GenMET & gm) {
83  genMET_.clear();
84  genMET_.push_back(gm);
85 }
86 
88 //unsigned int MET::nCorrections() const { checkUncor_(); return nCorrections_; }
89 
90 float MET::uncorrectedPt() const {
91  return shiftedPt(MET::METUncertainty::NoShift, MET::METUncertaintyLevel::Raw);
92 }
93 float MET::uncorrectedPhi() const {
94  return shiftedPhi(MET::METUncertainty::NoShift, MET::METUncertaintyLevel::Raw);
95 }
96 float MET::uncorrectedSumEt() const {
97  return shiftedSumEt(MET::METUncertainty::NoShift, MET::METUncertaintyLevel::Raw);
98 }
99 
100 
102  if (level != Type1 && level != Type1p2 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw, Type1 and Type1p2\n");
103  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : (level == Type1p2 ? uncertaintiesType1p2_ : uncertaintiesRaw_));
104  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type");
105  if (v.size() == 1) {
106  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)");
107  return Vector2{ (px() + v.front().dpx()), (py() + v.front().dpy()) };
108  }
109  Vector2 ret{ (px() + v[shift].dpx()), (py() + v[shift].dpy()) };
110  return ret;
111 }
113  if (level != Type1 && level != Type1p2 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw, Type1 and Type1p2\n");
114  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : (level == Type1p2 ? uncertaintiesType1p2_ : uncertaintiesRaw_));
115  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type");
116  if (v.size() == 1) {
117  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)");
118  return Vector(px() + v.front().dpx(), py() + v.front().dpy(), 0);
119  }
120  return Vector(px() + v[shift].dpx(), py() + v[shift].dpy(), 0);
121 }
123  if (level != Type1 && level != Type1p2 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw, Type1 and Type1p2\n");
124  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : (level == Type1p2 ? uncertaintiesType1p2_ : uncertaintiesRaw_));
125  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type");
126  if (v.size() == 1) {
127  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)");
128  double x = px() + v.front().dpx(), y = py() + v.front().dpy();
129  return LorentzVector(x, y, 0, std::hypot(x,y));
130  }
131  double x = px() + v[shift].dpx(), y = py() + v[shift].dpy();
132  return LorentzVector(x, y, 0, std::hypot(x,y));
133 }
135  if (level != Type1 && level != Type1p2 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw, Type1 and Type1p2\n");
136  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : (level == Type1p2 ? uncertaintiesType1p2_ : uncertaintiesRaw_));
137  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type");
138  if (v.size() == 1) {
139  if (shift != MET::METUncertainty::NoShift) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type (only central value available)");
140  return sumEt() + v.front().dsumEt();
141  }
142  return sumEt() + v[shift].dsumEt();
143 }
144 
145 void MET::setShift(double px, double py, double sumEt, MET::METUncertainty shift, MET::METUncertaintyLevel level) {
146  if( level != Calo ) {
147  if (level != Type1 && level != Type1p2 && level != Raw) throw cms::Exception("Unsupported", "MET uncertainties only supported for Raw, Type1 and Type1p2\n");
148  std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : (level == Type1p2 ? uncertaintiesType1p2_ : uncertaintiesRaw_));
149  if (shift == MET::METUncertainty::NoShift) {
150  if (v.empty()) { // fresh MET: make size 1, add this
151  v.resize(1);
152  v.back().set(px - this->px(), py - this->py(), sumEt - this->sumEt());
153  } else if (v.size() == 1) { // only unshifted, and I'm updating it
154  v.back().set(px - this->px(), py - this->py(), sumEt - this->sumEt());
155  } else if (v.size() != MET::METUncertainty::METUncertaintySize) {
156  // already initialized with something I don't understand
157  throw cms::Exception("Unsupported", "setShift called after the set of uncertainties is not of a supported size (not 0, 1, or METUncertaintySize)\n");
158  } else {
159  // full set of uncertainties, and I'm updating the no-shift one
160  v[shift].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
161  }
162  } else {
163  if (v.empty()) { // fresh MET. make room for all
164  v.resize(METUncertaintySize);
165  } else if (v.size() == 1) { // I had set only the unshifted, so I extend it copying over the existing one
166  v.resize(METUncertaintySize, v.back());
167  } else if (v.size() != MET::METUncertainty::METUncertaintySize) { // already initialized with something I don't understand
168  throw cms::Exception("Unsupported", "setShift called after the set of uncertainties is not of a supported size (not 0, 1, or METUncertaintySize)\n");
169  }
170  v[shift].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
171  }
172  } else {
173  caloPackedMet_.set(px, py, sumEt);
174  }
175 }
176 
177 
180  return ret;
181 }
182 
183 double MET::caloMETPt() const {
184  return caloMETP2().pt();
185 }
186 
187 double MET::caloMETPhi() const {
188  return caloMETP2().phi();
189 }
190 
191 double MET::caloMETSumEt() const {
192  return caloPackedMet_.dsumEt();
193 }
194 
196 
198  packedDpx_ = MiniFloatConverter::float32to16(dpx_);
199  packedDpy_ = MiniFloatConverter::float32to16(dpy_);
200  packedDSumEt_ = MiniFloatConverter::float32to16(dsumEt_);
201 }
203  unpacked_=true;
204  dpx_=MiniFloatConverter::float16to32(packedDpx_);
205  dpy_=MiniFloatConverter::float16to32(packedDpy_);
206  dsumEt_=MiniFloatConverter::float16to32(packedDSumEt_);
207 
208 }
209 
Analysis-level MET class.
Definition: MET.h:43
value_type const * get() const
Definition: RefToBase.h:212
std::vector< PackedMETUncertainty > uncertaintiesRaw_
Definition: MET.h:206
MET()
default constructor
Definition: MET.cc:11
SpecificPFMETData getSpecific() const
Definition: PFMET.h:72
double dpy() const
Definition: MET.h:183
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
Vector2 caloMETP2() const
Definition: MET.cc:178
std::vector< PackedMETUncertainty > uncertaintiesType1p2_
Definition: MET.h:206
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:143
float uncorrectedPhi() const
Definition: MET.cc:93
double shiftedSumEt(METUncertainty shift, METUncertaintyLevel level=Type1) const
Definition: MET.cc:134
virtual double y() const
rapidity
double dsumEt() const
Definition: MET.h:184
METUncertainty
Definition: MET.h:142
static float float16to32(uint16_t h)
Definition: libminifloat.h:10
double caloMETSumEt() const
Definition: MET.cc:191
SpecificCaloMETData getSpecific() const
Definition: CaloMET.h:79
double sumEt() const
Definition: MET.h:56
void setShift(double px, double py, double sumEt, METUncertainty shift, METUncertaintyLevel level=Type1)
Definition: MET.cc:145
float uncorrectedPt() const
return uncorrrection related stuff
Definition: MET.cc:90
METUncertaintyLevel
Definition: MET.h:147
Definition: MET.h:42
PackedMETUncertainty caloPackedMet_
Definition: MET.h:208
static uint16_t float32to16(float x)
Definition: libminifloat.h:15
double dpx() const
Definition: MET.h:182
double caloMETPhi() const
Definition: MET.cc:187
double phi() const
Definition: MET.h:153
std::vector< reco::GenMET > genMET_
Definition: MET.h:197
double pt() const
Definition: MET.h:152
MET & operator=(MET const &)
Definition: MET.cc:63
const reco::GenMET * genMET() const
return the associated GenMET
Definition: MET.cc:77
virtual double px() const
x coordinate of momentum vector
Vector2 shiftedP2(METUncertainty shift, METUncertaintyLevel level=Type1) const
Definition: MET.cc:101
std::vector< SpecificCaloMETData > caloMET_
Definition: MET.h:199
double shiftedPhi(METUncertainty shift, METUncertaintyLevel level=Type1) const
Definition: MET.h:161
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
std::vector< PackedMETUncertainty > uncertaintiesType1_
Definition: MET.h:206
Vector shiftedP3(METUncertainty shift, METUncertaintyLevel level=Type1) const
Definition: MET.cc:112
math::XYZVector Vector
point in the space
Definition: LeafCandidate.h:29
static unsigned int const shift
Templated PAT object container.
Definition: PATObject.h:41
tuple level
Definition: testEve_cfg.py:34
void setGenMET(const reco::GenMET &gm)
set the associated GenMET
Definition: MET.cc:82
std::vector< SpecificPFMETData > pfMET_
Definition: MET.h:201
virtual ~MET()
destructor
Definition: MET.cc:59
Definition: DDAxes.h:10
double caloMETPt() const
Definition: MET.cc:183
float uncorrectedSumEt() const
Definition: MET.cc:96
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
virtual double py() const
y coordinate of momentum vector
void unpack() const
Definition: MET.cc:202
void set(float dpx, float dpy, float dsumEt)
Definition: MET.h:185
double shiftedPt(METUncertainty shift, METUncertaintyLevel level=Type1) const
Definition: MET.h:160
LorentzVector shiftedP4(METUncertainty shift, METUncertaintyLevel level=Type1) const
Definition: MET.cc:122