PandaTree
RRNG.h
1 #ifndef PANDATREE_RRNG
2 #define PANDATREE_RRNG
3 
4 #include "TRandom3.h"
5 #include "TMath.h"
6 #include <vector>
7 #include <utility>
8 
9 #define RRNG_DEBUG 0
10 
11 
12 namespace panda {
13  class RRNG {
14  public:
15  RRNG(int maxEntropy = 50,
16  ULong64_t seed = 0,
17  const ULong64_t* seedAddress = nullptr,
18  bool stream=false);
19  RRNG(RRNG const& other);
20  RRNG(RRNG&& other);
21  ~RRNG() {}
22  RRNG& operator=(const RRNG& other);
23 
24  // configuration
25  void setSize(int maxEntropy);
26  void setFixedSeed(ULong64_t seed) { _seedAddress = nullptr; _editSeed(seed); }
27  void setSeedAddress(const ULong64_t* seedAddress) { _seedAddress = seedAddress; }
28  void setStreaming(bool b = true) { _streaming = b; if (b) { setSize(0); } }
29 
30  // request new data
31  void generate();
32  void generate(ULong64_t seed) { setFixedSeed(seed); generate(); }
33 
34  // various distributions
35  double uniform(int& idx = _default_idx);
36  void normal(double& x1, double& x2, int& idx = _default_idx);
37  double normal(int& idx = _default_idx);
38  double landau(double mu, double sigma, int& idx = _default_idx);
39  double exp(double alpha, int& idx = _default_idx);
40  int poisson(double mu, int& idx = _default_idx);
41 
42  private:
43  static int _default_idx; // used when user does not provide index
44 
45  void _editSeed(ULong64_t seed) { _rng.SetSeed(seed); _currentSeed = seed; }
46  double _requestNumber(int& idx);
47  int _nextAvailable(int start);
48 
49  TRandom3 _rng;
50  int _maxEntropy;
51  const ULong64_t* _seedAddress{nullptr};
52  ULong64_t _currentSeed{0};
53  std::vector<std::pair<double,bool>> _x;
54  bool _streaming;
55  };
56 }
57 
58 
59 #endif
Definition: generate.py:1
Definition: RRNG.h:13
Definition: Array.h:11