Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // FxFxEventHandler.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_FxFxEventHandler_H
0010 #define THEPEG_FxFxEventHandler_H
0011 //
0012 // This is the declaration of the FxFxEventHandler class.
0013 //
0014 
0015 #include "ThePEG/Handlers/EventHandler.h"
0016 #include "FxFxEventHandler.fh"
0017 #include "FxFxReader.fh"
0018 #include "ThePEG/Utilities/CompSelector.h"
0019 #include "ThePEG/Utilities/XSecStat.h"
0020 
0021 namespace ThePEG {
0022 
0023 /**
0024  * The FxFxEventHandler inherits from the general EventHandler
0025  * class and administers the reading of events generated by external
0026  * matrix element generator programs according to the Les Houches
0027  * accord.
0028  *
0029  * The class has a list of <code>FxFxReader</code>s which
0030  * typically are connected to files with event data produced by
0031  * external matrix element generator programs. When an event is
0032  * requested by FxFxEventHandler, one of the readers are chosen,
0033  * an event is read in and then passed to the different
0034  * <code>StepHandler</code> defined in the underlying
0035  * EventHandler class.
0036  *
0037  * @see \ref FxFxEventHandlerInterfaces "The interfaces"
0038  * defined for FxFxEventHandler.
0039  */
0040 class FxFxEventHandler: public EventHandler {
0041 
0042 public:
0043 
0044   /**
0045    * A vector of FxFxReader objects.
0046    */
0047   typedef vector<FxFxReaderPtr> ReaderVector;
0048 
0049   /**
0050    * A selector of readers.
0051    */
0052   typedef CompSelector<int,CrossSection> ReaderSelector;
0053 
0054   /**
0055    * Enumerate the weighting options.
0056    */
0057   enum WeightOpt {
0058     unitweight = 1,    /**< All events have unit weight. */
0059     unitnegweight = -1, /**< All events have wight +/- 1. */
0060     varweight = 2,      /**< Varying positive weights. */
0061     varnegweight = -2   /**< Varying positive or negative weights. */
0062   };
0063 
0064   friend class FxFxHandler;
0065 
0066 
0067 public:
0068 
0069   /**
0070    * The default constructor.
0071    */
0072   FxFxEventHandler()
0073     : theWeightOption(unitweight), theUnitTolerance(1.0e-6), warnPNum(true), theNormWeight(0), UseLHEEvent(0)
0074   {
0075     selector().tolerance(unitTolerance());
0076   }
0077 
0078 public:
0079 
0080   /** @name Initialization and finalization functions. */
0081   //@{
0082   /**
0083    * Initialize this event handler and all related objects needed to
0084    * generate events.
0085    */
0086   virtual void initialize();
0087 
0088   /**
0089    * Write out accumulated statistics about intergrated cross sections
0090    * and stuff.
0091    */
0092   virtual void statistics(ostream &) const;
0093 
0094   /**
0095    * Histogram scale. A histogram bin which has been filled with the
0096    * weights associated with the Event objects should be scaled by
0097    * this factor to give the correct cross section.
0098    */
0099   virtual CrossSection histogramScale() const;
0100 
0101   /**
0102    * The estimated total integrated cross section of the processes
0103    * generated in this run.
0104    * @return 0 if no integrated cross section could be estimated.
0105    */
0106   virtual CrossSection integratedXSec() const;
0107 
0108   virtual int ntriesinternal() const;
0109 
0110   /**
0111    * The estimated error in the total integrated cross section of the
0112    * processes generated in this run.
0113    *  @return 0 if no integrated cross section error could be estimated.
0114    */
0115   virtual CrossSection integratedXSecErr() const;
0116 
0117   virtual map<string,CrossSection> optintegratedXSecMap() const;
0118 
0119   //@}
0120 
0121   /** @name Functions used for the actual generation */
0122   //@{
0123   /**
0124    * Generate an event.
0125    */
0126   virtual EventPtr generateEvent();
0127 
0128   /**
0129    * Create the Event and Collision objects. Used by the
0130    * generateEvent() function.
0131    */
0132   virtual tCollPtr performCollision();
0133 
0134   /**
0135    * Continue generating an event if the generation has been stopped
0136    * before finishing.
0137    */
0138   virtual EventPtr continueEvent();
0139   //@}
0140 
0141   /** @name Functions to manipulate statistics. */
0142   //@{
0143   /**
0144    * An event has been selected. Signal that an event has been
0145    * selected with the given \a weight. If unit weights are requested,
0146    * the event will be accepted with that weight. This also takes care
0147    * of the statistics collection of the selected reader object.
0148    */
0149   void select(double weight);
0150 
0151   /**
0152    * Accept the current event, taking care of the statistics
0153    * collection of the corresponding reader objects.
0154    */
0155   void accept();
0156 
0157   /**
0158    * Reject the current event, taking care of the statistics
0159    * collection of the corresponding reader objects.
0160    */
0161   void reject(double weight);
0162 
0163   /**
0164    * Increase the overestimated cross section for the selected reader.
0165    */
0166   void increaseMaxXSec(CrossSection maxxsec);
0167 
0168   /**
0169    * Skip some events. To ensure a reader file is scanned an even
0170    * number of times, skip a number of events for the selected reader.
0171    */
0172   void skipEvents();
0173 
0174   //@}
0175 
0176   /** @name Simple access functions. */
0177   //@{
0178   /**
0179    * The way weights are to be treated.
0180    */
0181   WeightOpt weightOption() const { return theWeightOption; }
0182 
0183   /**
0184    * If the weight option is set to unit weight, do not start
0185    * compensating unless the weight is this much larger than unity.
0186    */
0187   double unitTolerance() const { return theUnitTolerance; }
0188 
0189   /**
0190    * Access the list of readers.
0191    */
0192   const ReaderVector & readers() const { return theReaders; }
0193 
0194   /**
0195    * The selector to choose readers according to their overestimated
0196    * cross section.
0197    */
0198   const ReaderSelector & selector() const { return theSelector; }
0199 
0200   /**
0201    * The currently selected reader object.
0202    */
0203   tFxFxReaderPtr currentReader() const { return theCurrentReader; }
0204 
0205 
0206   /**
0207    * Set the currently selected reader object.
0208    */
0209   void currentReader(tFxFxReaderPtr x) { theCurrentReader = x; }
0210 
0211   //@}
0212 
0213 public:
0214 
0215   /** @name Functions used by the persistent I/O system. */
0216   //@{
0217   /**
0218    * Function used to write out object persistently.
0219    * @param os the persistent output stream written to.
0220    */
0221   void persistentOutput(PersistentOStream & os) const;
0222 
0223   /**
0224    * Function used to read in object persistently.
0225    * @param is the persistent input stream read from.
0226    * @param version the version number of the object when written.
0227    */
0228   void persistentInput(PersistentIStream & is, int version);
0229   //@}
0230 
0231   /**
0232    * The standard Init function used to initialize the interfaces.
0233    * Called exactly once for each class by the class description system
0234    * before the main function starts or
0235    * when this class is dynamically loaded.
0236    */
0237   static void Init();
0238 
0239   /**
0240    * The currently selected reader object.
0241    */
0242   tFxFxReaderPtr theCurrentReader;
0243 
0244 
0245 
0246 protected:
0247 
0248   /** @name Clone Methods. */
0249   //@{
0250   /**
0251    * Make a simple clone of this object.
0252    * @return a pointer to the new object.
0253    */
0254   virtual IBPtr clone() const;
0255 
0256   /** Make a clone of this object, possibly modifying the cloned object
0257    * to make it sane.
0258    * @return a pointer to the new object.
0259    */
0260   virtual IBPtr fullclone() const;
0261   //@}
0262 
0263 protected:
0264 
0265   /** @name Standard Interfaced functions. */
0266   //@{
0267   /**
0268    * Initialize this object after the setup phase before saving an
0269    * EventGenerator to disk.
0270    * @throws InitException if object could not be initialized properly.
0271    */
0272   virtual void doinit();
0273 
0274   /**
0275    * Initialize this object. Called in the run phase just before
0276    * a run begins.
0277    */
0278   virtual void doinitrun();
0279 
0280   /**
0281    * Finalize this object. Called in the run phase just after a
0282    * run has ended. Used eg. to write out statistics.
0283    */
0284   virtual void dofinish();
0285   //@}
0286 
0287 protected:
0288 
0289   /**
0290    * Access the list of readers.
0291    */
0292   ReaderVector & readers() { return theReaders; }
0293 
0294   /**
0295    * The selector to choose readers according to their overestimated
0296    * cross section.
0297    */
0298   ReaderSelector & selector() { return theSelector; }
0299 
0300   /**
0301    * Helper function for the interface;
0302    */
0303   void setUnitTolerance(double);
0304 
0305   /**
0306    * Collect statistics for this event handler.
0307    */
0308   XSecStat stats;
0309 
0310   map<string,XSecStat> optstats;
0311 
0312   map<string,CrossSection> optxs;
0313   
0314   int ntries;
0315 
0316   map<string,XSecStat> OptStatsFunc() { return optstats; }
0317 
0318   map<string,CrossSection> OptXsFunc() { return optxs; }
0319 
0320 
0321   /**
0322    * Collect statistics for this event handler. To be used for
0323    * histogram scaling.
0324    */
0325   XSecStat histStats;
0326 
0327   map<string,XSecStat> opthistStats;
0328 
0329 
0330   /*
0331    * The weight identifiers for the events
0332    */ 
0333   
0334   vector<string> weightnames;
0335 
0336 private:
0337 
0338   /**
0339    * The list of readers.
0340    */
0341   ReaderVector theReaders;
0342 
0343   /**
0344    * The selector to choose readers according to their overestimated
0345    * cross section.
0346    */
0347   ReaderSelector theSelector;
0348 
0349   /**
0350    * The way weights are to be treated.
0351    */
0352   WeightOpt theWeightOption;
0353 
0354   /**
0355    * If the weight option is set to unit weight, do not start
0356    * compensating unless the weight is this much larger than unity.
0357    */
0358   double theUnitTolerance;
0359 
0360 
0361   /**
0362    * Warn if the same process number is used in more than one
0363    * FxFxReader.
0364    */
0365   bool warnPNum;
0366 
0367   /**
0368    *  How to normalize the weights
0369    */
0370   unsigned int theNormWeight;
0371 
0372   /** 
0373    * How to number the events
0374    */
0375   unsigned int UseLHEEvent;
0376 
0377 
0378 public:
0379 
0380   /** @cond EXCEPTIONCLASSES */
0381   /**
0382    * Exception class used if no readers were assigned.
0383    */
0384   class FxFxInitError: public InitException {};
0385 
0386   /**
0387    * Exception class used if the same process number is used by more
0388    * than ne reader.
0389    */
0390   class FxFxPNumException: public InitException {};
0391   /** @endcond */
0392 
0393 private:
0394 
0395   /**
0396    * The static object used to initialize the description of this class.
0397    * Indicates that this is a concrete class with persistent data.
0398    */
0399   static ClassDescription<FxFxEventHandler> initFxFxEventHandler;
0400 
0401   /**
0402    * The assignment operator is private and must never be called.
0403    * In fact, it should not even be implemented.
0404    */
0405   FxFxEventHandler & operator=(const FxFxEventHandler &) = delete;
0406 
0407 };
0408 
0409 }
0410 
0411 // CLASSDOC OFF
0412 
0413 #include "ThePEG/Utilities/ClassTraits.h"
0414 
0415 namespace ThePEG {
0416 
0417 /** @cond TRAITSPECIALIZATIONS */
0418 
0419 /** This template specialization informs ThePEG about the
0420  *  base classes of FxFxEventHandler. */
0421 template <>
0422 struct BaseClassTrait<FxFxEventHandler,1> {
0423   /** Typedef of the first base class of FxFxEventHandler. */
0424   typedef EventHandler NthBase;
0425 };
0426 
0427 /** This template specialization informs ThePEG about the name of
0428  *  the FxFxEventHandler class and the shared object where it is defined. */
0429 template <>
0430 struct ClassTraits<FxFxEventHandler>
0431   : public ClassTraitsBase<FxFxEventHandler> {
0432   /** Return a platform-independent class name */
0433   static string className() { return "Herwig::FxFxEventHandler"; }
0434   /** Return the name of the shared library be loaded to get access to
0435    *  the FxFxEventHandler class and every other class it uses
0436    *  (except the base class). */
0437   static string library() { return "HwFxFx.so"; }
0438 };
0439 
0440 /** @endcond */
0441 
0442 }
0443 
0444 #endif /* THEPEG_FxFxEventHandler_H */