-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhybrid_distr.hh
104 lines (74 loc) · 2.96 KB
/
hybrid_distr.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//==============================================================================
// Start of the file "hybrid_distr.hh"
//
// Version 3d.
//
// Written by Vladimir Florinski
//==============================================================================
#ifndef HYBRID_DISTR
#define HYBRID_DISTR
#define GEOM_CYL 0
#define GEOM_SPH 1
#define PDF_ZERO 0
#define PDF_SINGULAR 1
#define PDF_RANGE 2
#define PDF_GAUSS 3
#define PDF_CGAUSS 4
#define PDF_CUSTOM1 5
#define is_cylindrical(x) (x / 100 == GEOM_CYL)
#define is_spherical(x) (x / 100 == GEOM_SPH)
const int n_par = 4; // number of parameters per distribution
const int table_size = 10000; // length of CDF lookup tables
const int icdf_steps = 100; // CDF integration steps per dcdf
const double gauss_width = 3.0; // width of a Gaussian (times sigma)
const bool prefer_cdf = false; // true to prefer CDF lookup
const bool use_forward = true; // true to use forward CDF lookup
//==============================================================================
// The distribution class
//==============================================================================
class distribution_t {
private:
bool geom; // geometry (cylindrical or spherical)
int type1, type2; // types (range, Gauss, etc.)
double params[n_par]; // parameter list
double limits[n_par]; // minimum and maximum values
// PDf and roll functions
double (*PDF_func1) (double param1, double param2, double val);
double (*PDF_func2) (double param1, double param2, double val);
double (*Roll_func1)(double param1, double param2);
double (*Roll_func2)(double param1, double param2);
// CDF tables
double *cdf_table_f1;
double *cdf_table_f2;
double norm_f1, norm_f2;
double *cdf_table_i1;
double *cdf_table_i2;
double norm_i1, norm_i2;
// Binary search of the forward CDF table
double SearchForwardCDF(int table, double val);
// Lookup from the inverse CDF table
double SearchInverseCDF(int table, double val);
// Initialize a cylindrical distribution
void InitCyl(double *p_inp);
// Initialize a spherical distribution
void InitSph(double *p_inp);
// Generates the forward CDF lookup tables
void GenerateForwardTables(int table);
// Generates the inverse CDF lookup tables
void GenerateInverseTables(int table);
public:
// Default constructor
distribution_t();
// Allocate memory, assign the PDF functions and compute the CDF tables
void Activate(int type, double *p_inp);
// Complete class constructor with initialization
distribution_t(int type, double *p_inp);
// Generates an instance of a three-dimensional velocity vector
void RollOne(double *v);
// Class destructor
~distribution_t();
};
#endif
//==============================================================================
// End of the file "hybrid_distr.hh"
//==============================================================================