Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // ACDCGenCell.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 ACDCGenCell_H
0010 #define ACDCGenCell_H
0011 
0012 #include "ACDCGenConfig.h"
0013 #include "ACDCTraits.h"
0014 
0015 namespace ACDCGenerator {
0016 
0017 struct ACDCGenCellInfo;
0018 
0019 /** ACDCGenCell is the class representing a generation cell in ACDCGen. */
0020 class ACDCGenCell {
0021 
0022 public:
0023 
0024   /**
0025    * Constructor taking the maximum value as argument.
0026    */
0027   inline ACDCGenCell(double newG);
0028 
0029   /**
0030    * Constructor taking the maximum value and the volume as argument.
0031    */
0032   inline ACDCGenCell(double newG, double newV);
0033 
0034   /**
0035    * The destuctor will also delete all child cells.
0036    */
0037   inline ~ACDCGenCell();
0038 
0039   /**
0040    * Choose a cell recursively according to their relative
0041    * overestimated integrals.
0042    * @param lo the lower-left corner of the chosen cell.
0043    * @param up the upper-right corner of the chosen cell.
0044    * @param rnd the random generator object used to throw dice to
0045    * choose sub-cell.
0046    * @return a pointer to the chosen cell.
0047    */
0048   template <typename RndType>
0049   inline ACDCGenCell * generate(DVector & lo, DVector & up, RndType * rnd);
0050 
0051   /**
0052    * Choose a cell recursively according to their relative
0053    * overestimated integrals.
0054    * @param lo the lower-left corner of the chosen cell.
0055    * @param up the upper-right corner of the chosen cell.
0056    * @param rndv a pre-generated set of random numbers (one for each
0057    * dimension) used to choose sub-cell and then rescales that random
0058    * number to be reused by the sub-cell.
0059    * @return a pointer to the chosen cell.
0060    */
0061   inline ACDCGenCell * generate(DVector & lo, DVector & up, DVector & rndv);
0062 
0063   /**
0064    * Find a cell. For a given phase space point, \a x, find the
0065    * corresponding cell. Afterwards, the \a up and \a lo vectors will
0066    * contain the upper-right and lower-left corners of the chosen
0067    * cell.
0068    */
0069   inline ACDCGenCell * getCell(DVector & lo, const DVector & x, DVector &  up);
0070 
0071   /**
0072    * Smooth out the levels. If one cell has an overestimated integral
0073    * which is less than \a frac of the adjacent one, rescale it to
0074    * avoid situations where it is never sampled.
0075    */
0076   inline void smooth(double frac);
0077 
0078   /**
0079    * Returns true if this cell has been split.
0080    */
0081   inline bool isSplit() const;
0082 
0083   /**
0084    * Recalculate (recursively) the overestimated integral for this
0085    * cell (and of the sub-cells) and return it. Optionally \a rescale
0086    * the overestimated integral.
0087    */
0088   inline double doMaxInt(double rescale = 1.0);
0089 
0090   /**
0091    * Return the last calculated the overestimated integral for this
0092    * cell.
0093    */
0094   inline double maxInt() const;
0095 
0096   /**
0097    * Split this cell into two. The cell is split along the \a newDim
0098    * direction, where the lower and upper limit is given by \a lo and
0099    * \a up and the point of division is given by \a newDiv.
0100    */
0101   inline void splitme(double lo, double newDiv, double up, DimType newDim);
0102 
0103   /**
0104    * Set a new overestimated maximum function value in this cell.
0105    */
0106   inline void g(double newG);
0107 
0108   /**
0109    * Return the overestimated maximum function value in this cell.
0110    */
0111   inline double g() const;
0112 
0113   /**
0114    * Return the volume of this cell.
0115    */
0116   inline double v() const;
0117 
0118   /**
0119    * Return the direction in which it has been split. Return -1 if it
0120    * has not been split.
0121    */
0122   inline DimType dim() const;
0123 
0124   /**
0125    * Return the point of division in the dim() direction. Return -1.0
0126    * if it has not been split.
0127    */
0128   inline double div() const;
0129 
0130   /**
0131    * Return the upper sub-cell. Return null if it has not been split.
0132    */
0133   inline ACDCGenCell * upper() const;
0134 
0135   /**
0136    * Return the lower sub-cell. Return null if it has not been split.
0137    */
0138   inline ACDCGenCell * lower() const;
0139 
0140   /**
0141    * Return the number of cells in this sub-tree which have not been
0142    * split.
0143    */
0144   inline int nBins() const;
0145 
0146   /**
0147    * Return the maximum depth of this sub-tree.
0148    */
0149   inline int depth() const;
0150 
0151   /**
0152    * Append ACDCGenCellInfo objects describing this subtree to a given
0153    * vector.
0154    * @param lo the lower-left corner of this cell.
0155    * @param up the upper-right corner of this cell.
0156    * @param v the vector where the ACDCGenCellInfo objects will be appended.
0157    */
0158   inline void extract(DVector & lo, DVector & up,
0159               vector<ACDCGenCellInfo> & v) const;
0160 
0161   /**
0162    * Get the index of the given cell.
0163    */
0164   inline long getIndex(const ACDCGenCell * c) const;
0165 
0166   /**
0167    * Helper function for getIndex(const ACDCGenCell *) with an extra
0168    * argument to use as counter.
0169    */
0170   inline long getIndex(const ACDCGenCell * c, long & indx) const;
0171    
0172   /**
0173    * Return the cell corresponding to the given index \a i.
0174    */
0175   inline ACDCGenCell * getCell(long i);
0176 
0177   /**
0178    * Helper function for getCell(long) with an extra argument to use as
0179    * counter.
0180    */
0181   inline ACDCGenCell * getCell(long i, long & indx);
0182 
0183 public:
0184 
0185   /**
0186    * If the cell has not been split this is the overestimated maximum
0187    * function value in this cell. Otherwise it is the weighted
0188    * average of the sub-cells values.
0189    */
0190   double theG;
0191 
0192   /**
0193    * The volume of this cell.
0194    */
0195   double theV;
0196 
0197   /**
0198    * Pointers to the upper sub-cell.
0199    */
0200   ACDCGenCell * theUpper;
0201 
0202   /**
0203    * Pointers to the lower sub-cell.
0204    */
0205   ACDCGenCell * theLower;
0206 
0207   /**
0208    * The point of division in the dim() direction.
0209    */
0210   double theDivision;
0211 
0212   /**
0213    * The direction in which it has been split.
0214    */
0215   DimType theSplitDimension;
0216 
0217 private:
0218 
0219   /**
0220    * Default constructor is private and not implemented.
0221    */
0222   ACDCGenCell();
0223 
0224   /**
0225    * Copy constructor is private and not implemented.
0226    */
0227   ACDCGenCell(const ACDCGenCell &);
0228 
0229   /**
0230    * Assignment is private and not implemented.
0231    */
0232   ACDCGenCell & operator=(const ACDCGenCell &) = delete;
0233 
0234 };
0235 
0236 
0237 /**
0238  * This is a class describing cells to the outside world to be used
0239  * for debugging purposes. They only make sense if extracted with the
0240  * ACDCGenCell::extract function.
0241  */
0242 struct ACDCGenCellInfo {
0243 
0244   /** the integer used for indices. */
0245   typedef vector<ACDCGenCellInfo>::size_type Index;
0246 
0247   /**
0248    * The overestimated maximum function value of this cell.
0249    */
0250   double g;
0251 
0252   /**
0253    * The volume of the corresponding cell.
0254    */
0255   double v;
0256 
0257   /**
0258    * The upper-right corner of the corresponding cell.
0259    */
0260   DVector up;
0261   /**
0262    * The lower-left corner of the corresponding cell.
0263    */
0264   DVector lo;
0265 
0266   /**
0267    * The index of the upper sub-cells in the vector in which the
0268    * corresponding cell was inserted.
0269    */
0270   Index iup;
0271 
0272   /**
0273    * The index of the lower sub-cell in the vector in which the
0274    * corresponding cell was inserted.
0275    */
0276   Index ilo;
0277 
0278 };
0279 
0280 }
0281 
0282 #include "ACDCGenCell.icc"
0283 
0284 #endif