Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Heed::PointsRan Class Reference

#include <PointsRan.h>

Public Member Functions

 PointsRan ()
 
 PointsRan (const std::vector< double > &fx, const std::vector< double > &fy, double fxmin, double fxmax)
 
double ran (double flat_ran) const
 
double get_integ_total () const
 
double get_integ_active () const
 
void print (std::ostream &file) const
 

Detailed Description

Generates random numbers according to array. This class generates random numbers according to a pointwise distribution, with linear interpolation between given points and also with linear extrapolation.

Definition at line 24 of file PointsRan.h.

Constructor & Destructor Documentation

◆ PointsRan() [1/2]

Heed::PointsRan::PointsRan ( )
inline

Definition at line 46 of file PointsRan.h.

46{}

◆ PointsRan() [2/2]

Heed::PointsRan::PointsRan ( const std::vector< double > &  fx,
const std::vector< double > &  fy,
double  fxmin,
double  fxmax 
)

Constructor

Parameters
fxx values
fyy values
fxminMinimum of generated distribution. If less then x[0], extend the distribution by linear extrapolation. If the extrapolated line crosses zero, the extension stops there. Otherwise it stops at fxmin.
fxmaxMaximum of generated distribution. If greater than x[q-1], extend the distribution by linear extrapolation.

Definition at line 19 of file PointsRan.cpp.

21 : xmin(fxmin), xmax(fxmax), x(fx), y(fy) {
22 mfunnamep("PointsRan::PointsRan(...)");
23 check_econd12(x.size(), !=, y.size(), mcerr);
24 check_econd11(x.size(), < 2, mcerr);
25 check_econd12(xmin, >=, xmax, mcerr);
26 const long q = x.size();
27 for (long n = 0; n < q - 1; n++) {
28 check_econd12(x[n], >=, x[n + 1], mcerr);
29 }
30 for (long n = 0; n < q; n++) {
31 check_econd11(y[n], < 0.0, mcerr);
32 }
33 iy.resize(q);
34 a.resize(q - 1);
35 for (long n = 0; n < q - 1; n++) {
36 a[n] = (y[n + 1] - y[n]) / (x[n + 1] - x[n]);
37 }
38 if (xmin < x[0]) {
39 double y0 = y[0] - a[0] * (x[0] - xmin);
40 if (y0 < 0.0) {
41 x[0] = x[0] - y[0] / a[0];
42 check_econd12(xmax, <, x[0], mcerr);
43 xmin = x[0];
44 y[0] = 0.0;
45 } else {
46 y[0] = y0;
47 x[0] = xmin;
48 }
49 }
50 if (xmax > x[q - 1]) {
51 double yq = y[q - 1] + a[q - 2] * (xmax - x[q - 1]);
52 if (yq < 0.0) {
53 x[q - 1] = x[q - 1] - y[q - 1] / a[0];
54 check_econd12(xmin, >, x[q - 1], mcerr);
55 xmax = x[q - 1];
56 y[q - 1] = 0.0;
57 } else {
58 x[q - 1] = xmax;
59 y[q - 1] = yq;
60 }
61 }
62 // now xmin and xmax should be between x[0] and x[q-1]
63 iy[0] = 0.0;
64 integ_start = 0.0;
65 n_start = 0;
66 for (long n = 1; n < q; n++) {
67 iy[n] = iy[n - 1] + 0.5 * (x[n] - x[n - 1]) * (y[n - 1] + y[n]);
68 if (xmin >= x[n]) {
69 integ_start = iy[n];
70 n_start = n;
71 } else if (xmin > x[n - 1]) {
72 integ_start +=
73 (xmin - x[n - 1]) * (y[n - 1] + 0.5 * a[n - 1] * (xmin - x[n - 1]));
74 n_start = n - 1;
75 }
76 if (xmax >= x[n]) {
77 integ_finish = iy[n];
78 n_finish = n;
79 } else if (xmax > x[n - 1]) {
80 integ_finish +=
81 (xmax - x[n - 1]) * (y[n - 1] + 0.5 * a[n - 1] * (xmax - x[n - 1]));
82 n_finish = n;
83 }
84 }
85 integ_active = integ_finish - integ_start;
86 double s = iy[q - 1];
87 integ_total = s;
88 check_econd11(s, <= 0.0, mcerr);
89}
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:155
#define mfunnamep(string)
Definition: FunNameStack.h:49
#define check_econd12(a, sign, b, stream)
Definition: FunNameStack.h:163
#define mcerr
Definition: prstream.h:128

Member Function Documentation

◆ get_integ_active()

double Heed::PointsRan::get_integ_active ( ) const
inline

Definition at line 68 of file PointsRan.h.

68{ return integ_active; }

◆ get_integ_total()

double Heed::PointsRan::get_integ_total ( ) const
inline

Definition at line 66 of file PointsRan.h.

66{ return integ_total; }

◆ print()

void Heed::PointsRan::print ( std::ostream &  file) const

Definition at line 120 of file PointsRan.cpp.

120 {
121 Ifile << "PointsRan:\n";
122 indn.n += 2;
123 Ifile << "xmin=" << xmin << " xmax=" << xmax << '\n';
124 Ifile << "n_start=" << n_start << " n_finish=" << n_finish << '\n';
125 Ifile << "integ_start=" << integ_start << " integ_finish=" << integ_finish
126 << '\n';
127 Ifile << "integ_total=" << integ_total << " integ_active=" << integ_active
128 << '\n';
129 // Iprintn(file, integ);
130 const long q = x.size();
131 Iprintn(file, q);
132 for (long n = 0; n < q; n++) {
133 file << std::setw(3) << n << ' ' << std::setw(12) << x[n] << ' '
134 << std::setw(12) << y[n] << ' ' << std::setw(12) << iy[n];
135 if (n < q - 1) file << ' ' << std::setw(12) << a[n];
136 file << '\n';
137 }
138 indn.n -= 2;
139}
indentation indn
Definition: prstream.cpp:15
#define Ifile
Definition: prstream.h:196
#define Iprintn(file, name)
Definition: prstream.h:205

Referenced by Heed::PairProd::print().

◆ ran()

double Heed::PointsRan::ran ( double  flat_ran) const

Definition at line 91 of file PointsRan.cpp.

91 {
92 mfunnamep("double PointsRan::ran(double flat_ran) const");
93 flat_ran = integ_start + integ_active * flat_ran;
94 // long q = x.get_qel();
95 long n1 = n_start;
96 long n2 = n_finish;
97 long n3;
98 while (n2 - n1 > 1) {
99 n3 = n1 + (n2 - n1) / 2;
100 if (flat_ran < iy[n3]) {
101 n2 = n3;
102 } else {
103 n1 = n3;
104 }
105 }
106 double dran = flat_ran - iy[n1];
107 // double dx = sqrt(2.0 * dran);
108 double dx;
109 if (a[n1] != 0.0) {
110 dx = (-y[n1] + sqrt(y[n1] * y[n1] + 2.0 * a[n1] * dran)) / a[n1];
111 } else {
112 dx = (x[n2] - x[n1]) / (iy[n2] - iy[n1]) * dran;
113 }
114 // check_econd11(dx , < 0 , mcerr); // for debug
115 // check_econd11(dx , > x[n2] - x[n1] , mcerr); // for debug
116 double r = x[n1] + dx;
117 return r;
118}
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:314

Referenced by Heed::PairProd::get_eloss().


The documentation for this class was generated from the following files: