Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:24:23

0001 // -*- C++ -*-
0002 //
0003 // DipoleSplittingGenerator.h is a part of Herwig - A multi-purpose Monte Carlo event generator
0004 // Copyright (C) 2002-2019 The Herwig Collaboration
0005 //
0006 // Herwig is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef HERWIG_DipoleSplittingGenerator_H
0010 #define HERWIG_DipoleSplittingGenerator_H
0011 //
0012 // This is the declaration of the DipoleSplittingGenerator class.
0013 //
0014 
0015 #include "ThePEG/Handlers/HandlerBase.h"
0016 
0017 #include "Herwig/Shower/Dipole/Kernels/DipoleSplittingKernel.h"
0018 #include "DipoleSplittingReweight.h"
0019 #include "Herwig/Shower/Dipole/Utility/DipoleMCCheck.h"
0020 #include "Herwig/Sampling/exsample/exponential_generator.h"
0021 
0022 #include <tuple>
0023 
0024 namespace Herwig {
0025 
0026 using namespace ThePEG;
0027 
0028 /**
0029  * \ingroup DipoleShower
0030  * \author Simon Platzer, Johannes Bellm
0031  *
0032  * \brief DipoleSplittingGenerator is used by the dipole shower
0033  * to sample splittings from a given dipole splitting kernel.
0034  *
0035  * @see \ref DipoleSplittingGeneratorInterfaces "The interfaces"
0036  * defined for DipoleSplittingGenerator.
0037  */
0038 class DipoleSplittingGenerator: public HandlerBase {
0039 
0040 public:
0041 
0042   /** @name Standard constructors and destructors. */
0043   //@{
0044   /**
0045    * The default constructor.
0046    */
0047   DipoleSplittingGenerator();
0048 
0049   /**
0050    * The destructor.
0051    */
0052   virtual ~DipoleSplittingGenerator();
0053   //@}
0054 
0055 public:
0056 
0057   /**
0058    * Return the dipole splitting kernel.
0059    */
0060   Ptr<DipoleSplittingKernel>::tptr splittingKernel() const;
0061 
0062   /**
0063    * Return the dipole splitting reweight.
0064    */
0065   Ptr<DipoleSplittingReweight>::tptr splittingReweight() const;
0066 
0067   /**
0068    * Return the dipole splitting kinematics.
0069    */
0070   Ptr<DipoleSplittingKinematics>::tptr splittingKinematics() const;
0071 
0072   /**
0073    * Set the dipole splitting kernel.
0074    */
0075   void splittingKernel(Ptr<DipoleSplittingKernel>::tptr sp);
0076 
0077   /**
0078    * Set the dipole splitting reweight.
0079    */
0080   void splittingReweight(Ptr<DipoleSplittingReweight>::tptr sp);
0081 
0082   /**
0083    * Make a wrapper around another generator.
0084    */
0085   void wrap(Ptr<DipoleSplittingGenerator>::ptr other);
0086 
0087   /**
0088    * Return true, if this is actually a wrapper around
0089    * another splitting generator.
0090    */
0091   bool wrapping() const { return theOtherGenerator; }
0092 
0093 public:
0094 
0095   /**
0096    * Reset the current variations to one
0097    */
0098   void resetVariations();
0099 
0100   /**
0101    * Prepare to fill the given splitting.
0102    */
0103   void prepare(const DipoleSplittingInfo&);
0104 
0105   /**
0106    * Fix parameters from the given DipoleSplittingInfo
0107    * and generate the next splitting. Return the
0108    * pt selected for the next splitting.
0109    */
0110   Energy generate(const DipoleSplittingInfo&,
0111           map<string,double>& variations,
0112           Energy optHardPt = ZERO,
0113           Energy optCutoff = ZERO);
0114 
0115   /**
0116    * Fix parameters from the fiven DipoleSplittingInfo
0117    * and generate the next splitting. Return the
0118    * pt selected for the next splitting when called
0119    * from a wrapping generator.
0120    */
0121   Energy generateWrapped(DipoleSplittingInfo&,
0122              map<string,double>& variations,
0123              Energy optHardPt = ZERO,
0124              Energy optCutoff = ZERO);
0125 
0126   /**
0127    * Complete the given splitting.
0128    */
0129   void completeSplitting(DipoleSplittingInfo&) const;
0130 
0131   /**
0132    * Return the last generated splitting
0133    */
0134   const DipoleSplittingInfo& lastSplitting() const { return generatedSplitting; }
0135   
0136  
0137     /// Sample the Sudakov in monte carlo fashion.
0138   double sudakov(const DipoleSplittingInfo&,Energy down);
0139     /// do the actiual calculation of the sudakov exponent.
0140   double dosudakov(const DipoleSplittingInfo&,Energy down);
0141     /// wrapper for sudakovExpansion for identical dipoles.
0142   double wrappedSudakov(DipoleSplittingInfo& split,Energy down);
0143     /// Sample the Sudakov exponent for sudakovExpansion weights
0144   double sudakovExpansion(const DipoleSplittingInfo&,Energy down,Energy fixedScale);
0145     /// do the actual calculation for the sudakov expansion.
0146   double dosudakovExpansion(const DipoleSplittingInfo&,Energy down,Energy fixedScale);
0147     /// wrapper for sudakovExpansion
0148   double wrappedSudakovExpansion(DipoleSplittingInfo& split,Energy down,Energy fixedScale);
0149 
0150   /**
0151    * Turn on partial unweighting and set the reference weight.
0152    */
0153   void doPartialUnweighting(double wref) {
0154     partialUnweighting = true;
0155     theReferenceWeight = wref;
0156   }
0157 
0158 public:
0159 
0160   /**
0161    * Print debug information on the splitting
0162    * handled.
0163    */
0164   void debugGenerator(ostream&) const;
0165 
0166   /**
0167    * Print debug information on the last
0168    * generated event.
0169    */
0170   void debugLastEvent(ostream&) const;
0171 
0172 protected:
0173 
0174   /**
0175    * Update parameters given a splitting.
0176    */
0177   void fixParameters(const DipoleSplittingInfo&,
0178              Energy optHardPt = ZERO);
0179 
0180   /**
0181    * With the parameters previuosly supplied
0182    * through fixParameters generate the next
0183    * splitting.
0184    */
0185   void doGenerate(map<string,double>& variations,
0186           Energy optCutoff = ZERO);
0187 
0188 public:
0189 
0190   /**
0191    * Return the number of random numbers
0192    * needed to sample this kernel.
0193    */
0194   int nDim() const;
0195 
0196   /**
0197    * Flag, which variables are free variables.
0198    */
0199   const vector<bool>& sampleFlags();
0200 
0201   /**
0202    * Return the support of the splitting kernel.
0203    * The lower bound on the first variable is
0204    * assumed to correspond to the cutoff on the
0205    * evolution variable.
0206    */
0207   const pair<vector<double>,vector<double> >& support();
0208 
0209   /**
0210    * Return the parameter point associated to the splitting
0211    * previously supplied through fixParameters.
0212    */
0213   const vector<double>& parameterPoint() const { return parameters; }
0214 
0215   /**
0216    * Indicate that presampling of this kernel
0217    * will be performed in the next calls to
0218    * evaluate until stopPresampling() is called.
0219    */
0220   void startPresampling();
0221 
0222   /**
0223    * Indicate that presampling of this kernel
0224    * is done until startPresampling() is called.
0225    */
0226   void stopPresampling();
0227 
0228   /**
0229    * Return the number of points to presample this
0230    * splitting generator.
0231    */
0232   unsigned long presamplingPoints() const { return splittingKernel()->presamplingPoints(); }
0233 
0234   /**
0235    * Return the maximum number of trials
0236    * to generate a splitting.
0237    */
0238   unsigned long maxtry() const { return splittingKernel()->maxtry(); }
0239 
0240   /**
0241    * Return the number of accepted points after which the grid should
0242    * be frozen
0243    */
0244   unsigned long freezeGrid() const { return splittingKernel()->freezeGrid(); }
0245 
0246   /**
0247    * Return the detuning factor applied to the sampling overestimate kernel
0248    */
0249   double detuning() const { return splittingKernel()->detuning(); }
0250 
0251   /**
0252    * Return true, if this splitting generator
0253    * is able to deliver an overestimate to the sampled
0254    * kernel.
0255    */
0256   bool haveOverestimate() const;
0257 
0258   /**
0259    * Return an overestimate to the sampled kernel.
0260    */
0261   double overestimate(const vector<double>&);
0262 
0263   /**
0264    * Invert the integral over the overestimate to equal
0265    * the given value.
0266    */
0267   double invertOverestimateIntegral(double) const;
0268 
0269   /**
0270    * Evalute the splitting kernel.
0271    */
0272   double evaluate(const vector<double>&);
0273 
0274   /**
0275    * Indicate that a veto with the given kernel value and overestimate has occured.
0276    */
0277   void veto(const vector<double>&, double p, double r);
0278 
0279   /**
0280    * Indicate that an accept with the given kernel value and overestimate has occured.
0281    */
0282   void accept(const vector<double>&, double p, double r);
0283 
0284   /**
0285    * Return the weight associated to the currently generated splitting
0286    */
0287   double splittingWeight() const {
0288     if ( wrapping() )
0289       return theOtherGenerator->splittingWeight();
0290     return theSplittingWeight;
0291   }
0292 
0293   /**
0294    * True, if sampler should apply compensation
0295    */
0296   void doCompensate(bool yes = true) { theDoCompensate = yes; }
0297 
0298   /**
0299    * Return the weight vector associated to the currently generated splitting
0300    */
0301   vector<std::tuple<Energy,double,bool> > splittingWeightVector() const {
0302     if ( wrapping() )
0303       return theOtherGenerator->splittingWeightVector();
0304     return theSplittingWeightVector;
0305   }
0306 
0307 public:
0308 
0309   /**@name Wrap to the exsample2 interface until this is finally cleaned up. */
0310   //@{
0311 
0312   inline const vector<bool>& variable_flags () {
0313     return sampleFlags();
0314   }
0315 
0316   inline size_t evolution_variable () const { return 0; }
0317 
0318   inline double evolution_cutoff () { return support().first[0]; }
0319 
0320   inline const vector<double>& parameter_point () const {
0321     return parameterPoint();
0322   }
0323 
0324   inline void start_presampling () { 
0325     startPresampling();
0326   }
0327 
0328   inline void stop_presampling () { 
0329     stopPresampling();
0330   }
0331 
0332   inline size_t dimension () const { 
0333     return nDim();
0334   }
0335 
0336   inline unsigned long presampling_points () const { 
0337     return presamplingPoints();
0338   }
0339 
0340   //@}
0341 
0342 public:
0343 
0344   /** @name Functions used by the persistent I/O system. */
0345   //@{
0346   /**
0347    * Function used to write out object persistently.
0348    * @param os the persistent output stream written to.
0349    */
0350   void persistentOutput(PersistentOStream & os) const;
0351 
0352   /**
0353    * Function used to read in object persistently.
0354    * @param is the persistent input stream read from.
0355    * @param version the version number of the object when written.
0356    */
0357   void persistentInput(PersistentIStream & is, int version);
0358   //@}
0359 
0360   /**
0361    * The standard Init function used to initialize the interfaces.
0362    * Called exactly once for each class by the class description system
0363    * before the main function starts or
0364    * when this class is dynamically loaded.
0365    */
0366   static void Init();
0367 
0368 protected:
0369 
0370   /** @name Clone Methods. */
0371   //@{
0372   /**
0373    * Make a simple clone of this object.
0374    * @return a pointer to the new object.
0375    */
0376   virtual IBPtr clone() const;
0377 
0378   /** Make a clone of this object, possibly modifying the cloned object
0379    * to make it sane.
0380    * @return a pointer to the new object.
0381    */
0382   virtual IBPtr fullclone() const;
0383   //@}
0384 
0385 
0386 // If needed, insert declarations of virtual function defined in the
0387 // InterfacedBase class here (using ThePEG-interfaced-decl in Emacs).
0388 
0389 private:
0390 
0391   /**
0392    * Pointer to another generator to wrap around.
0393    */
0394   Ptr<DipoleSplittingGenerator>::ptr theOtherGenerator;
0395 
0396   /**
0397    * The dipole splitting kernel to sample
0398    * splitting from.
0399    */
0400   Ptr<DipoleSplittingKernel>::ptr theSplittingKernel;
0401 
0402   /**
0403    * The dipole splitting reweight.
0404    */
0405   Ptr<DipoleSplittingReweight>::ptr theSplittingReweight;
0406 
0407   /**
0408    * Pointer to the exponential generator
0409    */
0410   exsample::exponential_generator<DipoleSplittingGenerator,UseRandom>*
0411   theExponentialGenerator;
0412 
0413   /**
0414    * The dipole splitting to be completed.
0415    */
0416   DipoleSplittingInfo generatedSplitting;
0417 
0418   /**
0419    * A backup of the dipole splitting to be
0420    * completed, if this generator is presampled.
0421    */
0422   DipoleSplittingInfo presampledSplitting;
0423 
0424   /**
0425    * True, if prepared to sample splittings
0426    * of a given kind.
0427    */
0428   bool prepared;
0429 
0430   /**
0431    * Wether or not the kernel is currently
0432    * being presampled.
0433    */
0434   bool presampling;
0435 
0436   /**
0437    * The parameter point.
0438    */
0439   vector<double> parameters;
0440 
0441   /**
0442    * The sampling flags
0443    */
0444   vector<bool> theFlags;
0445 
0446   /**
0447    * The support.
0448    */
0449   pair<vector<double>,vector<double> > theSupport;
0450 
0451   /**
0452    * Pointer to a check histogram object
0453    */
0454   Ptr<DipoleMCCheck>::ptr theMCCheck;
0455 
0456   /**
0457    * True, if sampler should apply compensation
0458    */
0459   bool theDoCompensate;
0460 
0461   /**
0462    * The currently used weight map
0463    */
0464   map<string,double> currentWeights;
0465 
0466   /**
0467    * The weight associated to the currently generated splitting
0468    */
0469   double theSplittingWeight;
0470 
0471 
0472   /**
0473    * Sudakov sampling accuracy
0474    */
0475   double theSudakovAccuracy=0.05;
0476 
0477   /**
0478    * Reference weight to improve convergence for subleading Nc
0479    * corrections (by reducing time spent on events with very
0480    * small weights)
0481    */
0482   double theReferenceWeight;
0483 
0484   /**
0485    * Flag for partial unweighting.
0486    */
0487   bool partialUnweighting = false;
0488 
0489   /**
0490    * The scale, weight and a bool for all veto steps and the accept step.
0491    * The bool is false for a veto step and true for an accept step.
0492    */
0493   vector<std::tuple<Energy,double,bool> > theSplittingWeightVector;
0494 
0495 private:
0496 
0497   /**
0498    * The static object used to initialize the description of this class.
0499    * Indicates that this is a concrete class with persistent data.
0500    */
0501   static ClassDescription<DipoleSplittingGenerator> initDipoleSplittingGenerator;
0502 
0503   /**
0504    * The assignment operator is private and must never be called.
0505    * In fact, it should not even be implemented.
0506    */
0507   DipoleSplittingGenerator & operator=(const DipoleSplittingGenerator &) = delete;
0508 
0509 };
0510 
0511 }
0512 
0513 #include "ThePEG/Utilities/ClassTraits.h"
0514 
0515 namespace ThePEG {
0516 
0517 /** @cond TRAITSPECIALIZATIONS */
0518 
0519 /** This template specialization informs ThePEG about the
0520  *  base classes of DipoleSplittingGenerator. */
0521 template <>
0522 struct BaseClassTrait<Herwig::DipoleSplittingGenerator,1> {
0523   /** Typedef of the first base class of DipoleSplittingGenerator. */
0524   typedef HandlerBase NthBase;
0525 };
0526 
0527 /** This template specialization informs ThePEG about the name of
0528  *  the DipoleSplittingGenerator class and the shared object where it is defined. */
0529 template <>
0530 struct ClassTraits<Herwig::DipoleSplittingGenerator>
0531   : public ClassTraitsBase<Herwig::DipoleSplittingGenerator> {
0532   /** Return a platform-independent class name */
0533   static string className() { return "Herwig::DipoleSplittingGenerator"; }
0534   /**
0535    * The name of a file containing the dynamic library where the class
0536    * DipoleSplittingGenerator is implemented. It may also include several, space-separated,
0537    * libraries if the class DipoleSplittingGenerator depends on other classes (base classes
0538    * excepted). In this case the listed libraries will be dynamically
0539    * linked in the order they are specified.
0540    */
0541   static string library() { return "HwDipoleShower.so"; }
0542 };
0543 
0544 /** @endcond */
0545 
0546 }
0547 
0548 #endif /* HERWIG_DipoleSplittingGenerator_H */