CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/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( std::abs(t->pdgId())==TopInitID::tID ){
00032       bool hasTopMother = false;
00033       for(unsigned idx=0; idx<t->numberOfMothers(); ++idx)
00034         if( std::abs(t->mother(idx)->pdgId())==TopInitID::tID )
00035           hasTopMother = true;
00036       if(hasTopMother)
00037         continue;
00038       for(unsigned idx=0; idx<t->numberOfMothers(); ++idx){
00039         reco::GenParticle* cand = new reco::GenParticle( t->mother(idx)->threeCharge(), t->mother(idx)->p4(), 
00040                                                          t->mother(idx)->vertex(), t->mother(idx)->pdgId(), 
00041                                                          t->mother(idx)->status(), false );
00042         std::auto_ptr<reco::GenParticle> ptr( cand );
00043         sel.push_back( *ptr );
00044       }
00045       break;
00046     }
00047   }
00048 }