CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
noPileUpMEtUtilities.cc
Go to the documentation of this file.
2 
4 
5 #include <algorithm>
6 #include <math.h>
7 
8 namespace noPileUpMEtUtilities
9 {
10  //-------------------------------------------------------------------------------
11  // general auxiliary functions
13  {
14  metData.met = sqrt(metData.mex*metData.mex + metData.mey*metData.mey);
15  metData.mez = 0.;
16  metData.phi = atan2(metData.mey, metData.mex);
17  }
18  //-------------------------------------------------------------------------------
19 
20  //-------------------------------------------------------------------------------
21  // auxiliary functions for jets
23  const std::vector<reco::Candidate::LorentzVector>& leptons,
24  double dRoverlap, bool invert)
25  {
27  for ( reco::MVAMEtJetInfoCollection::const_iterator jet = jets.begin();
28  jet != jets.end(); ++jet ) {
29  bool isOverlap = false;
30  for ( std::vector<reco::Candidate::LorentzVector>::const_iterator lepton = leptons.begin();
31  lepton != leptons.end(); ++lepton ) {
32  if ( deltaR2(jet->p4_, *lepton) < dRoverlap*dRoverlap ) {
33  isOverlap = true;
34  break;
35  }
36  }
37  if ( (!isOverlap && !invert) || (isOverlap && invert) ) retVal.push_back(*jet);
38  }
39  return retVal;
40  }
41 
43  double minJetPt, double maxJetPt, int type)
44  {
46  for ( reco::MVAMEtJetInfoCollection::const_iterator jet = jets.begin();
47  jet != jets.end(); ++jet ) {
48  double jetPt = jet->p4_.pt();
49  if ( jetPt > minJetPt &&
50  jetPt < maxJetPt &&
51  (type == reco::MVAMEtJetInfo::kUndefined || jet->type_ == type) ) retVal.push_back(*jet);
52  }
53  return retVal;
54  }
55 
56  CommonMETData computeJetSum(const reco::MVAMEtJetInfoCollection& jets, double* sumAbsPx, double* sumAbsPy)
57  {
58  CommonMETData retVal;
59  retVal.mex = 0.;
60  retVal.mey = 0.;
61  retVal.sumet = 0.;
62  double retVal_sumAbsPx = 0.;
63  double retVal_sumAbsPy = 0.;
64  for ( reco::MVAMEtJetInfoCollection::const_iterator jet = jets.begin();
65  jet != jets.end(); ++jet ) {
66  retVal.mex += jet->p4_.px();
67  retVal.mey += jet->p4_.py();
68  retVal.sumet += jet->p4_.pt();
69  retVal_sumAbsPx += std::abs(jet->p4_.px());
70  retVal_sumAbsPy += std::abs(jet->p4_.py());
71  }
72  finalizeMEtData(retVal);
73  if ( sumAbsPx ) (*sumAbsPx) = retVal_sumAbsPx;
74  if ( sumAbsPy ) (*sumAbsPy) = retVal_sumAbsPy;
75  return retVal;
76  }
77 
78  CommonMETData computeJetSum_neutral(const reco::MVAMEtJetInfoCollection& jets, double* sumAbsPx, double* sumAbsPy)
79  {
80  CommonMETData retVal;
81  retVal.mex = 0.;
82  retVal.mey = 0.;
83  retVal.sumet = 0.;
84  double retVal_sumAbsPx = 0.;
85  double retVal_sumAbsPy = 0.;
86  for ( reco::MVAMEtJetInfoCollection::const_iterator jet = jets.begin();
87  jet != jets.end(); ++jet ) {
88  retVal.mex += (jet->p4_.px()*jet->neutralEnFrac_);
89  retVal.mey += (jet->p4_.py()*jet->neutralEnFrac_);
90  retVal.sumet += (jet->p4_.pt()*jet->neutralEnFrac_);
91  retVal_sumAbsPx += std::abs(jet->p4_.px());
92  retVal_sumAbsPy += std::abs(jet->p4_.py());
93  }
94  finalizeMEtData(retVal);
95  if ( sumAbsPx ) (*sumAbsPx) = retVal_sumAbsPx;
96  if ( sumAbsPy ) (*sumAbsPy) = retVal_sumAbsPy;
97  return retVal;
98  }
99 
101  {
102  reco::MVAMEtJetInfo retVal;
103  if ( idx < jets.size() ) {
104  reco::MVAMEtJetInfoCollection jets_sorted = jets;
105  std::sort(jets_sorted.begin(), jets_sorted.end());
106  retVal = jets_sorted[idx];
107  }
108  return retVal;
109  }
110 
112  {
113  return jet(jets, 0);
114  }
115 
117  {
118  return jet(jets, 1);
119  }
120  //-------------------------------------------------------------------------------
121 
122  //-------------------------------------------------------------------------------
123  // auxiliary functions for PFCandidates
125  const std::vector<reco::Candidate::LorentzVector>& leptons,
126  double dRoverlap, bool invert)
127  // invert: false = PFCandidates are required not to overlap with leptons
128  // true = PFCandidates are required to overlap with leptons
129  {
131  for ( reco::MVAMEtPFCandInfoCollection::const_iterator pfCandidate = pfCandidates.begin();
132  pfCandidate != pfCandidates.end(); ++pfCandidate ) {
133  bool isOverlap = false;
134  for ( std::vector<reco::Candidate::LorentzVector>::const_iterator lepton = leptons.begin();
135  lepton != leptons.end(); ++lepton ) {
136  if ( deltaR2(pfCandidate->p4_, *lepton) < dRoverlap*dRoverlap ) {
137  isOverlap = true;
138  break;
139  }
140  }
141  if ( (!isOverlap && !invert) || (isOverlap && invert) ) retVal.push_back(*pfCandidate);
142  }
143  return retVal;
144  }
145 
147  double minCharge, double maxCharge, int type, int isWithinJet)
148  // isWithinJet: -1 = no selection applied
149  // 0 = PFCandidates are required not to be within jets
150  // +1 = PFCandidates are required to be within jets
151  {
153  for ( reco::MVAMEtPFCandInfoCollection::const_iterator pfCandidate = pfCandidates.begin();
154  pfCandidate != pfCandidates.end(); ++pfCandidate ) {
155  int charge = abs(pfCandidate->charge_);
156  if ( charge > minCharge &&
157  charge < maxCharge &&
158  (type == reco::MVAMEtJetInfo::kUndefined || pfCandidate->type_ == type) &&
159  (isWithinJet == -1 || (isWithinJet == 1 && pfCandidate->isWithinJet_) || (isWithinJet == 0 && !pfCandidate->isWithinJet_)) )
160  retVal.push_back(*pfCandidate);
161  }
162  return retVal;
163  }
164 
166  {
167  CommonMETData retVal;
168  retVal.mex = 0.;
169  retVal.mey = 0.;
170  retVal.sumet = 0.;
171  double retVal_sumAbsPx = 0.;
172  double retVal_sumAbsPy = 0.;
173  for ( reco::MVAMEtPFCandInfoCollection::const_iterator pfCandidate = pfCandidates.begin();
174  pfCandidate != pfCandidates.end(); ++pfCandidate ) {
175  retVal.mex += pfCandidate->p4_.px();
176  retVal.mey += pfCandidate->p4_.py();
177  retVal.sumet += pfCandidate->p4_.pt();
178  retVal_sumAbsPx += std::abs(pfCandidate->p4_.px());
179  retVal_sumAbsPy += std::abs(pfCandidate->p4_.py());
180  }
181  finalizeMEtData(retVal);
182  if ( sumAbsPx ) (*sumAbsPx) = retVal_sumAbsPx;
183  if ( sumAbsPy ) (*sumAbsPy) = retVal_sumAbsPy;
184  return retVal;
185  }
186  //-------------------------------------------------------------------------------
187 
188  //-------------------------------------------------------------------------------
189  // auxiliary functions to compute different types of MEt/hadronic recoils
190  //
191  // NOTE: all pfCandidates and jets passed as function arguments
192  // need to be cleaned wrt. leptons
193  //
195  {
197  pfCandidates, 0.5, 1.e+3, reco::MVAMEtPFCandInfo::kUndefined, -1);
198  double trackSumAbsPx = 0.;
199  double trackSumAbsPy = 0.;
200  CommonMETData trackSum = computePFCandidateSum(chargedPFCandidates, &trackSumAbsPx, &trackSumAbsPy);
201  CommonMETData retVal;
202  retVal.mex = -trackSum.mex;
203  retVal.mey = -trackSum.mey;
204  retVal.sumet = trackSum.sumet;
205  finalizeMEtData(retVal);
206  if ( sumAbsPx ) (*sumAbsPx) = trackSumAbsPx;
207  if ( sumAbsPy ) (*sumAbsPy) = trackSumAbsPy;
208  return retVal;
209  }
210 
212  {
213  reco::MVAMEtPFCandInfoCollection chargedPFCandidatesNoPU = selectPFCandidates(
214  pfCandidates, 0.5, 1.e+3, reco::MVAMEtPFCandInfo::kNoPileUpCharged, -1);
215  return computePFCandidateSum(chargedPFCandidatesNoPU, sumAbsPx, sumAbsPy);
216  }
217 
219  {
221  pfCandidates, 0.5, 1.e+3, reco::MVAMEtPFCandInfo::kPileUpCharged, -1);
222  return computePFCandidateSum(chargedPFCandidatesPU, sumAbsPx, sumAbsPy);
223  }
224 
226  {
227  reco::MVAMEtPFCandInfoCollection neutralPFCandidates_unclustered = selectPFCandidates(
228  pfCandidates, -0.5, +0.5, reco::MVAMEtPFCandInfo::kNeutral, 0);
229  return computePFCandidateSum(neutralPFCandidates_unclustered, sumAbsPx, sumAbsPy);
230  }
231 
233  const reco::MVAMEtPFCandInfoCollection& pfCandidates, double* sumAbsPx, double* sumAbsPy)
234  {
235  double trackSumAbsPx = 0.;
236  double trackSumAbsPy = 0.;
237  CommonMETData trackSumNoPU = computeTrackRecoilNoPU(pfCandidates, &trackSumAbsPx, &trackSumAbsPy);
239  double jetSumNoPUabsPx_neutral = 0.;
240  double jetSumNoPUabsPy_neutral = 0.;
241  CommonMETData jetSumNoPU_neutral = computeJetSum_neutral(jetsNoPU, &jetSumNoPUabsPx_neutral, &jetSumNoPUabsPy_neutral);
242  CommonMETData retVal;
243  retVal.mex = trackSumNoPU.mex + jetSumNoPU_neutral.mex;
244  retVal.mey = trackSumNoPU.mey + jetSumNoPU_neutral.mey;
245  retVal.sumet = trackSumNoPU.sumet + jetSumNoPU_neutral.sumet;
246  finalizeMEtData(retVal);
247  if ( sumAbsPx ) (*sumAbsPx) = trackSumAbsPx + jetSumNoPUabsPx_neutral;
248  if ( sumAbsPy ) (*sumAbsPy) = trackSumAbsPy + jetSumNoPUabsPy_neutral;
249  return retVal;
250  }
251 
253  const reco::MVAMEtPFCandInfoCollection& pfCandidates, double* sumAbsPx, double* sumAbsPy)
254  {
255  double trackSumPUabsPx = 0.;
256  double trackSumPUabsPy = 0.;
257  CommonMETData trackSumPU = computeTrackRecoilPU(pfCandidates, &trackSumPUabsPx, &trackSumPUabsPy);
259  double jetSumPUabsPx_neutral = 0.;
260  double jetSumPUabsPy_neutral = 0.;
261  CommonMETData jetSumPU_neutral = computeJetSum_neutral(jetsPU, &jetSumPUabsPx_neutral, &jetSumPUabsPy_neutral);
262  CommonMETData retVal;
263  retVal.mex = trackSumPU.mex + jetSumPU_neutral.mex;
264  retVal.mey = trackSumPU.mey + jetSumPU_neutral.mey;
265  retVal.sumet = trackSumPU.sumet + jetSumPU_neutral.sumet;
266  finalizeMEtData(retVal);
267  if ( sumAbsPx ) (*sumAbsPx) = trackSumPUabsPx + jetSumPUabsPx_neutral;
268  if ( sumAbsPy ) (*sumAbsPy) = trackSumPUabsPy + jetSumPUabsPy_neutral;
269  return retVal;
270  }
271  //-------------------------------------------------------------------------------
272 }
273 
type
Definition: HCALResponse.h:21
CommonMETData computeJetSum(const reco::MVAMEtJetInfoCollection &, double *sumAbsPx=0, double *sumAbsPy=0)
reco::MVAMEtPFCandInfoCollection cleanPFCandidates(const reco::MVAMEtPFCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
reco::MVAMEtPFCandInfoCollection selectPFCandidates(const reco::MVAMEtPFCandInfoCollection &, double, double, int, int)
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
CommonMETData computeTrackRecoil(const reco::MVAMEtPFCandInfoCollection &, double *sumAbsPx=0, double *sumAbsPy=0)
CommonMETData computeHadRecoilNoPU(const reco::MVAMEtJetInfoCollection &, const reco::MVAMEtPFCandInfoCollection &, double *sumAbsPx=0, double *sumAbsPy=0)
void finalizeMEtData(CommonMETData &)
std::vector< reco::MVAMEtJetInfo > MVAMEtJetInfoCollection
Definition: MVAMEtDataFwd.h:10
reco::Candidate::LorentzVector p4_
Definition: MVAMEtData.h:29
CommonMETData computeHadRecoilPU(const reco::MVAMEtJetInfoCollection &, const reco::MVAMEtPFCandInfoCollection &, double *sumAbsPx=0, double *sumAbsPy=0)
T sqrt(T t)
Definition: SSEVec.h:48
vector< PseudoJet > jets
CommonMETData computeTrackRecoilPU(const reco::MVAMEtPFCandInfoCollection &, double *sumAbsPx=0, double *sumAbsPy=0)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
Structure containing data common to all types of MET.
Definition: CommonMETData.h:12
CommonMETData computeJetSum_neutral(const reco::MVAMEtJetInfoCollection &, double *sumAbsPx=0, double *sumAbsPy=0)
reco::MVAMEtJetInfo subleadJet(const reco::MVAMEtJetInfoCollection &)
std::vector< reco::MVAMEtPFCandInfo > MVAMEtPFCandInfoCollection
Definition: MVAMEtDataFwd.h:12
CommonMETData computeTrackRecoilNoPU(const reco::MVAMEtPFCandInfoCollection &, double *sumAbsPx=0, double *sumAbsPy=0)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
reco::MVAMEtJetInfoCollection selectJets(const reco::MVAMEtJetInfoCollection &, double, double, int)
reco::MVAMEtJetInfo leadJet(const reco::MVAMEtJetInfoCollection &)
reco::MVAMEtJetInfoCollection cleanJets(const reco::MVAMEtJetInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
CommonMETData computePFCandidateSum(const reco::MVAMEtPFCandInfoCollection &, double *sumAbsPx=0, double *sumAbsPy=0)
CommonMETData computeNeutralRecoil_unclustered(const reco::MVAMEtPFCandInfoCollection &, double *sumAbsPx=0, double *sumAbsPy=0)
reco::MVAMEtJetInfo jet(const reco::MVAMEtJetInfoCollection &, unsigned)