Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
EnergyMesh.cpp
Go to the documentation of this file.
1#include <cmath>
2#include <iomanip>
5
6namespace Heed {
7
8EnergyMesh::EnergyMesh(double femin, double femax, long fq)
9 : q(fq), emin(femin), emax(femax) {
10 mfunname("EnergyMesh::EnergyMesh(double femin, double femax, long fq)");
11 check_econd21(q, < 0 ||, > pqener - 1, mcerr);
12
13 const double rk = pow(emax / emin, (1.0 / double(q)));
14 double er = emin;
15 e[0] = er;
16 for (long n = 1; n < q + 1; n++) {
17 e[n] = er * rk;
18 ec[n - 1] = (e[n - 1] + e[n]) * 0.5;
19 er = e[n];
20 }
21}
22
23EnergyMesh::EnergyMesh(const std::vector<double>& fec) : q(fec.size()) {
24 mfunname("std::vector< double > fec");
25 check_econd21(q, < 0 ||, > pqener - 1, mcerr);
26 check_econd11(q, != 1, mcerr); // otherwise problems with emin/emax
27 if (q <= 0) {
28 emin = 0.0;
29 emax = 0.0;
30 return;
31 }
32 emin = fec[0] - (fec[1] - fec[0]) / 2.0;
33 emax = fec[q - 1] + (fec[q - 1] - fec[q - 2]) / 2.0;
34 e[0] = emin;
35 e[q] = emax;
36
37 for (long n = 0; n < q; n++) {
38 ec[n] = fec[n];
39 }
40 for (long n = 1; n < q; n++) {
41 e[n] = 0.5 * (fec[n - 1] + fec[n]);
42 }
43}
44
45long EnergyMesh::get_interval_number(const double ener) const {
46 if (ener < emin) return -1;
47 if (ener > emax) return q;
48
49 long n1 = 0;
50 long n2 = q; // right side of last
51 while (n2 - n1 > 1) {
52 const long n3 = n1 + ((n2 - n1) >> 1);
53 if (ener < e[n3]) {
54 n2 = n3;
55 } else {
56 n1 = n3;
57 }
58 }
59 return n1;
60}
61
63 if (ener < ec[0]) return -1;
64 if (ener > ec[q - 1]) return q;
65
66 long n1 = 0;
67 long n2 = q - 1; // right side of last
68 while (n2 - n1 > 1) {
69 const long n3 = n1 + ((n2 - n1) >> 1);
70 if (ener < ec[n3]) {
71 n2 = n3;
72 } else {
73 n1 = n3;
74 }
75 }
76 return n1;
77}
78
79std::ostream& operator<<(std::ostream& file, EnergyMesh& f) {
80 Ifile << "EnergyMesh: \n";
81 indn.n += 2;
82 Ifile << "emin=" << f.emin << " emax=" << f.emax
83 << " number of intervals=" << f.q << '\n'
84 << " maximal number of intervals=" << EnergyMesh::pqener << '\n';
85 Ifile << " bin left side center right side width\n";
86 for (int n = 0; n < f.q; n++) {
87 Ifile << std::setw(5) << n << std::setw(15) << f.e[n] << std::setw(15)
88 << f.ec[n] << std::setw(15) << f.e[n + 1] << std::setw(15)
89 << (f.e[n + 1] - f.e[n]) << '\n';
90 }
91 indn.n -= 2;
92 return file;
93}
94
95void EnergyMesh::print(std::ostream& file, int l) const {
96 if (l <= 0) return;
97 Ifile << "EnergyMesh (l=" << l << "): \n";
98 indn.n += 2;
99 Ifile << "emin=" << emin << " emax=" << emax << " quantity of intervals=" << q
100 << '\n' << " maximal possible quantity of intervals=" << pqener << '\n';
101 if (l > 1) {
102 Ifile << " number left side center right side widht\n";
103 for (int n = 0; n < q; n++) {
104 Ifile << std::setw(5) << n << std::setw(15) << e[n] << std::setw(15)
105 << ec[n] << std::setw(15) << e[n + 1] << std::setw(15)
106 << (e[n + 1] - e[n]) << '\n';
107 }
108 }
109 indn.n -= 2;
110}
111}
#define check_econd21(a, sign1_b1_sign0, sign2_b2, stream)
Definition: FunNameStack.h:191
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:155
#define mfunname(string)
Definition: FunNameStack.h:45
void print(std::ostream &file, int l) const
Definition: EnergyMesh.cpp:95
EnergyMesh()=default
Default constructor.
long get_interval_number_between_centers(const double ener) const
Definition: EnergyMesh.cpp:62
long get_interval_number(const double ener) const
Definition: EnergyMesh.cpp:45
Definition: BGMesh.cpp:6
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:37
DoubleAc pow(const DoubleAc &f, double p)
Definition: DoubleAc.cpp:337
indentation indn
Definition: prstream.cpp:15
#define Ifile
Definition: prstream.h:195
#define mcerr
Definition: prstream.h:128