CMS 3D CMS Logo

TopInitSubset.cc

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

Generated on Tue Jun 9 17:48:06 2009 for CMSSW by  doxygen 1.5.4