CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
metsig::METSignificance Class Reference

#include <METSignificance.h>

Public Member Functions

reco::METCovMatrix getCovariance (const edm::View< reco::Jet > &jets, const std::vector< edm::Handle< reco::CandidateView > > &leptons, const edm::Handle< edm::View< reco::Candidate > > &pfCandidates, double rho, JME::JetResolution &resPtObj, JME::JetResolution &resPhiObj, JME::JetResolutionScaleFactor &resSFObj, bool isRealData, double &sumPtUnclustered)
 
 METSignificance (const edm::ParameterSet &iConfig)
 
 ~METSignificance ()
 

Static Public Member Functions

static double getSignificance (const reco::METCovMatrix &cov, const reco::MET &met)
 

Private Member Functions

bool cleanJet (const reco::Jet &jet, const std::vector< edm::Handle< reco::CandidateView > > &leptons)
 

Private Attributes

double dR2match_
 
std::vector< double > jetEtas_
 
std::vector< double > jetParams_
 
double jetThreshold_
 
std::vector< double > pjetParams_
 
bool useDeltaRforFootprint_
 

Detailed Description

Definition at line 35 of file METSignificance.h.

Constructor & Destructor Documentation

METSignificance::METSignificance ( const edm::ParameterSet iConfig)

Definition at line 31 of file METSignificance.cc.

References CaloRecoTauDiscriminationAgainstMuon_cfi::dRmatch, and edm::ParameterSet::getParameter().

31  {
32 
33  edm::ParameterSet cfgParams = iConfig.getParameter<edm::ParameterSet>("parameters");
34 
35  double dRmatch = cfgParams.getParameter<double>("dRMatch");
36  dR2match_ = dRmatch*dRmatch;
37 
38  jetThreshold_ = cfgParams.getParameter<double>("jetThreshold");
39  jetEtas_ = cfgParams.getParameter<std::vector<double> >("jeta");
40  jetParams_ = cfgParams.getParameter<std::vector<double> >("jpar");
41  pjetParams_ = cfgParams.getParameter<std::vector<double> >("pjpar");
42  useDeltaRforFootprint_ = cfgParams.getParameter<bool>("useDeltaRforFootprint");
43 
44 }
T getParameter(std::string const &) const
std::vector< double > jetEtas_
std::vector< double > pjetParams_
std::vector< double > jetParams_
METSignificance::~METSignificance ( )

Definition at line 46 of file METSignificance.cc.

46 {}

Member Function Documentation

bool METSignificance::cleanJet ( const reco::Jet jet,
const std::vector< edm::Handle< reco::CandidateView > > &  leptons 
)
private

Definition at line 203 of file METSignificance.cc.

References reco::deltaR2(), and AK4GenJetFlavourInfos_cfi::leptons.

204  {
205 
206  for ( const auto& lep_i : leptons ) {
207  for( const auto& lep : *lep_i ) {
208  if ( reco::deltaR2(lep, jet) < dR2match_ ) {
209  return false;
210  }
211  }
212  }
213  return true;
214 }
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
reco::METCovMatrix METSignificance::getCovariance ( const edm::View< reco::Jet > &  jets,
const std::vector< edm::Handle< reco::CandidateView > > &  leptons,
const edm::Handle< edm::View< reco::Candidate > > &  pfCandidates,
double  rho,
JME::JetResolution resPtObj,
JME::JetResolution resPhiObj,
JME::JetResolutionScaleFactor resSFObj,
bool  isRealData,
double &  sumPtUnclustered 
)

Definition at line 48 of file METSignificance.cc.

References funct::abs(), edm::View< T >::begin(), EnergyCorrector::c, reco::deltaR2(), edm::View< T >::end(), JME::JetResolution::getResolution(), mps_fire::i, metsig::jet, METSignificanceParams_cfi::jeta, AK4GenJetFlavourInfos_cfi::leptons, gen::n, patMuonMerger_cfi::pfCandidates, edm::View< T >::ptrAt(), alignCSCRings::s, Scenarios_cff::scale, JME::JetParameters::setJetEta(), JME::JetParameters::setJetPt(), JME::JetParameters::setRho(), edm::View< T >::size(), met_cff::sumPtUnclustered, and create_public_lumi_plots::transform.

Referenced by cms::PFMETProducer::getMETCovMatrix(), pat::PATMETProducer::getMETCovMatrix(), and cms::METSignificanceProducer::produce().

56  {
57  //pfcandidates
58  const edm::View<reco::Candidate>& pfCandidates = *pfCandidatesH;
59 
60  // metsig covariance
61  double cov_xx = 0;
62  double cov_xy = 0;
63  double cov_yy = 0;
64 
65  // for lepton and jet subtraction
66  std::unordered_set<reco::CandidatePtr,ptr_hash> footprint;
67 
68  // subtract leptons out of sumPtUnclustered
69  for ( const auto& lep_i : leptons ) {
70  for (const auto& lep : lep_i->ptrs()) {
71  if (lep->pt() > 10) {
72  for (unsigned int n = 0; n < lep->numberOfSourceCandidatePtrs(); n++)
73  footprint.insert(lep->sourceCandidatePtr(n));
74  }
75  }
76  }
77 
78  std::vector<bool> cleanedJets(jets.size(), false);
79  std::transform(jets.begin(), jets.end(), cleanedJets.begin(), [this, &leptons](auto const& jet) -> bool {
80  return cleanJet(jet, leptons);
81  });
82  // subtract jets out of sumPtUnclustered
83  auto iCleaned = cleanedJets.begin();
84  for (const auto& jet : jets) {
85  // disambiguate jets and leptons
86  if (!(*iCleaned++))
87  continue;
88  for (unsigned int n = 0; n < jet.numberOfSourceCandidatePtrs(); n++) {
89  footprint.insert(jet.sourceCandidatePtr(n));
90  }
91 
92  }
93 
94  // calculate sumPtUnclustered
95  for(size_t i = 0; i< pfCandidates.size(); ++i) {
96 
97  // check if candidate exists in a lepton or jet
98  bool cleancand = true;
99  if(footprint.find( pfCandidates.ptrAt(i) )==footprint.end()) {
100 
101  //dP4 recovery
102  for( const auto& it : footprint) {
103  // Special treatment for PUPPI with dR, since jet candidates (puppi) and MET candidates (puppiForMet)
104  // can't be matched through the sourceCandidatePtrs and may have different energy, but same direction.
105  if((it.isNonnull()) && (it.isAvailable()) &&
106  (((!useDeltaRforFootprint_) && ((it->p4()-pfCandidates[i].p4()).Et2()<0.000025)) ||
107  (( useDeltaRforFootprint_) && (reco::deltaR2(*it, pfCandidates[i])<0.00000025)))){
108  cleancand = false;
109  break;
110  }
111  }
112  // if not, add to sumPtUnclustered
113  if( cleancand ){
114  sumPtUnclustered += pfCandidates[i].pt();
115  }
116  }
117  }
118 
119  // add jets to metsig covariance matrix and subtract them from sumPtUnclustered
120  iCleaned = cleanedJets.begin();
121  for(const auto& jet : jets) {
122 
123  // disambiguate jets and leptons
124  if(!(*iCleaned++) ) continue;
125 
126  double jpt = jet.pt();
127  double jeta = jet.eta();
128  double feta = std::abs(jeta);
129  double c = jet.px()/jet.pt();
130  double s = jet.py()/jet.pt();
131 
133  parameters.setJetPt(jpt).setJetEta(jeta).setRho(rho);
134 
135  // jet energy resolutions
136  double sigmapt = resPtObj.getResolution(parameters);
137  double sigmaphi = resPhiObj.getResolution(parameters);
138  // SF not needed since is already embedded in the sigma in the dataGlobalTag
139  // double sigmaSF = isRealData ? resSFObj.getScaleFactor(parameters) : 1.0;
140 
141  // split into high-pt and low-pt sector
142  if( jpt > jetThreshold_ ){
143  // high-pt jets enter into the covariance matrix via JER
144 
145  double scale = 0;
146  if(feta<jetEtas_[0]) scale = jetParams_[0];
147  else if(feta<jetEtas_[1]) scale = jetParams_[1];
148  else if(feta<jetEtas_[2]) scale = jetParams_[2];
149  else if(feta<jetEtas_[3]) scale = jetParams_[3];
150  else scale = jetParams_[4];
151 
152  // double dpt = sigmaSF*scale*jpt*sigmapt;
153  double dpt = scale*jpt*sigmapt;
154  double dph = jpt*sigmaphi;
155 
156  cov_xx += dpt*dpt*c*c + dph*dph*s*s;
157  cov_xy += (dpt*dpt-dph*dph)*c*s;
158  cov_yy += dph*dph*c*c + dpt*dpt*s*s;
159 
160  } else {
161 
162  // add the (corrected) jet to the sumPtUnclustered
163  sumPtUnclustered += jpt;
164 
165  }
166 
167  }
168 
169  //protection against unphysical events
171 
172  // add pseudo-jet to metsig covariance matrix
175 
176  reco::METCovMatrix cov;
177  cov(0,0) = cov_xx;
178  cov(1,0) = cov_xy;
179  cov(0,1) = cov_xy;
180  cov(1,1) = cov_yy;
181 
182  return cov;
183 }
bool cleanJet(const reco::Jet &jet, const std::vector< edm::Handle< reco::CandidateView > > &leptons)
float getResolution(const JetParameters &parameters) const
JetParameters & setJetEta(float eta)
JetParameters & setRho(float rho)
Ptr< value_type > ptrAt(size_type i) const
size_type size() const
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:40
std::vector< double > jetEtas_
const_iterator begin() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< double > pjetParams_
std::vector< double > jetParams_
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
sumPtUnclustered
Definition: met_cff.py:20
const_iterator end() const
JetParameters & setJetPt(float pt)
double METSignificance::getSignificance ( const reco::METCovMatrix cov,
const reco::MET met 
)
static

Definition at line 186 of file METSignificance.cc.

References reco::LeafCandidate::px(), and reco::LeafCandidate::py().

Referenced by pat::PATMETProducer::produce(), cms::METSignificanceProducer::produce(), and CorrectedPATMETProducer::produce().

186  {
187 
188  // covariance matrix determinant
189  double det = cov(0,0)*cov(1,1) - cov(0,1)*cov(1,0);
190 
191  // invert matrix
192  double ncov_xx = cov(1,1) / det;
193  double ncov_xy = -cov(0,1) / det;
194  double ncov_yy = cov(0,0) / det;
195 
196  // product of met and inverse of covariance
197  double sig = met.px()*met.px()*ncov_xx + 2*met.px()*met.py()*ncov_xy + met.py()*met.py()*ncov_yy;
198 
199  return sig;
200 }
double px() const final
x coordinate of momentum vector
double py() const final
y coordinate of momentum vector

Member Data Documentation

double metsig::METSignificance::dR2match_
private

Definition at line 57 of file METSignificance.h.

std::vector<double> metsig::METSignificance::jetEtas_
private

Definition at line 58 of file METSignificance.h.

std::vector<double> metsig::METSignificance::jetParams_
private

Definition at line 59 of file METSignificance.h.

double metsig::METSignificance::jetThreshold_
private

Definition at line 56 of file METSignificance.h.

std::vector<double> metsig::METSignificance::pjetParams_
private

Definition at line 60 of file METSignificance.h.

bool metsig::METSignificance::useDeltaRforFootprint_
private

Definition at line 61 of file METSignificance.h.