Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // ShowerApproximationKernel.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_ShowerApproximationKernel_H
0010 #define Herwig_ShowerApproximationKernel_H
0011 //
0012 // This is the declaration of the ShowerApproximationKernel class.
0013 //
0014 
0015 #include "ThePEG/Handlers/HandlerBase.h"
0016 #include "ThePEG/Handlers/StandardXComb.h"
0017 #include "Herwig/MatrixElement/Matchbox/Matching/ShowerApproximation.h"
0018 #include "Herwig/MatrixElement/Matchbox/Phasespace/InvertedTildeKinematics.h"
0019 #include "Herwig/MatrixElement/Matchbox/Dipoles/SubtractionDipole.h"
0020 #include "Herwig/Sampling/exsample/exponential_generator.h"
0021 
0022 namespace Herwig {
0023 
0024 using namespace ThePEG;
0025 
0026 class ShowerApproximationGenerator;
0027 
0028 /**
0029  * \ingroup Matchbox
0030  * \author Simon Platzer
0031  *
0032  * \brief ShowerApproximationKernel generates emissions according to a
0033  * shower approximation entering a NLO matching.
0034  *
0035  */
0036 class ShowerApproximationKernel: public HandlerBase {
0037 
0038 public:
0039 
0040   /**
0041    * Exception to communicate sampler maxtry events.
0042    */
0043   struct MaxTryException {};
0044 
0045 public:
0046 
0047   /**
0048    * The default constructor.
0049    */
0050   ShowerApproximationKernel();
0051 
0052 public:
0053 
0054   /**
0055    * Set the XComb object describing the Born process
0056    */
0057   void setBornXComb(tStdXCombPtr xc) { theBornXComb = xc; }
0058 
0059   /**
0060    * Return the XComb object describing the Born process
0061    */
0062   tcStdXCombPtr bornCXComb() const { return theBornXComb; }
0063 
0064   /**
0065    * Return the XComb object describing the Born process
0066    */
0067   tStdXCombPtr bornXComb() const { return theBornXComb; }
0068 
0069   /**
0070    * Set the XComb object describing the real emission process
0071    */
0072   void setRealXComb(tStdXCombPtr xc) { theRealXComb = xc; }
0073 
0074   /**
0075    * Return the XComb object describing the real emission process
0076    */
0077   tcStdXCombPtr realCXComb() const { return theRealXComb; }
0078 
0079   /**
0080    * Return the XComb object describing the real emission process
0081    */
0082   tStdXCombPtr realXComb() const { return theRealXComb; }
0083 
0084   /**
0085    * Set the tilde xcomb objects associated to the real xcomb
0086    */
0087   void setTildeXCombs(const vector<StdXCombPtr>& xc) { theTildeXCombs = xc; }
0088 
0089   /**
0090    * Return the tilde xcomb objects associated to the real xcomb
0091    */
0092   const vector<StdXCombPtr>& tildeXCombs() const { return theTildeXCombs; }
0093 
0094   /**
0095    * Set the dipole in charge for the emission
0096    */
0097   void setDipole(Ptr<SubtractionDipole>::tptr dip) { theDipole = dip; }
0098 
0099   /**
0100    * Return the dipole in charge for the emission
0101    */
0102   Ptr<SubtractionDipole>::tptr dipole() const { return theDipole; }
0103 
0104   /**
0105    * Set the shower approximation.
0106    */
0107   void showerApproximation(Ptr<ShowerApproximation>::tptr app) { theShowerApproximation = app; }
0108 
0109   /**
0110    * Return the shower approximation.
0111    */
0112   Ptr<ShowerApproximation>::tptr showerApproximation() const { return theShowerApproximation; }
0113 
0114   /**
0115    * Set the shower approximation generator.
0116    */
0117   void showerApproximationGenerator(Ptr<ShowerApproximationGenerator>::tptr);
0118 
0119   /**
0120    * Return the shower approximation generator.
0121    */
0122   Ptr<ShowerApproximationGenerator>::tptr showerApproximationGenerator() const;
0123 
0124   /**
0125    * Generate the next emission
0126    */
0127   double generate();
0128 
0129 public:
0130 
0131   /**
0132    * Set a pt cut on the dipole to generate the radiation
0133    */
0134   void ptCut(Energy pt) { dipole()->ptCut(pt); }
0135 
0136   /**
0137    * Return the number of random numbers
0138    * needed to sample this kernel.
0139    */
0140   int nDim() const {
0141     return 
0142       nDimBorn() +
0143       dipole()->nDimRadiation();
0144   }
0145 
0146   /**
0147    * Return the number of random numbers
0148    * needed to sample the Born process.
0149    */
0150   int nDimBorn() const {
0151     return bornCXComb()->lastRandomNumbers().size();
0152   }
0153 
0154   /**
0155    * Flag, which variables are free variables.
0156    */
0157   const vector<bool>& sampleFlags();
0158 
0159   /**
0160    * Return the support of the splitting kernel.
0161    * The lower bound on the first variable is
0162    * assumed to correspond to the cutoff on the
0163    * evolution variable.
0164    */
0165   const pair<vector<double>,vector<double> >& support();
0166 
0167   /**
0168    * Return the parameter point associated to the splitting
0169    * previously supplied through fixParameters.
0170    */
0171   const vector<double>& parameterPoint();
0172 
0173   /**
0174    * Indicate that presampling of this kernel
0175    * will be performed in the next calls to
0176    * evaluate until stopPresampling() is called.
0177    */
0178   void startPresampling();
0179 
0180   /**
0181    * Indicate that presampling of this kernel
0182    * is done until startPresampling() is called.
0183    */
0184   void stopPresampling();
0185 
0186   /**
0187    * Indicate that a veto with the given kernel value and overestimate has occured.
0188    */
0189   void veto(const vector<double>&, double, double) {
0190     /** use born and real xcombs in here to figure out what we need to reweight;
0191     it should have its kinematic variables completed at this step */
0192   }
0193 
0194   /**
0195    * Indicate that an accept with the given kernel value and overestimate has occured.
0196    */
0197   void accept(const vector<double>&, double, double) {
0198     /** use born and real xcombs in here to figure out what we need to reweight;
0199     it should have its kinematic variables completed at this step */
0200   }
0201 
0202   /**
0203    * Return true, if currently being presampled
0204    */
0205   bool presampling() const { return thePresampling; }
0206 
0207   /**
0208    * Return the number of points to presample this
0209    * splitting generator.
0210    */
0211   unsigned long presamplingPoints() const { return thePresamplingPoints; }
0212 
0213   /**
0214    * Return the maximum number of trials
0215    * to generate a splitting.
0216    */
0217   unsigned long maxtry() const { return theMaxTry; }
0218 
0219   /**
0220    * Return the number of accepted points after which the grid should
0221    * be frozen
0222    */
0223   unsigned long freezeGrid() const { return theFreezeGrid; }
0224 
0225   /**
0226    * Set the number of points to presample this
0227    * splitting generator.
0228    */
0229   void presamplingPoints(unsigned long p) { thePresamplingPoints = p; }
0230 
0231   /**
0232    * Set the maximum number of trials
0233    * to generate a splitting.
0234    */
0235   void maxtry(unsigned long p) { theMaxTry = p; }
0236 
0237   /**
0238    * Set the number of accepted points after which the grid should
0239    * be frozen
0240    */
0241   void freezeGrid(unsigned long n) { theFreezeGrid = n; }
0242 
0243   /**
0244    * Evalute the splitting kernel.
0245    */
0246   double evaluate(const vector<double>&);
0247 
0248   /**
0249    * Return the index of the random number corresponding
0250    * to the evolution variable.
0251    */
0252   int evolutionVariable() const {
0253     return
0254       nDimBorn() +
0255       (showerApproximation()->showerInvertedTildeKinematics() ?
0256        showerApproximation()->showerInvertedTildeKinematics()->evolutionVariable() :
0257        dipole()->invertedTildeKinematics()->evolutionVariable());
0258   }
0259 
0260   /**
0261    * Return the cutoff on the evolution
0262    * random number corresponding to the pt cut.
0263    */
0264   double evolutionCutoff() const {
0265     return 
0266       showerApproximation()->showerInvertedTildeKinematics() ?
0267       showerApproximation()->showerInvertedTildeKinematics()->evolutionCutoff() :
0268       dipole()->invertedTildeKinematics()->evolutionCutoff();
0269   }
0270 
0271   /**
0272    * True, if sampler should apply compensation
0273    */
0274   void doCompensate(bool yes = true) { theDoCompensate = yes; }
0275 
0276 public:
0277 
0278   /**@name Wrap to the exsample2 interface until this is finally cleaned up. */
0279   //@{
0280 
0281   inline const vector<bool>& variable_flags () {
0282     return sampleFlags();
0283   }
0284 
0285   inline size_t evolution_variable () const { return evolutionVariable(); }
0286 
0287   inline double evolution_cutoff () const { 
0288     return evolutionCutoff();
0289   }
0290 
0291   inline const vector<double>& parameter_point () {
0292     return parameterPoint();
0293   }
0294 
0295   inline void start_presampling () { 
0296     startPresampling();
0297   }
0298 
0299   inline void stop_presampling () { 
0300     stopPresampling();
0301   }
0302 
0303   inline size_t dimension () const { 
0304     return nDim();
0305   }
0306 
0307   inline unsigned long presampling_points () const { 
0308     return presamplingPoints();
0309   }
0310 
0311   //@}
0312 
0313 public:
0314 
0315   /** @name Functions used by the persistent I/O system. */
0316   //@{
0317   /**
0318    * Function used to write out object persistently.
0319    * @param os the persistent output stream written to.
0320    */
0321   void persistentOutput(PersistentOStream & os) const;
0322 
0323   /**
0324    * Function used to read in object persistently.
0325    * @param is the persistent input stream read from.
0326    * @param version the version number of the object when written.
0327    */
0328   void persistentInput(PersistentIStream & is, int version);
0329   //@}
0330 
0331   /**
0332    * The standard Init function used to initialize the interfaces.
0333    * Called exactly once for each class by the class description system
0334    * before the main function starts or
0335    * when this class is dynamically loaded.
0336    */
0337   static void Init();
0338 
0339 protected:
0340 
0341   /** @name Clone Methods. */
0342   //@{
0343   /**
0344    * Make a simple clone of this object.
0345    * @return a pointer to the new object.
0346    */
0347   virtual IBPtr clone() const;
0348 
0349   /** Make a clone of this object, possibly modifying the cloned object
0350    * to make it sane.
0351    * @return a pointer to the new object.
0352    */
0353   virtual IBPtr fullclone() const;
0354   //@}
0355 
0356 
0357 // If needed, insert declarations of virtual function defined in the
0358 // InterfacedBase class here (using ThePEG-interfaced-decl in Emacs).
0359 
0360 
0361 private:
0362 
0363   /**
0364    * The dipole in charge of the emission
0365    */
0366   Ptr<SubtractionDipole>::ptr theDipole;
0367 
0368   /**
0369    * The shower approximation to consider
0370    */
0371   Ptr<ShowerApproximation>::ptr theShowerApproximation;
0372 
0373   /**
0374    * The XComb off which radiation will be generated
0375    */
0376   StdXCombPtr theBornXComb;
0377 
0378   /**
0379    * The XComb describing the process after radiation
0380    */
0381   StdXCombPtr theRealXComb;
0382 
0383   /**
0384    * The tilde xcomb objects associated to the real xcomb
0385    */
0386   vector<StdXCombPtr> theTildeXCombs;
0387 
0388   /**
0389    * True, if currently being presampled
0390    */
0391   bool thePresampling;
0392 
0393   /**
0394    * The number of points to presample this
0395    * splitting generator.
0396    */
0397   unsigned long thePresamplingPoints;
0398 
0399   /**
0400    * The maximum number of trials
0401    * to generate a splitting.
0402    */
0403   unsigned long theMaxTry;
0404 
0405   /**
0406    * Return the number of accepted points after which the grid should
0407    * be frozen
0408    */
0409   unsigned long theFreezeGrid;
0410 
0411   /**
0412    * The sampling flags
0413    */
0414   vector<bool> theFlags;
0415 
0416   /**
0417    * The support.
0418    */
0419   pair<vector<double>,vector<double> > theSupport;
0420 
0421   /**
0422    * The shower approximation generator.
0423    */
0424   Ptr<ShowerApproximationGenerator>::tptr theShowerApproximationGenerator;
0425 
0426   /**
0427    * The last parameter point
0428    */
0429   vector<double> theLastParameterPoint;
0430 
0431   /**
0432    * The last random numbers used for Born sampling
0433    */
0434   vector<double> theLastBornPoint;
0435 
0436   /**
0437    * Define the Sudakov sampler
0438    */
0439   typedef
0440   exsample::exponential_generator<ShowerApproximationKernel,UseRandom>
0441   ExponentialGenerator;
0442 
0443   /**
0444    * Define a pointer to the Sudakov sampler
0445    */
0446   typedef
0447   exsample::exponential_generator<ShowerApproximationKernel,UseRandom>*
0448   ExponentialGeneratorPtr;
0449 
0450   /**
0451    * The Sudakov sampler
0452    */
0453   ExponentialGeneratorPtr sampler;
0454 
0455   /**
0456    * True, if sampler should apply compensation
0457    */
0458   bool theDoCompensate;
0459 
0460   /**
0461    * The assignment operator is private and must never be called.
0462    * In fact, it should not even be implemented.
0463    */
0464   ShowerApproximationKernel & operator=(const ShowerApproximationKernel &) = delete;
0465 
0466 };
0467 
0468 }
0469 
0470 #endif /* Herwig_ShowerApproximationKernel_H */