File indexing completed on 2024-04-06 12:04:25
0001
0002
0003 #include <sstream>
0004 #include <typeinfo>
0005
0006 #include "FWCore/Utilities/interface/Exception.h"
0007 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0008 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
0009
0010
0011 #include "DataFormats/JetReco/interface/PFJet.h"
0012
0013 using namespace reco;
0014
0015 PFJet::PFJet(const LorentzVector& fP4,
0016 const Point& fVertex,
0017 const Specific& fSpecific,
0018 const Jet::Constituents& fConstituents)
0019 : Jet(fP4, fVertex, fConstituents), m_specific(fSpecific) {}
0020
0021 PFJet::PFJet(const LorentzVector& fP4, const Point& fVertex, const Specific& fSpecific)
0022 : Jet(fP4, fVertex), m_specific(fSpecific) {}
0023
0024 PFJet::PFJet(const LorentzVector& fP4, const Specific& fSpecific, const Jet::Constituents& fConstituents)
0025 : Jet(fP4, Point(0, 0, 0), fConstituents), m_specific(fSpecific) {}
0026
0027 reco::PFCandidatePtr PFJet::getPFConstituent(unsigned fIndex) const {
0028 Constituent dau = daughterPtr(fIndex);
0029 if (dau.isNonnull() && dau.isAvailable()) {
0030 const PFCandidate* pfCandidate = dynamic_cast<const PFCandidate*>(dau.get());
0031 if (pfCandidate) {
0032 return edm::Ptr<PFCandidate>(dau.id(), pfCandidate, dau.key());
0033 } else {
0034 throw cms::Exception("Invalid Constituent") << "PFJet constituent is not of PFCandidate type";
0035 }
0036 } else {
0037 return PFCandidatePtr();
0038 }
0039 }
0040
0041 std::vector<reco::PFCandidatePtr> PFJet::getPFConstituents() const {
0042 std::vector<PFCandidatePtr> result;
0043 for (unsigned i = 0; i < numberOfDaughters(); i++)
0044 result.push_back(getPFConstituent(i));
0045 return result;
0046 }
0047
0048 reco::TrackRefVector PFJet::getTrackRefs() const {
0049
0050 reco::TrackRefVector result;
0051 result.reserve(chargedMultiplicity());
0052 for (unsigned i = 0; i < numberOfDaughters(); i++) {
0053 const reco::PFCandidatePtr pfcand = getPFConstituent(i);
0054 reco::TrackRef trackref = pfcand->trackRef();
0055 if (trackref.isNonnull()) {
0056 result.push_back(trackref);
0057 }
0058 }
0059
0060 return result;
0061 }
0062
0063 PFJet* PFJet::clone() const { return new PFJet(*this); }
0064
0065 bool PFJet::overlap(const Candidate&) const { return false; }
0066
0067 std::string PFJet::print() const {
0068 std::ostringstream out;
0069 out << Jet::print()
0070 << " PFJet specific:" << std::endl
0071 << " charged hadron energy/multiplicity: " << chargedHadronEnergy() << '/' << chargedHadronMultiplicity()
0072 << std::endl
0073 << " neutral hadron energy/multiplicity: " << neutralHadronEnergy() << '/' << neutralHadronMultiplicity()
0074 << std::endl
0075 << " photon energy/multiplicity: " << photonEnergy() << '/' << photonMultiplicity() << std::endl
0076 << " electron energy/multiplicity: " << electronEnergy() << '/' << electronMultiplicity() << std::endl
0077 << " muon energy/multiplicity: " << muonEnergy() << '/' << muonMultiplicity() << std::endl
0078 << " HF Hadron energy/multiplicity: " << HFHadronEnergy() << '/' << HFHadronMultiplicity() << std::endl
0079 << " HF EM particle energy/multiplicity: " << HFEMEnergy() << '/' << HFEMMultiplicity() << std::endl
0080 << " charged/neutral hadrons energy: " << chargedHadronEnergy() << '/' << neutralHadronEnergy() << std::endl
0081 << " charged/neutral em energy: " << chargedEmEnergy() << '/' << neutralEmEnergy() << std::endl
0082 << " charged muon energy: " << chargedMuEnergy() << '/' << std::endl
0083 << " charged/neutral multiplicity: " << chargedMultiplicity() << '/' << neutralMultiplicity() << std::endl
0084 << " HO energy: " << hoEnergy() << std::endl;
0085 out << " PFCandidate constituents:" << std::endl;
0086 std::vector<PFCandidatePtr> constituents = getPFConstituents();
0087 for (unsigned i = 0; i < constituents.size(); ++i) {
0088 if (constituents[i].get()) {
0089 out << " #" << i << " " << *(constituents[i]) << std::endl;
0090 } else {
0091 out << " #" << i << " PFCandidate is not available in the event" << std::endl;
0092 }
0093 }
0094 return out.str();
0095 }
0096
0097 std::ostream& reco::operator<<(std::ostream& out, const reco::PFJet& jet) {
0098 if (out) {
0099 out << "PFJet "
0100 << "(pt, eta, phi) = " << jet.pt() << "," << jet.eta() << "," << jet.phi()
0101 << " (Rch,Rnh,Rgamma,Re,Rmu,RHFHad,RHFEM) = " << jet.chargedHadronEnergyFraction() << ","
0102 << jet.neutralHadronEnergyFraction() << "," << jet.photonEnergyFraction() << "," << jet.electronEnergyFraction()
0103 << "," << jet.muonEnergyFraction() << "," << jet.HFHadronEnergyFraction() << "," << jet.HFEMEnergyFraction();
0104 }
0105 return out;
0106 }