Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // FactoryBase.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_FactoryBase_H
0010 #define THEPEG_FactoryBase_H
0011 //
0012 // This is the declaration of the FactoryBase class.
0013 //
0014 
0015 #include "ThePEG/Interface/Interfaced.h"
0016 #include "FactoryBase.fh"
0017 
0018 namespace AIDA {
0019   class IHistogram1D;
0020   class IHistogram2D;
0021   class IDataPointSet;
0022   class IAnalysisFactory;
0023   class ITree;
0024   class IHistogramFactory;
0025   class IDataPointSetFactory;
0026 }
0027 
0028 namespace ThePEG {
0029 
0030 /**
0031  * Here is the documentation of the FactoryBase class. This
0032  * abstract class is used to wrap the interface to a particular
0033  * AIDA-compliant histogram package to be used in
0034  * <code>AnalysisHandler</code>s in ThePEG. Concrete subclasses must
0035  * implement the doinitrun() function to create an object of a class
0036  * inheriting from AIDA::IAnalysisFactory and assign it with the
0037  * analysisFactory(AIDA::IAnalysisFactory*) function before calling
0038  * doinitrun() for the FactoryBase base class.
0039  *
0040  * A FactoryBase object should be assigned to the EventGenerator
0041  * object controlling a run, and <code>AnalysisHandler</code>s should
0042  * access it via the Generator with the generator() function.
0043  *
0044  * @see \ref FactoryBaseInterfaces "The interfaces"
0045  * defined for FactoryBase.
0046  */
0047 class FactoryBase: public Interfaced {
0048 
0049 public:
0050 
0051   /**
0052    * Convenient typedef for pointer to AIDA::IHistogram1D.
0053    */
0054   typedef AIDA::IHistogram1D * tH1DPtr;
0055 
0056   /**
0057    * Convenient typedef for pointer to const AIDA::IHistogram1D.
0058    */
0059   typedef const AIDA::IHistogram1D * tcH1DPtr;
0060 
0061   /**
0062    * Convenient typedef for pointer to AIDA::IHistogram2D.
0063    */
0064   typedef AIDA::IHistogram2D * tH2DPtr;
0065 
0066   /**
0067    * Convenient typedef for pointer to const AIDA::IHistogram2D.
0068    */
0069   typedef const AIDA::IHistogram2D * tcH2DPtr;
0070 
0071   /**
0072    * Convenient typedef for pointer to AIDA::IHistogram1D.
0073    */
0074   typedef AIDA::IDataPointSet * tDSetPtr;
0075 
0076   /**
0077    * Convenient typedef for pointer to const AIDA::IHistogram1D.
0078    */
0079   typedef const AIDA::IDataPointSet * tcDSetPtr;
0080 
0081 public:
0082 
0083   /**
0084    * DataFiller is a helper class to facilitate adding data to a
0085    * DataPointSet. For a D-dimensional DataPointSet N*3*D numbers should
0086    * be added with the standard &lt;&lt; operator ordered as x-value,
0087    * x-upper-error, x-lower-error, y-value, y-upper-error, etc.. Only
0088    * when the DataFIller object is detleted will the points be added.
0089    */
0090   class DataFiller {
0091 
0092   public:
0093 
0094     /**
0095      * The standard constructor needs a IDataPointSet as argument.
0096      */
0097     DataFiller(AIDA::IDataPointSet * dps) : dset(dps) {}
0098 
0099     /**
0100      * Copy constructor.
0101      */
0102     DataFiller(const DataFiller & df) : dset(df.dset) {}
0103 
0104     /**
0105      * Destructor. Will commit the pints filled to the underlying
0106      * IDataPointSet.
0107      */
0108     ~DataFiller();
0109 
0110     /**
0111      * Add a number to measurement currently being read.
0112      */
0113     DataFiller & operator<<(double x) {
0114       v.push_back(x);
0115       return *this;
0116     }
0117 
0118     /**
0119      * Automatic conversion to the underlying IDataPointSet.
0120      */
0121     operator AIDA::IDataPointSet * () { return dset; }
0122 
0123   private:
0124 
0125     /**
0126      * The underlying IDataPointSet.
0127      */
0128     AIDA::IDataPointSet * dset;
0129 
0130     /**
0131      * The collected numbers to be committed to the IDataPointSet.
0132      */
0133     deque<double> v;
0134 
0135   };
0136 
0137 public:
0138 
0139   /** @name Standard constructors and destructors. */
0140   //@{
0141   /**
0142    * The default constructor.
0143    */
0144   FactoryBase();
0145 
0146   /**
0147    * The copy constructor.
0148    */
0149   FactoryBase(const FactoryBase &);
0150 
0151   /**
0152    * The destructor.
0153    */
0154   virtual ~FactoryBase();
0155   //@}
0156 
0157 public:
0158 
0159   /** @name Simple access functions. */
0160   //@{
0161   /**
0162    * Together with suffix(), the name of the file where the resulting
0163    * histograms will be stored. If empty, generator()->filename() will
0164    * be used instead.
0165    */
0166   const string & filename() const { return theFilename; }
0167 
0168   /**
0169    * Together with filename(), the name of the file where the
0170    * resulting histograms will be stored.
0171    */
0172   const string & suffix() const { return theSuffix; }
0173 
0174   /**
0175    * The format in which the histograms are stored in the output file.
0176    */
0177   const string & storeType() const { return theStoreType; }
0178   //@}
0179 
0180   /** @name Manipulate histograms */
0181   //@{
0182   /**
0183    * Rescale the given \a histogram so that the integral over the bins
0184    * will give the correct integrated cross section for the observable
0185    * in the given \a unit.
0186    */
0187   virtual void
0188   normalizeToXSec(tH1DPtr histogram, CrossSection unit = picobarn) const = 0;
0189 
0190   /**
0191    * Rescale the given \a histogram so that the integral over the bins
0192    * will give the correct integrated cross section for the observable
0193    * in the given \a unit.
0194    */
0195   virtual void
0196   normalizeToXSec(tH2DPtr histogram, CrossSection unit = picobarn) const = 0;
0197 
0198   /**
0199    * Rescale the given \a histogram so that the integral over the bins
0200    * gives the fraction of the total cross section generated which is
0201    * contained in the bins.
0202    */
0203   virtual void normalizeToXSecFraction(tH1DPtr histogram) const = 0;
0204 
0205   /**
0206    * Rescale the given \a histogram so that the integral over the bins
0207    * gives the fraction of the total cross section generated which is
0208    * contained in the bins.
0209    */
0210   virtual void normalizeToXSecFraction(tH2DPtr histogram) const = 0;
0211 
0212   /**
0213    * Rescale the given \a histogram so that the integral over the bins
0214    * gives one.
0215    */
0216   virtual void normalizeToUnity(tH1DPtr histogram) const = 0;
0217 
0218   /**
0219    * Rescale the given \a histogram so that the integral over the bins
0220    * gives one.
0221    */
0222   virtual void normalizeToUnity(tH2DPtr histogram) const = 0;
0223   //@}
0224 
0225   /** @name Access the underlying AIDA objects. */
0226   //@{
0227   /**
0228    * Access the underlying AIDA::IAnalysisFactory object.
0229    */
0230   AIDA::IAnalysisFactory & analysisFactory() const {
0231     return *theAnalysisFactory;
0232   }
0233 
0234   /**
0235    * Access the underlying AIDA::ITree object.
0236    */
0237   AIDA::ITree & tree() const;
0238 
0239   /**
0240    * A pointer to the underlying AIDA::IHistogramFactory object.
0241    */
0242   AIDA::IHistogramFactory & histogramFactory() const;
0243 
0244   /**
0245    * A pointer to the underlying AIDA::IDataPointSetFactory object.
0246    */
0247   AIDA::IDataPointSetFactory & dataSetFactory() const;
0248 
0249   /**
0250    * Create a new directory in the underlying AIDA tree.
0251    */
0252   void mkdir(const string & path);
0253 
0254   /**
0255    * Create a new directory in the underlying AIDA tree.
0256    */
0257   void mkdirs(const string & path);
0258 
0259   /**
0260    * Set the default working directory for the underlying AIDA tree.
0261    */
0262   void cd(const string & path);
0263 
0264   /**
0265    * Create and return a AIDA::IHistogram1D object in the underlying
0266    * AIDA histogram factory. Note that the histogram factory is
0267    * responsible for deleting this histogram.
0268    * @param path the full path of where the histogram should be placed
0269    * in the underlying AIDA tree (on the form
0270    * "/dir/subdir/histogramname"). Not that the directory part of the
0271    * path typically must already exist in the tree. The directories
0272    * can be created with mkdir(string) or mkdirs(string).
0273    * The title of the histogram will be set to the name part of the path.
0274    * @param nb the number of bins in the histogram.
0275    * @param lo the lower edge of the histogram.
0276    * @param up the upper edge of the histogram.
0277    * @return a pointer to the created AIDA::IHistogram1D object.
0278    */
0279   tH1DPtr createHistogram1D(const string & path, int nb, double lo, double up);
0280 
0281   /**
0282    * Create and return a AIDA::IHistogram1D object in the underlying
0283    * AIDA histogram factory. Note that the histogram factory is
0284    * responsible for deleting this histogram.
0285    * @param path the full path of where the histogram should be placed
0286    * in the underlying AIDA tree (on the form
0287    * "/dir/subdir/histogramname"). Not that the directory part of the
0288    * path typically must already exist in the tree. The directories
0289    * can be created with mkdir(string) or mkdirs(string).
0290    * @param title the title of the histogram.
0291    * @param nb the number of bins in the histogram.
0292    * @param lo the lower edge of the histogram.
0293    * @param up the upper edge of the histogram.
0294    * @return a pointer to the created AIDA::IHistogram1D object.
0295    */
0296   tH1DPtr createHistogram1D(const string & path, const string & title, int nb,
0297                 double lo, double up);
0298 
0299   /**
0300    * Create and return a AIDA::IHistogram1D object in the underlying
0301    * AIDA histogram factory. Note that the histogram factory is
0302    * responsible for deleting this histogram.
0303    * @param path the full path of where the histogram should be placed
0304    * in the underlying AIDA tree (on the form
0305    * "/dir/subdir/histogramname"). Not that the directory part of the
0306    * path typically must already exist in the tree. The directories
0307    * can be created with mkdir(string) or mkdirs(string).
0308    * @param title the title of the histogram.
0309    * @param edges A vector of bin edges specifying th bins.
0310    * @return a pointer to the created AIDA::IHistogram1D object.
0311    */
0312   tH1DPtr createHistogram1D(const string & path, const string & title,
0313                 const std::vector<double> & edges);
0314 
0315   /**
0316    * Create and return a AIDA::IHistogram2D object in the underlying
0317    * AIDA histogram factory. Note that the histogram factory is
0318    * responsible for deleting this histogram.
0319    * @param path the full path of where the histogram should be placed
0320    * in the underlying AIDA tree (on the form
0321    * "/dir/subdir/histogramname"). Not that the directory part of the
0322    * path typically must already exist in the tree. The directories
0323    * can be created with mkdir(string) or mkdirs(string).
0324    * The title of the histogram will be set to the name part of the path.
0325    * @param nbx the number of x-bins in the histogram.
0326    * @param xlo the lower x-edge of the histogram.
0327    * @param xup the upper x-edge of the histogram.
0328    * @param nbx the number of y-bins in the histogram.
0329    * @param xlo the lower y-edge of the histogram.
0330    * @param xup the upper y-edge of the histogram.
0331    * @return a pointer to the created AIDA::IHistogram1D object.
0332    */
0333   tH2DPtr createHistogram2D(const string & path,
0334                 int nbx, double xlo, double xup,
0335                 int nby, double ylo, double yup);
0336 
0337   /**
0338    * Create and return a AIDA::IHistogram2D object in the underlying
0339    * AIDA histogram factory. Note that the histogram factory is
0340    * responsible for deleting this histogram.
0341    * @param path the full path of where the histogram should be placed
0342    * in the underlying AIDA tree (on the form
0343    * "/dir/subdir/histogramname"). Not that the directory part of the
0344    * path typically must already exist in the tree. The directories
0345    * can be created with mkdir(string) or mkdirs(string).
0346    * @param title the title of the histogram.
0347    * @param nbx the number of x-bins in the histogram.
0348    * @param xlo the lower x-edge of the histogram.
0349    * @param xup the upper x-edge of the histogram.
0350    * @param nby the number of y-bins in the histogram.
0351    * @param ylo the lower y-edge of the histogram.
0352    * @param yup the upper y-edge of the histogram.
0353    * @return a pointer to the created AIDA::IHistogram1D object.
0354    */
0355   tH2DPtr createHistogram2D(const string & path, const string & title,
0356                 int nbx, double xlo, double xup,
0357                 int nby, double ylo, double yup);
0358 
0359   /**
0360    * Create and return a AIDA::IHistogram2D object in the underlying
0361    * AIDA histogram factory. Note that the histogram factory is
0362    * responsible for deleting this histogram.
0363    * @param path the full path of where the histogram should be placed
0364    * in the underlying AIDA tree (on the form
0365    * "/dir/subdir/histogramname"). Not that the directory part of the
0366    * path typically must already exist in the tree. The directories
0367    * can be created with mkdir(string) or mkdirs(string).
0368    * @param title the title of the histogram.
0369    * @param xedges A vector of bin edges specifying the x-bins.
0370    * @param yedges A vector of bin edges specifying the y-bins.
0371    * @return a pointer to the created AIDA::IHistogram1D object.
0372    */
0373   tH2DPtr createHistogram2D(const string & path, const string & title,
0374                 const std::vector<double> & xedges,
0375                 const std::vector<double> & yedges);
0376 
0377   /**
0378    * Create a IDataPointSet with the given \a path and \a title and
0379    * containing points with the given number of dimensions, \a
0380    * dim. The returned object is a DataFiller which can be used to
0381    * facilitate the addition of data points to the set or be converted
0382    * to a pointer to the created IDataPointSet.
0383    */
0384   DataFiller createDataSet(const string & path, const string & title, int dim);
0385 
0386   /**
0387    * Used by a \a client object to indicate that he has required
0388    * histograms from this factory. It is guaranteed that the clients
0389    * finish() function is called before the underlying AIDA::ITree is
0390    * committed and the AIDA::IHistogramFactory is deleted together
0391    * with all histograms.
0392    */
0393   void registerClient(tIPtr client);
0394   //@}
0395 
0396 protected:
0397 
0398   /**
0399    * Set the underlying AIDA::IAnalysisFactory object. Note that this
0400    * surrenders the controll of the factory to the FactoryBase
0401    * object which will delete it in the finish() function. Typically
0402    * this function should be called by a concrete subclass in the
0403    * doinitrun() function before the doinitrun() function of this
0404    * class is called.
0405    */
0406   void analysisFactory(AIDA::IAnalysisFactory * x) {
0407     theAnalysisFactory = x;
0408   }
0409 
0410   /**
0411    * Delete all associated AIDA objects. Note that the tree is not
0412    * explicitly committed.
0413    */
0414   void clear();
0415 
0416 
0417 public:
0418 
0419   /** @name Functions used by the persistent I/O system. */
0420   //@{
0421   /**
0422    * Function used to write out object persistently.
0423    * @param os the persistent output stream written to.
0424    */
0425   void persistentOutput(PersistentOStream & os) const;
0426 
0427   /**
0428    * Function used to read in object persistently.
0429    * @param is the persistent input stream read from.
0430    * @param version the version number of the object when written.
0431    */
0432   void persistentInput(PersistentIStream & is, int version);
0433   //@}
0434 
0435   /**
0436    * The standard Init function used to initialize the interfaces.
0437    * Called exactly once for each class by the class description system
0438    * before the main function starts or
0439    * when this class is dynamically loaded.
0440    */
0441   static void Init();
0442 
0443 protected:
0444 
0445   /** @name Standard Interfaced functions. */
0446   //@{
0447   /**
0448    * Initialize this object. Called in the run phase just before
0449    * a run begins.
0450    */
0451   virtual void doinitrun();
0452 
0453   /**
0454    * Finalize this object. Called in the run phase just after a
0455    * run has ended. Used eg. to write out statistics.
0456    */
0457   virtual void dofinish();
0458   //@}
0459 
0460 private:
0461 
0462   /**
0463    * Together with theSuffix, the name of the file where the resulting
0464    * histograms will be stored. If empty, generator()->filename() will
0465    * be used instead.
0466    */
0467   string theFilename;
0468 
0469   /**
0470    * Together with theFilename, the name of the file where the
0471    * resulting histograms will be stored.
0472    */
0473   string theSuffix;
0474 
0475   /**
0476    * The format in which the histograms are stored in the output file.
0477    */
0478   string theStoreType;
0479 
0480   /**
0481    * A pointer to the underlying AIDA::IAnalysisFactory object.
0482    */
0483   AIDA::IAnalysisFactory * theAnalysisFactory;
0484 
0485   /**
0486    * A pointer to the underlying AIDA::ITree object.
0487    */
0488   AIDA::ITree * theTree;
0489 
0490   /**
0491    * A pointer to the underlying AIDA::IHistogramFactory object.
0492    */
0493   AIDA::IHistogramFactory * theHistogramFactory;
0494 
0495   /**
0496    * A pointer to the underlying AIDA::IDataPointSetFactory object.
0497    */
0498   AIDA::IDataPointSetFactory * theDataSetFactory;
0499 
0500   /**
0501    * A set of client objects which have required histograms from this
0502    * factory.
0503    */
0504   set<IPtr> clients;
0505 
0506 private:
0507 
0508   /**
0509    * The static object used to initialize the description of this class.
0510    * Indicates that this is an abstract class with persistent data.
0511    */
0512   static AbstractClassDescription<FactoryBase> initFactoryBase;
0513 
0514   /**
0515    * The assignment operator is private and must never be called.
0516    * In fact, it should not even be implemented.
0517    */
0518   FactoryBase & operator=(const FactoryBase &) = delete;
0519 
0520 };
0521 
0522 }
0523 
0524 #include "ThePEG/Utilities/ClassTraits.h"
0525 
0526 namespace ThePEG {
0527 
0528 /** @cond TRAITSPECIALIZATIONS */
0529 
0530 /** This template specialization informs ThePEG about the
0531  *  base classes of FactoryBase. */
0532 template <>
0533 struct BaseClassTrait<FactoryBase,1> {
0534   /** Typedef of the first base class of FactoryBase. */
0535   typedef Interfaced NthBase;
0536 };
0537 
0538 /** This template specialization informs ThePEG about the name of
0539  *  the FactoryBase class and the shared object where it is defined. */
0540 template <>
0541 struct ClassTraits<FactoryBase>
0542   : public ClassTraitsBase<FactoryBase> {
0543   /** Return a platform-independent class name */
0544   static string className() { return "ThePEG::FactoryBase"; }
0545 };
0546 
0547 /** @endcond */
0548 
0549 }
0550 
0551 #endif /* THEPEG_FactoryBase_H */