Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // ProcessHandler.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_ProcessHandler_H
0010 #define HERWIG_ProcessHandler_H
0011 //
0012 // This is the declaration of the ProcessHandler class.
0013 //
0014 #include "ThePEG/Interface/Interfaced.h"
0015 #include "ThePEG/Handlers/StandardEventHandler.h"
0016 #include "ThePEG/Handlers/StandardXComb.h"
0017 #include "ThePEG/Handlers/SubProcessHandler.h"
0018 #include "ThePEG/Handlers/LuminosityFunction.h"
0019 #include "ThePEG/Repository/EventGenerator.h"
0020 #include "ThePEG/Handlers/SamplerBase.h"
0021 #include "ThePEG/Cuts/Cuts.h"
0022 #include "ThePEG/MatrixElement/MEBase.h"
0023 #include "ThePEG/Handlers/CascadeHandler.h"
0024 
0025 #include <cassert>
0026 
0027 #include "ProcessHandler.fh"
0028 #include "stat.h"
0029 
0030 namespace Herwig {
0031 using namespace ThePEG;
0032 
0033   /** \ingroup UnderlyingEvent
0034    * \class ProcessHandler
0035    * This class is for handling the sampling of 
0036    * semi hard partonic interactions. If several types of partonic interactions
0037    * are needed. Each of them has it's own ProcessHandler. A reference to them is
0038    * stored in MPIHandler, which administers everything.
0039    * 
0040    * \author Manuel B\"ahr
0041    *
0042    * @see \ref ProcessHandlerInterfaces "The interfaces"
0043    * defined for ProcessHandler.
0044    * @see MPISampler
0045    * @see MPIHandler
0046    */
0047 
0048 class ProcessHandler: public Interfaced, public LastXCombInfo<> {
0049 
0050 public:
0051 
0052   /** A weighted list of pointers to StandardXComb objects. */
0053   typedef Selector<StdXCombPtr> XSelector;
0054 
0055   /** A vector of pointers to StandardXComb objects. */
0056   typedef vector<StdXCombPtr> XVector;
0057 
0058   /** A vector of cross sections. */
0059   typedef vector<CrossSection> XSVector;
0060 
0061   /** Map of pointers to StandardXComb objects indexed by pointers to
0062    *  the corresponding MEBase object. */
0063   typedef map<tMEPtr,XVector> MEXMap;
0064 
0065 public:
0066 
0067   /**
0068    * The default constructor.
0069    */
0070   ProcessHandler();
0071 
0072 public:
0073 
0074   /** @name Methods for the MPI generation. */
0075   //@{
0076 
0077   /**
0078    * Select a StandardXComb according to it's weight
0079    * @return that StandardXComb Object
0080    */
0081   inline tStdXCombPtr generate();
0082   //@}
0083 
0084 
0085   /** @name Functions used by the persistent I/O system. */
0086   //@{
0087   /**
0088    * Function used to write out object persistently.
0089    * @param os the persistent output stream written to.
0090    */
0091   void persistentOutput(PersistentOStream & os) const;
0092 
0093   /**
0094    * Function used to read in object persistently.
0095    * @param is the persistent input stream read from.
0096    * @param version the version number of the object when written.
0097    */
0098   void persistentInput(PersistentIStream & is, int version);
0099   //@}
0100 
0101   /**
0102    * The standard Init function used to initialize the interfaces.
0103    * Called exactly once for each class by the class description system
0104    * before the main function starts or
0105    * when this class is dynamically loaded.
0106    */
0107   static void Init();
0108 
0109   /**
0110    * Initialize this Multiple Interaction handler and all related objects needed to
0111    * generate additional events.
0112    */
0113   void initialize(tSubHdlPtr sub, tCutsPtr cuts, tEHPtr eh);
0114 
0115   /**
0116    * Return the integrated cross section.
0117    */
0118   CrossSection integratedXSec() const;
0119 
0120   /**
0121    * Write out accumulated statistics about intergrated cross sections
0122    * and stuff.
0123    */
0124   void statistics(ostream &, Stat &) const;
0125 
0126   /** @name Functions used for the actual generation */
0127   //@{
0128   /**
0129    * Return the cross section for the chosen phase space point.
0130    * @param r a vector of random numbers to be used in the generation
0131    * of a phase space point.
0132    */
0133   virtual CrossSection dSigDR(const vector<double> & r);
0134 
0135 
0136   /** @name Simple access functions. */
0137   //@{
0138 
0139   /**
0140    * The level of statistics. Controlls the amount of statistics
0141    * written out after each run to the <code>EventGenerator</code>s
0142    * <code>.out</code> file. Simply the EventHandler method is called here.
0143    */
0144   inline int statLevel() const;
0145 
0146   /**
0147    * The pair of incoming particle types obtained via the EventHandler
0148    */
0149   inline const cPDPair & incoming() const;
0150 
0151   /**
0152    * Access the luminosity function via the EventHandler.
0153    */
0154   inline const LuminosityFunction & lumiFn() const;
0155 
0156   /**
0157    * The number of phase space dimensions used by the luminosity
0158    * function. Calls the corresponding StandardEventHandler method.
0159    */
0160   inline int lumiDim() const;
0161 
0162   /**
0163    * Return the number of separate bins of StandardXComb objects to
0164    * sample.
0165    */
0166   int nBins() const;
0167 
0168   /**
0169    * Return the number of phase space dimensions needed for the
0170    * sampling of indicated bin of StandardXComb objects.
0171    */
0172   inline int maxDim(int bin) const;
0173 
0174   /**
0175    * The number of dimensions of the basic phase space to generate
0176    * sub-processes in for a given bin of StandardXComb objects.
0177    */
0178   inline int nDim(int bin) const;
0179 
0180   /**
0181    * Return the maximum number attemts allowed to select a sub-process
0182    * for each event. Calls the corresponding StandardEventHandler method.
0183    */
0184   inline long maxLoop() const;
0185 
0186 
0187 protected:
0188 
0189   /**
0190    * Generate a phase space point and return the corresponding cross
0191    * section. Is called from sSigDR(const vector<double> &).
0192    * @param ll a pair of doubles giving the logarithms of the (inverse
0193    * energy fractions of the maximum CMS energy of the incoming
0194    * particles.
0195    * @param maxS the maximum squared CMS energy of the incoming particles.
0196    * @param ibin the preselected bin of StandardXComb objects to choose
0197    * sub-process from
0198    * @param nr the number of random numbers availiable in \a r.
0199    * @param r an array of random numbers to be used to generate a
0200    * phase-space point.
0201    */
0202   virtual CrossSection dSigDR(const pair<double,double> ll, Energy2 maxS,
0203                   int ibin, int nr, const double * r);
0204 
0205 
0206   /**
0207    * Select an StandardXComb. Given a preselected bin, \a ibin of
0208    * StandardXComb objects pick one to generate the corresponding
0209    * sub-process with the given \a weight.
0210    */
0211   tStdXCombPtr select(int bin, double weight);
0212 
0213   /**
0214    * Create and add <code>StandardXComb</code> objects.
0215    *
0216    * @param maxEnergy the maximum CMS energy of the incoming particles.
0217    * @param sub a pointer to the SubProcessHandler object.
0218    * @param extractor a pointer to the PartonExtractor object.
0219    * @param cuts a pointer to the Cuts object.
0220    * @param ckkw a currently empty pointer to a CascadeHandler to be used for CKKW reweighting.
0221    * @param me a pointer to the MEBase object.
0222    * @param pBins a pair of <code>PartonBin</code>s describing the
0223    * partons extracted from the particles
0224    */
0225   void addME(Energy maxEnergy, tSubHdlPtr sub, tPExtrPtr extractor, tCutsPtr cuts, 
0226          tCascHdlPtr ckkw, tMEPtr me, const PBPair & pBins);
0227 
0228   /**
0229    * Return the vector of StandardXComb objects.
0230    */
0231   inline const XVector & xCombs() const;
0232 
0233   /**
0234    * Return the vector of StandardXComb objects.
0235    */
0236   inline XVector & xCombs();
0237 
0238   /**
0239    * Return the vector of cross sections.
0240    */
0241   inline const XSVector & xSecs() const;
0242 
0243   /**
0244    * Return the vector of cross sections.
0245    */
0246   inline XSVector & xSecs();
0247 
0248   /**
0249    * Return the strategy to be used when sampling different StandardXComb
0250    * objects.
0251    * @return 0 if all StandardXComb objects are sampled together. 1 if
0252    * all StandardXComb objects which have the same matrix element object are
0253    * sampled together. 2 if all StandardXComb objects are sampled separately.
0254    */
0255   inline int binStrategy() const;
0256 
0257 
0258   /** @name Clone Methods. */
0259   //@{
0260   /**
0261    * Make a simple clone of this object.
0262    * @return a pointer to the new object.
0263    */
0264   inline virtual IBPtr clone() const;
0265 
0266   /** Make a clone of this object, possibly modifying the cloned object
0267    * to make it sane.
0268    * @return a pointer to the new object.
0269    */
0270   inline virtual IBPtr fullclone() const;
0271   //@}
0272 
0273 private:
0274 
0275   /**
0276    * Return the ThePEG::EventHandler assigned to this handler.
0277    * This methods shadows ThePEG::StepHandler::eventHandler(), because
0278    * it is not virtual in ThePEG::StepHandler. This is ok, because this
0279    * method would give a null-pointer at some stages, whereas this method
0280    * gives access to the explicitely copied pointer (in doinitrun()) 
0281    * to the ThePEG::EventHandler.
0282    */
0283   inline tEHPtr eventHandler() const;
0284 
0285   /**
0286    * Return the sampler assigned to this handler.
0287    */
0288   inline tSamplerPtr sampler();
0289 
0290   /**
0291    * Return the sampler assigned to this handler.
0292    */
0293   inline tcSamplerPtr sampler() const;
0294 
0295   /**
0296    * Return a reference to the Cuts of this
0297    * MultipleInteractionHandler. Note that these cuts may be overridden by the
0298    * SubProcess chosen.
0299    */
0300   inline tCutsPtr cuts() const;
0301 
0302   /**
0303    * Access the sub-process handler.
0304    */
0305   inline tSubHdlPtr subProcess();
0306 
0307 
0308 protected:
0309 
0310   /** @name Standard Interfaced functions. */
0311   //@{
0312   /**
0313    * Initialize this object. Called in the run phase just before
0314    * a run begins.
0315    */
0316   virtual void doinitrun();
0317 
0318   //@}
0319 
0320 private:
0321 
0322   /**
0323    * The assignment operator is private and must never be called.
0324    * In fact, it should not even be implemented.
0325    */
0326   ProcessHandler & operator=(const ProcessHandler &) = delete;
0327 
0328   /**
0329    * The phase space sampler responsible for generating phase space
0330    * points according to the cross section given by this handler.
0331    */
0332   SamplerPtr theSampler;
0333 
0334   /**
0335    * A pointer to the EventHandler that calls us. Has to be saved, because the
0336    * method eventHandler() inherited from ThePEG::StepHandler returns a null-pointer
0337    * sometimes. Leif changed that in r1053 so that a valid pointer is present, when
0338    * calling doinitrun().
0339    */
0340   tEHPtr theHandler;
0341 
0342   /**
0343    * The kinematical cuts used for this collision handler.
0344    */
0345   tCutsPtr theCuts;//used a transient pointer, 
0346   //because regular pointer is already in MPIHandler
0347 
0348 
0349   /**
0350    * The SubProcessHandler that is connected to this ProcessHandler.
0351    */
0352   tSubHdlPtr theSubProcess;//used a transient pointer, 
0353   //because regular pointer is already in MPIHandler
0354 
0355   /**
0356    * The StandardXComb objects.
0357    */
0358   XVector theXCombs;
0359 
0360   /**
0361    * The (incrementally summed) cross sections associated with the
0362    * StandardXComb objects for the last selected phase space point.
0363    */
0364   XSVector theXSecs;
0365 
0366   /**
0367    * The strategy to be used when sampling different StandardXComb
0368    * objects. 0 means all StandardXComb objects are sampled
0369    * together. 1 means all StandardXComb objects which have the same
0370    * matrix element object are sampled together. 2 means all
0371    * StandardXComb objects are sampled separately.
0372    */
0373   int theBinStrategy;
0374 
0375   /**
0376    * The map used to store all XBins with the same matrix element for
0377    * option 1 in theBinStrategy.
0378    */
0379   MEXMap theMEXMap;
0380 
0381 
0382   /**
0383    * The number of degrees of freedom needed to generate the phase
0384    * space for the different bins.
0385    */
0386   vector<int> theMaxDims;
0387 
0388 
0389 
0390 protected:
0391 
0392   /** @cond EXCEPTIONCLASSES */
0393 
0394   /**
0395    * Exception class used by the MultipleInteractionHandler, when something
0396    * during initialization went wrong.
0397    * \todo understand!!!
0398    */
0399   class InitError: public Exception {};
0400 
0401   /** @endcond */
0402 
0403 };
0404 
0405 }
0406 
0407 #include "ProcessHandler.icc"
0408 
0409 #endif /* HERWIG_ProcessHandler_H */