CMS 3D CMS Logo

NoPileUpMEtUtilities.cc
Go to the documentation of this file.
2 
4 
5 #include <algorithm>
6 #include <cmath>
7 
9  minPtDef_ = -1;
10  maxPtDef_ = 1000000;
11 }
12 
14 
15 // namespace NoPileUpMEtUtilities
16 // {
17 //-------------------------------------------------------------------------------
18 // general auxiliary functions
20  metData.met = sqrt(metData.mex * metData.mex + metData.mey * metData.mey);
21  metData.mez = 0.;
22  metData.phi = atan2(metData.mey, metData.mex);
23 }
24 //-------------------------------------------------------------------------------
25 
26 //-------------------------------------------------------------------------------
27 // auxiliary functions for jets
30  const std::vector<reco::Candidate::LorentzVector>& leptons,
31  double dRoverlap,
32  bool invert) {
34  for (reco::PUSubMETCandInfoCollection::const_iterator jet = jets.begin(); jet != jets.end(); ++jet) {
35  bool isOverlap = false;
36  for (std::vector<reco::Candidate::LorentzVector>::const_iterator lepton = leptons.begin(); lepton != leptons.end();
37  ++lepton) {
38  if (deltaR2(jet->p4(), *lepton) < dRoverlap * dRoverlap) {
39  isOverlap = true;
40  break;
41  }
42  }
43  if ((!isOverlap && !invert) || (isOverlap && invert))
44  retVal.push_back(*jet);
45  }
46  return retVal;
47 }
48 
50  bool neutralFracOnly,
51  double& sumAbsPx,
52  double& sumAbsPy) {
53  CommonMETData retVal;
54  retVal.mex = 0.;
55  retVal.mey = 0.;
56  retVal.sumet = 0.;
57  double retVal_sumAbsPx = 0.;
58  double retVal_sumAbsPy = 0.;
59  double pFrac = 1;
60  for (reco::PUSubMETCandInfoCollection::const_iterator cand = cands.begin(); cand != cands.end(); ++cand) {
61  pFrac = 1;
62  if (neutralFracOnly)
63  pFrac = (1 - cand->chargedEnFrac());
64 
65  retVal.mex += cand->p4().px() * pFrac;
66  retVal.mey += cand->p4().py() * pFrac;
67  retVal.sumet += cand->p4().pt() * pFrac;
68  retVal_sumAbsPx += std::abs(cand->p4().px());
69  retVal_sumAbsPy += std::abs(cand->p4().py());
70  }
71  finalizeMEtData(retVal);
72  sumAbsPx = retVal_sumAbsPx;
73  sumAbsPy = retVal_sumAbsPy;
74  return retVal;
75 }
76 
77 //-------------------------------------------------------------------------------
78 
79 //-------------------------------------------------------------------------------
80 // auxiliary functions for PFCandidates
83  const std::vector<reco::Candidate::LorentzVector>& leptons,
84  double dRoverlap,
85  bool invert) {
86  // invert: false = PFCandidates are required not to overlap with leptons
87  // true = PFCandidates are required to overlap with leptons
88 
90  for (reco::PUSubMETCandInfoCollection::const_iterator pfCandidate = pfCandidates.begin();
91  pfCandidate != pfCandidates.end();
92  ++pfCandidate) {
93  bool isOverlap = false;
94  for (std::vector<reco::Candidate::LorentzVector>::const_iterator lepton = leptons.begin(); lepton != leptons.end();
95  ++lepton) {
96  if (deltaR2(pfCandidate->p4(), *lepton) < dRoverlap * dRoverlap) {
97  isOverlap = true;
98  break;
99  }
100  }
101  if ((!isOverlap && !invert) || (isOverlap && invert))
102  retVal.push_back(*pfCandidate);
103  }
104  return retVal;
105 }
106 
108  double minPt,
109  double maxPt,
110  int type,
111  bool isCharged,
112  int isWithinJet) {
114  for (reco::PUSubMETCandInfoCollection::const_iterator cand = cands.begin(); cand != cands.end(); ++cand) {
115  if (isCharged && cand->charge() == 0)
116  continue;
117  double jetPt = cand->p4().pt();
118  if (jetPt < minPt || jetPt > maxPt)
119  continue;
120  if (type != reco::PUSubMETCandInfo::kUndefined && cand->type() != type)
121  continue;
122 
123  //for pf candidates
124  if (isWithinJet != NoPileUpMEtUtilities::kAll && (cand->isWithinJet() != isWithinJet))
125  continue;
126 
127  retVal.push_back(*cand);
128  }
129  return retVal;
130 }
131 //-------------------------------------------------------------------------------
132 
133 //-------------------------------------------------------------------------------
134 // auxiliary functions to compute different types of MEt/hadronic recoils
135 //
136 // NOTE: all pfCandidates and jets passed as function arguments
137 // need to be cleaned wrt. leptons
138 //
139 
144 
147 
150 
153 
158 
159  //not used so far
160  //_chPfcSum = computeCandidateSum(pfcsCh, false, &_chPfcSumAbsPx, &_chPfcSumAbsPy);
164 
167 }
168 
169 CommonMETData NoPileUpMEtUtilities::computeRecoil(int metType, double& sumAbsPx, double& sumAbsPy) {
170  CommonMETData retVal;
171  double retSumAbsPx = 0.;
172  double retSumAbsPy = 0.;
173 
174  //never used....
175  // if(metType==NoPileUpMEtUtilities::kChMET) {
176  // CommonMETData chPfcSum = computeCandidateSum(_pfcsCh, false, &trackSumAbsPx, &trackSumAbsPy);
177  // retVal.mex = -chPfcSum.mex;
178  // retVal.mey = -chPfcSum.mey;
179  // retVal.sumet = chPfcSum.sumet;
180  // retSumAbsPx = ;
181  // retSumAbsPy = ;
182  // }
184  retVal.mex = chHSPfcSum_.mex;
185  retVal.mey = chHSPfcSum_.mey;
186  retVal.sumet = chHSPfcSum_.sumet;
187  retSumAbsPx = chHSPfcSumAbsPx_;
188  retSumAbsPy = chHSPfcSumAbsPy_;
189  }
191  retVal.mex = chPUPfcSum_.mex;
192  retVal.mey = chPUPfcSum_.mey;
193  retVal.sumet = chPUPfcSum_.sumet;
194  retSumAbsPx = chPUPfcSumAbsPx_;
195  retSumAbsPy = chPUPfcSumAbsPy_;
196  }
198  retVal.mex = nUncPfcSum_.mex;
199  retVal.mey = nUncPfcSum_.mey;
200  retVal.sumet = nUncPfcSum_.sumet;
201  retSumAbsPx = nUncPfcSumAbsPx_;
202  retSumAbsPy = nUncPfcSumAbsPy_;
203  }
205  retVal.mex = chHSPfcSum_.mex + nHSJetSum_.mex;
206  retVal.mey = chHSPfcSum_.mey + nHSJetSum_.mey;
208  retSumAbsPx = chHSPfcSumAbsPx_ + nHSJetSumAbsPx_;
209  retSumAbsPy = chHSPfcSumAbsPy_ + nHSJetSumAbsPy_;
210  }
212  retVal.mex = chPUPfcSum_.mex + nHSJetSum_.mex;
213  retVal.mey = chPUPfcSum_.mey + nHSJetSum_.mey;
215  retSumAbsPx = chPUPfcSumAbsPx_ + nHSJetSumAbsPx_;
216  retSumAbsPy = chPUPfcSumAbsPy_ + nHSJetSumAbsPy_;
217  }
218 
219  sumAbsPx = retSumAbsPx;
220  sumAbsPy = retSumAbsPy;
221 
222  return retVal;
223 }
CommonMETData computeRecoil(int metType, double &sumAbsPx, double &sumAbsPy)
reco::PUSubMETCandInfoCollection cleanJets(const reco::PUSubMETCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
void computeAllSums(const reco::PUSubMETCandInfoCollection &jets, const reco::PUSubMETCandInfoCollection &pfCandidates)
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< reco::PUSubMETCandInfo > PUSubMETCandInfoCollection
Structure containing data common to all types of MET.
Definition: CommonMETData.h:12
CommonMETData computeCandidateSum(const reco::PUSubMETCandInfoCollection &cands, bool neutralFracOnly, double &sumAbsPx, double &sumAbsPy)
reco::PUSubMETCandInfoCollection cleanPFCandidates(const reco::PUSubMETCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
reco::PUSubMETCandInfoCollection selectCandidates(const reco::PUSubMETCandInfoCollection &cands, double minPt, double maxPt, int type, bool isCharged, int isWithinJet)
void finalizeMEtData(CommonMETData &)