CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATMETProducer.cc
Go to the documentation of this file.
1 //
2 // $Id: PATMETProducer.cc,v 1.14 2009/06/25 23:49:35 gpetrucc Exp $
3 //
4 
9 
12 
13 #include <memory>
14 
15 
16 using namespace pat;
17 
18 
20  useUserData_(iConfig.exists("userData"))
21 {
22  // initialize the configurables
23  metSrc_ = iConfig.getParameter<edm::InputTag>("metSource");
24  addGenMET_ = iConfig.getParameter<bool> ("addGenMET");
25  genMETSrc_ = iConfig.getParameter<edm::InputTag>("genMETSource");
26  addResolutions_ = iConfig.getParameter<bool> ("addResolutions");
27 
28  // Efficiency configurables
29  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
30  if (addEfficiencies_) {
32  }
33 
34  // Resolution configurables
35  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
36  if (addResolutions_) {
38  }
39 
40  // Check to see if the user wants to add user data
41  if ( useUserData_ ) {
43  }
44 
45 
46  // produces vector of mets
47  produces<std::vector<MET> >();
48 }
49 
50 
52 }
53 
54 
56 
57  // Get the vector of MET's from the event
59  iEvent.getByLabel(metSrc_, mets);
60 
61  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";
63  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
64 
65  // Get the vector of generated met from the event if needed
67  if (addGenMET_) {
68  iEvent.getByLabel(genMETSrc_, genMETs);
69  }
70 
71  // loop over mets
72  std::vector<MET> * patMETs = new std::vector<MET>();
73  for (edm::View<reco::MET>::const_iterator itMET = mets->begin(); itMET != mets->end(); itMET++) {
74  // construct the MET from the ref -> save ref to original object
75  unsigned int idx = itMET - mets->begin();
76  edm::RefToBase<reco::MET> metsRef = mets->refAt(idx);
77  edm::Ptr<reco::MET> metsPtr = mets->ptrAt(idx);
78  MET amet(metsRef);
79  // add the generated MET
80  if (addGenMET_) amet.setGenMET((*genMETs)[idx]);
81 
82  if (efficiencyLoader_.enabled()) {
83  efficiencyLoader_.setEfficiencies( amet, metsRef );
84  }
85 
86  if (resolutionLoader_.enabled()) {
88  }
89 
90 
91  if ( useUserData_ ) {
92  userDataHelper_.add( amet, iEvent, iSetup );
93  }
94 
95 
96  // correct for muons if demanded... never more: it's now done by JetMETCorrections
97  // add the MET to the vector of METs
98  patMETs->push_back(amet);
99  }
100 
101  // sort MET in ET .. don't mess with this
102  // std::sort(patMETs->begin(), patMETs->end(), eTComparator_);
103 
104  // put genEvt object in Event
105  std::auto_ptr<std::vector<MET> > myMETs(patMETs);
106  iEvent.put(myMETs);
107 
108 }
109 
110 // ParameterSet description for module
112 {
114  iDesc.setComment("PAT MET producer module");
115 
116  // input source
117  iDesc.add<edm::InputTag>("metSource", edm::InputTag("no default"))->setComment("input collection");
118 
119  // MC configurations
120  iDesc.add<bool>("addGenMET", false);
121  iDesc.add<edm::InputTag>("genMETSource", edm::InputTag("genMetCalo"));
122 
124 
125  // Efficiency configurables
126  edm::ParameterSetDescription efficienciesPSet;
127  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
128  iDesc.add("efficiencies", efficienciesPSet);
129  iDesc.add<bool>("addEfficiencies", false);
130 
131  // Check to see if the user wants to add user data
132  edm::ParameterSetDescription userDataPSet;
134  iDesc.addOptional("userData", userDataPSet);
135 
136  // muon correction
137  iDesc.add<bool>("addMuonCorrections", false);
138  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("muons"));
139 
140 }
141 
143 
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
Analysis-level MET class.
Definition: MET.h:42
T getParameter(std::string const &) const
Assists in assimilating all pat::UserData into pat objects.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Produces the pat::MET.
void setAllowAnything()
allow any parameter label/value pairs
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
pat::PATUserDataHelper< pat::MET > userDataHelper_
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
edm::InputTag metSrc_
std::string encode() const
Definition: InputTag.cc:72
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
static void fillDescription(edm::ParameterSetDescription &iDesc)
void setComment(std::string const &value)
edm::InputTag genMETSrc_
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
pat::helper::EfficiencyLoader efficiencyLoader_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
pat::helper::KinResolutionsLoader resolutionLoader_
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
void setGenMET(const reco::GenMET &gm)
set the associated GenMET
Definition: MET.cc:53
void newEvent(const edm::Event &event, const edm::EventSetup &setup) const
To be called for each new event, reads in the EventSetup object.
PATMETProducer(const edm::ParameterSet &iConfig)
void newEvent(const edm::Event &event) const
To be called for each new event, reads in the ValueMaps for efficiencies.
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)