Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

TrackJet.hh

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_TrackJet_HH
00003 #define RIVET_TrackJet_HH
00004 
00005 #include "Rivet/Projection.hh"
00006 #include "Rivet/Projections/FinalState.hh"
00007 #include "Rivet/RivetCLHEP.hh"
00008 
00009 
00010 // *** Only count hits where SUMPT is different from 0! 
00011 
00012 
00013 namespace Rivet {
00014 
00015   namespace {
00016     /// Calculate \f$ p_T^2 \f$ for the provided LorentzVector.
00017     inline double pT2(const LorentzVector& lv) {
00018       return lv.x()*lv.x() + lv.y()*lv.y();
00019     }
00020     
00021     /// Calculate \f$ p_T \f$ for the provided LorentzVector.
00022     inline double pT(const LorentzVector& lv) {
00023       return sqrt(pT2(lv));
00024     }
00025   }
00026 
00027   
00028   /// Project out jets of charged tracks a la CDF.
00029   class TrackJet : public Projection {
00030   public:
00031 
00032     /// @name Standard constructors and destructors.
00033     //@{
00034     /// Constructor. The specified FinalState projection is assumed to live
00035     /// throughout the run and should be used to specify the max and min \f$
00036     /// \eta \f$ values and the min \f$ p_T \f$ (in GeV).
00037     inline TrackJet(FinalState& fsp)
00038       : _fsproj(&fsp)
00039     { 
00040       addProjection(fsp);
00041     }
00042 
00043     /// Typedef for the tracks (a list so that elements can be consistently removed
00044     typedef list<LorentzVector> Tracks;
00045 
00046 
00047   public:    
00048 
00049     /// Inner class used to represent a jet as defined by this algorithm.
00050     class Jet {
00051     public:
00052       /// Constructor.
00053       inline Jet() { 
00054         clear();
00055       }
00056 
00057       /// Define a Jet::iterator via a typedef.
00058       typedef vector<LorentzVector>::iterator iterator;
00059 
00060       /// Define a Jet::const_iterator via a typedef.
00061       typedef vector<LorentzVector>::const_iterator const_iterator;
00062 
00063       /// Get a begin iterator over the particles/tracks in this jet.
00064       inline iterator begin() {
00065         return _particles.begin();
00066       }
00067 
00068       /// Get an end iterator over the particles/tracks in this jet.
00069       inline iterator end() {
00070         return _particles.end();
00071       }
00072 
00073       /// Get a const begin iterator over the particles/tracks in this jet.
00074       inline const_iterator begin() const {
00075         return _particles.begin();
00076       }
00077 
00078       /// Get a const end iterator over the particles/tracks in this jet.
00079       inline const_iterator end() const {
00080         return _particles.end();
00081       }
00082 
00083       /// Get the particles (tracks) in this jet.
00084       inline vector<LorentzVector>& getParticles() {
00085         return _particles;
00086       }
00087 
00088       /// Get the particles (tracks) in this jet (const version).
00089       inline const vector<LorentzVector>& getParticles() const {
00090         return _particles;
00091       }
00092 
00093       /// Set the particles/tracks collection.
00094       inline Jet setParticles(vector<LorentzVector> particles) {
00095         _particles = particles;
00096         _resetCaches();
00097         return *this;
00098       }
00099 
00100       /// Add a particle/track to this jet.
00101       inline Jet addParticle(LorentzVector particle) {
00102         _particles.push_back(particle);
00103         _resetCaches();
00104         return *this;
00105       }
00106 
00107       /// Reset this jet as empty.
00108       inline Jet clear() {
00109         _particles.clear();
00110         _resetCaches();
00111         return *this;
00112       }
00113 
00114       /// Get the average \f$ \phi \f$ for this jet, with the average weighted
00115       /// by the \f$ p_T \f$ values of the constituent tracks. (caches)
00116       inline double getPtWeightedPhi() const {
00117         if (_ptWeightedPhi < 0) {
00118           double ptwphi(0.0), ptsum(0.0);
00119           for (const_iterator p = this->begin(); p != this->end(); ++p) {
00120             double pt = pT(*p);
00121             ptwphi += pt * p->phi();
00122             ptsum += pt;
00123           }
00124           _totalPt = ptsum;
00125           _ptWeightedPhi = ptwphi / getPtSum();
00126         }
00127         return _ptWeightedPhi;
00128       }
00129 
00130       /// Get the sum of the \f$ p_T \f$ values of the constituent tracks. (caches)
00131       inline double getPtSum() const {
00132         if (_totalPt < 0) {
00133           double ptsum(0.0);
00134           for (const_iterator p = this->begin(); p != this->end(); ++p) {
00135             ptsum += pT(*p);
00136           }
00137           _totalPt = ptsum;
00138         }
00139         return _totalPt;
00140       }
00141 
00142       /// Get the number of particles/tracks in this jet.
00143       inline size_t getNumParticles() const {
00144         return _particles.size();
00145       }
00146 
00147 
00148     private:
00149 
00150       /// Clear the internal cached values.
00151       inline Jet _resetCaches() {
00152         _totalPt = -1.0;
00153         _ptWeightedPhi = -1.0;
00154         return *this;
00155       }
00156 
00157       /// The particle tracks.
00158       vector<LorentzVector> _particles;
00159 
00160       /// Cached value of the \f$ p_T \f$-weighted \f$ \bar{\phi} \f$
00161       mutable double _ptWeightedPhi;
00162 
00163       /// Cached value of the \f$ p_T \f$ sum.
00164       mutable double _totalPt;
00165     };
00166 
00167 
00168     /// Typedef for a collection of Jet objects.
00169     typedef vector<Jet> Jets;
00170 
00171 
00172   public:
00173     /// Return the name of the projection
00174     inline string getName() const {
00175       return "TrackJet";
00176     }
00177 
00178     /// Get the computed jets.
00179     inline Jets& getJets() {
00180       return _jets;
00181     }
00182 
00183     /// Get the computed jets (const version).
00184     inline const Jets& getJets() const {
00185       return _jets;
00186     }
00187 
00188   protected:   
00189 
00190     /// Perform the projection on the Event. The collection of jets that results
00191     /// will be sorted in order of decreasing \f$ p_T \f$.
00192     void project(const Event& e);
00193 
00194     /// Compare projections.
00195     int compare(const Projection& p) const;  
00196 
00197   private:
00198     
00199     /// The FinalState projection used by this projection.
00200     FinalState* _fsproj;
00201 
00202     /// The computed jets
00203     Jets _jets;
00204 
00205   private:
00206     
00207     /// Hiding the assignment operator.
00208     //TrackJet& operator=(const TrackJet&);
00209   
00210   };
00211 
00212 
00213   /// Hide helper functions in an anonymous namespace
00214   namespace {
00215     /// Sorts Lorentz four-vectors by pT.
00216     inline bool compareVecsByPt(const LorentzVector& first, const LorentzVector& second) {
00217       return pT2(first) > pT2(second);
00218     }
00219     
00220     /// Sorts Jet objects by pT.
00221     inline bool compareJetsByPt(const TrackJet::Jet& first, const TrackJet::Jet& second) {
00222       return first.getPtSum() > second.getPtSum();
00223     }
00224   }
00225   
00226 
00227   
00228 }
00229 
00230 #endif