CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/PhysicsTools/PatAlgos/plugins/VertexAssociationProducer.cc

Go to the documentation of this file.
00001 
00016 #include "FWCore/Framework/interface/EDProducer.h"
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "FWCore/Utilities/interface/InputTag.h"
00020 
00021 #include "DataFormats/Common/interface/ValueMap.h"
00022 #include "DataFormats/Common/interface/View.h"
00023 #include "DataFormats/PatCandidates/interface/Vertexing.h"
00024 #include "PhysicsTools/PatAlgos/interface/VertexingHelper.h"
00025 
00026 
00027 namespace pat {
00028 
00029   class PATVertexAssociationProducer : public edm::EDProducer {
00030 
00031     typedef edm::ValueMap<pat::VertexAssociation> VertexAssociationMap;
00032 
00033     public:
00034 
00035       explicit PATVertexAssociationProducer(const edm::ParameterSet & iConfig);
00036       ~PATVertexAssociationProducer();
00037 
00038       virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
00039 
00040     private:
00041       typedef std::vector<edm::InputTag> VInputTag;
00042       // configurables
00043       std::vector<edm::InputTag>   particles_;
00044       pat::helper::VertexingHelper vertexing_;
00045   
00046   };
00047 
00048 }
00049 
00050 using pat::PATVertexAssociationProducer;
00051 
00052 PATVertexAssociationProducer::PATVertexAssociationProducer(const edm::ParameterSet& iConfig) :
00053   particles_( iConfig.existsAs<VInputTag>("candidates") ?       // if it's a VInputTag
00054                 iConfig.getParameter<VInputTag>("candidates") :
00055                 VInputTag(1, iConfig.getParameter<edm::InputTag>("candidates")) ),
00056   vertexing_(iConfig) 
00057 {
00058     produces<VertexAssociationMap>();
00059 }
00060 
00061 
00062 PATVertexAssociationProducer::~PATVertexAssociationProducer() {
00063 }
00064 
00065 
00066 void PATVertexAssociationProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
00067   using namespace edm; using namespace std; 
00068   // read in vertices and EventSetup
00069   vertexing_.newEvent(iEvent, iSetup);
00070 
00071   // prepare room and tools for output
00072   auto_ptr<VertexAssociationMap> result(new VertexAssociationMap());
00073   VertexAssociationMap::Filler filler(*result);
00074   vector<pat::VertexAssociation> assos;
00075  
00076   // loop on input tags  
00077   for (VInputTag::const_iterator it = particles_.begin(), end = particles_.end(); it != end; ++it) {
00078       // read candidates
00079       Handle<View<reco::Candidate> > cands;
00080       iEvent.getByLabel(*it, cands);
00081       assos.clear(); assos.reserve(cands->size()); 
00082       // loop on candidates
00083       for (size_t i = 0, n = cands->size(); i < n; ++i) {
00084         assos.push_back( vertexing_(cands->refAt(i)) );
00085       }
00086       // insert into ValueMap
00087       filler.insert(cands, assos.begin(), assos.end());
00088   }
00089 
00090   // do the real filling
00091   filler.fill(); 
00092 
00093   // put our produced stuff in the event
00094   iEvent.put(result);
00095 }
00096 
00097 
00098 #include "FWCore/Framework/interface/MakerMacros.h"
00099 
00100 DEFINE_FWK_MODULE(PATVertexAssociationProducer);