CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/JetReco/src/GenJet.cc

Go to the documentation of this file.
00001 // GenJet.cc
00002 // Fedor Ratnikov, UMd
00003 // $Id: GenJet.cc,v 1.12 2008/05/26 11:22:12 arizzi Exp $
00004 
00005 #include <sstream>
00006 
00007 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00008 
00009 //Own header file
00010 #include "DataFormats/JetReco/interface/GenJet.h"
00011 
00012 using namespace reco;
00013 
00014 GenJet::GenJet (const LorentzVector& fP4, const Point& fVertex, 
00015                 const Specific& fSpecific)
00016   : Jet (fP4, fVertex),
00017     m_specific (fSpecific)
00018 {}
00019 
00020 GenJet::GenJet (const LorentzVector& fP4, const Point& fVertex, 
00021                 const Specific& fSpecific, 
00022                 const Jet::Constituents& fConstituents)
00023   : Jet (fP4, fVertex, fConstituents),
00024     m_specific (fSpecific)
00025 {}
00026 
00027 GenJet::GenJet (const LorentzVector& fP4, 
00028                 const Specific& fSpecific, 
00029                 const Jet::Constituents& fConstituents)
00030   : Jet (fP4, Point(0,0,0), fConstituents),
00031     m_specific (fSpecific)
00032 {}
00033 
00035 float GenJet::detectorEta (float fZVertex) const {
00036   return Jet::detectorEta (fZVertex, eta());
00037 }
00038 
00039 const GenParticle* GenJet::genParticle (const Candidate* fConstituent) {
00040   const Candidate* base = fConstituent;
00041   if (fConstituent->hasMasterClone ()) base = fConstituent->masterClone().get ();
00042   const GenParticle* result = dynamic_cast<const GenParticle*> (base);
00043   if (!result) throw cms::Exception("Invalid Constituent") << "GenJet constituent is not of the type GenParticle";
00044   return result;
00045 }
00046 
00047 const GenParticle* GenJet::getGenConstituent (unsigned fIndex) const {
00048   // no direct access, have to iterate for now
00049   int index (fIndex);
00050   Candidate::const_iterator daugh = begin ();
00051   for (; --index >= 0 && daugh != end (); daugh++) {}
00052   if (daugh != end ()) { // in range
00053     const Candidate* constituent = &*daugh; // deref
00054     return genParticle (constituent);
00055   }
00056   return 0;
00057 }
00058 
00059 std::vector <const GenParticle*> GenJet::getGenConstituents () const {
00060   std::vector <const GenParticle*> result;
00061   for (unsigned i = 0;  i <  numberOfDaughters (); i++) result.push_back (getGenConstituent (i));
00062   return result;
00063 }
00064 
00065 GenJet* GenJet::clone () const {
00066   return new GenJet (*this);
00067 }
00068 
00069 bool GenJet::overlap( const Candidate & ) const {
00070   return false;
00071 }
00072 
00073 std::string GenJet::print () const {
00074   std::ostringstream out;
00075   out << Jet::print () // generic jet info
00076       << "    GenJet specific:" << std::endl
00077       << "      em/had/invisible/aux  energies: " 
00078       << emEnergy() << '/' << hadEnergy()  << '/' << invisibleEnergy() << '/' << auxiliaryEnergy() << std::endl;
00079   out << "      MC particles:" << std::endl;
00080   std::vector <const GenParticle*> mcparts = getGenConstituents ();
00081   for (unsigned i = 0; i < mcparts.size (); i++) {
00082     const GenParticle* mcpart = mcparts[i];
00083     if (mcpart) {
00084       out << "      #" << i << "  PDG code:" << mcpart->pdgId() 
00085           << ", p/pt/eta/phi: " << mcpart->p() << '/' << mcpart->pt() << '/' << mcpart->eta() << '/' << mcpart->phi() << std::endl;
00086     }
00087     else {
00088       out << "      #" << i << "  No information about constituent" << std::endl;
00089     }
00090   }
00091   return out.str ();
00092 }