CMS 3D CMS Logo

METSignificance.cc
Go to the documentation of this file.
1 
2 // -*- C++ -*-
3 //
4 // Package: METAlgorithms
5 // Class: METSignificance
6 //
12 //
13 // Original Author: Nathan Mirman (Cornell University)
14 // Created: Thu May 30 16:39:52 CDT 2013
15 //
16 //
17 
19 
20 
22 
23  edm::ParameterSet cfgParams = iConfig.getParameter<edm::ParameterSet>("parameters");
24 
25  double dRmatch = cfgParams.getParameter<double>("dRMatch");
26  dR2match_ = dRmatch*dRmatch;
27 
28  jetThreshold_ = cfgParams.getParameter<double>("jetThreshold");
29  jetEtas_ = cfgParams.getParameter<std::vector<double> >("jeta");
30  jetParams_ = cfgParams.getParameter<std::vector<double> >("jpar");
31  pjetParams_ = cfgParams.getParameter<std::vector<double> >("pjpar");
32 
33 }
34 
36 }
37 
38 
41  const std::vector< edm::Handle<reco::CandidateView> >& leptons,
42  const edm::Handle<edm::View<reco::Candidate> >& pfCandidatesH,
43  double rho,
44  JME::JetResolution& resPtObj,
45  JME::JetResolution& resPhiObj,
47  bool isRealData) {
48 
49  //pfcandidates
50  const edm::View<reco::Candidate>* pfCandidates=pfCandidatesH.product();
51 
52  // metsig covariance
53  double cov_xx = 0;
54  double cov_xy = 0;
55  double cov_yy = 0;
56 
57  // for lepton and jet subtraction
58  std::set<reco::CandidatePtr> footprint;
59 
60  // subtract leptons out of sumPt
61  for ( std::vector< edm::Handle<reco::CandidateView> >::const_iterator lep_i = leptons.begin();
62  lep_i != leptons.end(); ++lep_i ) {
63  for( reco::CandidateView::const_iterator lep = (*lep_i)->begin(); lep != (*lep_i)->end(); lep++ ){
64  if( lep->pt() > 10 ){
65  for( unsigned int n=0; n < lep->numberOfSourceCandidatePtrs(); n++ ){
66  if( lep->sourceCandidatePtr(n).isNonnull() and lep->sourceCandidatePtr(n).isAvailable() ){
67  footprint.insert(lep->sourceCandidatePtr(n));
68  }
69  }
70  }
71  }
72  }
73  // subtract jets out of sumPt
74  for(edm::View<reco::Jet>::const_iterator jet = jets.begin(); jet != jets.end(); ++jet) {
75 
76  // disambiguate jets and leptons
77  if(!cleanJet(*jet, leptons) ) continue;
78  for( unsigned int n=0; n < jet->numberOfSourceCandidatePtrs(); n++){
79  if( jet->sourceCandidatePtr(n).isNonnull() and jet->sourceCandidatePtr(n).isAvailable() ){
80 
81  footprint.insert(jet->sourceCandidatePtr(n));
82  }
83  }
84 
85  }
86 
87  // calculate sumPt
88  double sumPt = 0;
89  for(size_t i = 0; i< pfCandidates->size(); ++i) {
90 
91  // check if candidate exists in a lepton or jet
92  bool cleancand = true;
93  if(footprint.find( pfCandidates->ptrAt(i) )==footprint.end()) {
94 
95  //dP4 recovery
96  for( std::set<reco::CandidatePtr>::const_iterator it=footprint.begin();it!=footprint.end();it++) {
97  if( ((*it)->p4()-(*pfCandidates)[i].p4()).Et2()<0.000025 ){
98  cleancand = false;
99  break;
100  }
101  }
102  // if not, add to sumPt
103  if( cleancand ){
104  sumPt += (*pfCandidates)[i].pt();
105  }
106  }
107  }
108 
109  // add jets to metsig covariance matrix and subtract them from sumPt
110  for(edm::View<reco::Jet>::const_iterator jet = jets.begin(); jet != jets.end(); ++jet) {
111 
112  // disambiguate jets and leptons
113  if(!cleanJet(*jet, leptons) ) continue;
114 
115  double jpt = jet->pt();
116  double jeta = jet->eta();
117  double feta = std::abs(jeta);
118  double c = jet->px()/jet->pt();
119  double s = jet->py()/jet->pt();
120 
122  parameters.setJetPt(jpt).setJetEta(jeta).setRho(rho);
123 
124  // jet energy resolutions
125  double sigmapt = resPtObj.getResolution(parameters);
126  double sigmaphi = resPhiObj.getResolution(parameters);
127  // SF not needed since is already embedded in the sigma in the dataGlobalTag
128  // double sigmaSF = isRealData ? resSFObj.getScaleFactor(parameters) : 1.0;
129 
130  // split into high-pt and low-pt sector
131  if( jpt > jetThreshold_ ){
132  // high-pt jets enter into the covariance matrix via JER
133 
134  double scale = 0;
135  if(feta<jetEtas_[0]) scale = jetParams_[0];
136  else if(feta<jetEtas_[1]) scale = jetParams_[1];
137  else if(feta<jetEtas_[2]) scale = jetParams_[2];
138  else if(feta<jetEtas_[3]) scale = jetParams_[3];
139  else scale = jetParams_[4];
140 
141  // double dpt = sigmaSF*scale*jpt*sigmapt;
142  double dpt = scale*jpt*sigmapt;
143  double dph = jpt*sigmaphi;
144 
145  cov_xx += dpt*dpt*c*c + dph*dph*s*s;
146  cov_xy += (dpt*dpt-dph*dph)*c*s;
147  cov_yy += dph*dph*c*c + dpt*dpt*s*s;
148 
149  } else {
150 
151  // add the (corrected) jet to the sumPt
152  sumPt += jpt;
153 
154  }
155 
156  }
157 
158  //protection against unphysical events
159  if(sumPt<0) sumPt=0;
160 
161  // add pseudo-jet to metsig covariance matrix
162  cov_xx += pjetParams_[0]*pjetParams_[0] + pjetParams_[1]*pjetParams_[1]*sumPt;
163  cov_yy += pjetParams_[0]*pjetParams_[0] + pjetParams_[1]*pjetParams_[1]*sumPt;
164 
165  reco::METCovMatrix cov;
166  cov(0,0) = cov_xx;
167  cov(1,0) = cov_xy;
168  cov(0,1) = cov_xy;
169  cov(1,1) = cov_yy;
170 
171  return cov;
172 }
173 
174 double
176 
177  // covariance matrix determinant
178  double det = cov(0,0)*cov(1,1) - cov(0,1)*cov(1,0);
179 
180  // invert matrix
181  double ncov_xx = cov(1,1) / det;
182  double ncov_xy = -cov(0,1) / det;
183  double ncov_yy = cov(0,0) / det;
184 
185  // product of met and inverse of covariance
186  double sig = met.px()*met.px()*ncov_xx + 2*met.px()*met.py()*ncov_xy + met.py()*met.py()*ncov_yy;
187 
188  return sig;
189 }
190 
191 bool
193  const std::vector< edm::Handle<reco::CandidateView> >& leptons ){
194 
195  for ( std::vector< edm::Handle<reco::CandidateView> >::const_iterator lep_i = leptons.begin();
196  lep_i != leptons.end(); ++lep_i ) {
197  for( reco::CandidateView::const_iterator lep = (*lep_i)->begin(); lep != (*lep_i)->end(); lep++ ){
198  if ( reco::deltaR2(*lep, jet) < dR2match_ ) {
199  return false;
200  }
201  }
202  }
203  return true;
204 }
T getParameter(std::string const &) const
bool cleanJet(const reco::Jet &jet, const std::vector< edm::Handle< reco::CandidateView > > &leptons)
float getResolution(const JetParameters &parameters) const
JetParameters & setJetEta(float eta)
static double getSignificance(const reco::METCovMatrix &cov, const reco::MET &met)
JetParameters & setRho(float rho)
Ptr< value_type > ptrAt(size_type i) const
Base class for all types of Jets.
Definition: Jet.h:20
size_type size() const
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:40
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)
std::vector< double > jetEtas_
const_iterator begin() const
Definition: MET.h:42
virtual double px() const final
x coordinate of momentum vector
vector< PseudoJet > jets
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< double > pjetParams_
std::vector< double > jetParams_
METSignificance(const edm::ParameterSet &iConfig)
met
===> hadronic RAZOR
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
const_iterator end() const
JetParameters & setJetPt(float pt)
virtual double py() const final
y coordinate of momentum vector