Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:25

0001 
0002 #include "DataFormats/JetReco/interface/TrackJet.h"
0003 
0004 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0005 #include "DataFormats/VertexReco/interface/Vertex.h"
0006 
0007 reco::TrackJet::TrackJet() : reco::Jet() {}
0008 
0009 reco::TrackJet::TrackJet(const LorentzVector& fP4, const Point& fVertex) : reco::Jet(fP4, fVertex) {}
0010 
0011 reco::TrackJet::TrackJet(const LorentzVector& fP4, const Point& fVertex, const Jet::Constituents& fConstituents)
0012     : reco::Jet(fP4, fVertex, fConstituents) {
0013   this->resetCharge();
0014 }
0015 
0016 reco::TrackJet* reco::TrackJet::clone() const { return new reco::TrackJet(*this); }
0017 
0018 edm::Ptr<reco::Track> reco::TrackJet::track(size_t i) const {
0019   Constituent dau = daughterPtr(i);
0020   // check the daughter to be ok
0021   if (dau.isNonnull() && dau.isAvailable()) {
0022     // convert to concrete candidate type
0023     const RecoChargedRefCandidate* trkCand = dynamic_cast<const RecoChargedRefCandidate*>(dau.get());
0024     // check the candidate is of the right type
0025     if (trkCand) {
0026       // check the track link in the recochargedcandidate to be there
0027       if (trkCand->track().get()) {
0028         // ok, return pointer to the originating track
0029         return edm::Ptr<reco::Track>(trkCand->track().id(), trkCand->track().get(), trkCand->track().key());
0030       } else {
0031         throw cms::Exception("TrackRef unavailable") << "TrackJet consituent track not in the event.";
0032       }
0033     } else {
0034       throw cms::Exception("Invalid Constituent") << "TrackJet constituent is not of RecoChargedRefCandidate type";
0035     }
0036     // otherwise return empty ptr
0037   } else {
0038     return edm::Ptr<reco::Track>();
0039   }
0040 }
0041 
0042 std::vector<edm::Ptr<reco::Track> > reco::TrackJet::tracks() const {
0043   std::vector<edm::Ptr<reco::Track> > result;
0044   for (unsigned i = 0; i < numberOfDaughters(); i++)
0045     result.push_back(track(i));
0046   return result;
0047 }
0048 
0049 void reco::TrackJet::resetCharge() {
0050   reco::LeafCandidate::Charge charge = 0;
0051   for (reco::Candidate::const_iterator ida = this->begin(); ida != this->end(); ++ida) {
0052     charge += ida->charge();
0053   }
0054   this->setCharge(charge);
0055 }
0056 
0057 const reco::VertexRef reco::TrackJet::primaryVertex() const { return vtx_; }
0058 
0059 void reco::TrackJet::setPrimaryVertex(const reco::VertexRef& vtx) { vtx_ = vtx; }
0060 
0061 bool reco::TrackJet::overlap(const Candidate& dummy) const { return false; }
0062 
0063 std::string reco::TrackJet::print() const {
0064   std::ostringstream out;
0065   out << Jet::print()  // generic jet info
0066       << "    TrackJet specific:" << std::endl;
0067   if (primaryVertex().get()) {
0068     out << "      Associated PV:"
0069         << " x=" << primaryVertex()->x() << " y=" << primaryVertex()->y() << " z=" << primaryVertex()->z() << std::endl;
0070   } else {
0071     out << "      Associated PV not available on the event" << std::endl;
0072   }
0073   std::vector<edm::Ptr<reco::Track> > thetracks = tracks();
0074   for (unsigned i = 0; i < thetracks.size(); i++) {
0075     if (thetracks[i].get()) {
0076       out << "      #" << i << " px=" << thetracks[i]->px() << " py=" << thetracks[i]->py()
0077           << " pz=" << thetracks[i]->pz() << " eta=" << thetracks[i]->eta() << " phi=" << thetracks[i]->phi()
0078           << std::endl;
0079     } else {
0080       out << "      #" << i << " track is not available in the event" << std::endl;
0081     }
0082   }
0083   return out.str();
0084 }