Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 //
0003 // Defines the FastPrune Plugin to FastJet.  This is the "pruned" version of
0004 //   a recombination algorithm specifed in the constructor (Cambridge/Aachen and
0005 //   kT are both sensible choices), as described in arXiv:0912.0033.
0006 //
0007 // The helper class PrunedRecombiner is defined in PrunedRecombiner.hh.
0008 //
0009 // When a ClusterSequence created with this plugin calls "run_clustering" on a
0010 //   set of input particles, the following occurs:
0011 //
0012 // 1) Normal jets are formed using the JetDefintion _find_definition.
0013 // 2) For each of these jets, create a second ClusterSequence with the JetDef.
0014 //      _prune_definition and the Recombiner PrunedRecombiner.
0015 //      See comments below for more on how this works.  The pruned jet is the
0016 //      original jet with certain branches removed.
0017 // 3) This creates a pruned jet.  For each of these, the helper function
0018 //      output_mergings takes the cluster sequence from the pruned jet and
0019 //      feeds it into the input ClusterSequence with the
0020 //      plugin_record_{ij,iB}_recombination functions.  This leaves the
0021 //      ClusterSequence holding pruned versions of all the original jets.
0022 // 4) Pruned away branches are marked in the history as entries that are not
0023 //      not subsequently recombined (i.e., child == Invalid).  This means that
0024 //      only inclusive_jets(ptcut) makes sense.  Future versions of this plugin
0025 //      will hopefully include an Extras() object with the ClusterSequence so
0026 //      that the pruned branches can be associated with the points they were
0027 //      pruned from.
0028 //
0029 // An external Recombiner can be passed to the constructor: the
0030 //   PrunedRecombiner will only determine whether to prune a recombination; the
0031 //   external Recombiner will perform the actual recombination.  If a
0032 //   Recombiner is not explicitly passed, the Recombiner from the pruned_def is
0033 //   used -- this will be DefaultRecombiner if not otherwise set.
0034 //
0035 // New in v0.3.4: the plugin now uses the helper class CutSetter to store
0036 //   zcut and Rcut; the user can create their own derived class to set these
0037 //   on a jet-by-jet basis.
0038 //
0039 ///////////////////////////////////////////////////////////////////////////////
0040 
0041 #ifndef __FASTPRUNEPLUGIN_HH__
0042 #define __FASTPRUNEPLUGIN_HH__
0043 
0044 #include "RecoJets/JetAlgorithms/interface/PrunedRecombiner.hh"
0045 
0046 #include "fastjet/ClusterSequence.hh"
0047 #include "fastjet/JetDefinition.hh"
0048 
0049 #include <string>
0050 
0051 FASTJET_BEGIN_NAMESPACE  // defined in fastjet/internal/base.hh
0052 
0053     class FastPrunePlugin : public JetDefinition::Plugin {
0054 public:
0055   class CutSetter;
0056 
0057   /// Constructors for the FastPrunePlugin, whose arguments have the
0058   /// following meaning:
0059   ///
0060   ///   - find_definition, which is a JetDefinition object, specifies which
0061   ///     jet algorithm to run to find jets.
0062   ///
0063   ///   - prune_definition is the algorithm used when pruning the found jet
0064   ///     (typically the same as find_algorithm).  Also a JetDefinition.
0065   ///     The PrunedRecombiner will be used in this definition.
0066   ///
0067   ///   - zcut and Rcut_factor are parameters to the pruning procedure.
0068   ///     Jet alg. prune_algorithm is run as normal, but with infinite R
0069   ///     (actually R = pi/2, since FastJet asserts that R <= pi/2), and
0070   ///     recombinations with DeltaR > Rcut and z < zcut are vetoed, and the
0071   ///     softer PseudoJet is discarded.  (It will appear in the history as a
0072   ///     PJ that never merged again -- it is not merged with the beam!
0073   ///     inclusive_jets(ptCut) should be used to access the pruned jets.
0074   ///     Rcut is chosen for each jet according to
0075   ///           Rcut = Rcut_factor * 2*m/pT,
0076   ///     where m and pT correspond to the four-momentum of the found jet.
0077   ///
0078   ///  - recomb specifies the user's own Recombiner class, useful for
0079   ///    implementing, say, flavor recombination.  The internal PrunedRecombiner
0080   ///    class only checks if pruning should be done.  If this is not passed,
0081   ///    the Recombiner from prune_definition is used instead.
0082   ///
0083   /// Note that the PrunedRecombiner is set up in the constructor, but specific
0084   /// values of Rcut are selected jet-by-jet in run_clustering().
0085   ///
0086   FastPrunePlugin(const JetDefinition &find_definition,
0087                   const JetDefinition &prune_definition,
0088                   const double &zcut = 0.1,
0089                   const double &Rcut_factor = 0.5);
0090 
0091   FastPrunePlugin(const JetDefinition &find_definition,
0092                   const JetDefinition &prune_definition,
0093                   const JetDefinition::Recombiner *recomb,
0094                   const double &zcut = 0.1,
0095                   const double &Rcut_factor = 0.5);
0096 
0097   /// Two new constructors that allow you to pass your own CutSetter.
0098   ///  This lets you define zcut and Rcut on a jet-by-jet basis.
0099   ///  See below for CutSetter definition.
0100   FastPrunePlugin(const JetDefinition &find_definition,
0101                   const JetDefinition &prune_definition,
0102                   CutSetter *const cut_setter);
0103 
0104   FastPrunePlugin(const JetDefinition &find_definition,
0105                   const JetDefinition &prune_definition,
0106                   CutSetter *const cut_setter,
0107                   const JetDefinition::Recombiner *recomb);
0108 
0109   // Get the set of pruned away PseudoJets (valid in pruned ClusterSequence)
0110   // Each vector corresponds to one of the unpruned jets, in pT order
0111   virtual std::vector<std::vector<PseudoJet> > pruned_subjets() const { return _pruned_subjets; }
0112 
0113   // The things that are required by base class.
0114   std::string description() const override;
0115   void run_clustering(ClusterSequence &) const override;
0116 
0117   // Sets minimum pT for unpruned jets (default is 20 GeV)
0118   //  (Just to save time by not pruning jets we don't care about)
0119   virtual void set_unpruned_minpT(double pt) { _minpT = pt; }
0120 
0121   // Access to parameters.
0122   double R() const override { return _find_definition.R(); }
0123   virtual double zcut() const { return _cut_setter->zcut; }
0124   virtual double Rcut() const { return _cut_setter->Rcut; }
0125   // only meaningful for DefaultCutSetter:
0126   virtual double Rcut_factor() const {
0127     if (DefaultCutSetter *cs = dynamic_cast<DefaultCutSetter *>(_cut_setter))
0128       return cs->Rcut_factor;
0129     else
0130       return -1.0;
0131   }
0132 
0133   // ***** DEPRECATED **** -- use FastPruneTool instead; this will be removed
0134   //  in a future release!
0135   // Access to unpruned cluster sequence that gets made along the way
0136   //  This should only be used after run_clustering() has been called,
0137   //  i.e., after the plugin has been used to find jets.  I've added
0138   //  this for speed, so you don't have to duplicate the effort of
0139   //  finding unpruned jets.
0140   virtual ClusterSequence *get_unpruned_sequence() const { return _unpruned_seq; }
0141 
0142   ~FastPrunePlugin() override {
0143     delete _unpruned_seq;
0144     delete _pruned_recombiner;
0145     delete _cut_setter;
0146   }
0147 
0148 protected:
0149   JetDefinition _find_definition;
0150   mutable JetDefinition _prune_definition;  // mutable: we change its Recombiner*
0151   double _minpT;                            // minimum pT for unpruned jets
0152 
0153   mutable std::vector<std::vector<PseudoJet> > _pruned_subjets;
0154   mutable ClusterSequence *_unpruned_seq;
0155 
0156   mutable PrunedRecombiner *_pruned_recombiner;
0157 
0158   // Takes the merging structure of "in_seq" and feeds this into
0159   //  "out_seq" using _plugin_record_{ij,iB}_recombination()
0160   void _output_mergings(ClusterSequence &in_seq, std::vector<int> &pruned_pseudojets, ClusterSequence &out_seq) const;
0161 
0162   // this class stores info on how to dynamically set zcut and Rcut
0163   //  const because we won't change it
0164   CutSetter *_cut_setter;
0165 
0166 public:
0167   /// A helper class to define cuts, possibly on a jet-by-jet basis
0168   class CutSetter {
0169   public:
0170     CutSetter(const double &z = 0.1, const double &R = 0.5) : zcut(z), Rcut(R) {}
0171     double zcut, Rcut;
0172     virtual void SetCuts(const PseudoJet &jet, const ClusterSequence &clust_seq) = 0;
0173     virtual ~CutSetter() {}
0174   };
0175 
0176   /// Default CutSetter implementation: never changes zcut,
0177   ///   and Rcut = Rcut_factor * 2m/pT for a given jet
0178   class DefaultCutSetter : public CutSetter {
0179   public:
0180     DefaultCutSetter(const double &z = 0.1, const double &Rcut_fact = 0.5) : CutSetter(z), Rcut_factor(Rcut_fact) {}
0181     double Rcut_factor;
0182     void SetCuts(const PseudoJet &jet, const ClusterSequence &clust_seq) override {
0183       PseudoJet p1, p2;
0184       if (!clust_seq.has_parents(jet, p1, p2))
0185         Rcut = 0.0;
0186       else
0187         Rcut = Rcut_factor * 2.0 * jet.m() / jet.perp();
0188     }
0189   };
0190 };
0191 
0192 FASTJET_END_NAMESPACE  // defined in fastjet/internal/base.hh
0193 
0194 #endif  // __FASTPRUNEPLUGIN_HH__