00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ACDCGen_H
00010 #define ACDCGen_H
00011
00012 #include "ACDCGenConfig.h"
00013 #include "ACDCTraits.h"
00014 #include "ACDCGenCell.h"
00015 #include "ThePEG/Utilities/Exception.h"
00016
00017 namespace ACDCGenerator {
00018
00047 template <typename Rnd, typename FncPtr>
00048 class ACDCGen {
00049
00050 public:
00051
00053 typedef Rnd RndType;
00055 typedef ACDCRandomTraits<RndType> RndTraits;
00057 typedef FncPtr FncPtrType;
00059 typedef vector<ACDCGenCell*> CellVector;
00061 typedef vector<FncPtrType> FncVector;
00063 typedef vector<DimType> DimVector;
00065 typedef DimVector::size_type size_type;
00067 typedef ACDCFncTraits<FncPtrType> FncTraits;
00068
00069 public:
00070
00075 inline ACDCGen(Rnd * r);
00076
00080 inline ACDCGen();
00081
00085 inline ~ACDCGen();
00086
00094 inline bool addFunction(DimType dim, FncPtrType f, double maxrat = -1.0);
00095
00099 inline void clear();
00100
00101 public:
00102
00108 inline FncPtrType generate();
00109
00114 inline void reject();
00115
00120 inline const DVector & lastPoint() const;
00121
00125 inline double lastF() const;
00126
00130 inline FncPtrType lastFunction() const;
00131
00136 inline size_type last() const;
00137
00138 public:
00139
00147 inline void eps(double newEps);
00148
00154 inline void margin(double newMargin);
00155
00161 inline void nTry(size_type newNTry);
00162
00167 inline void maxTry(long);
00169
00170 public:
00171
00178 inline double integral(FncPtrType f = FncPtrType()) const;
00179
00185 inline double integralErr(FncPtrType f = FncPtrType()) const;
00186
00190 inline long n() const;
00191
00197 inline long N() const;
00198
00203 inline double efficiency() const;
00204
00208 inline int nBins() const;
00209
00213 inline int depth() const;
00214
00219 inline double maxInt() const;
00221
00227 inline double eps() const;
00228
00233 inline double margin() const;
00234
00239 inline size_type nTry() const;
00240
00245 inline long maxTry() const;
00246
00252 inline bool cheapRandom() const;
00253
00257 inline size_type size() const;
00258
00265 inline bool compensating();
00266
00271 inline long compleft() const;
00272
00276 vector<ACDCGenCellInfo> extractCellInfo() const;
00278
00279 public:
00280
00288 inline void cheapRandom(bool b);
00289
00293 inline void setRnd(Rnd * r);
00294
00298 inline double rnd() const;
00299
00303 inline double rnd(double lo, double up) const;
00304
00308 inline void rnd(const DVector & lo, const DVector & up, DVector & r)const;
00309
00314 inline void rnd(DimType D, DVector & r) const;
00315
00319 inline long rndInt(long x) const;
00321
00322 public:
00323
00329 template <typename POStream>
00330 void output(POStream &) const;
00331
00336 template <typename PIStream>
00337 void input(PIStream &);
00338
00339 private:
00340
00344 inline double doMaxInt();
00345
00349 inline const FncVector & functions() const;
00350
00354 inline FncPtrType function(size_type i) const;
00355
00359 inline const DimVector & dimensions() const;
00360
00364 inline DimType dimension(size_type i) const;
00365
00370 inline DimType lastDimension() const;
00371
00375 inline const CellVector & cells() const;
00376
00380 inline ACDCGenCell * cell(size_type i) const;
00381
00386 inline ACDCGenCell * lastPrimary() const;
00387
00392 inline const DVector & sumMaxInts() const;
00393
00397 inline ACDCGenCell * lastCell() const;
00398
00399
00404 inline void chooseCell(DVector & lo, DVector & up);
00405
00411 inline void compensate(const DVector & lo, const DVector & up);
00412
00413 private:
00414
00418 RndType * theRnd;
00419
00423 long theNAcc;
00424
00428 long theN;
00429
00433 vector<long> theNI;
00434
00438 DVector theSumW;
00439
00443 DVector theSumW2;
00444
00448 double theEps;
00449
00453 double theMargin;
00454
00458 size_type theNTry;
00459
00464 long theMaxTry;
00465
00471 bool useCheapRandom;
00472
00476 FncVector theFunctions;
00477
00481 DimVector theDimensions;
00482
00486 CellVector thePrimaryCells;
00487
00492 DVector theSumMaxInts;
00493
00497 size_type theLast;
00498
00502 ACDCGenCell * theLastCell;
00503
00507 DVector theLastPoint;
00508
00512 double theLastF;
00513
00517 struct Level {
00518
00522 long lastN;
00523
00527 double g;
00528
00532 ACDCGenCell * cell;
00533
00537 size_type index;
00538
00542 DVector up;
00546 DVector lo;
00547
00548 };
00549
00553 typedef vector<Level> LevelVector;
00554
00558 LevelVector levels;
00559
00560
00565 struct Slicer {
00566
00573 Slicer(DimType, ACDCGen &, const DVector &, const DVector &);
00574
00579 Slicer(DimType Din, const Slicer & s, ACDCGenCell * cellin,
00580 const DVector & loin, const DVector & xselin, const DVector & upin,
00581 double fselin);
00582
00586 ~Slicer();
00587
00591 void divideandconquer();
00592
00597 void init();
00598
00604 void slice();
00605
00610 double shiftmaxmin();
00611
00615 void dohalf(DimType);
00616
00621 void checkdiag(ACDCGenCell * cell, DimType d, double lod, double upd);
00622
00626 DimType D;
00627
00631 DVector lo;
00635 DVector up;
00636
00641 DVector xcl;
00646 DVector xcu;
00647
00653 DVector xhl;
00659 DVector xhu;
00660
00664 DVector fhl;
00665
00669 DVector fhu;
00670
00674 DVector xsel;
00675
00679 double fsel;
00680
00684 ACDCGenCell * current;
00685
00692 ACDCGenCell * first;
00693
00697 DVector firstlo;
00701 DVector firstup;
00702
00706 FncPtr f;
00707
00712 double epsilon;
00713
00718 double margin;
00719
00725 multimap<double,DimType> rateslice;
00726
00731 double minf;
00732
00737 bool wholecomp;
00738
00739 };
00740
00741 public:
00742
00744 static size_type maxsize;
00745
00746 private:
00747
00751 ACDCGen(const ACDCGen &);
00752
00756 ACDCGen & operator=(const ACDCGen &);
00757
00758 };
00759
00760 }
00761
00762 #include "ACDCGen.icc"
00763
00764 #endif