Garfield++ v1r0
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 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 //pcm_e = PointCoorMesh< double, double[pqener] >( q, &e);
22 //pcm_ec = PointCoorMesh< double, double[pqener-1] >( q-1, &ec);
23 //mcout<<"EnergyMesh is done"<<endl;
24}
25
27 mfunname("DynLinArr< double > fec");
28 check_econd21(q, < 0 ||, > pqener - 1, mcerr);
29 check_econd11(q, != 1, mcerr); // otherwise problems with emin/emax
30 if (q > 0) {
31 emin = fec[0] - (fec[1] - fec[0]) / 2.0;
32 emax = fec[q - 1] + (fec[q - 1] - fec[q - 2]) / 2.0;
33 e[0] = emin;
34 e[q] = emax;
35
36 for (long n = 0; n < q; n++) {
37 ec[n] = fec[n];
38 }
39 for (long n = 1; n < q; n++) {
40 e[n] = 0.5 * (fec[n - 1] + fec[n]);
41 }
42 } else {
43 emin = 0.0;
44 emax = 0.0;
45 }
46 //pcm_e = PointCoorMesh< double, double[pqener] >( q, &e);
47 //pcm_ec = PointCoorMesh< double, double[pqener-1] >( q-1, &ec);
48}
49
50/*
51EnergyMesh::EnergyMesh(const EnergyMesh& fem)
52{
53 *this = fem;
54}
55
56EnergyMesh& EnergyMesh::operator=(const EnergyMesh& fem)
57{
58 q = fem.q;
59 emin = fem.emin;
60 emax = fem.emax;
61 long n;
62 for(n=0; n<q+1; n++)
63 {
64 e[n] = fem.e[n];
65 }
66 for(n=0; n<q; n++)
67 {
68 ec[n] = fem.ec[n];
69 }
70 pcm_e = PointCoorMesh< double, double[pqener] >( q, &e);
71 pcm_ec = PointCoorMesh< double, double[pqener-1] >( q-1, &ec);
72}
73*/
74
76 if (ener < emin) return -1;
77 if (ener > emax) return q;
78
79 long n1 = 0;
80 long n2 = q; // right side of last
81 long n3 = n1;
82 while (n2 - n1 > 1) {
83 n3 = n1 + (n2 - n1) / 2;
84 if (ener < e[n3]) {
85 n2 = n3;
86 } else {
87 n1 = n3;
88 }
89 }
90 return n1;
91}
92
94 if (ener < ec[0]) return -1;
95 if (ener > ec[q - 1]) return q;
96
97 long n1 = 0;
98 long n2 = q - 1; // right side of last
99 long n3 = n1;
100 while (n2 - n1 > 1) {
101 n3 = n1 + (n2 - n1) / 2;
102 if (ener < ec[n3]) {
103 n2 = n3;
104 } else {
105 n1 = n3;
106 }
107 }
108 return n1;
109}
110
111std::ostream& operator<<(std::ostream& file, EnergyMesh& f) {
112 Ifile << "EnergyMesh: \n";
113 indn.n += 2;
114 Ifile << "emin=" << f.emin << " emax=" << f.emax
115 << " quantity of intervals=" << f.q << '\n'
116 << " maximal possible quantity of intervals=" << pqener << '\n';
117 Ifile << " number left side center right side widht\n";
118 for (int n = 0; n < f.q; n++) {
119 Ifile << std::setw(5) << n << std::setw(15) << f.e[n] << std::setw(15)
120 << f.ec[n] << std::setw(15) << f.e[n + 1] << std::setw(15)
121 << (f.e[n + 1] - f.e[n]) << '\n';
122 }
123 //f.pcm_e.print(mcout);
124 //f.pcm_ec.print(mcout);
125 indn.n -= 2;
126 return file;
127}
128
129void EnergyMesh::print(std::ostream& file, int l) const {
130 if (l <= 0) return;
131 Ifile << "EnergyMesh (l=" << l << "): \n";
132 indn.n += 2;
133 Ifile << "emin=" << emin << " emax=" << emax << " quantity of intervals=" << q
134 << '\n' << " maximal possible quantity of intervals=" << pqener << '\n';
135 if (l > 1) {
136 Ifile << " number left side center right side widht\n";
137 for (int n = 0; n < q; n++) {
138 Ifile << std::setw(5) << n << std::setw(15) << e[n] << std::setw(15)
139 << ec[n] << std::setw(15) << e[n + 1] << std::setw(15)
140 << (e[n + 1] - e[n]) << '\n';
141 }
142 }
143 indn.n -= 2;
144}
145
146DynLinArr<double> make_log_mesh_ec(double emin, double emax, long q) {
147 mfunname(
148 "DynLinArr< double > make_log_mesh_ec(double emin, double emax, long q)");
149
150 double rk = pow(emax / emin, (1.0 / double(q)));
151 double er = emin;
152 DynLinArr<double> ec(q);
153 double e1;
154 double e2 = er;
155 for (long n = 0; n < q; n++) {
156 e1 = e2;
157 e2 = e2 * rk;
158 ec[n] = (e1 + e2) * 0.5;
159 }
160 return ec;
161}
162
163}
DoubleAc pow(const DoubleAc &f, double p)
Definition: DoubleAc.cpp:336
#define check_econd21(a, sign1_b1_sign0, sign2_b2, stream)
Definition: FunNameStack.h:428
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
#define mfunname(string)
Definition: FunNameStack.h:67
virtual void print(std::ostream &file, int l) const
Definition: EnergyMesh.cpp:129
long get_interval_number_between_centers(double ener)
Definition: EnergyMesh.cpp:93
long get_interval_number(double ener)
Definition: EnergyMesh.cpp:75
Definition: BGMesh.cpp:3
DynLinArr< double > make_log_mesh_ec(double emin, double emax, long q)
Definition: EnergyMesh.cpp:146
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:22
const int pqener
Definition: EnergyMesh.h:39
indentation indn
Definition: prstream.cpp:13
#define Ifile
Definition: prstream.h:207
#define mcerr
Definition: prstream.h:135