Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:19

0001 #ifndef __SISCONEBASEPLUGIN_HH__
0002 #define __SISCONEBASEPLUGIN_HH__
0003 
0004 #include "fastjet/JetDefinition.hh"
0005 #include "fastjet/ClusterSequence.hh"
0006 #include <vector>
0007 #include <memory>
0008 #include <cmath>
0009 
0010 #include <sstream>
0011 
0012 // questionable whether this should be in fastjet namespace or not...
0013 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
0014 
0015 //----------------------------------------------------------------------
0016 //
0017 /// \if internal_doc
0018 /// @ingroup internal
0019 /// \class SISConeBasePlugin
0020 /// Implementation of the SISCone algorithm, base class (plugin for fastjet v2.1 upwards)
0021 ///
0022 /// SISConeBasePlugin is a plugin for fastjet (v2.1 upwards) that
0023 /// provides a base interface to SISCone-type cone jet finder by
0024 /// Gregory Soyez and Gavin Salam.
0025 ///
0026 /// This is a purely virtual class that needs to be overloaded
0027 /// for the specific implementations of SISCone (i.e. regular or
0028 /// spherical as of July 16th 2008).
0029 ///
0030 /// any derived plugin MUST overload the following methods:
0031 ///   description()
0032 ///   run_siscone_clustering()
0033 ///   reset_stored_plugin()
0034 ///
0035 /// For further details, see the derived plugins or
0036 /// http://projects.hepforge.com/siscone
0037 ///
0038 /// \endif
0039 //
0040 class SISConeBasePlugin : public JetDefinition::Plugin {
0041 public:
0042   /// default ctor
0043   SISConeBasePlugin (){
0044     _use_jet_def_recombiner = false;
0045     set_progressive_removal(false);
0046   }
0047 
0048   /// copy constructor
0049   SISConeBasePlugin (const SISConeBasePlugin & plugin) {
0050     *this = plugin;
0051   }
0052 
0053   /// set whether to use SISCone with progressive removal instead of
0054   /// the default split_merge step.
0055   ///
0056   /// If progressive removal is enabled, the following SISCone
0057   /// variables are not used:
0058   ///
0059   /// - overlap_threshold
0060   /// - caching
0061   /// - split_merge_stopping_scale
0062   ///
0063   /// The split_merge_scale choice is reinterpreted as the ordering
0064   /// variable for progressive removal. It is also possible for the
0065   /// user to supply his/her own function for the scale that orders
0066   /// progressive removal, with set_user_scale(...)
0067   void set_progressive_removal(bool progressive_removal_in=true){
0068     _progressive_removal = progressive_removal_in;
0069   }
0070 
0071   /// returns true if progressive_removal is enabled
0072   bool progressive_removal() const{ return _progressive_removal;}
0073 
0074   /// the cone radius
0075   double cone_radius        () const {return _cone_radius        ;}
0076 
0077   /// Fraction of overlap energy in a jet above which jets are merged
0078   /// and below which jets are split.
0079   double overlap_threshold  () const {return _overlap_threshold  ;}
0080 
0081   /// the maximum number of passes of stable-cone searching (<=0 is same
0082   /// as infinity).
0083   int n_pass_max  () const {return _n_pass_max  ;}
0084 
0085   /// set the "split_merge_stopping_scale": if the scale variable for
0086   /// all protojets is below this, then stop the split-merge procedure
0087   /// and keep only those jets found so far. This is useful in
0088   /// determination of areas of hard jets because it can be used to
0089   /// avoid running the split-merging on the pure ghost-part of the
0090   /// event.
0091   void set_split_merge_stopping_scale(double scale) {
0092     _split_merge_stopping_scale = scale;}
0093 
0094   /// return the value of the split_merge_stopping_scale (see
0095   /// set_split_merge_stopping_scale(...) for description)
0096   double split_merge_stopping_scale() {return _split_merge_stopping_scale;}
0097 
0098   /// allow the user to decide if one uses the jet_def's own recombination scheme
0099   void set_use_jet_def_recombiner(bool choice) {_use_jet_def_recombiner = choice;}
0100 
0101   /// indicate if the jet_def's recombination scheme is being used
0102   bool use_jet_def_recombiner() const {return _use_jet_def_recombiner;}
0103 
0104   /// indicates whether caching is turned on or not.
0105   bool caching() const {return _caching ;}
0106 
0107   /// the plugin mechanism's standard way of accessing the jet radius
0108   virtual double R() const {return cone_radius();}
0109 
0110   /// return true since there is specific support for the measurement
0111   /// of passive areas, in the sense that areas determined from all
0112   /// particles below the ghost separation scale will be a passive
0113   /// area. 
0114   virtual bool supports_ghosted_passive_areas() const {
0115     return true;
0116   }
0117   
0118   /// set the ghost separation scale for passive area determinations
0119   /// _just_ in the next run (strictly speaking that makes the routine
0120   /// a non const, so related internal info must be stored as a mutable)
0121   virtual void set_ghost_separation_scale(double scale) const {
0122     _ghost_sep_scale = scale;
0123   }
0124 
0125   virtual double ghost_separation_scale() const {
0126     return _ghost_sep_scale;
0127   }
0128 
0129   // user-defined scale for progressive removal
0130   //------------------------------------------------------------
0131 
0132   /// \class UserScaleBase
0133   /// base class for user-defined ordering of stable cones (used for
0134   /// prorgessive removal)
0135   ///
0136   /// derived classes have to implement the () operator that returns
0137   /// the scale associated with a given jet.
0138   /// 
0139   /// It is also highly recommended to implement the is_larger()
0140   /// method whenever possible, in order to avoid rounding issues
0141   /// known to lead to possible infrared unsafeties.
0142   ///
0143   /// The jets that are passed to this class will carry the structure
0144   /// of type SISConePlugin::StructureType which allows to retreive
0145   /// easily the following information:
0146   ///
0147   ///   vector<PseudoJet> constituents = jet.constituents();
0148   ///   unsigned int n_constituents = jet.structure_of<SISConePlugin::UserScaleBase>().size();
0149   ///   int index = jet.structure_of<SISConePlugin::UserScaleBase>().constituent_index(index i);
0150   ///   const PseudoJet & p = jet.structure_of<SISConePlugin::UserScaleBase>().constituent(index i);
0151   ///   double scalar_pt = jet.structure_of<SISConePlugin::UserScaleBase>().pt_tilde();
0152   ///
0153   /// see SISConePlugin::StructureType below for further details
0154   class UserScaleBase : public FunctionOfPseudoJet<double>{
0155   public:
0156     /// empty virtual dtor
0157     virtual ~UserScaleBase(){}
0158 
0159     /// returns the scale associated with a given jet
0160     ///
0161     /// "progressive removal" iteratively removes the stable cone with
0162     /// the largest scale
0163     virtual double result(const PseudoJet & jet) const = 0;
0164 
0165     /// returns true when the scale associated with jet a is larger than
0166     /// the scale associated with jet b
0167     ///
0168     /// By default this does a simple direct comparison but it can be
0169     /// overloaded for higher precision [recommended if possible]
0170     virtual bool is_larger(const PseudoJet & a, const PseudoJet & b) const;
0171 
0172     class StructureType; // defined below
0173   };
0174 
0175   // template class derived from UserScaleBase::StryctureType that
0176   // works for both SISCone jet classes
0177   // implemented below 
0178   template<class Tjet> 
0179   class UserScaleBaseStructureType;
0180 
0181   /// set a user-defined scale for stable-cone ordering in
0182   /// progressive removal
0183   void set_user_scale(const UserScaleBase *user_scale_in){ _user_scale = user_scale_in;}
0184 
0185   /// returns the user-defined scale in use (0 if none)
0186   const UserScaleBase * user_scale() const{ return _user_scale;}
0187 
0188 
0189   // the things that one MUST overload required by base class
0190   //---------------------------------------------------------
0191 
0192   /// plugin description
0193   virtual std::string description () const =0;
0194 
0195   /// really do the clustering work
0196   virtual void run_clustering(ClusterSequence &) const = 0;
0197 
0198 protected:
0199   double _cone_radius, _overlap_threshold;
0200   int    _n_pass_max;
0201   bool   _caching;//, _split_merge_on_transverse_mass;
0202   double _split_merge_stopping_scale;
0203   bool   _use_jet_def_recombiner;
0204   bool   _progressive_removal;
0205 
0206   mutable double _ghost_sep_scale;
0207 
0208   // the part that HAS to be overloaded
0209   /// call the re-clustering itself 
0210   virtual void reset_stored_plugin() const =0;
0211 
0212   const UserScaleBase * _user_scale;
0213 
0214 };
0215 
0216 
0217 //======================================================================
0218 /// @ingroup extra_info
0219 /// \class SISConeBaseExtras
0220 /// Class that provides extra information about a SISCone clustering
0221 ///
0222 /// This is only the base class that the "regular" and "spherical"
0223 /// implementations of SISCone will have to overload. The only thing
0224 /// that needs to be done for the derived classes is to define
0225 /// '_jet_def_plugin', implement
0226 ///   jet_def_plugin();
0227 /// and add the corresponding plugin class as a friend
0228 class SISConeBaseExtras : public ClusterSequence::Extras {
0229 public:
0230 
0231   /// constructor
0232   //  it just initialises the pass information 
0233   SISConeBaseExtras(int nparticles) : _pass(nparticles*2,-1) {}
0234 
0235   /// purely virtual destructor
0236   inline virtual ~SISConeBaseExtras()=0;
0237 
0238   /// returns a reference to the vector of stable cones (aka protocones)
0239   const std::vector<PseudoJet> & stable_cones() const {return _protocones;}
0240 
0241   /// an old name for getting the vector of stable cones (aka protocones)
0242   const std::vector<PseudoJet> & protocones() const {return _protocones;}
0243 
0244   /// return the # of the pass at which a given jet was found; will
0245   /// return -1 if the pass is invalid
0246   int pass(const PseudoJet & jet) const {return _pass[jet.cluster_hist_index()];}
0247 
0248   /// return a brief summary of the contents of the extras object
0249   /// (specifically, the number of protocones.
0250   std::string description() const{
0251     std::ostringstream ostr;
0252     ostr << "This SISCone clustering found " << protocones().size()
0253      << " stable protocones";
0254     return ostr.str();
0255   };
0256 
0257   /// return the smallest difference in squared distance encountered
0258   /// during splitting between a particle and two overlapping
0259   /// protojets.
0260   inline double most_ambiguous_split() const {return _most_ambiguous_split;}
0261 
0262 protected:
0263   std::vector<PseudoJet> _protocones;
0264   std::vector<int>       _pass;
0265   double                _most_ambiguous_split;
0266   const SISConeBasePlugin * _jet_def_plugin;
0267 };
0268 
0269 /// give the destructor its required implementation
0270 inline SISConeBaseExtras::~SISConeBaseExtras(){}
0271 
0272 //----------------------------------------------------------------------
0273 // implementation of the structure type associated with the UserScaleBase class
0274 
0275 /// \class SISConeBasePlugin::UserScaleBase::StructureType
0276 /// the structure that allows to store the information contained
0277 /// into a siscone::Cjet (built internally in SISCone from a stable
0278 /// cone) into a PseudoJet
0279 class SISConeBasePlugin::UserScaleBase::StructureType : public PseudoJetStructureBase {
0280 public:
0281   /// base ctor (constructed from a ClusterSequence tin order to have
0282   /// access to the initial particles
0283   StructureType(const ClusterSequence &cs)
0284     : _cs(cs){}
0285 
0286   /// empty virtual dtor 
0287   virtual ~StructureType(){}
0288   
0289   //--------------------------------------------------
0290   // members inherited from the base class
0291   /// the textual descripotion
0292   virtual std::string description() const{
0293     return "PseudoJet wrapping a siscone jet from a stable cone"; 
0294   }
0295 
0296   /// this structure has constituents
0297   virtual bool has_constituents() const {return true;}
0298 
0299   /// retrieve the constituents 
0300   ///
0301   /// if you simply need to iterate over the constituents, it will be
0302   /// faster to access them via constituent(i)
0303   virtual std::vector<PseudoJet> constituents(const PseudoJet & /*reference*/) const{ 
0304     std::vector<PseudoJet> constits;
0305     constits.reserve(size());
0306     for (unsigned int i=0; i<size();i++)
0307       constits.push_back(constituent(i));
0308     return constits;
0309   }
0310   
0311   //--------------------------------------------------
0312   // additional information relevant for this structure
0313 
0314   /// returns the number of constituents
0315   virtual unsigned int size() const = 0;
0316 
0317   /// returns the index (in the original particle list) of the ith
0318   /// constituent
0319   virtual int constituent_index(unsigned int i) const = 0;
0320 
0321   /// returns the ith constituent (as a PseusoJet)
0322   const PseudoJet & constituent(unsigned int i) const{
0323     return _cs.jets()[constituent_index(i)];
0324   }
0325 
0326   // /// returns the scalar pt of this stable cone
0327   // virtual double pt_tilde() const = 0;
0328 
0329   /// returns the sm_var2 (signed ordering variable squared) for this stable cone
0330   virtual double ordering_var2() const = 0;
0331 
0332 protected:
0333   const ClusterSequence &_cs; ///< a reference to the CS (for access to the particles)
0334 };
0335 
0336 
0337 ///@ingroup internal
0338 /// template class derived from UserScaleBase::StryctureType that
0339 /// works for both SISCone jet classes
0340 /// implemented below 
0341 template<class Tjet>
0342 class SISConeBasePlugin::UserScaleBaseStructureType : public UserScaleBase::StructureType{
0343 public:
0344   UserScaleBaseStructureType(const Tjet &jet, const ClusterSequence &cs)
0345     : UserScaleBase::StructureType(cs), _jet(jet){}
0346 
0347   /// empty virtual dtor 
0348   virtual ~UserScaleBaseStructureType(){}
0349 
0350   //--------------------------------------------------
0351   // additional information relevant for this structure
0352 
0353   /// returns the number of constituents
0354   virtual unsigned int size() const{
0355     return _jet.n;
0356   }
0357 
0358   /// returns the index (in the original particle list) of the ith
0359   /// constituent
0360   virtual int constituent_index(unsigned int i) const{
0361     return _jet.contents[i];
0362   }
0363 
0364   // /// returns the scalar pt of this stable cone
0365   // virtual double pt_tilde() const{
0366   //   return _jet.pt_tilde;
0367   // }
0368 
0369   /// returns the sm_var2 (signed ordering variable squared) for this stable cone
0370   virtual double ordering_var2() const{
0371     return _jet.sm_var2;
0372   }
0373 
0374 protected:
0375   const Tjet &_jet; ///< a reference to the internal jet in SISCone
0376 };
0377 
0378 
0379 FASTJET_END_NAMESPACE        // defined in fastjet/internal/base.hh
0380 
0381 #endif // __SISCONEBASEPLUGIN_HH__
0382