CMS 3D CMS Logo

TopGenEvent.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 "PhysicsTools/CandUtils/interface/pdgIdUtils.h"
00005 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00006 #include "AnalysisDataFormats/TopObjects/interface/TopGenEvent.h"
00007 
00008 
00010 TopGenEvent::TopGenEvent(reco::GenParticleRefProd& parts, reco::GenParticleRefProd& inits)
00011 {
00012   parts_ = parts; 
00013   initPartons_= inits;
00014 }
00015 
00016 const reco::GenParticle*
00017 TopGenEvent::candidate(int id) const
00018 {
00019   const reco::GenParticle* cand=0;
00020   const reco::GenParticleCollection & partsColl = *parts_;
00021   for (unsigned int i = 0; i < partsColl.size(); ++i) {
00022     if (partsColl[i].pdgId()==id) {
00023       cand = &partsColl[i];
00024     }
00025   }  
00026   return cand;
00027 }
00028 
00029 void
00030 TopGenEvent::dumpEventContent() const 
00031 {
00032   edm::LogVerbatim log("TopGenEvent");
00033   log << "\n"
00034       << "--------------------------------------\n"
00035       << "- Dump TopGenEvent Content           -\n"
00036       << "--------------------------------------\n";
00037   for (reco::GenParticleCollection::const_iterator part = parts_->begin(); 
00038        part<parts_->end(); ++part) {
00039     log << "pdgId:"  << std::setw(5)  << part->pdgId()     << ", "
00040         << "mass:"   << std::setw(11) << part->p4().mass() << ", "
00041         << "energy:" << std::setw(11) << part->energy()    << ", " 
00042         << "pt:"     << std::setw(11) << part->pt()        << "\n"; 
00043   }
00044 }
00045 
00046 int
00047 TopGenEvent::numberOfLeptons(bool fromWBoson) const
00048 {
00049   int lep=0;
00050   const reco::GenParticleCollection & partsColl = *parts_;
00051   for (unsigned int i = 0; i < partsColl.size(); ++i) {
00052     if (reco::isLepton(partsColl[i])) {
00053       if(fromWBoson){
00054         if(partsColl[i].mother() &&  abs(partsColl[i].mother()->pdgId())==TopDecayID::WID){
00055           ++lep;
00056         }
00057       }
00058       else{
00059         ++lep;
00060       }
00061     }
00062   }  
00063   return lep;
00064 }
00065 
00066 int
00067 TopGenEvent::numberOfLeptons(WDecay::LeptonType typeRestriction, bool fromWBoson) const
00068 {
00069   int leptonType=-1;
00070   switch(typeRestriction){
00071     // resolve whether or not there is
00072     // any restriction in lepton types
00073   case WDecay::kElec: 
00074     leptonType=TopDecayID::elecID;
00075     break;
00076   case WDecay::kMuon: 
00077     leptonType=TopDecayID::muonID;
00078     break;
00079   case WDecay::kTau: 
00080     leptonType=TopDecayID::tauID;
00081     break;
00082   case WDecay::kNone:
00083     break;
00084   }
00085   int lep=0;
00086   const reco::GenParticleCollection & partsColl = *parts_;
00087   for(unsigned int i = 0; i < partsColl.size(); ++i) {
00088     if(fromWBoson){
00089       // restrict to particles originating from the W boson
00090       if( !(partsColl[i].mother() &&  abs(partsColl[i].mother()->pdgId())==TopDecayID::WID) ){
00091         continue;
00092       }
00093     }
00094     if(leptonType>0){
00095       // in case of lepton type restriction
00096       if( abs(partsColl[i].pdgId())==leptonType ){
00097         ++lep;
00098       }
00099     }
00100     else{
00101       // take any lepton type into account else
00102       if( reco::isLepton(partsColl[i]) ){
00103         ++lep;
00104       }
00105     }
00106   }  
00107   return lep;
00108 }
00109 
00110 int
00111 TopGenEvent::numberOfBQuarks(bool fromTopQuark) const
00112 {
00113   int bq=0;
00114   const reco::GenParticleCollection & partsColl = *parts_;
00115   for (unsigned int i = 0; i < partsColl.size(); ++i) {
00116     if (abs(partsColl[i].pdgId())==TopDecayID::bID) {
00117       if(fromTopQuark){
00118         if(partsColl[i].mother() &&  abs(partsColl[i].mother()->pdgId())==TopDecayID::tID){
00119           ++bq;
00120         }
00121       }
00122       else{
00123         ++bq;
00124       }
00125     }
00126   }  
00127   return bq;
00128 }
00129 
00130 std::vector<const reco::GenParticle*> 
00131 TopGenEvent::topSisters() const
00132 {
00133   std::vector<const reco::GenParticle*> sisters;
00134   for(reco::GenParticleCollection::const_iterator part = parts_->begin(); part<parts_->end(); ++part){
00135     if( part->numberOfMothers()==0 && abs(part->pdgId())!= TopDecayID::tID){
00136       // choose top sister which do not have a 
00137       // mother and are whether top nor anti-top 
00138       if( dynamic_cast<const reco::GenParticle*>( &(*part) ) == 0){
00139         throw edm::Exception( edm::errors::InvalidReference, "Not a GenParticle" );
00140       }
00141       sisters.push_back( part->clone() );
00142     }
00143   }  
00144   return sisters;
00145 }
00146 
00147 std::vector<const reco::GenParticle*> 
00148 TopGenEvent::lightQuarks(bool bIncluded) const 
00149 {
00150   std::vector<const reco::GenParticle*> lightQuarks;
00151   reco::GenParticleCollection::const_iterator part = parts_->begin();
00152   for ( ; part < parts_->end(); ++part) {
00153     if( (bIncluded && abs(part->pdgId())==TopDecayID::bID) || abs(part->pdgId())<TopDecayID::bID ) {
00154       if( dynamic_cast<const reco::GenParticle*>( &(*part) ) == 0){
00155         throw edm::Exception( edm::errors::InvalidReference, "Not a GenParticle" );
00156       }
00157       lightQuarks.push_back( part->clone() );
00158     }
00159   }  
00160   return lightQuarks;
00161 }
00162 
00163 std::vector<const reco::GenParticle*> 
00164 TopGenEvent::radiatedGluons(int pdgId) const{
00165   std::vector<const reco::GenParticle*> rads;
00166   for (reco::GenParticleCollection::const_iterator part = parts_->begin(); part < parts_->end(); ++part) {
00167     if(part->pdgId()==TopDecayID::glueID){
00168       if ( part->mother() && part->mother()->pdgId()==pdgId ){
00169         if( dynamic_cast<const reco::GenParticle*>( &(*part) ) == 0){
00170           throw edm::Exception( edm::errors::InvalidReference, "Not a GenParticle" );
00171         }
00172         rads.push_back( part->clone() );
00173       }
00174     }
00175   }  
00176   return rads;
00177 }
00178 

Generated on Tue Jun 9 17:25:09 2009 for CMSSW by  doxygen 1.5.4