CMS 3D CMS Logo

NoPileUpMEtUtilities.cc
Go to the documentation of this file.
2 
4 
5 #include <algorithm>
6 #include <cmath>
7 
8 
10  minPtDef_=-1;
11  maxPtDef_=1000000;
12 }
13 
15 }
16 
17 // namespace NoPileUpMEtUtilities
18 // {
19 //-------------------------------------------------------------------------------
20 // general auxiliary functions
21 void
23  metData.met = sqrt(metData.mex*metData.mex + metData.mey*metData.mey);
24  metData.mez = 0.;
25  metData.phi = atan2(metData.mey, metData.mex);
26 }
27 //-------------------------------------------------------------------------------
28 
29 //-------------------------------------------------------------------------------
30 // auxiliary functions for jets
33  const std::vector<reco::Candidate::LorentzVector>& leptons,
34  double dRoverlap, bool invert) {
36  for ( reco::PUSubMETCandInfoCollection::const_iterator jet = jets.begin();
37  jet != jets.end(); ++jet ) {
38  bool isOverlap = false;
39  for ( std::vector<reco::Candidate::LorentzVector>::const_iterator lepton = leptons.begin();
40  lepton != leptons.end(); ++lepton ) {
41  if ( deltaR2(jet->p4(), *lepton) < dRoverlap*dRoverlap ) {
42  isOverlap = true;
43  break;
44  }
45  }
46  if ( (!isOverlap && !invert) || (isOverlap && invert) ) retVal.push_back(*jet);
47  }
48  return retVal;
49 }
50 
51 
54  bool neutralFracOnly, double& sumAbsPx, double& sumAbsPy) {
55 
56  CommonMETData retVal;
57  retVal.mex = 0.;
58  retVal.mey = 0.;
59  retVal.sumet = 0.;
60  double retVal_sumAbsPx = 0.;
61  double retVal_sumAbsPy = 0.;
62  double pFrac=1;
63  for ( reco::PUSubMETCandInfoCollection::const_iterator cand = cands.begin();
64  cand != cands.end(); ++cand ) {
65 
66  pFrac=1;
67  if(neutralFracOnly) pFrac = (1-cand->chargedEnFrac() );
68 
69  retVal.mex += cand->p4().px()*pFrac;
70  retVal.mey += cand->p4().py()*pFrac;
71  retVal.sumet += cand->p4().pt()*pFrac;
72  retVal_sumAbsPx += std::abs(cand->p4().px());
73  retVal_sumAbsPy += std::abs(cand->p4().py());
74  }
75  finalizeMEtData(retVal);
76  sumAbsPx = retVal_sumAbsPx;
77  sumAbsPy = retVal_sumAbsPy;
78  return retVal;
79 }
80 
81 //-------------------------------------------------------------------------------
82 
83 //-------------------------------------------------------------------------------
84 // auxiliary functions for PFCandidates
87  const std::vector<reco::Candidate::LorentzVector>& leptons,
88  double dRoverlap, bool invert) {
89 // invert: false = PFCandidates are required not to overlap with leptons
90 // true = PFCandidates are required to overlap with leptons
91 
93  for ( reco::PUSubMETCandInfoCollection::const_iterator pfCandidate = pfCandidates.begin();
94  pfCandidate != pfCandidates.end(); ++pfCandidate ) {
95  bool isOverlap = false;
96  for ( std::vector<reco::Candidate::LorentzVector>::const_iterator lepton = leptons.begin();
97  lepton != leptons.end(); ++lepton ) {
98  if ( deltaR2(pfCandidate->p4(), *lepton) < dRoverlap*dRoverlap ) {
99  isOverlap = true;
100  break;
101  }
102  }
103  if ( (!isOverlap && !invert) || (isOverlap && invert) ) retVal.push_back(*pfCandidate);
104  }
105  return retVal;
106 }
107 
108 
111  double minPt, double maxPt, int type,
112  bool isCharged, int isWithinJet) {
114  for ( reco::PUSubMETCandInfoCollection::const_iterator cand = cands.begin();
115  cand != cands.end(); ++cand ) {
116 
117  if( isCharged && cand->charge()==0) continue;
118  double jetPt = cand->p4().pt();
119  if( jetPt < minPt || jetPt > maxPt ) continue;
120  if(type != reco::PUSubMETCandInfo::kUndefined && cand->type() != type) continue;
121 
122  //for pf candidates
123  if( isWithinJet!=NoPileUpMEtUtilities::kAll && ( cand->isWithinJet()!=isWithinJet ) ) continue;
124 
125  retVal.push_back(*cand);
126  }
127  return retVal;
128 }
129 //-------------------------------------------------------------------------------
130 
131 //-------------------------------------------------------------------------------
132 // auxiliary functions to compute different types of MEt/hadronic recoils
133 //
134 // NOTE: all pfCandidates and jets passed as function arguments
135 // need to be cleaned wrt. leptons
136 //
137 
138 void
141 
145 
149 
153 
154  reco::PUSubMETCandInfoCollection pfcsNUnclustered = selectCandidates( pfCandidates, minPtDef_, maxPtDef_,
157 
162 
163  //not used so far
164  //_chPfcSum = computeCandidateSum(pfcsCh, false, &_chPfcSumAbsPx, &_chPfcSumAbsPy);
168 
171 
172 }
173 
175 NoPileUpMEtUtilities::computeRecoil(int metType, double& sumAbsPx, double& sumAbsPy) {
176  CommonMETData retVal;
177  double retSumAbsPx = 0.;
178  double retSumAbsPy = 0.;
179 
180  //never used....
181  // if(metType==NoPileUpMEtUtilities::kChMET) {
182  // CommonMETData chPfcSum = computeCandidateSum(_pfcsCh, false, &trackSumAbsPx, &trackSumAbsPy);
183  // retVal.mex = -chPfcSum.mex;
184  // retVal.mey = -chPfcSum.mey;
185  // retVal.sumet = chPfcSum.sumet;
186  // retSumAbsPx = ;
187  // retSumAbsPy = ;
188  // }
189  if(metType==NoPileUpMEtUtilities::kChHSMET) {
190  retVal.mex = chHSPfcSum_.mex;
191  retVal.mey = chHSPfcSum_.mey;
192  retVal.sumet = chHSPfcSum_.sumet;
193  retSumAbsPx = chHSPfcSumAbsPx_;
194  retSumAbsPy = chHSPfcSumAbsPy_;
195  }
196  if(metType==NoPileUpMEtUtilities::kChPUMET) {
197  retVal.mex = chPUPfcSum_.mex;
198  retVal.mey = chPUPfcSum_.mey;
199  retVal.sumet = chPUPfcSum_.sumet;
200  retSumAbsPx = chPUPfcSumAbsPx_;
201  retSumAbsPy = chPUPfcSumAbsPy_;
202  }
204  retVal.mex = nUncPfcSum_.mex;
205  retVal.mey = nUncPfcSum_.mey;
206  retVal.sumet = nUncPfcSum_.sumet;
207  retSumAbsPx = nUncPfcSumAbsPx_;
208  retSumAbsPy = nUncPfcSumAbsPy_;
209  }
211  retVal.mex = chHSPfcSum_.mex + nHSJetSum_.mex;
212  retVal.mey = chHSPfcSum_.mey + nHSJetSum_.mey;
214  retSumAbsPx = chHSPfcSumAbsPx_ + nHSJetSumAbsPx_;
215  retSumAbsPy = chHSPfcSumAbsPy_ + nHSJetSumAbsPy_;
216  }
218  retVal.mex = chPUPfcSum_.mex + nHSJetSum_.mex;
219  retVal.mey = chPUPfcSum_.mey + nHSJetSum_.mey;
221  retSumAbsPx = chPUPfcSumAbsPx_ + nHSJetSumAbsPx_;
222  retSumAbsPy = chPUPfcSumAbsPy_ + nHSJetSumAbsPy_;
223  }
224 
225  sumAbsPx = retSumAbsPx;
226  sumAbsPy = retSumAbsPy;
227 
228  return retVal;
229 }
type
Definition: HCALResponse.h:21
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:18
vector< PseudoJet > jets
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)
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
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 &)