Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:22

0001 // -*- C++ -*-
0002 //
0003 // StandardEventHandler.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG 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 ThePEG_StandardEventHandler_H
0010 #define ThePEG_StandardEventHandler_H
0011 // This is the declaration of the StandardEventHandler class.
0012 
0013 #include "ThePEG/Config/ThePEG.h"
0014 #include "ThePEG/Handlers/EventHandler.h"
0015 #include "ThePEG/Repository/Strategy.fh"
0016 #include "ThePEG/Handlers/SamplerBase.fh"
0017 #include "ThePEG/PDF/PartonBin.fh"
0018 #include "ThePEG/MatrixElement/MEBase.fh"
0019 #include "SubProcessHandler.fh"
0020 #include "StandardXComb.fh"
0021 #include "StandardEventHandler.fh"
0022 #include "ThePEG/Utilities/XSecStat.h"
0023 #include <fstream>
0024 
0025 namespace ThePEG {
0026 
0027 /**
0028  * The StandardEventHandler class is the main class for generating simple
0029  * events without overlayed collisions. It is derived from the
0030  * basic EventHandler class.
0031  *
0032  * Besides the standard doinit() method, the StandardEventHandler needs to be
0033  * separately initialized with the initialize() method. In the
0034  * dofinish() method statistics is written out to the EventGenerators
0035  * default output file.
0036  *
0037  * @see \ref StandardEventHandlerInterfaces "The interfaces"
0038  * defined for StandardEventHandler.
0039  * @see EventHandler
0040  * @see EventGenerator
0041  * @see Event
0042  * 
0043  */
0044 class StandardEventHandler: public EventHandler {
0045 
0046 public:
0047 
0048   /** A vector of <code>SubProcessHandler</code>s. */
0049   typedef vector<SubHdlPtr> SubHandlerList;
0050 
0051   /** A weighted list of pointers to StandardXComb objects. */
0052   typedef Selector<StdXCombPtr> XSelector;
0053 
0054   /** A vector of pointers to StandardXComb objects. */
0055   typedef vector<StdXCombPtr> XVector;
0056 
0057   /** A vector of cross sections. */
0058   typedef vector<CrossSection> XSVector;
0059 
0060   /** Map of pointers to StandardXComb objects indexed by pointers to
0061    *  the corresponding MEBase object. */
0062   typedef map<tMEPtr,XVector> MEXMap;
0063 
0064 public:
0065 
0066   /** @name Standard constructors and destructors. */
0067   //@{
0068   /**
0069    * Default constructor.
0070    */
0071   StandardEventHandler();
0072 
0073   /**
0074    * Destructor.
0075    */
0076   virtual ~StandardEventHandler();
0077   //@}
0078 
0079 public:
0080 
0081   /**
0082    * Initialize this event handler and all related objects needed to
0083    * generate events.
0084    */
0085   virtual void initialize();
0086 
0087   /**
0088    * Write out accumulated statistics about intergrated cross sections
0089    * and stuff.
0090    */
0091   virtual void statistics(ostream &) const;
0092 
0093   /**
0094    * Return the sampler assigned to this event handler.
0095    */
0096   tSamplerPtr sampler() { return theSampler; }
0097 
0098   /**
0099    * Return the sampler assigned to this event handler.
0100    */
0101   tcSamplerPtr sampler() const { return theSampler; }
0102 
0103   /**
0104    * Histogram scale. A histogram bin which has been filled with the
0105    * weights associated with the Event objects should be scaled by
0106    * this factor to give the correct cross section.
0107    */
0108   virtual CrossSection histogramScale() const;
0109 
0110   /**
0111    * The estimated total integrated cross section of the processes
0112    * generated in this run.
0113    * @return 0 if no integrated cross section could be estimated.
0114    */
0115   virtual CrossSection integratedXSec() const;
0116 
0117   /**
0118    * The estimated error int total integrated cross section of the
0119    * processes generated in this run. 
0120    * @return 0 if no integrated cross section error could be estimated.
0121    */
0122   virtual CrossSection integratedXSecErr() const;
0123 
0124   /**
0125    * The estimated total integrated cross section of the processes
0126    * generated in this run, excluding reweighting.
0127    * @return 0 if no integrated cross section could be estimated.
0128    */
0129   virtual CrossSection integratedXSecNoReweight() const;
0130 
0131   /**
0132    * The estimated error int total integrated cross section of the
0133    * processes generated in this run, excluding reweighting. 
0134    * @return 0 if no integrated cross section error could be estimated.
0135    */
0136   virtual CrossSection integratedXSecErrNoReweight() const;
0137 
0138   /** @name Functions used for the actual generation */
0139   //@{
0140   /**
0141    * Return the cross section for the chosen phase space point.
0142    * @param r a vector of random numbers to be used in the generation
0143    * of a phase space point.
0144    */
0145   virtual CrossSection dSigDR(const vector<double> & r);
0146 
0147   /**
0148    * Generate an event.
0149    */
0150   virtual EventPtr generateEvent();
0151 
0152   /**
0153    * Continue generating an event if the generation has been stopped
0154    * before finishing.
0155    */
0156   virtual EventPtr continueEvent();
0157 
0158   /**
0159    * Reweight a partially generated event.
0160    */
0161   void reweight(double factor) const;
0162 
0163   /**
0164    * Return the vector of StandardXComb objects.
0165    */
0166   const XVector & xCombs() const { return theXCombs; }
0167 
0168   /**
0169    * Change the XComb object
0170    */
0171   virtual void select(tXCombPtr newXComb);
0172 
0173   /**
0174    * Return the boost needed to transform the current event from the
0175    * CMS system to the lab system.
0176    */
0177   const LorentzRotation & currentEventBoost() const { return theCurrentEventBoost; }
0178   //@}
0179 
0180   /** @name Simple access functions */
0181   //@{
0182   /**
0183    * Return a reference to the Cuts of this
0184    * EventHandler. Note that these cuts may be overridden by the
0185    * SubProcess chosen.
0186    */
0187   tCutsPtr cuts() const { return theCuts; }
0188 
0189   /**
0190    * Return the number of separate bins of StandardXComb objects to
0191    * sample.
0192    */
0193   int nBins() const;
0194 
0195   /**
0196    * Return the number of phase space dimensions needed for the
0197    * sampling of indicated bin of StandardXComb objects.
0198    */
0199   int maxDim(int bin) const { return theMaxDims[bin]; }
0200 
0201   /**
0202    * The number of phase space dimensions used by the luminosity
0203    * function.
0204    */
0205   int lumiDim() const { return theLumiDim; }
0206 
0207   /**
0208    * The number of dimensions of the basic phase space to generate
0209    * sub-processes in for a given bin of StandardXComb objects.
0210    */
0211   int nDim(int bin) const { return lumiDim() + maxDim(bin); }
0212   //@}
0213 
0214 protected:
0215 
0216   /**
0217    * Generate a phase space point and return the corresponding cross
0218    * section. Is called from sSigDR(const vector<double> &).
0219    * @param ll a pair of doubles giving the logarithms of the (inverse
0220    * energy fractions of the maximum CMS energy of the incoming
0221    * particles.
0222    * @param maxS the maximum squared CMS energy of the incoming particles.
0223    * @param ibin the preselected bin of StandardXComb objects to choose
0224    * sub-process from
0225    * @param nr the number of random numbers availiable in \a r.
0226    * @param r an array of random numbers to be used to generate a
0227    * phase-space point.
0228    */
0229   virtual CrossSection dSigDR(const pair<double,double> ll, Energy2 maxS,
0230               int ibin, int nr, const double * r);
0231 
0232   /**
0233    * Select an StandardXComb. Given a preselected bin, \a ibin of
0234    * StandardXComb objects pick one to generate the corresponding
0235    * sub-process with the given \a weight.
0236    */
0237   tStdXCombPtr select(int bin, double & weight);
0238 
0239   /**
0240    * Create and add <code>StandardXComb</code> objects.
0241    *
0242    * @param maxEnergy the maximum CMS energy of the incoming particles.
0243    * @param sub a pointer to the SubProcessHandler object.
0244    * @param extractor a pointer to the PartonExtractor object.
0245    * @param cuts a pointer to the Cuts object.
0246    * @param ckkw a pointer to a CascadeHandler to be used for CKKW reweighting.
0247    * @param me a pointer to the MEBase object.
0248    * @param pBins a pair of <code>PartonBin</code>s describing the
0249    * partons extracted from the particles
0250    * @param allPBins all available parton bins at the given energy
0251    */
0252   void addME(Energy maxEnergy, tSubHdlPtr sub, tPExtrPtr extractor,
0253          tCutsPtr cuts, tCascHdlPtr ckkw, tMEPtr me, const PBPair & pBins,
0254          const PartonPairVec& allPBins);
0255 
0256   /**
0257    * For the sub-procss and phase-space point selected in the previous
0258    * call to dSigDR, produce the first step of an actual Collision.
0259    */
0260   tCollPtr performCollision();
0261 
0262   /**
0263    * Initialize groups of <code>StepHandler</code>s. This overrides
0264    * the method in the EventHandler, and the
0265    * <code>StepHandler</code>s given in the currently selected
0266    * SubProcess take precedence over the ones specified in the
0267    * EventHandler sub class.
0268    */
0269   virtual void initGroups();
0270 
0271   /**
0272    * Return the boost needed to transform the current collision from
0273    * the CMS system to the lab system. By default this is the unit
0274    * transformation, but an EventHandler derived from this class may
0275    * override it.
0276    */
0277   LorentzRotation & currentEventBoost() { return theCurrentEventBoost; }
0278 
0279   /**
0280    * Set information about the current sub-process.
0281    */
0282   void setScale(Energy2);
0283 
0284   /**
0285    * Return the vector of StandardXComb objects.
0286    */
0287   XVector & xCombs()  { return theXCombs; }
0288 
0289   /**
0290    * Throw away the last generated event before generating a new one.
0291    */
0292   virtual void clean();
0293 
0294 private:
0295 
0296   /**
0297    * Access the list of sub-process handlers.
0298    */
0299   const SubHandlerList & subProcesses() const { return theSubProcesses; }
0300 
0301   /**
0302    * Access the list of sub-process handlers.
0303    */
0304   SubHandlerList & subProcesses() { return theSubProcesses; }
0305 
0306 public:
0307 
0308   /** @name Standard Interfaced functions. */
0309   //@{
0310   /**
0311    * Check sanity of the object during the setup phase.
0312    */
0313   virtual void doupdate();
0314 
0315   /**
0316    * Initialize this object after the setup phase before saving an
0317    * EventGenerator to disk.
0318    * @throws InitException if object could not be initialized properly.
0319    */
0320   virtual void doinit();
0321 
0322   /**
0323    * Initialize this object. Called in the run phase just before
0324    * a run begins.
0325    */
0326   virtual void doinitrun();
0327 
0328   /**
0329    * Finalize this object. Called in the run phase just after a
0330    * run has ended. Writes out statistics on the generation.
0331    */
0332   virtual void dofinish();
0333   //@}
0334 
0335   /** @name Functions used by the persistent I/O system. */
0336   //@{
0337   /**
0338    * Function used to write out object persistently.
0339    * @param os the persistent output stream written to.
0340    */
0341   void persistentOutput(PersistentOStream & os) const;
0342 
0343   /**
0344    * Function used to read in object persistently.
0345    * @param is the persistent input stream read from.
0346    * @param version the version number of the object when written.
0347    */
0348   void persistentInput(PersistentIStream & is, int version);
0349   //@}
0350 
0351   /**
0352    * Standard Init function used to initialize the interface.
0353    */
0354   static void Init();
0355 
0356 protected:
0357 
0358   /** @name Clone Methods. */
0359   //@{
0360   /**
0361    * Make a simple clone of this object.
0362    * @return a pointer to the new object.
0363    */
0364   virtual IBPtr clone() const;
0365 
0366   /** Make a clone of this object, possibly modifying the cloned object
0367    * to make it sane.
0368    * @return a pointer to the new object.
0369    */
0370   virtual IBPtr fullclone() const;
0371   //@}
0372 
0373   /**
0374    * Reject a (partially) generated event.
0375    * @param weight the weight given for the event.
0376    */
0377   void reject(double weight);
0378 
0379 private:
0380 
0381   /**
0382    * The first of the incoming particle types.
0383    */
0384 
0385   PDPtr theIncomingA;
0386   /**
0387    * The second of the incoming particle types.
0388    */
0389 
0390   PDPtr theIncomingB;
0391 
0392   /**
0393    * The list of <code>SubProcessHandler</code>s.
0394    */
0395   SubHandlerList theSubProcesses;
0396 
0397   /**
0398    * The kinematical cuts used for this collision handler.
0399    */
0400   CutsPtr theCuts;
0401 
0402   /**
0403    * True if cuts on collision objects should be performed
0404    */
0405   bool collisionCuts;
0406 
0407   /**
0408    * The StandardXComb objects.
0409    */
0410   XVector theXCombs;
0411 
0412   /**
0413    * The number of degrees of freedom needed to generate the phase
0414    * space for the different bins.
0415    */
0416   vector<int> theMaxDims;
0417 
0418   /**
0419    * The boost needed to transform the current collision from the CMS
0420    * system to the lab system.
0421    */
0422   LorentzRotation theCurrentEventBoost;
0423 
0424   /**
0425    * The phase space sampler responsible for generating phase space
0426    * points according to the cross section given by this event
0427    * handler.
0428    */
0429   SamplerPtr theSampler;
0430 
0431   /**
0432    * The number of phase space dimensions used by the luminosity
0433    * function.
0434    */
0435   int theLumiDim;
0436 
0437   /**
0438    * The overall cross section statistics
0439    */
0440   mutable XSecStat xSecStats;
0441 
0442   /**
0443    * Standard Initialization object.
0444    */
0445   static ClassDescription<StandardEventHandler> initStandardEventHandler;
0446 
0447   /**
0448    * Helper function for the interface.
0449    */
0450   void setIncomingA(PDPtr);
0451 
0452   /**
0453    * Helper function for the interface.
0454    */
0455   void setIncomingB(PDPtr);
0456 
0457 protected:
0458 
0459   /** @cond EXCEPTIONCLASSES */
0460   /**
0461    * Exception class used by EventHandler when a StepHandler of the
0462    * wrong class was added.
0463    */
0464   class StandardEventHandlerUpdateException: public UpdateException {};
0465 
0466   /**
0467    * Exception class used by EventHandler when a StepHandler of the
0468    * wrong class was added.
0469    */
0470   class StandardEventHandlerInitError: public Exception {};
0471   /** @endcond */
0472 
0473 private:
0474 
0475   /**
0476    * Private and non-existent assignment operator.
0477    */
0478   const StandardEventHandler & operator=(const StandardEventHandler &) = delete;
0479 
0480 };
0481 
0482 /** @cond TRAITSPECIALIZATIONS */
0483 
0484 /**
0485  * The following template specialization informs ThePEG about the
0486  * base class of StandardEventHandler.
0487  */
0488 template <>
0489 struct BaseClassTrait<StandardEventHandler,1>: public ClassTraitsType {
0490   /** Typedef of the base class of StandardEventHandler. */
0491   typedef EventHandler NthBase;
0492 };
0493 
0494 /**
0495  * The following template specialization informs ThePEG about the name
0496  * of theEventHandler class and the shared object where it is defined.
0497  */
0498 template <>
0499 struct ClassTraits<StandardEventHandler>
0500   : public ClassTraitsBase<StandardEventHandler> {
0501   /**
0502    * Return the class name.
0503    */
0504   static string className() { return "ThePEG::StandardEventHandler"; }
0505 };
0506 
0507 /** @endcond */
0508 
0509 }
0510 
0511 #endif /* ThePEG_StandardEventHandler_H */