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