CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/PhysicsTools/PatAlgos/plugins/PATCompositeCandidateProducer.cc

Go to the documentation of this file.
00001 //
00002 // $Id: PATCompositeCandidateProducer.cc,v 1.3 2009/06/25 23:49:35 gpetrucc Exp $
00003 //
00004 
00005 #include "PhysicsTools/PatAlgos/plugins/PATCompositeCandidateProducer.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "DataFormats/Common/interface/View.h"
00008 #include "PhysicsTools/CandUtils/interface/AddFourMomenta.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "CommonTools/Utils/interface/StringObjectFunction.h"
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 #include <memory>
00013 
00014 
00015 #include <iostream>
00016 
00017 using namespace pat;
00018 using namespace std;
00019 using namespace edm;
00020 
00021 PATCompositeCandidateProducer::PATCompositeCandidateProducer(const ParameterSet & iConfig) :
00022   userDataHelper_( iConfig.getParameter<edm::ParameterSet>("userData") )
00023 {
00024   // initialize the configurables
00025   src_ = iConfig.getParameter<InputTag>( "src" );
00026 
00027   useUserData_ = false;
00028   if ( iConfig.exists("userData") ) {
00029     useUserData_ = true;
00030   }
00031 
00032   // Efficiency configurables
00033   addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
00034   if (addEfficiencies_) {
00035      efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"));
00036   }
00037 
00038   // Resolution configurables
00039   addResolutions_ = iConfig.getParameter<bool>("addResolutions");
00040   if (addResolutions_) {
00041      resolutionLoader_ = pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"));
00042   }
00043 
00044 
00045   // produces vector of particles
00046   produces<vector<pat::CompositeCandidate> >();
00047 
00048 }
00049 
00050 PATCompositeCandidateProducer::~PATCompositeCandidateProducer() {
00051 }
00052 
00053 void PATCompositeCandidateProducer::produce(Event & iEvent, const EventSetup & iSetup) {
00054   // Get the vector of CompositeCandidate's from the event
00055   Handle<View<reco::CompositeCandidate> > cands;
00056   iEvent.getByLabel(src_, cands);
00057 
00058   if (efficiencyLoader_.enabled()) efficiencyLoader_.newEvent(iEvent);
00059   if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
00060 
00061   auto_ptr<vector<pat::CompositeCandidate> > myCompositeCandidates ( new vector<pat::CompositeCandidate>() );
00062 
00063   if ( cands.isValid() ) {
00064 
00065     View<reco::CompositeCandidate>::const_iterator ibegin = cands->begin(),
00066       iend = cands->end(), i = ibegin;
00067     for ( ; i != iend; ++i ) {
00068 
00069       pat::CompositeCandidate cand(*i);
00070       
00071       if ( useUserData_ ) {
00072         userDataHelper_.add( cand, iEvent, iSetup );
00073       }
00074 
00075       if (efficiencyLoader_.enabled()) efficiencyLoader_.setEfficiencies( cand, cands->refAt(i - cands->begin()) );
00076       if (resolutionLoader_.enabled()) resolutionLoader_.setResolutions(cand);
00077 
00078       myCompositeCandidates->push_back( cand );
00079     }
00080 
00081   }// end if the two handles are valid
00082 
00083   iEvent.put(myCompositeCandidates);
00084 
00085 }
00086 
00087 #include "FWCore/Framework/interface/MakerMacros.h"
00088 
00089 DEFINE_FWK_MODULE(PATCompositeCandidateProducer);