CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/CommonTools/ParticleFlow/plugins/PFPileUp.cc

Go to the documentation of this file.
00001 #include "CommonTools/ParticleFlow/plugins/PFPileUp.h"
00002 
00003 #include "DataFormats/ParticleFlowCandidate/interface/PileUpPFCandidate.h"
00004 #include "DataFormats/ParticleFlowCandidate/interface/PileUpPFCandidateFwd.h"
00005 #include "DataFormats/VertexReco/interface/Vertex.h"
00006 
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 
00009 // #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 
00013 
00014 using namespace std;
00015 using namespace edm;
00016 using namespace reco;
00017 
00018 PFPileUp::PFPileUp(const edm::ParameterSet& iConfig) {
00019   
00020   inputTagPFCandidates_ 
00021     = iConfig.getParameter<InputTag>("PFCandidates");
00022 
00023   inputTagVertices_ 
00024     = iConfig.getParameter<InputTag>("Vertices");
00025 
00026   enable_ = iConfig.getParameter<bool>("Enable");
00027 
00028   verbose_ = 
00029     iConfig.getUntrackedParameter<bool>("verbose",false);
00030 
00031 
00032   if ( iConfig.exists("checkClosestZVertex") ) {
00033     checkClosestZVertex_ = iConfig.getParameter<bool>("checkClosestZVertex");
00034   } else {
00035     checkClosestZVertex_ = false;
00036   }
00037 
00038   // Configure the algo
00039   pileUpAlgo_.setVerbose(verbose_);
00040   pileUpAlgo_.setCheckClosestZVertex(checkClosestZVertex_);
00041 
00042   produces<reco::PFCandidateCollection>();
00043   
00044 }
00045 
00046 
00047 
00048 PFPileUp::~PFPileUp() { }
00049 
00050 
00051 
00052 void PFPileUp::beginJob() { }
00053 
00054 
00055 void PFPileUp::produce(Event& iEvent, 
00056                           const EventSetup& iSetup) {
00057   
00058 //   LogDebug("PFPileUp")<<"START event: "<<iEvent.id().event()
00059 //                       <<" in run "<<iEvent.id().run()<<endl;
00060   
00061    
00062   // get PFCandidates
00063 
00064   auto_ptr< reco::PFCandidateCollection > 
00065     pOutput( new reco::PFCandidateCollection ); 
00066   
00067   if(enable_) {
00068 
00069     Handle<PFCandidateCollection> pfCandidates;
00070     iEvent.getByLabel( inputTagPFCandidates_, pfCandidates);
00071 
00072   
00073     // get vertices 
00074 
00075     Handle<VertexCollection> vertices;
00076     iEvent.getByLabel( inputTagVertices_, vertices);
00077     
00078     pileUpAlgo_.process(*pfCandidates,*vertices,&pfCandidates);
00079     
00080     pOutput->insert(pOutput->end(),pileUpAlgo_.getPFCandidatesFromPU().begin(),pileUpAlgo_.getPFCandidatesFromPU().end());
00081   }  
00082   // outsize of the loop to fill the collection anyway even when disabled
00083   iEvent.put( pOutput );
00084 }
00085