CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Type1METAlgo.cc
Go to the documentation of this file.
1 // File: Type1METAlgo.cc
2 // Description: see Type1METAlgo.h
3 // Author: M. Schmitt, R. Cavanaugh, The University of Florida
4 // Creation Date: MHS May 31, 2005 Initial version.
5 //
6 //--------------------------------------------
7 // $Id: Type1METAlgo.cc,v 1.29 2011/09/13 14:35:35 veelken Exp $
8 
9 #include <math.h>
10 #include <vector>
23 
24 using namespace std;
25 using namespace reco;
26 
28 
29 namespace {
30  CaloMET makeMet (const CaloMET& fMet,
31  double fSumEt,
32  const std::vector<CorrMETData>& fCorrections,
33  const MET::LorentzVector& fP4) {
34  return CaloMET (fMet.getSpecific (), fSumEt, fCorrections, fP4, fMet.vertex ());
35  }
36 
37  MET makeMet (const PFMET& fMet,
38  double fSumEt,
39  const std::vector<CorrMETData>& fCorrections,
40  const MET::LorentzVector& fP4) {
41  return MET (fSumEt, fCorrections, fP4, fMet.vertex ());
42  }
43 
44 
46  // CALO MET
48 
49  template <class T>
50  void Type1METAlgo_run(const std::vector<T>& uncorMET,
51  const JetCorrector& corrector,
52  const JetCorrector& corrector2,
53  const CaloJetCollection& uncorJet,
54  double jetPTthreshold,
55  double jetEMfracLimit,
56  double UscaleA,
57  double UscaleB,
58  double UscaleC,
59  bool useTypeII,
60  bool hasMuonsCorr,
61  const edm::View<reco::Muon>& inputMuons,
62  const edm::ValueMap<reco::MuonMETCorrectionData>& vm_muCorrData,
63  vector<T>* corMET, edm::Event& iEvent, const edm::EventSetup& iSetup, const bool subtractL1Fast)
64  {
65  if (!corMET) {
66  std::cerr << "Type1METAlgo_run-> undefined output MET collection. Stop. " << std::endl;
67  return;
68  }
69 
70  const T* u = &(uncorMET.front());
71 
72  double DeltaPx = 0.0;
73  double DeltaPy = 0.0;
74  double UDeltaP = 0.0;
75  double UDeltaPx = 0.0;
76  double UDeltaPy = 0.0;
77  double DeltaSumET = 0.0;
78  double USumET = u->sumEt();
79  // ---------------- Calculate jet corrections, but only for those uncorrected jets
80  // ---------------- which are above the given threshold. This requires that the
81  // ---------------- uncorrected jets be matched with the corrected jets.
82  for( CaloJetCollection::const_iterator jet = uncorJet.begin(); jet != uncorJet.end(); ++jet) {
83  int index = jet-uncorJet.begin();
85  if( jet->pt()*corrector.correction (*jet,jetRef,iEvent,iSetup) > jetPTthreshold && jet->emEnergyFraction() < jetEMfracLimit ) {
86  if (!subtractL1Fast)
87  {
88  double corr = corrector.correction (*jet,jetRef,iEvent,iSetup) - 1.; // correction itself
89  DeltaPx += jet->px() * corr;
90  DeltaPy += jet->py() * corr;
91  DeltaSumET += jet->et() * corr;
92  }
93  else
94  {
95  double corr = corrector.correction (*jet,jetRef,iEvent,iSetup) - 1.; // correction itself
96  double corr2 = corrector2.correction (*jet,jetRef,iEvent,iSetup) - 1.;
97  DeltaPx += jet->px() * corr - (jet->px() * corr2);
98  DeltaPy += jet->py() * corr - (jet->py() * corr2);
99  DeltaSumET += jet->et() * corr - (jet->et() * corr2);
100  }
101  UDeltaPx += jet->px() ;
102  UDeltaPy += jet->py() ;
103  USumET -=jet->et();
104  }
105  if( jet->pt() *corrector.correction (*jet,jetRef,iEvent,iSetup)> jetPTthreshold && jet->emEnergyFraction() > jetEMfracLimit ) {
106  UDeltaPx += jet->px() ;
107  UDeltaPy += jet->py() ;
108  USumET -=jet->et();
109  }
110  }
111  if( hasMuonsCorr) {
112  unsigned int nMuons = inputMuons.size();
113  for(unsigned int iMu = 0; iMu<nMuons; iMu++) {
114  const reco::Muon *mu = &inputMuons[iMu]; //new
115  reco::MuonMETCorrectionData muCorrData = (vm_muCorrData)[inputMuons.refAt(iMu)];
116  int flag = muCorrData.type();
117 
118  LorentzVector mup4;
119  if (flag == 0) //this muon is not used to correct the MET
120  continue;
121  mup4 = mu->p4();
122 
123  UDeltaPx += mup4.px();
124  UDeltaPy += mup4.py();
125  USumET -=mup4.pt();
126  }
127 
128  } // end hasMuonsCorr
129 
130 
131  //----------------- Calculate and set deltas for new MET correction
133  delta.mex = - DeltaPx; //correction to MET (from Jets) is negative,
134  delta.mey = - DeltaPy; //since MET points in direction opposite of jets
135  delta.sumet = DeltaSumET;
136  //----------------- Fill holder with corrected MET (= uncorrected + delta) values
137  UDeltaPx += u->px();
138  UDeltaPy += u->py();
139 
140 
141  UDeltaP = sqrt(UDeltaPx*UDeltaPx+UDeltaPy*UDeltaPy);
142  double Uscale = UscaleA+UscaleB*exp(UscaleC*UDeltaP);
143 
144  if(useTypeII){
145  delta.mex += (Uscale-1.)*UDeltaPx;
146  delta.mey += (Uscale-1.)*UDeltaPy;
147  delta.sumet += (Uscale-1.)*USumET;
148  }
149 
150  double corrMetPx = u->px()+delta.mex;
151  double corrMetPy = u->py()+delta.mey;
152 
153 
154  MET::LorentzVector correctedMET4vector( corrMetPx, corrMetPy, 0.,
155  sqrt (corrMetPx*corrMetPx + corrMetPy*corrMetPy)
156  );
157  //----------------- get previous corrections and push into new corrections
158  std::vector<CorrMETData> corrections = u->mEtCorr();
159  corrections.push_back( delta );
160  //----------------- Push onto MET Collection
161  T result = makeMet (*u, u->sumEt()+delta.sumet, corrections,correctedMET4vector);
162  corMET->push_back(result);
163  }
164 
165 
167  // PF MET (PFJetCollection)
169 
170 
171  void Type1METAlgo_run(const reco::PFMETCollection& uncorMET,
172  const JetCorrector& corrector,
173  const JetCorrector& corrector2,
174  const PFJetCollection& uncorJet,
175  const PFCandidateCollection& uncorUnclustered,
176  double jetPTthreshold,
177  double jetEMfracLimit,
178  double UscaleA,
179  double UscaleB,
180  double UscaleC,
181  bool useTypeII,
182  vector<reco::PFMET>* corMET, edm::Event& iEvent, const edm::EventSetup& iSetup, const bool subtractL1Fast)
183  {
184  if (!corMET) {
185  std::cerr << "Type1METAlgo_run-> undefined output MET collection. Stop. " << std::endl;
186  return;
187  }
188 
189  const reco::PFMET* u = &(uncorMET.front());
190 
191  //Jet j = uncorJet->front(); std::cout << j.px() << std::endl;
192  double DeltaPx = 0.0;
193  double DeltaPy = 0.0;
194  double DeltaSumET = 0.0;
195 
196  double UDeltaP = 0.0;
197  double UDeltaPx = 0.0;
198  double UDeltaPy = 0.0;
199  double USumET = 0;
200  // ---------------- Calculate jet corrections, but only for those uncorrected jets
201  // ---------------- which are above the given threshold. This requires that the
202  // ---------------- uncorrected jets be matched with the corrected jets.
203  for( PFJetCollection::const_iterator jet = uncorJet.begin(); jet != uncorJet.end(); ++jet) {
204  int index = jet-uncorJet.begin();
205  edm::RefToBase<reco::Jet> jetRef(edm::Ref<PFJetCollection>(&uncorJet,index));
206  if( jet->pt()*corrector.correction (*jet,jetRef,iEvent,iSetup) > jetPTthreshold && jet->photonEnergyFraction() < jetEMfracLimit ) {
207 
208  if (!subtractL1Fast)
209  {
210  double corr = corrector.correction (*jet,jetRef,iEvent,iSetup) - 1.; // correction itself
211  DeltaPx += jet->px() * corr;
212  DeltaPy += jet->py() * corr;
213  DeltaSumET += jet->et() * corr;
214  }
215  else
216  {
217  double corr = corrector.correction (*jet,jetRef,iEvent,iSetup) - 1.; // correction itself
218  double corr2 = corrector2.correction (*jet,jetRef,iEvent,iSetup) - 1.;
219  DeltaPx += jet->px() * corr - (jet->px() * corr2);
220  DeltaPy += jet->py() * corr - (jet->py() * corr2);
221  DeltaSumET += jet->et() * corr - (jet->et() * corr2);
222  }
223  }
224 
225  if (jet->pt() * corrector.correction (*jet,jetRef,iEvent,iSetup) < jetPTthreshold && jet->photonEnergyFraction() < jetEMfracLimit) {
226  UDeltaPx -= jet->px();
227  UDeltaPy -= jet->py();
228  USumET += jet->et();
229  }
230 
231  }
232  //if typeII correction should be added, calculate U using collections of unclustered PFCandidates handed in by user
233  if (useTypeII) {
234  for (PFCandidateCollection::const_iterator cand =
235  uncorUnclustered.begin(); cand != uncorUnclustered.end(); ++cand) {
236 
237  UDeltaPx -= cand->px();
238  UDeltaPy -= cand->py();
239  USumET += cand->et();
240 
241  }
242  }
243 
244  //----------------- Calculate and set deltas for new MET correction
246  delta.mex = - DeltaPx; //correction to MET (from Jets) is negative,
247  delta.mey = - DeltaPy; //since MET points in direction opposite of jets
248  delta.sumet = DeltaSumET;
249 
250  //std::cout << "delta.mex = " << delta.mex << std::endl;
251 
252  UDeltaP = sqrt(UDeltaPx*UDeltaPx+UDeltaPy*UDeltaPy);
253 
254  double Uscale = UscaleA+UscaleB*exp(UscaleC*UDeltaP);
255  if (UDeltaP == 0){
256  Uscale = 1;
257  }
258 
259  if(useTypeII){
260  delta.mex += (Uscale-1.)*UDeltaPx;
261  delta.mey += (Uscale-1.)*UDeltaPy;
262  delta.sumet += (Uscale-1.)*USumET;
263  }
264 
265  double corrMetPx = u->px()+delta.mex;
266  double corrMetPy = u->py()+delta.mey;
267 
268 
269  MET::LorentzVector correctedMET4vector( corrMetPx, corrMetPy, 0.,
270  sqrt (corrMetPx*corrMetPx + corrMetPy*corrMetPy)
271  );
272  //----------------- get previous corrections and push into new corrections
273  std::vector<CorrMETData> corrections = u->mEtCorr();
274  corrections.push_back( delta );
275  //----------------- Push onto MET Collection
276 
277  reco::PFMET specificPFMET( u->getSpecific(), u->sumEt()+delta.sumet, correctedMET4vector, u->vertex() );
278  corMET->push_back(specificPFMET);
279 
280  }
281 
282 }
283 
284 //----------------------------------------------------------------------------
286 //----------------------------------------------------------------------------
287 
288 //----------------------------------------------------------------------------
290 
291 void Type1METAlgo::run(const CaloMETCollection& uncorMET,
292  const JetCorrector& corrector,
293  const JetCorrector& corrector2,
294  const CaloJetCollection& uncorJet,
295  double jetPTthreshold,
296  double jetEMfracLimit,
297  double UscaleA,
298  double UscaleB,
299  double UscaleC,
300  bool useTypeII,
301  bool hasMuonsCorr,
302  const edm::View<reco::Muon>& inputMuons,
303  const edm::ValueMap<reco::MuonMETCorrectionData>& vm_muCorrData,
304  CaloMETCollection* corMET, edm::Event& iEvent, const edm::EventSetup& iSetup, const bool subtractL1Fast)
305 {
306  return Type1METAlgo_run(uncorMET, corrector, corrector2, uncorJet, jetPTthreshold, jetEMfracLimit, UscaleA, UscaleB, UscaleC, useTypeII, hasMuonsCorr,inputMuons, vm_muCorrData, corMET, iEvent, iSetup, subtractL1Fast);
307 }
308 
309 void Type1METAlgo::run(const PFMETCollection& uncorMET,
310  const JetCorrector& corrector,
311  const JetCorrector& corrector2,
312  const PFJetCollection& uncorJet,
313  const PFCandidateCollection& uncorUnclustered,
314  double jetPTthreshold,
315  double jetEMfracLimit,
316  double UscaleA,
317  double UscaleB,
318  double UscaleC,
319  bool useTypeII,
320  PFMETCollection* corMET, edm::Event& iEvent, const edm::EventSetup& iSetup, const bool subtractL1Fast)
321 {
322  return Type1METAlgo_run(uncorMET, corrector, corrector2, uncorJet, uncorUnclustered, jetPTthreshold, jetEMfracLimit, UscaleA, UscaleB, UscaleC, useTypeII, corMET, iEvent, iSetup, subtractL1Fast);
323 }
324 
dbl * delta
Definition: mlp_gen.cc:36
long int flag
Definition: mlp_lapack.h:47
SpecificPFMETData getSpecific() const
Definition: PFMET.h:72
virtual const Point & vertex() const
vertex position
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
math::XYZTLorentzVector LorentzVector
RefToBase< value_type > refAt(size_type i) const
Collection of Calo MET.
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
SpecificCaloMETData getSpecific() const
Definition: CaloMET.h:79
int iEvent
Definition: GenABIO.cc:243
double sumEt() const
Definition: MET.h:48
Definition: MET.h:32
T sqrt(T t)
Definition: SSEVec.h:46
tuple result
Definition: query.py:137
const int mu
Definition: Constants.h:23
virtual ~Type1METAlgo()
double sumet
Definition: CorrMETData.h:20
JetCorrectorParameters corr
Definition: classes.h:9
std::vector< CorrMETData > mEtCorr() const
Definition: MET.h:63
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
virtual double px() const
x coordinate of momentum vector
size_type size() const
a MET correction term
Definition: CorrMETData.h:14
std::vector< PFJet > PFJetCollection
collection of PFJet objects
virtual void run(const reco::CaloMETCollection &, const JetCorrector &, const JetCorrector &, const reco::CaloJetCollection &, double, double, double, double, double, bool, bool, const edm::View< reco::Muon > &, const edm::ValueMap< reco::MuonMETCorrectionData > &, reco::CaloMETCollection *, edm::Event &iEvent, const edm::EventSetup &iSetup, const bool subtractL1Fast)
std::vector< reco::PFMET > PFMETCollection
collection of PFMET objects
double mey
Definition: CorrMETData.h:18
double mex
Definition: CorrMETData.h:17
long double T
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
virtual double py() const
y coordinate of momentum vector
math::PtEtaPhiELorentzVectorF LorentzVector
std::vector< CaloJet > CaloJetCollection
collection of CaloJet objects
Collection of PF MET.