Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:44

0001 // GenJet.cc
0002 // Fedor Ratnikov, UMd
0003 
0004 #include <sstream>
0005 
0006 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0007 
0008 //Own header file
0009 #include "DataFormats/JetReco/interface/GenJet.h"
0010 
0011 using namespace reco;
0012 
0013 GenJet::GenJet(const LorentzVector& fP4, const Point& fVertex, const Specific& fSpecific)
0014     : Jet(fP4, fVertex), m_specific(fSpecific) {}
0015 
0016 GenJet::GenJet(const LorentzVector& fP4,
0017                const Point& fVertex,
0018                const Specific& fSpecific,
0019                const Jet::Constituents& fConstituents)
0020     : Jet(fP4, fVertex, fConstituents), m_specific(fSpecific) {}
0021 
0022 GenJet::GenJet(const LorentzVector& fP4, const Specific& fSpecific, const Jet::Constituents& fConstituents)
0023     : Jet(fP4, Point(0, 0, 0), fConstituents), m_specific(fSpecific) {}
0024 
0025 /// Detector Eta (use reference Z and jet kinematics only)
0026 float GenJet::detectorEta(float fZVertex) const { return Jet::detectorEta(fZVertex, eta()); }
0027 
0028 const GenParticle* GenJet::genParticle(const Candidate* fConstituent) {
0029   const Candidate* base = fConstituent;
0030   if (fConstituent->hasMasterClone())
0031     base = fConstituent->masterClone().get();
0032   const GenParticle* result = dynamic_cast<const GenParticle*>(base);
0033   if (!result)
0034     throw cms::Exception("Invalid Constituent") << "GenJet constituent is not of the type GenParticle";
0035   return result;
0036 }
0037 
0038 const GenParticle* GenJet::getGenConstituent(unsigned fIndex) const {
0039   // no direct access, have to iterate for now
0040   int index(fIndex);
0041   Candidate::const_iterator daugh = begin();
0042   for (; --index >= 0 && daugh != end(); daugh++) {
0043   }
0044   if (daugh != end()) {                      // in range
0045     const Candidate* constituent = &*daugh;  // deref
0046     return genParticle(constituent);
0047   }
0048   return nullptr;
0049 }
0050 
0051 std::vector<const GenParticle*> GenJet::getGenConstituents() const {
0052   std::vector<const GenParticle*> result;
0053   for (unsigned i = 0; i < numberOfDaughters(); i++)
0054     result.push_back(getGenConstituent(i));
0055   return result;
0056 }
0057 
0058 GenJet* GenJet::clone() const { return new GenJet(*this); }
0059 
0060 bool GenJet::overlap(const Candidate&) const { return false; }
0061 
0062 std::string GenJet::print() const {
0063   std::ostringstream out;
0064   out << Jet::print()  // generic jet info
0065       << "    GenJet specific:" << std::endl
0066       << "      em/had/invisible/aux  energies: " << emEnergy() << '/' << hadEnergy() << '/' << invisibleEnergy() << '/'
0067       << auxiliaryEnergy() << std::endl;
0068   out << "      MC particles:" << std::endl;
0069   std::vector<const GenParticle*> mcparts = getGenConstituents();
0070   for (unsigned i = 0; i < mcparts.size(); i++) {
0071     const GenParticle* mcpart = mcparts[i];
0072     if (mcpart) {
0073       out << "      #" << i << "  PDG code:" << mcpart->pdgId() << ", p/pt/eta/phi: " << mcpart->p() << '/'
0074           << mcpart->pt() << '/' << mcpart->eta() << '/' << mcpart->phi() << std::endl;
0075     } else {
0076       out << "      #" << i << "  No information about constituent" << std::endl;
0077     }
0078   }
0079   return out.str();
0080 }