1 #ifndef UserCode_ICHiggsTauTau_ICMetProducer_h
2 #define UserCode_ICHiggsTauTau_ICMetProducer_h
7 #include "Math/Vector4D.h"
8 #include "Math/Vector4Dfwd.h"
9 #include "boost/functional/hash.hpp"
10 #include "FWCore/Framework/interface/EDProducer.h"
11 #include "FWCore/ParameterSet/interface/ParameterSet.h"
12 #include "FWCore/Framework/interface/Event.h"
13 #include "FWCore/Framework/interface/EventSetup.h"
14 #include "FWCore/Utilities/interface/InputTag.h"
15 #include "DataFormats/METReco/interface/MET.h"
16 #include "DataFormats/PatCandidates/interface/MET.h"
21 #include "FWCore/Utilities/interface/Exception.h"
33 virtual void beginJob();
34 virtual void produce(edm::Event&,
const edm::EventSetup&);
35 virtual void endJob();
36 void constructSpecific(edm::Handle<edm::View<T> >
const& mets_handle,
37 edm::Event& event,
const edm::EventSetup& setup);
38 std::vector<ic::Met>* met_;
41 boost::hash<T const*> met_hasher_;
43 edm::InputTag inputID_;
44 bool store_id_from_user_cand_;
48 edm::InputTag metsigcov00;
49 edm::InputTag metsigcov01;
50 edm::InputTag metsigcov10;
51 edm::InputTag metsigcov11;
55 struct SigTagsMethod2 {
57 edm::InputTag metsigcov;
63 bool do_external_metsig_;
64 bool do_external_metsig_method2_;
66 SigTagsMethod2 metsig_method2_;
68 bool do_metcorrections_;
69 std::vector<std::string> metcorrections_;
70 bool do_metuncertainties_;
71 std::vector<std::string> metuncertainties_;
76 : metsig(pset.getParameter<
edm::InputTag>(
"metsig")),
77 metsigcov00(pset.getParameter<
edm::InputTag>(
"metsigcov00")),
78 metsigcov01(pset.getParameter<
edm::InputTag>(
"metsigcov01")),
79 metsigcov10(pset.getParameter<
edm::InputTag>(
"metsigcov10")),
80 metsigcov11(pset.getParameter<
edm::InputTag>(
"metsigcov11")) {
81 collector.consumes<
double>(metsig);
82 collector.consumes<
double>(metsigcov00);
83 collector.consumes<
double>(metsigcov01);
84 collector.consumes<
double>(metsigcov10);
85 collector.consumes<
double>(metsigcov11);
90 : metsig(pset.getParameter<
edm::InputTag>(
"metsig")),
91 metsigcov(pset.getParameter<
edm::InputTag>(
"metsigcov")) {
92 collector.consumes<
double>(metsig);
93 collector.consumes<math::Error<2>::type>(metsigcov);
98 : input_(config.getParameter<
edm::InputTag>(
"input")),
99 branch_(config.getParameter<
std::string>(
"branch")),
100 do_custom_id_(config.getParameter<bool>(
"includeCustomID")),
101 inputID_(config.getParameter<
edm::InputTag>(
"inputCustomID")),
102 do_gen_met_(config.getParameter<bool>(
"doGenMet")),
103 do_external_metsig_(config.getParameter<bool>(
"includeExternalMetsig")),
104 do_external_metsig_method2_(config.getParameter<bool>(
"includeExternalMetsigMethod2")),
109 consumes<edm::View<T>>(input_);
110 consumes<std::vector<std::size_t>>(inputID_);
111 met_ =
new std::vector<ic::Met>();
118 : input_(config.getParameter<
edm::InputTag>(
"input")),
119 branch_(config.getParameter<
std::string>(
"branch")),
120 do_custom_id_(config.getParameter<bool>(
"includeCustomID")),
121 inputID_(config.getParameter<
edm::InputTag>(
"inputCustomID")),
122 store_id_from_user_cand_(config.getParameter<bool>(
"includeUserCandID")),
123 do_gen_met_(config.getParameter<bool>(
"doGenMet")),
124 do_external_metsig_(config.getParameter<bool>(
"includeExternalMetsig")),
125 do_external_metsig_method2_(config.getParameter<bool>(
"includeExternalMetsigMethod2")),
128 do_metcorrections_(config.getParameter<bool>(
"includeMetCorrections")),
129 metcorrections_(config.getParameter<
std::vector<
std::string> >(
"metcorrections")),
130 do_metuncertainties_(config.getParameter<bool>(
"includeMetUncertainties")),
131 metuncertainties_(config.getParameter<
std::vector<
std::string> >(
"metuncertainties")) {
132 consumes<edm::View<pat::MET>>(input_);
133 consumes<std::vector<std::size_t>>(inputID_);
135 met_ =
new std::vector<ic::Met>();
138 PrintOptional(1, do_metuncertainties_,
"includeMetUncertainties");
139 PrintOptional(1, do_metcorrections_,
"includeMetCorrections");
150 edm::Handle<edm::View<T> > mets_handle;
151 event.getByLabel(input_, mets_handle);
152 edm::Handle<std::vector<std::size_t> > id_handle;
154 event.getByLabel(inputID_, id_handle);
159 met_->resize(mets_handle->size(),
ic::Met());
162 for (
unsigned i = 0; i < mets_handle->size(); ++i) {
163 T
const& src = mets_handle->at(i);
166 dest.
set_id(id_handle->at(i));
168 dest.
set_id(met_hasher_(&src));
172 if(!do_external_metsig_&&!do_external_metsig_method2_){
174 dest.
set_xx_sig(src.getSignificanceMatrix()(0, 0));
175 dest.
set_xy_sig(src.getSignificanceMatrix()(0, 1));
176 dest.
set_yx_sig(src.getSignificanceMatrix()(1, 0));
177 dest.
set_yy_sig(src.getSignificanceMatrix()(1, 1));
180 if(!do_external_metsig_method2_){
181 edm::Handle<double> metsig;
182 edm::Handle<double> metsigcov00;
183 edm::Handle<double> metsigcov01;
184 edm::Handle<double> metsigcov10;
185 edm::Handle<double> metsigcov11;
186 event.getByLabel(metsig_.metsig, metsig);
187 event.getByLabel(metsig_.metsigcov00, metsigcov00);
188 event.getByLabel(metsig_.metsigcov01, metsigcov01);
189 event.getByLabel(metsig_.metsigcov10, metsigcov10);
190 event.getByLabel(metsig_.metsigcov11, metsigcov11);
197 edm::Handle<double> metsig;
198 edm::Handle<math::Error<2>::type> metsigcov;
199 event.getByLabel(metsig_method2_.metsig, metsig);
200 event.getByLabel(metsig_method2_.metsigcov, metsigcov);
210 constructSpecific(mets_handle, event, setup);
216 edm::Handle<edm::View<T> >
const& mets_handle, edm::Event& event,
217 const edm::EventSetup& setup) {}
221 edm::Handle<edm::View<reco::MET> >
const& mets_handle, edm::Event& event,
222 const edm::EventSetup& setup) {
223 for (
unsigned i = 0; i < mets_handle->size(); ++i) {
224 reco::MET
const& src = mets_handle->at(i);
236 edm::Handle<edm::View<pat::MET> >
const& mets_handle, edm::Event& event,
237 const edm::EventSetup& setup) {
238 for (
unsigned i = 0; i < mets_handle->size(); ++i) {
239 pat::MET
const& src = mets_handle->at(i);
241 if(store_id_from_user_cand_){
243 std::vector<std::string> candidate_names = src.userCandNames();
244 for(
unsigned j = 0; j < candidate_names.size(); ++j){
245 reco::CandidatePtr cand_ref = src.userCand(candidate_names.at(j));
246 boost::hash_combine(
id, cand_ref.get());
253 dest.
set_pt(src.genMET()->pt());
254 dest.
set_eta(src.genMET()->eta());
255 dest.
set_phi(src.genMET()->phi());
268 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION ==7 && CMSSW_MINOR_VERSION >=4)
270 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_REVISION >= 12)
271 if (do_metcorrections_) {
272 if (metcorrections_.size() != pat::MET::METCorrectionLevel::METCorrectionLevelSize){
273 throw cms::Exception(
"MetCorrectionNotRecognised")<<__FILE__ <<
" line " << __LINE__ <<
": size of expected met correction object is " << metcorrections_.size() <<
" but pat::MET::METCorrectionLevel enum contains " << pat::MET::METCorrectionLevel::METCorrectionLevelSize <<
" elements. Code needs updating.\n";
276 for (
unsigned j = 0; j < static_cast<unsigned>(pat::MET::METCorrectionLevel::METCorrectionLevelSize) ; ++j) {
278 tmp.
px = src.corPx(static_cast<pat::MET::METCorrectionLevel>(j));
279 tmp.
py = src.corPy(static_cast<pat::MET::METCorrectionLevel>(j));
280 tmp.
sumet = src.corSumEt(static_cast<pat::MET::METCorrectionLevel>(j));
286 if(do_metuncertainties_){
287 if (metuncertainties_.size() != pat::MET::METUncertainty::METUncertaintySize){
288 throw cms::Exception(
"MetCorrectionNotRecognised")<<__FILE__ <<
" line " << __LINE__ <<
": size of expected met uncertainties object is " << metuncertainties_.size() <<
" but pat::MET::METUncertainty enum contains " << pat::MET::METUncertainty::METUncertaintySize <<
" elements. Code needs updating.\n";
291 for(
unsigned iunc=0;iunc<static_cast<unsigned>(pat::MET::METUncertainty::METUncertaintySize);iunc++){
293 tmp.
px = src.shiftedPx(static_cast<pat::MET::METUncertainty>(iunc));
294 tmp.
py = src.shiftedPy(static_cast<pat::MET::METUncertainty>(iunc));
295 tmp.
sumet = src.shiftedSumEt(static_cast<pat::MET::METUncertainty>(iunc));
Stores a missing transverse energy object and the corresponding significance and corrections.
void set_xx_sig(double const &xx_sig)
The component of the significance matrix.
void set_yy_sig(double const &yy_sig)
The component of the significance matrix.
void set_et_sig(double const &et_sig)
Signifiance of the missing transverse energy.
void set_phi(double const &phi)
Direct access to .
void set_id(std::size_t const &id)
Unique identifier.
void SetCorrectedMet(std::string const &name, ic::Met::BasicMet const &value)
Store a corrected met, overwriting any existing value with label name
void set_energy(double const &energy)
Direct access to the energy.
void set_yx_sig(double const &yx_sig)
The component of the significance matrix.
void SetShiftedMet(std::string const &name, ic::Met::BasicMet const &value)
Store a shifted met, overwriting any existing value with label name
ICMetProducer(const edm::ParameterSet &)
edm::ConsumesCollector consumesCollector()
void set_pt(double const &pt)
Direct access to the .
void set_eta(double const &eta)
Direct access to .
void set_sum_et(double const &sum_et)
Scalar sum of transverse energies for all input objects.
void set_xy_sig(double const &xy_sig)
The component of the significance matrix.