CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/TopQuarkAnalysis/TopEventProducers/src/TopInitSubset.cc

Go to the documentation of this file.
00001 #include "TopQuarkAnalysis/TopEventProducers/interface/TopInitSubset.h"
00002 
00003 TopInitSubset::TopInitSubset(const edm::ParameterSet& cfg):
00004   src_ ( cfg.getParameter<edm::InputTag>( "src" ) )
00005 {
00006   produces<reco::GenParticleCollection>();
00007 }
00008 
00009 TopInitSubset::~TopInitSubset()
00010 {
00011 }
00012 
00013 void
00014 TopInitSubset::produce(edm::Event& evt, const edm::EventSetup& setup)
00015 {     
00016   edm::Handle<reco::GenParticleCollection> src;
00017   evt.getByLabel(src_, src);
00018   
00019   const reco::GenParticleRefProd ref = evt.getRefBeforePut<reco::GenParticleCollection>(); 
00020   std::auto_ptr<reco::GenParticleCollection> sel( new reco::GenParticleCollection );
00021 
00022   //fill output collection
00023   fillOutput( *src, *sel );
00024 
00025   evt.put( sel );
00026 }
00027 
00028 void TopInitSubset::fillOutput(const reco::GenParticleCollection& src, reco::GenParticleCollection& sel)
00029 {
00030   for(reco::GenParticleCollection::const_iterator t=src.begin(); t!=src.end(); ++t){
00031     if( t->status()==TopInitID::status && std::abs(t->pdgId())==TopInitID::tID ){ //is top
00032       for(int idx=0; idx<(int)t->numberOfMothers(); ++idx){      
00033         reco::GenParticle* cand = new reco::GenParticle( t->mother(idx)->threeCharge(), t->mother(idx)->p4(), 
00034                                                          t->mother(idx)->vertex(), t->mother(idx)->pdgId(), 
00035                                                          t->mother(idx)->status(), false );
00036         std::auto_ptr<reco::GenParticle> ptr( cand );
00037         sel.push_back( *ptr );
00038       }
00039       break;
00040     }
00041   }
00042 }