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 }
Analysis-level MET class.
Definition: MET.h:42
float uncorrectedPhi(UncorrectionType ix=uncorrALL) const
Definition: MET.cc:108
MET()
default constructor
Definition: MET.cc:11
SpecificPFMETData getSpecific() const
Definition: PFMET.h:72
uncorrect for JES only
Definition: MET.h:83
void checkUncor_() const
check and set transients
Definition: MET.cc:115
#define nullptr
float corEx(UncorrectionType ix=uncorrALL) const
Definition: MET.cc:92
virtual double py() const GCC11_FINAL
y coordinate of momentum vector
unsigned int nCorrections_
Definition: MET.h:183
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
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
std::atomic< std::vector< UncorInfo > * > uncorInfo_
Definition: MET.h:179
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:143
Definition: MET.h:32
T sqrt(T t)
Definition: SSEVec.h:48
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
std::vector< reco::GenMET > genMET_
Definition: MET.h:171
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:63
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
std::vector< SpecificCaloMETData > caloMET_
Definition: MET.h:173
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Templated PAT object container.
Definition: PATObject.h:41
void setGenMET(const reco::GenMET &gm)
set the associated GenMET
Definition: MET.cc:84
std::vector< SpecificPFMETData > pfMET_
Definition: MET.h:175
virtual ~MET()
destructor
Definition: MET.cc:57
uncorrect for TAU only
Definition: MET.h:85
virtual float pt() const GCC11_FINAL
transverse momentum
UncorrectionType
Definition: MET.h:79
value_type const * get() const
Definition: RefToBase.h:212
do nothing
Definition: MET.h:81
unsigned int nCorrections() const
return uncorrrection related stuff
Definition: MET.cc:90