ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/DGele/PhysicsTools/PatAlgos/plugins/PATMETProducer.cc
Revision: 1.1.1.1 (vendor branch)
Committed: Tue Oct 20 17:15:14 2009 UTC (15 years, 6 months ago) by dgele
Content type: text/plain
Branch: ANA
CVS Tags: start
Changes since 1.1: +0 -0 lines
Log Message:
version CMSSW_2_2_10

File Contents

# User Rev Content
1 dgele 1.1 //
2     // $Id: PATMETProducer.cc,v 1.7.4.3 2009/04/30 09:11:46 gpetrucc Exp $
3     //
4    
5     #include "PhysicsTools/PatAlgos/plugins/PATMETProducer.h"
6     #include "FWCore/MessageLogger/interface/MessageLogger.h"
7     #include "FWCore/ParameterSet/interface/FileInPath.h"
8     #include "DataFormats/Common/interface/View.h"
9    
10     #include <memory>
11    
12    
13     using namespace pat;
14    
15    
16     PATMETProducer::PATMETProducer(const edm::ParameterSet & iConfig):
17     userDataHelper_ ( iConfig.getParameter<edm::ParameterSet>("userData") )
18     {
19     // initialize the configurables
20     metSrc_ = iConfig.getParameter<edm::InputTag>("metSource");
21     addGenMET_ = iConfig.getParameter<bool> ("addGenMET");
22     genMETSrc_ = iConfig.getParameter<edm::InputTag>("genMETSource");
23     addTrigMatch_ = iConfig.getParameter<bool> ( "addTrigMatch" );
24     trigMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "trigPrimMatch" );
25    
26     // Efficiency configurables
27     addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
28     if (addEfficiencies_) {
29     efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"));
30     }
31    
32     // Resolution configurables
33     addResolutions_ = iConfig.getParameter<bool>("addResolutions");
34     if (addResolutions_) {
35     resolutionLoader_ = pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"));
36     }
37    
38     // Check to see if the user wants to add user data
39     useUserData_ = false;
40     if ( iConfig.exists("userData") ) {
41     useUserData_ = true;
42     }
43    
44    
45     // produces vector of mets
46     produces<std::vector<MET> >();
47     }
48    
49    
50     PATMETProducer::~PATMETProducer() {
51     }
52    
53    
54     void PATMETProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
55    
56     // Get the vector of MET's from the event
57     edm::Handle<edm::View<METType> > mets;
58     iEvent.getByLabel(metSrc_, mets);
59    
60     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";
61     if (efficiencyLoader_.enabled()) efficiencyLoader_.newEvent(iEvent);
62     if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
63    
64     // Get the vector of generated met from the event if needed
65     edm::Handle<edm::View<reco::GenMET> > genMETs;
66     if (addGenMET_) {
67     iEvent.getByLabel(genMETSrc_, genMETs);
68     }
69    
70     // loop over mets
71     std::vector<MET> * patMETs = new std::vector<MET>();
72     for (edm::View<METType>::const_iterator itMET = mets->begin(); itMET != mets->end(); itMET++) {
73     // construct the MET from the ref -> save ref to original object
74     unsigned int idx = itMET - mets->begin();
75     edm::RefToBase<METType> metsRef = mets->refAt(idx);
76     edm::Ptr<METType> metsPtr = mets->ptrAt(idx);
77     MET amet(metsRef);
78     // add the generated MET
79     if (addGenMET_) amet.setGenMET((*genMETs)[idx]);
80     // matches to trigger primitives
81     if ( addTrigMatch_ ) {
82     for ( size_t i = 0; i < trigMatchSrc_.size(); ++i ) {
83     edm::Handle<edm::Association<TriggerPrimitiveCollection> > trigMatch;
84     iEvent.getByLabel(trigMatchSrc_[i], trigMatch);
85     TriggerPrimitiveRef trigPrim = (*trigMatch)[metsRef];
86     if ( trigPrim.isNonnull() && trigPrim.isAvailable() ) {
87     amet.addTriggerMatch(*trigPrim);
88     }
89     }
90     }
91    
92     if (efficiencyLoader_.enabled()) {
93     efficiencyLoader_.setEfficiencies( amet, metsRef );
94     }
95    
96     if (resolutionLoader_.enabled()) {
97     resolutionLoader_.setResolutions(amet);
98     }
99    
100    
101     if ( useUserData_ ) {
102     userDataHelper_.add( amet, iEvent, iSetup );
103     }
104    
105    
106     // correct for muons if demanded... never more: it's now done by JetMETCorrections
107     // add the MET to the vector of METs
108     patMETs->push_back(amet);
109     }
110    
111     // sort MET in ET .. don't mess with this
112     // std::sort(patMETs->begin(), patMETs->end(), eTComparator_);
113    
114     // put genEvt object in Event
115     std::auto_ptr<std::vector<MET> > myMETs(patMETs);
116     iEvent.put(myMETs);
117    
118     }
119    
120     #include "FWCore/Framework/interface/MakerMacros.h"
121    
122     DEFINE_FWK_MODULE(PATMETProducer);