Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
HeedParticle.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, particle_def* fpardef,
24 HeedFieldMap* fieldmap, const bool floss_only,
25 const bool fprint_listing)
26 : eparticle(primvol, pt, vel, ftime, fpardef, fieldmap),
27 m_print_listing(fprint_listing),
28 m_loss_only(floss_only),
29 m_particle_number(last_particle_number++) {}
30
31void HeedParticle::physics(std::vector<gparticle*>& secondaries) {
32 mfunname("void HeedParticle::physics()");
33 if (m_print_listing) {
34 mcout << "HeedParticle::physics is started\n";
36 }
37 m_edep = 0.;
38 // Get the step.
39 if (m_currpos.prange <= 0.0) return;
40 const double step = m_currpos.prange / cm;
41 const vec dir = unit_vec(m_currpos.pt - m_prevpos.pt);
42 const double range = (m_currpos.pt - m_prevpos.pt).length();
43 if (m_print_listing) Iprint3n(mcout, m_prevpos.pt, dir, range);
44 // Get local volume.
45 const absvol* av = m_currpos.volume();
46 auto etcs = dynamic_cast<const EnTransfCS*>(av);
47 if (!etcs) return;
48 HeedMatterDef* hmd = etcs->hmd;
49 MatterDef* matter = hmd->matter;
50 EnergyMesh* emesh = hmd->energy_mesh;
51 const double* aetemp = emesh->get_ae();
52 PointCoorMesh<double, const double*> pcm(emesh->get_q() + 1, &(aetemp));
53 basis tempbas(m_currpos.dir, "tempbas");
54 // Particle mass and energy.
55 const double mp = m_mass * c_squared;
56 const double ep = mp + m_curr_ekin;
57 // Electron mass.
58 const double mt = electron_def.mass * c_squared;
59 // Particle velocity.
60 const double invSpeed = 1. / m_prevpos.speed;
61 // Shorthand.
62 const auto sampleTransfer = t_hisran_step_ar<double, std::vector<double>,
64 const long qa = matter->qatom();
65 if (m_print_listing) Iprintn(mcout, qa);
66 for (long na = 0; na < qa; ++na) {
67 if (m_print_listing) Iprintn(mcout, na);
68 const long qs = hmd->apacs[na]->get_qshell();
69 for (long ns = 0; ns < qs; ++ns) {
70 if (m_print_listing) Iprintn(mcout, ns);
71 if (etcs->quan[na][ns] <= 0.0) continue;
72 // Sample the number of collisions for this shell.
73 const long qt = pois(etcs->quan[na][ns] * step);
74 if (m_print_listing) Iprintn(mcout, qt);
75 if (qt <= 0) continue;
76 for (long nt = 0; nt < qt; ++nt) {
77 // Sample the energy transfer in this collision.
78 const double r = sampleTransfer(pcm, etcs->fadda[na][ns], SRANLUX());
79 // Convert to internal units.
80 const double et = r * MeV;
81 m_edep += et;
82 if (m_print_listing) Iprint2n(mcout, nt, et);
83 // Sample the position of the collision.
84 const double arange = SRANLUX() * range;
85 point pt = m_prevpos.pt + dir * arange;
86 if (m_loss_only) continue;
87 if (m_print_listing) mcout << "generating new cluster\n";
88 if (m_store_clusters) {
89 m_clusterBank.emplace_back(HeedCluster(et, pt, na, ns));
90 }
91 // Generate a virtual photon.
92 double theta_p, theta_t;
93 theta_two_part(ep, ep - et, mp, mt, theta_p, theta_t);
94 vec vel;
95 vel.random_conic_vec(fabs(theta_t));
96 vel.down(&tempbas); // direction is OK
97 vel *= c_light;
98 const double t = m_prevpos.time + arange * invSpeed;
99 if (m_print_listing) mcout << "generating new virtual photon\n";
100 HeedPhoton* hp = new HeedPhoton(m_currpos.tid.eid[0], pt, vel, t,
101 m_particle_number, et, m_fieldMap);
102 if (!hp->alive()) {
103 delete hp;
104 continue;
105 }
106 hp->m_photon_absorbed = true;
107 hp->m_delta_generated = false;
108 hp->m_na_absorbing = na;
109 hp->m_ns_absorbing = ns;
110 secondaries.push_back(hp);
111 }
112 }
113 }
114 if (m_print_listing) {
115 Iprintn(mcout, m_edep);
116 mcout << "Exiting HeedParticle::physics\n";
117 }
118}
119
120void HeedParticle::print(std::ostream& file, int l) const {
121 if (l < 0) return;
122 Ifile << "HeedParticle (l=" << l << "): particle_number="
123 << m_particle_number << " type=";
124 print_notation(file);
125 file << std::endl;
126 if (l == 1) return;
127 mparticle::print(file, l - 1);
128 Iprintn(mcout, m_edep);
129}
130}
#define mfunname(string)
Definition: FunNameStack.h:45
long qatom() const
Definition: AtomDef.h:133
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
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, ...).
HeedParticle()
Default constructor.
Definition: HeedParticle.h:18
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
Basis.
Definition: vec.h:313
HeedFieldMap * m_fieldMap
Pointer to field map.
Definition: eparticle.h:34
stvpoint m_prevpos
Previous point.
Definition: gparticle.h:262
bool alive() const
Definition: gparticle.h:192
stvpoint m_currpos
Current point.
Definition: gparticle.h:264
std::vector< manip_absvol * > eid
List of volumes.
Definition: volume.h:37
Abstract base classs for volume "manipulators".
Definition: volume.h:128
double m_curr_ekin
Current kinetic energy.
Definition: mparticle.h:73
void step(std::vector< gparticle * > &secondaries) override
Definition: mparticle.cpp:71
void print(std::ostream &file, int l) const override
Print-out.
Definition: mparticle.cpp:243
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:368
vfloat time
Definition: gparticle.h:47
absvol * volume()
Definition: gparticle.h:137
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
vfloat speed
Longitudinal velocity.
Definition: gparticle.h:31
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:179
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
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
long pois(const double amu)
Definition: pois.cpp:9
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:106
double vfloat
Definition: vfloat.h:16
#define mcout
Definition: prstream.h:126
#define Iprint3n(file, name1, name2, name3)
Definition: prstream.h:232
#define Ifile
Definition: prstream.h:195
#define Iprintn(file, name)
Definition: prstream.h:204
#define Iprint2n(file, name1, name2)
Definition: prstream.h:219