FastJets.hh

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_FastJets_HH
00003 #define RIVET_FastJets_HH
00004 
00005 #include "Rivet/Projection.hh"
00006 #include "Rivet/Projections/JetAlg.hh"
00007 #include "Rivet/Projections/FinalState.hh"
00008 #include "Rivet/Particle.hh"
00009 #include "Rivet/Jet.hh"
00010 
00011 #include "fastjet/JetDefinition.hh"
00012 #include "fastjet/AreaDefinition.hh"
00013 #include "fastjet/ClusterSequence.hh"
00014 #include "fastjet/ClusterSequenceArea.hh"
00015 #include "fastjet/PseudoJet.hh"
00016 
00017 namespace Rivet {
00018 
00019 
00020   /// Make a 3-momentum vector from a FastJet pseudo-jet
00021   inline Vector3 momentum3(const fastjet::PseudoJet& pj) {
00022     return Vector3(pj.px(), pj.py(), pj.pz());
00023   }
00024 
00025   /// Make a 4-momentum vector from a FastJet pseudo-jet
00026   inline FourMomentum momentum(const fastjet::PseudoJet& pj) {
00027     return FourMomentum(pj.E(), pj.px(), pj.py(), pj.pz());
00028   }
00029 
00030 
00031   /// Typedef for a collection of PseudoJets.
00032   typedef vector<fastjet::PseudoJet> PseudoJets;
00033 
00034 
00035 
00036   /////////////////////////
00037 
00038 
00039 
00040   /// Project out jets found using the FastJet package jet algorithms.
00041   class FastJets : public JetAlg {
00042 
00043   public:
00044     /// Wrapper enum for selected Fastjet jet algorithms.
00045     enum JetAlgName { KT, CAM, SISCONE, ANTIKT, PXCONE,
00046                       CDFJETCLU, CDFMIDPOINT, D0ILCONE,
00047                       JADE, DURHAM, TRACKJET };
00048 
00049 
00050     /// @name Constructors etc.
00051     //@{
00052 
00053     /// "Wrapped" argument constructor using Rivet enums for most common
00054     /// jet alg choices (including some plugins). For the built-in algs,
00055     /// E-scheme recombination is used. For full control of
00056     /// FastJet built-in jet algs, use the native arg constructor.
00057     FastJets(const FinalState& fsp, JetAlgName alg,
00058              double rparameter, double seed_threshold=1.0);
00059 
00060     /// Native argument constructor, using FastJet alg/scheme enums.
00061     FastJets(const FinalState& fsp, fastjet::JetAlgorithm type,
00062              fastjet::RecombinationScheme recom, double rparameter);
00063 
00064     /// Explicitly pass in an externally-constructed plugin
00065     FastJets(const FinalState& fsp, fastjet::JetDefinition::Plugin& plugin);
00066 
00067     // /// Explicit copy constructor.
00068     // FastJets(const FastJets& other);
00069 
00070     /// Clone on the heap.
00071     virtual const Projection* clone() const {
00072       return new FastJets(*this);
00073     }
00074 
00075     //@}
00076 
00077 
00078   public:
00079 
00080     /// Reset the projection. Jet def, etc. are unchanged.
00081     void reset();
00082 
00083     /// @brief Use provided jet area definition
00084     /// @warning adef is NOT copied, the user must ensure that it remains valid!
00085     /// Provide an adef null pointer to re-disable jet area calculation
00086     void useJetArea(fastjet::AreaDefinition* adef) {
00087       _adef = adef;
00088     }
00089 
00090     /// Number of jets above the \f$ p_\perp \f$ cut.
00091     size_t numJets(double ptmin = 0.0) const;
00092 
00093     /// Number of jets.
00094     size_t size() const {
00095       return numJets();
00096     }
00097 
00098     /// Get the jets (unordered).
00099     Jets _jets(double ptmin = 0.0) const;
00100 
00101     /// Get the pseudo jets (unordered).
00102     PseudoJets pseudoJets(double ptmin = 0.0) const;
00103 
00104     /// Get the pseudo jets, ordered by \f$ p_T \f$.
00105     PseudoJets pseudoJetsByPt(double ptmin = 0.0) const {
00106       return sorted_by_pt(pseudoJets(ptmin));
00107     }
00108 
00109     /// Get the pseudo jets, ordered by \f$ E \f$.
00110     PseudoJets pseudoJetsByE(double ptmin = 0.0) const {
00111       return sorted_by_E(pseudoJets(ptmin));
00112     }
00113 
00114     /// Get the pseudo jets, ordered by rapidity.
00115     PseudoJets pseudoJetsByRapidity(double ptmin = 0.0) const {
00116       return sorted_by_rapidity(pseudoJets(ptmin));
00117     }
00118 
00119     /// Return the cluster sequence (FastJet-specific).
00120     const fastjet::ClusterSequence* clusterSeq() const {
00121       return _cseq.get();
00122     }
00123 
00124     /// Return the cluster sequence (FastJet-specific).
00125     const fastjet::ClusterSequenceArea* clusterSeqArea() const {
00126       /// @todo Throw error if no area def? Or just blindly call dynamic_cast?
00127       if (_adef == 0) return (fastjet::ClusterSequenceArea*) 0;
00128       return dynamic_cast<fastjet::ClusterSequenceArea*>(_cseq.get());
00129     }
00130 
00131     /// Return the jet definition (FastJet-specific).
00132     const fastjet::JetDefinition& jetDef() const {
00133       return _jdef;
00134     }
00135 
00136     /// Return the area definition (FastJet-specific). May be null.
00137     const fastjet::AreaDefinition* areaDef() const {
00138       return _adef;
00139     }
00140 
00141     /// Get the subjet splitting variables for the given jet.
00142     vector<double> ySubJet(const fastjet::PseudoJet& jet) const;
00143 
00144     /// @brief Split a jet a la PRL100,242001(2008).
00145     /// Based on code from G.Salam, A.Davison.
00146     fastjet::PseudoJet splitJet(fastjet::PseudoJet jet, double& last_R) const;
00147 
00148     /// @brief Filter a jet a la PRL100,242001(2008).
00149     /// Based on code from G.Salam, A.Davison.
00150     fastjet::PseudoJet filterJet(fastjet::PseudoJet jet, double& stingy_R, const double def_R) const;
00151 
00152   private:
00153 
00154     Jets _pseudojetsToJets(const PseudoJets& pjets) const;
00155 
00156   protected:
00157 
00158     /// Perform the projection on the Event.
00159     void project(const Event& e);
00160 
00161     /// Compare projections.
00162     int compare(const Projection& p) const;
00163 
00164   public:
00165 
00166     /// Do the calculation locally (no caching).
00167     void calc(const ParticleVector& ps);
00168 
00169 
00170   private:
00171 
00172     /// Jet definition
00173     fastjet::JetDefinition _jdef;
00174 
00175     /// Pointer to user-handled area definition
00176     fastjet::AreaDefinition* _adef;
00177 
00178     /// Cluster sequence
00179     shared_ptr<fastjet::ClusterSequence> _cseq;
00180 
00181     /// FastJet external plugin
00182     shared_ptr<fastjet::JetDefinition::Plugin> _plugin;
00183 
00184     /// Map of vectors of y scales. This is mutable so we can use caching/lazy evaluation.
00185     mutable map<int, vector<double> > _yscales;
00186 
00187     /// set of particles sorted by their PT2
00188     //set<Particle, ParticleBase::byPTAscending> _particles;
00189     map<int, Particle> _particles;
00190 
00191   };
00192 
00193 }
00194 
00195 #endif