Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
HeedParticle_BGM.cpp
Go to the documentation of this file.
1#include <iomanip>
2#include <numeric>
12
13// 2003-2008, I. Smirnov
14
15namespace Heed {
16
17using CLHEP::c_light;
18using CLHEP::c_squared;
19using CLHEP::cm;
20using CLHEP::MeV;
21
23 const vec& vel, vfloat ftime,
24 particle_def* fpardef,
25 HeedFieldMap* fieldmap,
26 const bool floss_only,
27 const bool fprint_listing)
28 : eparticle(primvol, pt, vel, ftime, fpardef, fieldmap),
29 m_print_listing(fprint_listing),
30 m_particle_number(last_particle_number++),
31 m_loss_only(floss_only) {
32 mfunname("HeedParticle_BGM::HeedParticle_BGM(...)");
33 m_etransf.reserve(100);
34 m_natom.reserve(100);
35 m_nshell.reserve(100);
36 m_clusterBank.reserve(100);
37}
38
39void HeedParticle_BGM::physics(std::vector<gparticle*>& secondaries) {
40 mfunname("void HeedParticle_BGM::physics()");
41 if (m_print_listing) {
42 mcout << "HeedParticle_BGM::physics is started\n";
44 }
45 m_etransf.clear();
46 m_natom.clear();
47 m_nshell.clear();
48 if (m_currpos.prange <= 0.0) return;
49 // Get least address of volume
50 const absvol* av = m_currpos.tid.G_lavol();
51 const EnTransfCS_BGM* etcs = dynamic_cast<const EnTransfCS_BGM*>(av);
52 // Check if dynamic cast was successful.
53 if (!etcs) return;
54 HeedMatterDef* hmd = etcs->hmd;
55 MatterDef* matter = hmd->matter;
56 EnergyMesh* emesh = hmd->energy_mesh;
57 const double* aetemp = hmd->energy_mesh->get_ae();
58 PointCoorMesh<double, const double*> pcm_e(emesh->get_q() + 1, &(aetemp));
59
60 const double bg = sqrt(m_curr_gamma_1 * (m_curr_gamma_1 + 2.0));
62 &(etcs->mesh->x));
63 long n1, n2;
64 double b1, b2;
65 int s_ret = pcm.get_interval(bg, n1, b1, n2, b2);
66 if (s_ret != 1) {
67 mcerr << "ERROR in void HeedParticle_BGM::physics()\n";
68 mcerr << "beta*gamma is outside range of cross-section table\n";
69 std::streamsize old_prec = mcerr.precision(15);
71 mcerr.precision(old_prec);
72 Iprint2n(mcerr, n1, n2);
73 Iprint2n(mcerr, b1, b2);
74 Iprintn(mcerr, etcs->mesh);
75 mcerr << "This particle is:\n";
76 print(mcerr, 2);
77 mcerr << "This volume is:\n";
78 av->print(mcerr, 2);
80 return;
81 }
82
83 const long qa = matter->qatom();
84 if (m_print_listing) Iprintn(mcout, qa);
85 basis tempbas(m_currpos.dir, "tempbas");
86 for (long na = 0; na < qa; ++na) {
87 if (m_print_listing) Iprintn(mcout, na);
88 long qs = hmd->apacs[na]->get_qshell();
89 for (long ns = 0; ns < qs; ++ns) {
90 if (m_print_listing) Iprintn(mcout, ns);
91 const double y1 = etcs->etcs_bgm[n1].quan[na][ns];
92 const double y2 = etcs->etcs_bgm[n2].quan[na][ns];
93 const double mean_pois = y1 + (bg - b1) * (y2 - y1) / (b2 - b1);
94 if (mean_pois <= 0.) continue;
95 int ierror;
96 long qt = pois(mean_pois * m_currpos.prange / cm, ierror);
97 check_econd11a(ierror, == 1, " mean_pois=" << mean_pois
98 << " currpos.prange/cm="
99 << m_currpos.prange / cm << '\n',
100 mcerr);
101 if (m_print_listing) Iprintn(mcout, qt);
102 if (qt <= 0) continue;
103 point curpt = m_prevpos.pt;
104 vec dir = unit_vec(m_currpos.pt - m_prevpos.pt);
105 // This approximation ignores curvature
106 const double range = (m_currpos.pt - m_prevpos.pt).length();
107 if (m_print_listing) Iprint3n(mcout, curpt, dir, range);
108 for (long nt = 0; nt < qt; nt++) {
109 // Sample the energy transfer in this collision.
110 double rn = SRANLUX();
111 const double r1 = t_hisran_step_ar<
112 double, std::vector<double>, PointCoorMesh<double, const double*> >(
113 pcm_e, etcs->etcs_bgm[n1].fadda[na][ns], rn);
114 const double r2 = t_hisran_step_ar<
115 double, std::vector<double>, PointCoorMesh<double, const double*> >(
116 pcm_e, etcs->etcs_bgm[n2].fadda[na][ns], rn);
117 const double r = r1 + (bg - b1) * (r2 - r1) / (b2 - b1);
118 if (m_print_listing) {
119 Iprintn(mcout, rn);
120 Iprint3n(mcout, r1, r2, r);
121 }
122 // Convert to internal units.
123 const double et = r * MeV;
124 m_etransf.push_back(et);
125 m_natom.push_back(na);
126 m_nshell.push_back(ns);
127 if (m_print_listing) Iprint2n(mcout, nt, et);
128 // Sample the position of the collision.
129 const double arange = SRANLUX() * range;
130 point pt = curpt + dir * arange;
131 point ptloc = pt;
132 m_prevpos.tid.up_absref(&ptloc);
133 if (m_loss_only) continue;
134 if (m_print_listing) mcout << "generating new cluster\n";
135 m_clusterBank.push_back(
136 HeedCluster(et, 0, pt, ptloc, m_prevpos.tid, na, ns));
137 // Generate a virtual photon.
138 const double Ep0 = m_mass * c_squared + m_curr_ekin;
139 const double Ep1 = Ep0 - m_etransf.back();
140 const double Mp = m_mass * c_squared;
141 const double Mt = electron_def.mass * c_squared;
142 double theta_p, theta_t;
143 theta_two_part(Ep0, Ep1, Mp, Mt, theta_p, theta_t);
144 vec vel;
145 vel.random_conic_vec(fabs(theta_t));
146 vel.down(&tempbas); // direction is OK
147 vel *= c_light;
148 if (m_print_listing) mcout << "generating new virtual photon\n";
149 HeedPhoton* hp =
150 new HeedPhoton(m_currpos.tid.eid[0], pt, vel, m_currpos.time,
151 m_particle_number, et, m_fieldMap);
152 hp->m_photon_absorbed = true;
153 hp->m_delta_generated = false;
154 hp->m_na_absorbing = na;
155 hp->m_ns_absorbing = ns;
156 secondaries.push_back(hp);
157 }
158 }
159 }
160 if (m_print_listing) {
161 const double sum = std::accumulate(m_etransf.begin(), m_etransf.end(), 0.);
162 Iprint2n(mcout, m_etransf.size(), sum);
163 mcout << "Exiting HeedParticle_BGM::physics\n";
164 }
165}
166
167void HeedParticle_BGM::print(std::ostream& file, int l) const {
168 if (l < 0) return;
169 Ifile << "HeedParticle_BGM (l=" << l
170 << "): particle_number=" << m_particle_number << " type=";
171 print_notation(file);
172 file << std::endl;
173 if (l == 1) return;
174 mparticle::print(file, l - 1);
175 const double sum = std::accumulate(m_etransf.begin(), m_etransf.end(), 0.);
176 Iprintn(mcout, sum);
177 Iprintn(mcout, m_etransf.size());
178 if (l >= 5) {
179 Ifile << " nt natom nshell etransf\n";
180 const long qt = m_etransf.size();
181 for (long nt = 0; nt < qt; nt++) {
182 Ifile << std::setw(3) << nt << ' ' << std::setw(3) << m_natom[nt] << ' '
183 << std::setw(3) << m_nshell[nt] << ' '
184 << std::setw(12) << m_etransf[nt] << '\n';
185 }
186 }
187}
188}
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:172
#define spexit(stream)
Definition: FunNameStack.h:256
#define mfunname(string)
Definition: FunNameStack.h:45
long qatom() const
Definition: AtomDef.h:133
long q
Total number of points (not number of intervals).
Definition: BGMesh.h:17
std::vector< double > x
Definition: BGMesh.h:18
Energy transfer cross-section.
std::vector< EnTransfCS > etcs_bgm
HeedMatterDef * hmd
const double * get_ae(void) const
Return all left sides.
Definition: EnergyMesh.h:52
long get_q() const
Return number of bins.
Definition: EnergyMesh.h:42
Retrieve electric and magnetic field from Sensor.
Definition: HeedFieldMap.h:15
std::vector< const AtomPhotoAbsCS * > apacs
Definition: HeedMatterDef.h:29
MatterDef * matter
Definition: HeedMatterDef.h:28
EnergyMesh * energy_mesh
Definition: HeedMatterDef.h:39
HeedParticle_BGM()
Default constructor.
void print(std::ostream &file, int l) const override
Print-out.
void physics(std::vector< gparticle * > &secondaries) override
Apply any other processes (turn the trajectory, kill the particle, ...).
long m_na_absorbing
Index of absorbing atom.
Definition: HeedPhoton.h:42
long m_ns_absorbing
Index of absorbing shell.
Definition: HeedPhoton.h:44
bool m_photon_absorbed
Definition: HeedPhoton.h:40
bool m_delta_generated
Flag that delta-electrons are already generated (or cannot be created).
Definition: HeedPhoton.h:51
virtual int get_interval(long n, T &b1, T &b2) const
Definition: tline.h:402
virtual void print(std::ostream &file, int l) const
Definition: volume.cpp:119
Basis.
Definition: vec.h:311
HeedFieldMap * m_fieldMap
Pointer to field map.
Definition: eparticle.h:34
stvpoint m_prevpos
Previous point.
Definition: gparticle.h:248
stvpoint m_currpos
Current point.
Definition: gparticle.h:250
void up_absref(absref *f)
Definition: volume.cpp:26
std::vector< manip_absvol * > eid
List of volumes.
Definition: volume.h:37
absvol * G_lavol() const
Get last address of volume.
Definition: volume.cpp:17
Abstract base classs for volume "manipulators".
Definition: volume.h:128
double m_curr_ekin
Current kinetic energy.
Definition: mparticle.h:73
void print(std::ostream &file, int l) const override
Print-out.
Definition: mparticle.cpp:243
double m_curr_gamma_1
Current .
Definition: mparticle.h:80
double m_mass
Mass (not mass * speed_of_light^2)
Definition: mparticle.h:70
void print_notation(std::ostream &file) const
Point.
Definition: vec.h:366
vfloat time
Definition: gparticle.h:47
vec dir
Unit vector, in the first system in the tree.
Definition: gparticle.h:25
vfloat prange
Range from previous point.
Definition: gparticle.h:46
point pt
Coordinates in the first system in the tree.
Definition: gparticle.h:23
manip_absvol_treeid tid
Definition: gparticle.h:32
Definition: vec.h:177
void random_conic_vec(double theta)
Definition: vec.cpp:236
void down(const basis *fabas)
Definition: vec.cpp:168
Definition: BGMesh.cpp:6
long last_particle_number
Definition: HeedParticle.h:9
long pois(const double amu, int &ierror)
Definition: pois.cpp:9
void theta_two_part(const double Ep0, const double Ep1, const double Mp, const double Mt, double &theta_p, double &theta_t)
Scattering angles as function of incident and final projectile energy.
Definition: kinem.cpp:28
T t_hisran_step_ar(const M &mesh, const D &integ_y, T rannum)
Definition: tline.h:1403
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:615
particle_def electron_def("electron", "e-", electron_mass_c2/c_squared, electron_charge, 1, 0, 0.5, spin_def(0.0, 0.0))
Definition: particle_def.h:99
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:314
double vfloat
Definition: vfloat.h:16
#define mcout
Definition: prstream.h:126
#define Iprint3n(file, name1, name2, name3)
Definition: prstream.h:233
#define Ifile
Definition: prstream.h:196
#define mcerr
Definition: prstream.h:128
#define Iprintn(file, name)
Definition: prstream.h:205
#define Iprint2n(file, name1, name2)
Definition: prstream.h:220