forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CorrectedPATMETProducer.cc
81 lines (58 loc) · 2.67 KB
/
CorrectedPATMETProducer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// -*- C++ -*-
//____________________________________________________________________________||
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/Candidate/interface/Candidate.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/PatCandidates/interface/MET.h"
#include "DataFormats/METReco/interface/MET.h"
#include "DataFormats/METReco/interface/CorrMETData.h"
#include "JetMETCorrections/Type1MET/interface/AddCorrectionsToGenericMET.h"
#include "RecoMET/METAlgorithms/interface/METSignificance.h"
#include <vector>
//____________________________________________________________________________||
class CorrectedPATMETProducer : public edm::stream::EDProducer<>
{
public:
explicit CorrectedPATMETProducer(const edm::ParameterSet& cfg)
: corrector(),
token_(consumes<METCollection>(cfg.getParameter<edm::InputTag>("src")))
{
std::vector<edm::InputTag> corrInputTags = cfg.getParameter<std::vector<edm::InputTag> >("srcCorrections");
std::vector<edm::EDGetTokenT<CorrMETData> > corrTokens;
for (std::vector<edm::InputTag>::const_iterator inputTag = corrInputTags.begin(); inputTag != corrInputTags.end(); ++inputTag) {
corrTokens.push_back(consumes<CorrMETData>(*inputTag));
}
corrector.setCorTokens(corrTokens);
produces<METCollection>("");
}
~CorrectedPATMETProducer() { }
private:
AddCorrectionsToGenericMET corrector;
typedef std::vector<pat::MET> METCollection;
edm::EDGetTokenT<METCollection> token_;
void produce(edm::Event& evt, const edm::EventSetup& es) override
{
edm::Handle<METCollection> srcMETCollection;
evt.getByToken(token_, srcMETCollection);
const pat::MET& srcMET = (*srcMETCollection)[0];
//dispatching to be sure we retrieve all the informations
reco::MET corrMET = corrector.getCorrectedMET(srcMET, evt, es);
pat::MET outMET(corrMET, srcMET);
auto product = std::make_unique<METCollection>();
reco::METCovMatrix cov=srcMET.getSignificanceMatrix();
if( !(cov(0,0)==0 && cov(0,1)==0 && cov(1,0)==0 && cov(1,1)==0) ) {
outMET.setSignificanceMatrix(cov);
double metSig=metsig::METSignificance::getSignificance(cov, outMET);
outMET.setMETSignificance(metSig);
}
product->push_back(outMET);
evt.put(std::move(product));
}
};
//____________________________________________________________________________||
DEFINE_FWK_MODULE(CorrectedPATMETProducer);