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

#include <EnergyMesh.h>

Public Member Functions

 EnergyMesh ()=default
 Default constructor.
 
 EnergyMesh (double femin, double femax, long fq)
 Constructor from min./max energy and number of bins.
 
 EnergyMesh (const std::vector< double > &fec)
 Constructor from a list of energies.
 
long get_q () const
 Return number of bins.
 
double get_emin () const
 Return left side of the first bin.
 
double get_emax () const
 Return right side of the last bin.
 
double get_e (long n) const
 Return left side of a given bin.
 
double get_ec (long n) const
 Return center of a given bin.
 
const double * get_ae (void) const
 Return all left sides.
 
const double * get_aec (void) const
 Return all interval centres.
 
long get_interval_number (const double ener) const
 
long get_interval_number_between_centers (const double ener) const
 
EnergyMeshcopy () const
 
void print (std::ostream &file, int l) const
 

Friends

std::ostream & operator<< (std::ostream &file, EnergyMesh &f)
 

Detailed Description

Energy mesh (in MeV, as everywhere in HEED, unless otherwise specified). Internal calculations in HEED are conveniently performed with some standard energy mesh. This mesh should be logarithmic or similar, with dense spacing at small energies and sparse spacing at large energies. The class below determines such mesh and some standard functions, namely getting center of energy interval get_ec(long n), left edge of interval get_e(long n) (right edge is left one for the next bin), and some other simple functions. There may be many meshes in program (but currently only one mesh is used in a single program, different meshes may be used for totally different matters and cross sections). The pointer to mesh should be given as parameter of class constructor, when a class depends on mesh.

The class keeps the left sides of bins and their centers in arrays. Since the right side of interval is the left of the next one, the array keeping the left sides should be by one larger then the dimension of the mesh.

For reasons of speed the internal arrays keep right sides of intervals and their centers are defined as simple fixed-size arrays.

2003, I. Smirnov

Definition at line 32 of file EnergyMesh.h.

Constructor & Destructor Documentation

◆ EnergyMesh() [1/3]

Heed::EnergyMesh::EnergyMesh ( )
default

Default constructor.

Referenced by copy().

◆ EnergyMesh() [2/3]

Heed::EnergyMesh::EnergyMesh ( double  femin,
double  femax,
long  fq 
)

Constructor from min./max energy and number of bins.

Definition at line 8 of file EnergyMesh.cpp.

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}
#define check_econd21(a, sign1_b1_sign0, sign2_b2, stream)
Definition: FunNameStack.h:191
#define mfunname(string)
Definition: FunNameStack.h:45
DoubleAc pow(const DoubleAc &f, double p)
Definition: DoubleAc.cpp:337
#define mcerr
Definition: prstream.h:128

◆ EnergyMesh() [3/3]

Heed::EnergyMesh::EnergyMesh ( const std::vector< double > &  fec)

Constructor from a list of energies.

Definition at line 23 of file EnergyMesh.cpp.

23 : 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}
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:155

Member Function Documentation

◆ copy()

EnergyMesh * Heed::EnergyMesh::copy ( ) const
inline

Definition at line 60 of file EnergyMesh.h.

60{ return new EnergyMesh(*this); }
EnergyMesh()=default
Default constructor.

◆ get_ae()

const double * Heed::EnergyMesh::get_ae ( void  ) const
inline

Return all left sides.

Definition at line 52 of file EnergyMesh.h.

52{ return e; }

Referenced by Heed::EnTransfCS::EnTransfCS(), Heed::HeedParticle::physics(), and Heed::HeedParticle_BGM::physics().

◆ get_aec()

const double * Heed::EnergyMesh::get_aec ( void  ) const
inline

Return all interval centres.

Definition at line 54 of file EnergyMesh.h.

54{ return ec; }

◆ get_e()

double Heed::EnergyMesh::get_e ( long  n) const
inline

Return left side of a given bin.

Definition at line 48 of file EnergyMesh.h.

48{ return e[n]; }

Referenced by Heed::EnTransfCS::EnTransfCS(), and Heed::HeedMatterDef::print().

◆ get_ec()

double Heed::EnergyMesh::get_ec ( long  n) const
inline

◆ get_emax()

double Heed::EnergyMesh::get_emax ( ) const
inline

Return right side of the last bin.

Definition at line 46 of file EnergyMesh.h.

46{ return emax; }

Referenced by Heed::EnTransfCS::EnTransfCS().

◆ get_emin()

double Heed::EnergyMesh::get_emin ( ) const
inline

Return left side of the first bin.

Definition at line 44 of file EnergyMesh.h.

44{ return emin; }

Referenced by Heed::EnTransfCS::EnTransfCS().

◆ get_interval_number()

long Heed::EnergyMesh::get_interval_number ( const double  ener) const

Definition at line 45 of file EnergyMesh.cpp.

45 {
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}

◆ get_interval_number_between_centers()

long Heed::EnergyMesh::get_interval_number_between_centers ( const double  ener) const

Definition at line 62 of file EnergyMesh.cpp.

62 {
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}

◆ get_q()

◆ print()

void Heed::EnergyMesh::print ( std::ostream &  file,
int  l 
) const

Definition at line 95 of file EnergyMesh.cpp.

95 {
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}
indentation indn
Definition: prstream.cpp:15
#define Ifile
Definition: prstream.h:195

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  file,
EnergyMesh f 
)
friend

Definition at line 79 of file EnergyMesh.cpp.

79 {
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}

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