Go to the documentation of this file.00001
00002
00003
00004
00005 #include "PhysicsTools/PatAlgos/plugins/PATMETProducer.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/ParameterSet/interface/FileInPath.h"
00008 #include "DataFormats/Common/interface/View.h"
00009
00010 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00012
00013 #include <memory>
00014
00015
00016 using namespace pat;
00017
00018
00019 PATMETProducer::PATMETProducer(const edm::ParameterSet & iConfig):
00020 useUserData_(iConfig.exists("userData"))
00021 {
00022
00023 metSrc_ = iConfig.getParameter<edm::InputTag>("metSource");
00024 addGenMET_ = iConfig.getParameter<bool> ("addGenMET");
00025 genMETSrc_ = iConfig.getParameter<edm::InputTag>("genMETSource");
00026 addResolutions_ = iConfig.getParameter<bool> ("addResolutions");
00027
00028
00029 addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
00030 if (addEfficiencies_) {
00031 efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"));
00032 }
00033
00034
00035 addResolutions_ = iConfig.getParameter<bool>("addResolutions");
00036 if (addResolutions_) {
00037 resolutionLoader_ = pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"));
00038 }
00039
00040
00041 if ( useUserData_ ) {
00042 userDataHelper_ = PATUserDataHelper<MET>(iConfig.getParameter<edm::ParameterSet>("userData"));
00043 }
00044
00045
00046
00047 produces<std::vector<MET> >();
00048 }
00049
00050
00051 PATMETProducer::~PATMETProducer() {
00052 }
00053
00054
00055 void PATMETProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
00056
00057
00058 edm::Handle<edm::View<reco::MET> > mets;
00059 iEvent.getByLabel(metSrc_, mets);
00060
00061 if (mets->size() != 1) throw cms::Exception("Corrupt Data") << "The input MET collection " << metSrc_.encode() << " has size " << mets->size() << " instead of 1 as it should.\n";
00062 if (efficiencyLoader_.enabled()) efficiencyLoader_.newEvent(iEvent);
00063 if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
00064
00065
00066 edm::Handle<edm::View<reco::GenMET> > genMETs;
00067 if (addGenMET_) {
00068 iEvent.getByLabel(genMETSrc_, genMETs);
00069 }
00070
00071
00072 std::vector<MET> * patMETs = new std::vector<MET>();
00073 for (edm::View<reco::MET>::const_iterator itMET = mets->begin(); itMET != mets->end(); itMET++) {
00074
00075 unsigned int idx = itMET - mets->begin();
00076 edm::RefToBase<reco::MET> metsRef = mets->refAt(idx);
00077 edm::Ptr<reco::MET> metsPtr = mets->ptrAt(idx);
00078 MET amet(metsRef);
00079
00080 if (addGenMET_) amet.setGenMET((*genMETs)[idx]);
00081
00082 if (efficiencyLoader_.enabled()) {
00083 efficiencyLoader_.setEfficiencies( amet, metsRef );
00084 }
00085
00086 if (resolutionLoader_.enabled()) {
00087 resolutionLoader_.setResolutions(amet);
00088 }
00089
00090
00091 if ( useUserData_ ) {
00092 userDataHelper_.add( amet, iEvent, iSetup );
00093 }
00094
00095
00096
00097
00098 patMETs->push_back(amet);
00099 }
00100
00101
00102
00103
00104
00105 std::auto_ptr<std::vector<MET> > myMETs(patMETs);
00106 iEvent.put(myMETs);
00107
00108 }
00109
00110
00111 void PATMETProducer::fillDescriptions(edm::ConfigurationDescriptions & descriptions)
00112 {
00113 edm::ParameterSetDescription iDesc;
00114 iDesc.setComment("PAT MET producer module");
00115
00116
00117 iDesc.add<edm::InputTag>("metSource", edm::InputTag("no default"))->setComment("input collection");
00118
00119
00120 iDesc.add<bool>("addGenMET", false);
00121 iDesc.add<edm::InputTag>("genMETSource", edm::InputTag("genMetCalo"));
00122
00123 pat::helper::KinResolutionsLoader::fillDescription(iDesc);
00124
00125
00126 edm::ParameterSetDescription efficienciesPSet;
00127 efficienciesPSet.setAllowAnything();
00128 iDesc.add("efficiencies", efficienciesPSet);
00129 iDesc.add<bool>("addEfficiencies", false);
00130
00131
00132 edm::ParameterSetDescription userDataPSet;
00133 PATUserDataHelper<MET>::fillDescription(userDataPSet);
00134 iDesc.addOptional("userData", userDataPSet);
00135
00136
00137 iDesc.add<bool>("addMuonCorrections", false);
00138 iDesc.add<edm::InputTag>("muonSource", edm::InputTag("muons"));
00139
00140 }
00141
00142 #include "FWCore/Framework/interface/MakerMacros.h"
00143
00144 DEFINE_FWK_MODULE(PATMETProducer);