CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
METSignificanceProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: METProducers
4 // Class: METSignificanceProducer
5 //
6 //
7 
8 //____________________________________________________________________________||
10 
11 //____________________________________________________________________________||
12 namespace cms {
13 
14  //____________________________________________________________________________||
16  std::vector<edm::InputTag> srcLeptonsTags = iConfig.getParameter<std::vector<edm::InputTag>>("srcLeptons");
17  for (std::vector<edm::InputTag>::const_iterator it = srcLeptonsTags.begin(); it != srcLeptonsTags.end(); it++) {
18  lepTokens_.push_back(consumes<edm::View<reco::Candidate>>(*it));
19  }
20 
21  pfjetsToken_ = consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("srcPfJets"));
22 
23  metToken_ = consumes<edm::View<reco::MET>>(iConfig.getParameter<edm::InputTag>("srcMet"));
24  pfCandidatesToken_ = consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("srcPFCandidates"));
25 
26  jetSFType_ = iConfig.getParameter<std::string>("srcJetSF");
27  jetResPtType_ = iConfig.getParameter<std::string>("srcJetResPt");
28  jetResPhiType_ = iConfig.getParameter<std::string>("srcJetResPhi");
30  jetResPtTypeToken_ = esConsumes(edm::ESInputTag("", jetResPtType_));
31  jetResPhiTypeToken_ = esConsumes(edm::ESInputTag("", jetResPhiType_));
32  rhoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("srcRho"));
33 
34  edm::InputTag srcWeights = iConfig.getParameter<edm::InputTag>("srcWeights");
35  if (!srcWeights.label().empty())
36  weightsToken_ = consumes<edm::ValueMap<float>>(srcWeights);
37 
38  metSigAlgo_ = new metsig::METSignificance(iConfig);
39 
40  produces<double>("METSignificance");
41  produces<math::Error<2>::type>("METCovariance");
42  }
43 
45 
46  //____________________________________________________________________________||
48  //
49  // met
50  //
52  event.getByToken(metToken_, metHandle);
53  const reco::MET& met = (*metHandle)[0];
54 
55  //
56  // candidates
57  //
59  event.getByToken(pfCandidatesToken_, pfCandidates);
60 
61  //
62  // leptons
63  //
64  std::vector<edm::Handle<reco::CandidateView>> leptons;
65  for (std::vector<edm::EDGetTokenT<edm::View<reco::Candidate>>>::const_iterator srcLeptons_i = lepTokens_.begin();
66  srcLeptons_i != lepTokens_.end();
67  ++srcLeptons_i) {
69  event.getByToken(*srcLeptons_i, leptons_i);
70  leptons.push_back(leptons_i);
71  }
72 
73  //
74  // jets
75  //
77  event.getByToken(pfjetsToken_, jets);
78 
80  event.getByToken(rhoToken_, rho);
81 
84  event.getByToken(weightsToken_, weights);
85 
89 
90  //
91  // compute the significance
92  //
93  double sumPtUnclustered = 0;
94  const edm::ValueMap<float>* weightsPtr = nullptr;
95  if (met.isWeighted()) {
97  throw cms::Exception("InvalidInput")
98  << "MET is weighted (e.g. PUPPI), but no weights given in METSignificanceProducer\n";
99  weightsPtr = &*weights;
100  }
102  leptons,
103  pfCandidates,
104  *rho,
105  resPtObj,
106  resPhiObj,
107  resSFObj,
108  event.isRealData(),
109  sumPtUnclustered,
110  weightsPtr);
111  double sig = metSigAlgo_->getSignificance(cov, met);
112 
113  auto significance = std::make_unique<double>();
114  (*significance) = sig;
115 
116  auto covPtr = std::make_unique<math::Error<2>::type>();
117  (*covPtr)(0, 0) = cov(0, 0);
118  (*covPtr)(1, 0) = cov(1, 0);
119  (*covPtr)(1, 1) = cov(1, 1);
120 
121  event.put(std::move(covPtr), "METCovariance");
122  event.put(std::move(significance), "METSignificance");
123  }
124 
125  //____________________________________________________________________________||
127 } // namespace cms
128 
129 //____________________________________________________________________________||
static const JetResolutionScaleFactor get(const edm::EventSetup &, const Token &)
int isWeighted() const
boolean if weights were applied by algorithm (e.g. PUPPI weights)
Definition: MET.h:79
reco::METCovMatrix getCovariance(const edm::View< reco::Jet > &jets, const std::vector< edm::Handle< reco::CandidateView > > &leptons, const edm::Handle< edm::View< reco::Candidate > > &pfCandidates, double rho, JME::JetResolution &resPtObj, JME::JetResolution &resPhiObj, JME::JetResolutionScaleFactor &resSFObj, bool isRealData, double &sumPtUnclustered, edm::ValueMap< float > const *weights=nullptr)
void produce(edm::Event &, const edm::EventSetup &) override
static double getSignificance(const reco::METCovMatrix &cov, const reco::MET &met)
JME::JetResolution::Token jetResPhiTypeToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:39
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandidatesToken_
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > lepTokens_
bool isRealData() const
Definition: EventBase.h:62
tuple METSignificance
____________________________________________________________________________||
edm::EDGetTokenT< double > rhoToken_
edm::EDGetTokenT< edm::ValueMap< float > > weightsToken_
Definition: MET.h:41
vector< PseudoJet > jets
def move
Definition: eostools.py:511
METSignificanceProducer(const edm::ParameterSet &)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::string const & label() const
Definition: InputTag.h:36
metsig::METSignificance * metSigAlgo_
edm::EDGetTokenT< edm::View< reco::Jet > > pfjetsToken_
JME::JetResolutionScaleFactor::Token jetSFTypeToken_
edm::EDGetTokenT< edm::View< reco::MET > > metToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
static const JetResolution get(const edm::EventSetup &, const Token &)
JME::JetResolution::Token jetResPtTypeToken_