CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DataFormats/JetReco/src/TrackJet.cc

Go to the documentation of this file.
00001 // $Id: TrackJet.cc,v 1.2 2009/12/10 15:13:43 lowette Exp $
00002 
00003 #include "DataFormats/JetReco/interface/TrackJet.h"
00004 
00005 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00006 #include "DataFormats/VertexReco/interface/Vertex.h"
00007 
00008 
00009 reco::TrackJet::TrackJet()
00010   : reco::Jet()
00011 {
00012 }
00013 
00014 
00015 reco::TrackJet::TrackJet(const LorentzVector & fP4, const Point & fVertex) 
00016   : reco::Jet(fP4, fVertex)
00017 {
00018 }
00019 
00020 
00021 reco::TrackJet::TrackJet(const LorentzVector & fP4, const Point & fVertex, const Jet::Constituents & fConstituents)
00022   : reco::Jet(fP4, fVertex, fConstituents)
00023 {
00024   this->resetCharge();
00025 }
00026 
00027 
00028 
00029 reco::TrackJet * reco::TrackJet::clone() const {
00030   return new reco::TrackJet(*this);
00031 }
00032 
00033 
00034 
00035 edm::Ptr<reco::Track> reco::TrackJet::track(size_t i) const {
00036   Constituent dau = daughterPtr (i);
00037   // check the daughter to be ok
00038   if ( dau.isNonnull() && dau.isAvailable() ) {
00039     // convert to concrete candidate type
00040     const RecoChargedRefCandidate* trkCand = dynamic_cast <const RecoChargedRefCandidate*> (dau.get());
00041     // check the candidate is of the right type
00042     if (trkCand) {
00043       // check the track link in the recochargedcandidate to be there
00044       if (trkCand->track().get()) {
00045         // ok, return pointer to the originating track
00046         return edm::Ptr<reco::Track> ( trkCand->track().id(), trkCand->track().get(), trkCand->track().key() );
00047       } else {
00048         throw cms::Exception("TrackRef unavailable") << "TrackJet consituent track not in the event.";
00049       }
00050     } else {
00051      throw cms::Exception("Invalid Constituent") << "TrackJet constituent is not of RecoChargedRefCandidate type";
00052     }
00053   // otherwise return empty ptr
00054   } else {
00055     return edm::Ptr<reco::Track>();
00056   }
00057 }
00058 
00059 
00060 std::vector<edm::Ptr<reco::Track> > reco::TrackJet::tracks() const {
00061   std::vector <edm::Ptr<reco::Track> > result;
00062   for (unsigned i = 0;  i <  numberOfDaughters (); i++) result.push_back (track (i));
00063   return result;
00064 }
00065 
00066 
00067 void reco::TrackJet::resetCharge() {
00068   reco::LeafCandidate::Charge charge = 0;
00069   for ( reco::Candidate::const_iterator ida = this->begin(); ida != this->end(); ++ida ) {
00070     charge += ida->charge();
00071   }
00072   this->setCharge(charge);
00073 }
00074 
00075 
00076 const reco::VertexRef reco::TrackJet::primaryVertex() const {
00077   return vtx_;
00078 }
00079 
00080 
00081 void reco::TrackJet::setPrimaryVertex(const reco::VertexRef & vtx) {
00082   vtx_ = vtx;
00083 }
00084 
00085 
00086 bool reco::TrackJet::overlap(const Candidate & dummy) const {
00087   return false;
00088 }
00089 
00090 
00091 std::string reco::TrackJet::print() const {
00092   std::ostringstream out;
00093   out << Jet::print() // generic jet info
00094       << "    TrackJet specific:" << std::endl;
00095   if (primaryVertex().get()) {
00096     out << "      Associated PV:"
00097         << " x=" << primaryVertex()->x()
00098         << " y=" << primaryVertex()->y()
00099         << " z=" << primaryVertex()->z() << std::endl;
00100   } else {
00101     out << "      Associated PV not available on the event" << std::endl;
00102   }
00103   std::vector<edm::Ptr<reco::Track> > thetracks = tracks();
00104   for (unsigned i = 0; i < thetracks.size (); i++) {
00105     if (thetracks[i].get ()) {
00106       out << "      #" << i
00107           << " px=" << thetracks[i]->px()
00108           << " py=" << thetracks[i]->py()
00109           << " pz=" << thetracks[i]->pz()
00110           << " eta=" << thetracks[i]->eta()
00111           << " phi=" << thetracks[i]->phi() << std::endl;
00112     }
00113     else {
00114       out << "      #" << i << " track is not available in the event"  << std::endl;
00115     }
00116   }
00117   return out.str();
00118 }