CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DataFormats/JetReco/src/CaloJet.cc

Go to the documentation of this file.
00001 // CaloJet.cc
00002 // Fedor Ratnikov UMd
00003 // $Id: CaloJet.cc,v 1.22 2009/04/16 20:04:20 srappocc Exp $
00004 #include <sstream>
00005 
00006 #include "FWCore/Utilities/interface/Exception.h"
00007 #include "DataFormats/RecoCandidate/interface/RecoCaloTowerCandidate.h"
00008 
00009 //Own header file
00010 #include "DataFormats/JetReco/interface/CaloJet.h"
00011 
00012 using namespace reco;
00013 
00014  CaloJet::CaloJet (const LorentzVector& fP4, const Point& fVertex, 
00015                    const Specific& fSpecific)
00016    : Jet (fP4, fVertex),
00017      m_specific (fSpecific)
00018  {}
00019 
00020  CaloJet::CaloJet (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 CaloJet::CaloJet (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 
00034 
00036 //float CaloJet::physicsEtaQuick (float fZVertex) const {
00037 //  return Jet::physicsEta (fZVertex, eta());
00038 //}
00039 
00041 //float CaloJet::physicsEtaDetailed (float fZVertex) const {
00042 //  Jet::LorentzVector correctedMomentum;
00043 //  std::vector<const Candidate*> towers = getJetConstituentsQuick ();
00044 //  for (unsigned i = 0; i < towers.size(); ++i) {
00045 //    const Candidate* c = towers[i];
00046 //    double etaRef = Jet::physicsEta (fZVertex, c->eta());
00047 //    math::PtEtaPhiMLorentzVectorD p4 (c->p()/cosh(etaRef), etaRef, c->phi(), c->mass());
00048 //    correctedMomentum += p4;
00049 //  }
00050 //  return correctedMomentum.eta();
00051 //}
00052 
00054 //deprecated, with 3d vertex correction not clear anymore!
00055 //CaloJet::LorentzVector CaloJet::physicsP4 (float fZVertex) const {
00056 //  double physicsEta = Jet::physicsEta (fZVertex, eta());
00057 //  math::PtEtaPhiMLorentzVectorD p4 (p()/cosh(physicsEta), physicsEta, phi(), mass());
00058 //  return CaloJet::LorentzVector (p4);
00059 //}
00060 
00061 CaloJet::LorentzVector CaloJet::physicsP4 (const Particle::Point &vertex) const {
00062   return Jet::physicsP4(vertex,*this,this->vertex());
00063 }
00064 
00065 CaloJet::LorentzVector CaloJet::detectorP4 () const {
00066   return Jet::detectorP4(this->vertex(),*this);
00067 }
00068 
00069 
00070 CaloTowerPtr CaloJet::getCaloConstituent (unsigned fIndex) const {
00071    Constituent dau = daughterPtr (fIndex);
00072 
00073    if ( dau.isNonnull() && dau.isAvailable() ) {
00074 
00075    const CaloTower* towerCandidate = dynamic_cast <const CaloTower*> (dau.get());
00076 
00077     if (towerCandidate) {
00078 //      return towerCandidate;
00079 // 086     Ptr(ProductID const& productID, T const* item, key_type item_key) :
00080       return edm::Ptr<CaloTower> (dau.id(), towerCandidate, dau.key() );
00081     }
00082     else {
00083       throw cms::Exception("Invalid Constituent") << "CaloJet constituent is not of CaloTowere type";
00084     }
00085 
00086    }
00087 
00088    else {
00089      return CaloTowerPtr();
00090    }
00091 }
00092 
00093 
00094 std::vector <CaloTowerPtr > CaloJet::getCaloConstituents () const {
00095   std::vector <CaloTowerPtr> result;
00096   for (unsigned i = 0;  i <  numberOfDaughters (); i++) result.push_back (getCaloConstituent (i));
00097   return result;
00098 }
00099 
00100 
00101 CaloJet* CaloJet::clone () const {
00102   return new CaloJet (*this);
00103 }
00104 
00105 bool CaloJet::overlap( const Candidate & ) const {
00106   return false;
00107 }
00108 
00109 std::string CaloJet::print () const {
00110   std::ostringstream out;
00111   out << Jet::print () // generic jet info
00112       << "    CaloJet specific:" << std::endl
00113       << "      energy fractions em/had: " << emEnergyFraction () << '/' << energyFractionHadronic () << std::endl
00114       << "      em energy in EB/EE/HF: " << emEnergyInEB() << '/' << emEnergyInEE() << '/' << emEnergyInHF() << std::endl
00115       << "      had energy in HB/HO/HE/HF: " << hadEnergyInHB() << '/' << hadEnergyInHO() << '/' << hadEnergyInHE() << '/' << hadEnergyInHF() << std::endl
00116       << "      constituent towers area: " << towersArea() << std::endl;
00117   out << "      Towers:" << std::endl;
00118   std::vector <CaloTowerPtr > towers = getCaloConstituents ();
00119   for (unsigned i = 0; i < towers.size (); i++) {
00120     if (towers[i].get ()) {
00121       out << "      #" << i << " " << *(towers[i]) << std::endl;
00122     }
00123     else {
00124       out << "      #" << i << " tower is not available in the event"  << std::endl;
00125     }
00126   }
00127   return out.str ();
00128 }
00129 
00130 //----------------------------------------------------------
00131 // here are methods extracting information from constituents
00132 //----------------------------------------------------------
00133 
00134 std::vector<CaloTowerDetId> CaloJet::getTowerIndices() const {
00135   std::vector<CaloTowerDetId> result;
00136   std::vector <CaloTowerPtr> towers = getCaloConstituents ();
00137   for (unsigned i = 0; i < towers.size(); ++i) {
00138     result.push_back (towers[i]->id());
00139   }
00140   return result;
00141 }