Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // CaloJet.cc
0002 // Fedor Ratnikov UMd
0003 #include <sstream>
0004 
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 #include "DataFormats/RecoCandidate/interface/RecoCaloTowerCandidate.h"
0007 
0008 //Own header file
0009 #include "DataFormats/JetReco/interface/CaloJet.h"
0010 
0011 using namespace reco;
0012 
0013 CaloJet::CaloJet(const LorentzVector& fP4, const Point& fVertex, const Specific& fSpecific)
0014     : Jet(fP4, fVertex), m_specific(fSpecific) {}
0015 
0016 CaloJet::CaloJet(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 CaloJet::CaloJet(const LorentzVector& fP4, const Specific& fSpecific, const Jet::Constituents& fConstituents)
0023     : Jet(fP4, Point(0, 0, 0), fConstituents), m_specific(fSpecific) {}
0024 
0025 /// Physics Eta (use reference Z and jet kinematics only)
0026 //float CaloJet::physicsEtaQuick (float fZVertex) const {
0027 //  return Jet::physicsEta (fZVertex, eta());
0028 //}
0029 
0030 /// Physics Eta (loop over constituents)
0031 //float CaloJet::physicsEtaDetailed (float fZVertex) const {
0032 //  Jet::LorentzVector correctedMomentum;
0033 //  std::vector<const Candidate*> towers = getJetConstituentsQuick ();
0034 //  for (unsigned i = 0; i < towers.size(); ++i) {
0035 //    const Candidate* c = towers[i];
0036 //    double etaRef = Jet::physicsEta (fZVertex, c->eta());
0037 //    math::PtEtaPhiMLorentzVectorD p4 (c->p()/cosh(etaRef), etaRef, c->phi(), c->mass());
0038 //    correctedMomentum += p4;
0039 //  }
0040 //  return correctedMomentum.eta();
0041 //}
0042 
0043 /// Physics p4 (use jet Z and kinematics only)
0044 //deprecated, with 3d vertex correction not clear anymore!
0045 //CaloJet::LorentzVector CaloJet::physicsP4 (float fZVertex) const {
0046 //  double physicsEta = Jet::physicsEta (fZVertex, eta());
0047 //  math::PtEtaPhiMLorentzVectorD p4 (p()/cosh(physicsEta), physicsEta, phi(), mass());
0048 //  return CaloJet::LorentzVector (p4);
0049 //}
0050 
0051 CaloJet::LorentzVector CaloJet::physicsP4(const Particle::Point& vertex) const {
0052   return Jet::physicsP4(vertex, *this, this->vertex());
0053 }
0054 
0055 CaloJet::LorentzVector CaloJet::detectorP4() const { return Jet::detectorP4(this->vertex(), *this); }
0056 
0057 CaloTowerPtr CaloJet::getCaloConstituent(unsigned fIndex) const {
0058   Constituent dau = daughterPtr(fIndex);
0059 
0060   if (dau.isNonnull() && dau.isAvailable()) {
0061     const CaloTower* towerCandidate = dynamic_cast<const CaloTower*>(dau.get());
0062 
0063     if (towerCandidate) {
0064       //      return towerCandidate;
0065       // 086     Ptr(ProductID const& productID, T const* item, key_type item_key) :
0066       return edm::Ptr<CaloTower>(dau.id(), towerCandidate, dau.key());
0067     } else {
0068       throw cms::Exception("Invalid Constituent") << "CaloJet constituent is not of CaloTowere type";
0069     }
0070 
0071   }
0072 
0073   else {
0074     return CaloTowerPtr();
0075   }
0076 }
0077 
0078 std::vector<CaloTowerPtr> CaloJet::getCaloConstituents() const {
0079   std::vector<CaloTowerPtr> result;
0080   for (unsigned i = 0; i < numberOfDaughters(); i++)
0081     result.push_back(getCaloConstituent(i));
0082   return result;
0083 }
0084 
0085 CaloJet* CaloJet::clone() const { return new CaloJet(*this); }
0086 
0087 bool CaloJet::overlap(const Candidate&) const { return false; }
0088 
0089 std::string CaloJet::print() const {
0090   std::ostringstream out;
0091   out << Jet::print()  // generic jet info
0092       << "    CaloJet specific:" << std::endl
0093       << "      energy fractions em/had: " << emEnergyFraction() << '/' << energyFractionHadronic() << std::endl
0094       << "      em energy in EB/EE/HF: " << emEnergyInEB() << '/' << emEnergyInEE() << '/' << emEnergyInHF()
0095       << std::endl
0096       << "      had energy in HB/HO/HE/HF: " << hadEnergyInHB() << '/' << hadEnergyInHO() << '/' << hadEnergyInHE()
0097       << '/' << hadEnergyInHF() << std::endl
0098       << "      constituent towers area: " << towersArea() << std::endl;
0099   out << "      Towers:" << std::endl;
0100   std::vector<CaloTowerPtr> towers = getCaloConstituents();
0101   for (unsigned i = 0; i < towers.size(); i++) {
0102     if (towers[i].get()) {
0103       out << "      #" << i << " " << *(towers[i]) << std::endl;
0104     } else {
0105       out << "      #" << i << " tower is not available in the event" << std::endl;
0106     }
0107   }
0108   return out.str();
0109 }
0110 
0111 //----------------------------------------------------------
0112 // here are methods extracting information from constituents
0113 //----------------------------------------------------------
0114 
0115 std::vector<CaloTowerDetId> CaloJet::getTowerIndices() const {
0116   std::vector<CaloTowerDetId> result;
0117   std::vector<CaloTowerPtr> towers = getCaloConstituents();
0118   for (unsigned i = 0; i < towers.size(); ++i) {
0119     result.push_back(towers[i]->id());
0120   }
0121   return result;
0122 }