File indexing completed on 2024-04-06 12:01:07
0001 #include "CommonTools/ParticleFlow/interface/PFMETAlgo.h"
0002
0003 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0004
0005 #include "DataFormats/METReco/interface/MET.h"
0006 #include "DataFormats/METReco/interface/METFwd.h"
0007 #include "DataFormats/Math/interface/LorentzVector.h"
0008
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010
0011 using namespace std;
0012 using namespace edm;
0013 using namespace reco;
0014 using namespace math;
0015 using namespace pf2pat;
0016
0017 PFMETAlgo::PFMETAlgo(const edm::ParameterSet& iConfig) {
0018 verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
0019
0020 hfCalibFactor_ = iConfig.getParameter<double>("hfCalibFactor");
0021 }
0022
0023 reco::MET PFMETAlgo::produce(const reco::PFCandidateCollection& pfCandidates) const {
0024 double sumEx = 0;
0025 double sumEy = 0;
0026 double sumEt = 0;
0027
0028 for (unsigned i = 0; i < pfCandidates.size(); i++) {
0029 const reco::PFCandidate& cand = pfCandidates[i];
0030
0031 double E = cand.energy();
0032
0033
0034 if (cand.particleId() == PFCandidate::h_HF || cand.particleId() == PFCandidate::egamma_HF)
0035 E *= hfCalibFactor_;
0036
0037 double phi = cand.phi();
0038 double cosphi = cos(phi);
0039 double sinphi = sin(phi);
0040
0041 double theta = cand.theta();
0042 double sintheta = sin(theta);
0043
0044 double et = E * sintheta;
0045 double ex = et * cosphi;
0046 double ey = et * sinphi;
0047
0048 sumEx += ex;
0049 sumEy += ey;
0050 sumEt += et;
0051 }
0052
0053 double Et = sqrt(sumEx * sumEx + sumEy * sumEy);
0054 XYZTLorentzVector missingEt(-sumEx, -sumEy, 0, Et);
0055
0056 if (verbose_) {
0057 cout << "PFMETAlgo: mEx, mEy, mEt = " << missingEt.X() << ", " << missingEt.Y() << ", " << missingEt.T() << endl;
0058 }
0059
0060 XYZPoint vertex;
0061 return MET(sumEt, missingEt, vertex);
0062 }