CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoMET/METProducers/src/ParticleFlowForChargedMETProducer.cc

Go to the documentation of this file.
00001 #include "RecoMET/METProducers/interface/ParticleFlowForChargedMETProducer.h"
00002 
00003 #include <DataFormats/VertexReco/interface/Vertex.h>
00004 #include <DataFormats/VertexReco/interface/VertexFwd.h>
00005 #include <DataFormats/ParticleFlowCandidate/interface/PFCandidate.h>
00006 #include <DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h>
00007 
00008 using namespace edm;
00009 using namespace std;
00010 using namespace reco;
00011 
00012 ParticleFlowForChargedMETProducer::ParticleFlowForChargedMETProducer(const edm::ParameterSet& iConfig)
00013 {
00014   pfCollectionLabel    = iConfig.getParameter<edm::InputTag>("PFCollectionLabel");
00015   pvCollectionLabel    = iConfig.getParameter<edm::InputTag>("PVCollectionLabel");
00016   dzCut    = iConfig.getParameter<double>("dzCut");
00017   neutralEtThreshold    = iConfig.getParameter<double>("neutralEtThreshold");
00018 
00019   produces<PFCandidateCollection>();
00020 }
00021 
00022 void ParticleFlowForChargedMETProducer::produce(Event& iEvent, const EventSetup& iSetup)
00023 {
00024 
00025   //Get the PV collection
00026   Handle<VertexCollection> pvCollection;
00027   iEvent.getByLabel(pvCollectionLabel, pvCollection);
00028   VertexCollection::const_iterator vertex = pvCollection->begin();
00029 
00030   //Get pfCandidates
00031   Handle<PFCandidateCollection> pfCandidates;
00032   iEvent.getByLabel(pfCollectionLabel, pfCandidates);
00033 
00034   // the output collection
00035   auto_ptr<PFCandidateCollection> chargedPFCandidates( new PFCandidateCollection ) ;
00036   if (pvCollection->size()>0) {
00037     for( unsigned i=0; i<pfCandidates->size(); i++ ) {
00038       const PFCandidate& pfCand = (*pfCandidates)[i];
00039       PFCandidatePtr pfCandPtr(pfCandidates, i);
00040       
00041       if (pfCandPtr->trackRef().isNonnull()) { 
00042         if (pfCandPtr->trackRef()->dz((*vertex).position()) < dzCut) {
00043           chargedPFCandidates->push_back( pfCand );
00044           chargedPFCandidates->back().setSourceCandidatePtr( pfCandPtr );
00045         }
00046         
00047       }
00048       else if (neutralEtThreshold>0 and 
00049                pfCandPtr->pt()>neutralEtThreshold) {
00050         chargedPFCandidates->push_back( pfCand );
00051         chargedPFCandidates->back().setSourceCandidatePtr( pfCandPtr );
00052       }  
00053         
00054 
00055     }
00056   }
00057 
00058 
00059   iEvent.put(chargedPFCandidates); 
00060 
00061   return;
00062 }
00063 
00064 ParticleFlowForChargedMETProducer::~ParticleFlowForChargedMETProducer(){}