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 
11 MET::MET(): uncorInfo_(nullptr) {
12 }
13 
14 
16 MET::MET(const reco::MET & aMET) : PATObject<reco::MET>(aMET), uncorInfo_(nullptr) {
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 }
22 
23 
25 MET::MET(const edm::RefToBase<reco::MET> & aMETRef) : PATObject<reco::MET>(aMETRef), uncorInfo_(nullptr) {
26  const reco::CaloMET * calo = dynamic_cast<const reco::CaloMET *>(aMETRef.get());
27  if (calo != 0) caloMET_.push_back(calo->getSpecific());
28  const reco::PFMET * pf = dynamic_cast<const reco::PFMET *>(aMETRef.get());
29  if (pf != 0) pfMET_.push_back(pf->getSpecific());
30 }
31 
33 MET::MET(const edm::Ptr<reco::MET> & aMETRef) : PATObject<reco::MET>(aMETRef), uncorInfo_(nullptr) {
34  const reco::CaloMET * calo = dynamic_cast<const reco::CaloMET *>(aMETRef.get());
35  if (calo != 0) caloMET_.push_back(calo->getSpecific());
36  const reco::PFMET * pf = dynamic_cast<const reco::PFMET *>(aMETRef.get());
37  if (pf != 0) pfMET_.push_back(pf->getSpecific());
38 }
39 
41 MET::MET(MET const& iOther):
42 PATObject<reco::MET>(iOther),
43 genMET_(iOther.genMET_),
44 caloMET_(iOther.caloMET_),
45 pfMET_(iOther.pfMET_),
46 uncorInfo_(nullptr)
47 {
48  auto tmp = iOther.uncorInfo_.load(std::memory_order_acquire);
49  if(tmp != nullptr) {
50  //Only thread-safe to read iOther.nCorrections_ if iOther.uncorInfo_ != nullptr
52  uncorInfo_.store( new std::vector<UncorInfo>{*tmp},std::memory_order_release);
53  }
54 }
55 
58  delete uncorInfo_.load(std::memory_order_acquire);
59 }
60 
61 MET& MET::operator=(MET const& iOther) {
63  genMET_ = iOther.genMET_;
64  caloMET_ =iOther.caloMET_;
65  pfMET_ =iOther.pfMET_;
66  auto tmp = iOther.uncorInfo_.load(std::memory_order_acquire);
67  if(tmp != nullptr) {
68  //Only thread-safe to read iOther.nCorrections_ if iOther.uncorInfo_ != nullptr
70  delete uncorInfo_.exchange( new std::vector<UncorInfo>{*tmp},std::memory_order_acq_rel);
71  } else {
72  nCorrections_ = 0;
73  delete uncorInfo_.exchange(nullptr, std::memory_order_acq_rel);
74  }
75  return *this;
76 }
77 
79 const reco::GenMET * MET::genMET() const {
80  return (genMET_.size() > 0 ? &genMET_.front() : 0 );
81 }
82 
84 void MET::setGenMET(const reco::GenMET & gm) {
85  genMET_.clear();
86  genMET_.push_back(gm);
87 }
88 
90 unsigned int MET::nCorrections() const { checkUncor_(); return nCorrections_; }
91 
92 float MET::corEx(UncorrectionType ix) const {
93  if (ix == uncorrNONE) return 0;
94  checkUncor_(); return (*uncorInfo_.load(std::memory_order_acquire))[ix].corEx;
95 }
96 float MET::corEy(UncorrectionType ix) const {
97  if (ix == uncorrNONE) return 0;
98  checkUncor_(); return (*uncorInfo_.load(std::memory_order_acquire))[ix].corEy;
99 }
101  if (ix == uncorrNONE) return 0;
102  checkUncor_(); return (*uncorInfo_.load(std::memory_order_acquire))[ix].corSumEt;
103 }
105  if (ix == uncorrNONE) return pt();
106  checkUncor_(); return (*uncorInfo_.load(std::memory_order_acquire))[ix].pt;
107 }
109  if (ix == uncorrNONE) return phi();
110  checkUncor_(); return (*uncorInfo_.load(std::memory_order_acquire))[ix].phi;
111 }
112 
113 
115 void MET::checkUncor_() const {
116  if (uncorInfo_.load(std::memory_order_acquire)!=nullptr ) return;
117 
118  const std::vector<CorrMETData>& corrs(mEtCorr());
119  const auto nCorrectionsTmp = corrs.size();
120 
121  std::unique_ptr<std::vector<UncorInfo>> uncorInfoTmpPtr{ new std::vector<UncorInfo>{uncorrMAXN} };
122  auto& uncorInfoTmp = *uncorInfoTmpPtr;
123 
124  UncorrectionType ix;
125 
128  ix = uncorrALL;
129  uncorInfoTmp[ix] = UncorInfo();
130  for (unsigned int iC=0; iC < nCorrectionsTmp; ++iC){
131  uncorInfoTmp[ix].corEx += corrs[iC].mex;
132  uncorInfoTmp[ix].corEy += corrs[iC].mey;
133  uncorInfoTmp[ix].corSumEt += corrs[iC].sumet;
134  }
135  setPtPhi_(uncorInfoTmp[ix]);
136 
138  ix = uncorrJES;
139  uncorInfoTmp[ix] = UncorInfo();
140  if (nCorrectionsTmp >=1 ){
141  unsigned int iC = 0;
142  uncorInfoTmp[ix].corEx += corrs[iC].mex;
143  uncorInfoTmp[ix].corEy += corrs[iC].mey;
144  uncorInfoTmp[ix].corSumEt += corrs[iC].sumet;
145  }
146  setPtPhi_(uncorInfoTmp[ix]);
147 
149  ix = uncorrMUON;
150  uncorInfoTmp[ix] = UncorInfo();
151  if (nCorrectionsTmp >=2 ){
152  unsigned int iC = 1;
153  uncorInfoTmp[ix].corEx += corrs[iC].mex;
154  uncorInfoTmp[ix].corEy += corrs[iC].mey;
155  uncorInfoTmp[ix].corSumEt += corrs[iC].sumet;
156  }
157  setPtPhi_(uncorInfoTmp[ix]);
158 
160  ix = uncorrTAU;
161  uncorInfoTmp[ix] = UncorInfo();
162  if (nCorrectionsTmp >=3 ){
163  unsigned int iC = 2;
164  uncorInfoTmp[ix].corEx += corrs[iC].mex;
165  uncorInfoTmp[ix].corEy += corrs[iC].mey;
166  uncorInfoTmp[ix].corSumEt += corrs[iC].sumet;
167  }
168  setPtPhi_(uncorInfoTmp[ix]);
169 
170  //The compare_exchange_strong guarantees that the new value of nCorrections_ will be seen by other
171  // threads
172  nCorrections_ = nCorrectionsTmp;
173 
174  std::vector<UncorInfo>* expected=nullptr;
175  if(uncorInfo_.compare_exchange_strong(expected,uncorInfoTmpPtr.get(),std::memory_order_acq_rel)) {
176  uncorInfoTmpPtr.release();
177  }
178 }
179 
180 void MET::setPtPhi_(UncorInfo& uci) const {
181  float lpx = px() - uci.corEx;
182  float lpy = py() - uci.corEy;
183  uci.pt = sqrt(lpx*lpx + lpy*lpy);
184  uci.phi = atan2(lpy, lpx);
185 }
186 
188  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : (level == Type1p2 ? uncertaintiesType1p2_ : uncertaintiesRaw_));
189  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type");
190  Vector2 ret{ (px() + v[shift].dpx()), (py() + v[shift].dpy()) };
191  return ret;
192 }
194  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : (level == Type1p2 ? uncertaintiesType1p2_ : uncertaintiesRaw_));
195  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type");
196  return Vector(px() + v[shift].dpx(), py() + v[shift].dpy(), 0);
197 }
199  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : (level == Type1p2 ? uncertaintiesType1p2_ : uncertaintiesRaw_));
200  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type");
201  double x = px() + v[shift].dpx(), y = py() + v[shift].dpy();
202  return LorentzVector(x, y, 0, std::hypot(x,y));
203 }
205  const std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : (level == Type1p2 ? uncertaintiesType1p2_ : uncertaintiesRaw_));
206  if (v.empty()) throw cms::Exception("Unsupported", "MET uncertainties not available for the specified correction type");
207  return sumEt() + v[shift].dsumEt();
208 }
209 void MET::setShift(double px, double py, double sumEt, MET::METUncertainty shift, MET::METUncertaintyLevel level) {
210  std::vector<PackedMETUncertainty> &v = (level == Type1 ? uncertaintiesType1_ : (level == Type1p2 ? uncertaintiesType1p2_ : uncertaintiesRaw_));
211  if (v.empty()) v.resize(METUncertaintySize);
212  v[shift].set(px - this->px(), py - this->py(), sumEt - this->sumEt());
213 }
Analysis-level MET class.
Definition: MET.h:42
float uncorrectedPhi(UncorrectionType ix=uncorrALL) const
Definition: MET.cc:108
std::vector< PackedMETUncertainty > uncertaintiesRaw_
Definition: MET.h:229
MET()
default constructor
Definition: MET.cc:11
SpecificPFMETData getSpecific() const
Definition: PFMET.h:72
math::XYZVector Vector
point in the space
Definition: Candidate.h:47
virtual float pt() const
transverse momentum
std::vector< PackedMETUncertainty > uncertaintiesType1p2_
Definition: MET.h:229
uncorrect for JES only
Definition: MET.h:83
virtual float phi() const
momentum azimuthal angle
void checkUncor_() const
check and set transients
Definition: MET.cc:115
double shiftedSumEt(METUncertainty shift, METUncertaintyLevel level=Type1) const
Definition: MET.cc:204
virtual double y() const
rapidity
float corEx(UncorrectionType ix=uncorrALL) const
Definition: MET.cc:92
METUncertainty
Definition: MET.h:168
#define nullptr
unsigned int nCorrections_
Definition: MET.h:221
float corSumEt(UncorrectionType ix=uncorrALL) const
Definition: MET.cc:100
uncorrect to bare bones
Definition: MET.h:82
SpecificCaloMETData getSpecific() const
Definition: CaloMET.h:79
double sumEt() const
Definition: MET.h:53
void setShift(double px, double py, double sumEt, METUncertainty shift, METUncertaintyLevel level=Type1)
Definition: MET.cc:209
std::atomic< std::vector< UncorInfo > * > uncorInfo_
Definition: MET.h:217
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:143
METUncertaintyLevel
Definition: MET.h:173
Definition: MET.h:39
T sqrt(T t)
Definition: SSEVec.h:48
std::vector< reco::GenMET > genMET_
Definition: MET.h:209
uncorrect for MUON only
Definition: MET.h:84
float uncorrectedPt(UncorrectionType ix=uncorrALL) const
Definition: MET.cc:104
std::vector< CorrMETData > mEtCorr() const
Definition: MET.h:67
float corEy(UncorrectionType ix=uncorrALL) const
Definition: MET.cc:96
MET & operator=(MET const &)
Definition: MET.cc:61
const reco::GenMET * genMET() const
return the associated GenMET
Definition: MET.cc:79
void setPtPhi_(UncorInfo &uci) const
Definition: MET.cc:180
virtual double px() const
x coordinate of momentum vector
Vector2 shiftedP2(METUncertainty shift, METUncertaintyLevel level=Type1) const
Definition: MET.cc:187
std::vector< SpecificCaloMETData > caloMET_
Definition: MET.h:211
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::vector< PackedMETUncertainty > uncertaintiesType1_
Definition: MET.h:229
Vector shiftedP3(METUncertainty shift, METUncertaintyLevel level=Type1) const
Definition: MET.cc:193
math::XYZVector Vector
point in the space
Definition: LeafCandidate.h:34
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:84
std::vector< SpecificPFMETData > pfMET_
Definition: MET.h:213
virtual ~MET()
destructor
Definition: MET.cc:57
Definition: DDAxes.h:10
uncorrect for TAU only
Definition: MET.h:85
UncorrectionType
Definition: MET.h:79
value_type const * get() const
Definition: RefToBase.h:212
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:28
virtual double py() const
y coordinate of momentum vector
do nothing
Definition: MET.h:81
unsigned int nCorrections() const
return uncorrrection related stuff
Definition: MET.cc:90
LorentzVector shiftedP4(METUncertainty shift, METUncertaintyLevel level=Type1) const
Definition: MET.cc:198