00001
00002
00003
00004 #include "Rivet/Tools/Logging.hh"
00005 #include "Rivet/Projections/TrackJet.hh"
00006 #include "Rivet/Cmp.hh"
00007 #include "Rivet/RivetCLHEP.hh"
00008 #include <algorithm>
00009
00010 using namespace Rivet;
00011 using namespace CLHEP;
00012 using namespace std;
00013
00014
00015 int TrackJet::compare(const Projection& p) const {
00016 const TrackJet& other = dynamic_cast<const TrackJet&>(p);
00017 return pcmp(*_fsproj, *other._fsproj);
00018 }
00019
00020
00021 void TrackJet::project(const Event & e) {
00022 Log& log = getLog();
00023 _jets.clear();
00024
00025
00026
00027
00028 log << Log::DEBUG << "About to apply the final state projection with eta and pt cuts" << endl;
00029 const FinalState& fs = e.applyProjection(*_fsproj);
00030
00031
00032 vector<LorentzVector> tracksvector;
00033 for (ParticleVector::const_iterator p = fs.particles().begin(); p != fs.particles().end(); ++p) {
00034 HepMC::FourVector fv = p->getMomentum();
00035 LorentzVector lv(fv.px(), fv.py(), fv.pz(), fv.e());
00036 tracksvector.push_back(lv);
00037 }
00038
00039 sort(tracksvector.begin(), tracksvector.end(), compareVecsByPt);
00040
00041 Tracks tracks(tracksvector.begin(), tracksvector.end());
00042
00043
00044 log << Log::DEBUG << "About to assign tracks into jets" << endl;
00045 while (!tracks.empty()) {
00046
00047 Tracks::iterator t = tracks.begin();
00048
00049 const double eta = t->eta();
00050 const double phi = t->phi();
00051
00052
00053 Jet thisjet;
00054 thisjet.addParticle(*t);
00055 tracks.erase(t);
00056
00057
00058 Tracks::iterator t2 = tracks.begin();
00059 while (t2 != tracks.end()) {
00060 log << Log::DEBUG << "Building jet from tracks" << endl;
00061
00062
00063 double Deta = eta - t2->eta();
00064 double Dphi = phi - t2->phi();
00065 if (Dphi > PI) Dphi = 2*PI - Dphi;
00066
00067
00068 if (sqrt(Deta*Deta + Dphi*Dphi) <= 0.7) {
00069
00070 thisjet.addParticle(*t2);
00071 t2 = tracks.erase(t2);
00072 } else {
00073 ++t2;
00074 }
00075 }
00076
00077 _jets.push_back(thisjet);
00078 }
00079
00080
00081 sort(_jets.begin(), _jets.end(), compareJetsByPt);
00082
00083
00084 if (log.isActive(Log::DEBUG)) {
00085 log << Log::DEBUG << "Number of jets = " << _jets.size() << endl;
00086 size_t njet = 1;
00087 for (Jets::const_iterator j = _jets.begin(); j != _jets.end(); ++j)
00088 log << Log::DEBUG << "Number of tracks in jet #" << njet++ << " = " << j->getNumParticles() << endl;
00089 }
00090 }