ThePEG  1.8.0
ACDCGen.h
1 // -*- C++ -*-
2 //
3 // ACDCGen.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef ACDCGen_H
10 #define ACDCGen_H
11 
12 #include "ACDCGenConfig.h"
13 #include "ACDCTraits.h"
14 #include "ACDCGenCell.h"
15 #include "ThePEG/Utilities/Exception.h"
16 
17 namespace ACDCGenerator {
18 
47 template <typename Rnd, typename FncPtr>
48 class ACDCGen {
49 
50 public:
51 
53  typedef Rnd RndType;
57  typedef FncPtr FncPtrType;
59  typedef vector<ACDCGenCell*> CellVector;
61  typedef vector<FncPtrType> FncVector;
63  typedef vector<DimType> DimVector;
65  typedef DimVector::size_type size_type;
68 
69 public:
70 
75  inline ACDCGen(Rnd * r);
76 
80  inline ACDCGen();
81 
85  inline ~ACDCGen();
86 
94  inline bool addFunction(DimType dim, FncPtrType f, double maxrat = -1.0);
95 
99  inline void clear();
100 
101 public:
102 
108  inline FncPtrType generate();
109 
114  inline void reject();
115 
120  inline const DVector & lastPoint() const;
121 
125  inline double lastF() const;
126 
130  inline FncPtrType lastFunction() const;
131 
136  inline size_type last() const;
137 
138 public:
139 
147  inline void eps(double newEps);
148 
154  inline void margin(double newMargin);
155 
161  inline void nTry(size_type newNTry);
162 
167  inline void maxTry(long);
169 
170 public:
171 
178  inline double integral(FncPtrType f = FncPtrType()) const;
179 
185  inline double integralErr(FncPtrType f = FncPtrType()) const;
186 
190  inline long n() const;
191 
197  inline long N() const;
198 
203  inline double efficiency() const;
204 
208  inline int nBins() const;
209 
213  inline int depth() const;
214 
219  inline double maxInt() const;
221 
227  inline double eps() const;
228 
233  inline double margin() const;
234 
239  inline size_type nTry() const;
240 
245  inline long maxTry() const;
246 
252  inline bool cheapRandom() const;
253 
257  inline size_type size() const;
258 
265  inline bool compensating();
266 
271  inline long compleft() const;
272 
276  vector<ACDCGenCellInfo> extractCellInfo() const;
278 
279 public:
280 
288  inline void cheapRandom(bool b);
289 
293  inline void setRnd(Rnd * r);
294 
298  inline double rnd() const;
299 
303  inline double rnd(double lo, double up) const;
304 
308  inline void rnd(const DVector & lo, const DVector & up, DVector & r)const;
309 
314  inline void rnd(DimType D, DVector & r) const;
315 
319  inline long rndInt(long x) const;
321 
322 public:
323 
329  template <typename POStream>
330  void output(POStream &) const;
331 
336  template <typename PIStream>
337  void input(PIStream &);
338 
339 private:
340 
344  inline double doMaxInt();
345 
349  inline const FncVector & functions() const;
350 
354  inline FncPtrType function(size_type i) const;
355 
359  inline const DimVector & dimensions() const;
360 
364  inline DimType dimension(size_type i) const;
365 
370  inline DimType lastDimension() const;
371 
375  inline const CellVector & cells() const;
376 
380  inline ACDCGenCell * cell(size_type i) const;
381 
386  inline ACDCGenCell * lastPrimary() const;
387 
392  inline const DVector & sumMaxInts() const;
393 
397  inline ACDCGenCell * lastCell() const;
398 
399 
404  inline void chooseCell(DVector & lo, DVector & up);
405 
411  inline void compensate(const DVector & lo, const DVector & up);
412 
413 private:
414 
419 
423  long theNAcc;
424 
428  long theN;
429 
433  vector<long> theNI;
434 
439 
444 
448  double theEps;
449 
453  double theMargin;
454 
459 
464  long theMaxTry;
465 
472 
477 
482 
487 
493 
498 
503 
508 
512  double theLastF;
513 
517  struct Level {
518 
522  long lastN;
523 
527  double g;
528 
533 
538 
547 
548  };
549 
553  typedef vector<Level> LevelVector;
554 
559 
560 
565  struct Slicer {
566 
573  Slicer(DimType, ACDCGen &, const DVector &, const DVector &);
574 
579  Slicer(DimType Din, const Slicer & s, ACDCGenCell * cellin,
580  const DVector & loin, const DVector & xselin, const DVector & upin,
581  double fselin);
582 
586  ~Slicer();
587 
591  void divideandconquer();
592 
597  void init();
598 
604  void slice();
605 
610  double shiftmaxmin();
611 
615  void dohalf(DimType);
616 
621  void checkdiag(ACDCGenCell * cell, DimType d, double lod, double upd);
622 
627 
636 
647 
660 
665 
670 
675 
679  double fsel;
680 
685 
693 
702 
706  FncPtr f;
707 
712  double epsilon;
713 
718  double margin;
719 
725  multimap<double,DimType> rateslice;
726 
731  double minf;
732 
737  bool wholecomp;
738 
739  };
740 
741 public:
742 
745 
746 private:
747 
751  ACDCGen(const ACDCGen &);
752 
756  ACDCGen & operator=(const ACDCGen &);
757 
758 };
759 
760 }
761 
762 #include "ACDCGen.icc"
763 
764 #endif