Garfield++ v2r0
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 time, particle_def* fpardef,
24 HeedFieldMap* fieldmap, const bool fs_loss_only,
25 const bool fs_print_listing)
26 : eparticle(primvol, pt, vel, time, fpardef, fieldmap),
27 s_print_listing(fs_print_listing),
28 particle_number(last_particle_number++),
29 s_loss_only(fs_loss_only),
30 s_store_clusters(false) {
31
32 mfunname("HeedParticle::HeedParticle(...)");
33 etransf.reserve(100);
34 natom.reserve(100);
35 nshell.reserve(100);
36}
37
38void HeedParticle::physics(std::vector<gparticle*>& secondaries) {
39 mfunname("void HeedParticle::physics()");
40 if (s_print_listing) {
41 mcout << "HeedParticle::physics is started\n";
43 }
44 etransf.clear();
45 natom.clear();
46 nshell.clear();
47 if (currpos.prange <= 0.0) return;
48 // Get local volume.
49 const absvol* av = currpos.tid.G_lavol();
50 const EnTransfCS* etcs = dynamic_cast<const EnTransfCS*>(av);
51 if (!etcs) return;
52 HeedMatterDef* hmd = etcs->hmd.getver();
53 MatterDef* matter = hmd->matter.getver();
54 EnergyMesh* emesh = hmd->energy_mesh.getver();
55 const double* aetemp = hmd->energy_mesh->get_ae();
56 PointCoorMesh<double, const double*> pcm(emesh->get_q() + 1, &(aetemp));
57 const long qa = matter->qatom();
58 if (s_print_listing) Iprintn(mcout, qa);
59 basis tempbas(currpos.dir, "tempbas");
60 for (long na = 0; na < qa; ++na) {
61 if (s_print_listing) Iprintn(mcout, na);
62 const long qs = hmd->apacs[na]->get_qshell();
63 for (long ns = 0; ns < qs; ++ns) {
64 if (s_print_listing) Iprintn(mcout, ns);
65 if (etcs->quan[na][ns] <= 0.0) continue;
66 // Sample the number of collisions for this shell.
67 int ierror = 0;
68 const long qt = pois(etcs->quan[na][ns] * currpos.prange / cm, ierror);
69 check_econd11a(ierror, == 1,
70 " etcs->quan[na][ns]=" << etcs->quan[na][ns]
71 << " currpos.prange/cm="
72 << currpos.prange / cm << '\n',
73 mcerr);
74 if (s_print_listing) Iprintn(mcout, qt);
75 if (qt <= 0) continue;
76 point curpt = prevpos.pt;
77 vec dir = unit_vec(currpos.pt - prevpos.pt);
78 const double range = (currpos.pt - prevpos.pt).length();
79 if (s_print_listing) Iprint3n(mcout, curpt, dir, range);
80 for (long nt = 0; nt < qt; ++nt) {
81 // Sample the energy transfer in this collision.
82 const double rn = SRANLUX();
83 if (s_print_listing) Iprint3n(mcout, rn, etcs, etcs->fadda[na][ns][1]);
84 const double r = t_hisran_step_ar<
85 double, std::vector<double>, PointCoorMesh<double, const double*> >(
86 pcm, etcs->fadda[na][ns], rn);
87
88 // Convert to internal units.
89 const double et = r * MeV;
90 etransf.push_back(et);
91 natom.push_back(na);
92 nshell.push_back(ns);
93 if (s_print_listing) Iprint2n(mcout, nt, et);
94 // Sample the position of the collision.
95 const double arange = SRANLUX() * range;
96 point pt = curpt + dir * arange;
97 point ptloc = pt;
98 prevpos.tid.up_absref(&ptloc);
99 if (s_loss_only) continue;
100 if (s_print_listing) mcout << "generating new cluster\n";
101 if (s_store_clusters) {
102 m_clusterBank.push_back(
103 HeedCluster(et, 0, pt, ptloc, prevpos.tid, na, ns));
104 }
105 // Generate a virtual photon.
106 const double Ep0 = mass * c_squared + curr_kin_energy;
107 const double Ep1 = Ep0 - etransf.back();
108 const double Mp = mass * c_squared;
109 const double Mt = electron_def.mass * c_squared;
110 double theta_p, theta_t;
111 theta_two_part(Ep0, Ep1, Mp, Mt, theta_p, theta_t);
112 vec vel;
113 vel.random_conic_vec(fabs(theta_t));
114 vel.down(&tempbas); // direction is OK
115 vel *= c_light;
116 // HS
117 double speed = vel.length();
118 double time = arange / speed;
119 if (s_print_listing) mcout << "generating new virtual photon\n";
120 HeedPhoton* hp = new HeedPhoton(currpos.tid.eid[0].getver(), pt, vel,
121 time, particle_number, et, m_fieldMap);
122 hp->s_photon_absorbed = true;
123 hp->s_delta_generated = false;
124 hp->na_absorbing = na;
125 hp->ns_absorbing = ns;
126 secondaries.push_back(hp);
127 }
128 }
129 }
130 if (s_print_listing) {
131 const double sum = std::accumulate(etransf.begin(), etransf.end(), 0.);
132 Iprint2n(mcout, etransf.size(), sum);
133 mcout << "Exiting HeedParticle::physics\n";
134 }
135}
136
137void HeedParticle::print(std::ostream& file, int l) const {
138 if (l < 0) return;
139 Ifile << "HeedParticle (l=" << l << "): particle_number=" << particle_number
140 << " type=";
141 print_notation(file);
142 file << std::endl;
143 if (l == 1) return;
144 mparticle::print(file, l - 1);
145 const double sum = std::accumulate(etransf.begin(), etransf.end(), 0.);
146 Iprintn(mcout, sum);
147 Iprintn(mcout, etransf.size());
148 if (l >= 5) {
149 Ifile << " nt natom nshell transferred energy\n";
150 const long qt = etransf.size();
151 for (long nt = 0; nt < qt; nt++) {
152 Ifile << std::setw(3) << nt << ' ' << std::setw(3) << natom[nt] << ' '
153 << std::setw(3) << nshell[nt] << ' ' << std::setw(12) << etransf[nt]
154 << '\n';
155 }
156 }
157}
158}
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:172
#define mfunname(string)
Definition: FunNameStack.h:45
long qatom() const
Definition: AtomDef.h:143
std::vector< std::vector< double > > quan
Definition: EnTransfCS.h:118
std::vector< std::vector< std::vector< double > > > fadda
Integral, normalised to unity.
Definition: EnTransfCS.h:101
PassivePtr< HeedMatterDef > hmd
Definition: EnTransfCS.h:52
long get_q() const
Return number of bins.
Definition: EnergyMesh.h:45
Retrieve electric and magnetic field from Sensor.
Definition: HeedFieldMap.h:15
std::vector< PassivePtr< const AtomPhotoAbsCS > > apacs
Definition: HeedMatterDef.h:30
PassivePtr< MatterDef > matter
Definition: HeedMatterDef.h:29
PassivePtr< EnergyMesh > energy_mesh
Definition: HeedMatterDef.h:40
HeedParticle()
Default constructor.
Definition: HeedParticle.h:19
virtual void print(std::ostream &file, int l) const
virtual void physics(std::vector< gparticle * > &secondaries)
bool s_photon_absorbed
Definition: HeedPhoton.h:40
bool s_delta_generated
Flag that delta-electrons are already generated (or cannot be created).
Definition: HeedPhoton.h:50
long ns_absorbing
Index of absorbing shell.
Definition: HeedPhoton.h:44
long na_absorbing
Index of absorbing atom.
Definition: HeedPhoton.h:42
Basis.
Definition: vec.h:319
HeedFieldMap * m_fieldMap
Definition: eparticle.h:33
stvpoint prevpos
Definition: gparticle.h:176
stvpoint currpos
Definition: gparticle.h:177
void up_absref(absref *f)
Definition: volume.cpp:26
std::vector< PassivePtr< 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:178
double curr_kin_energy
Definition: mparticle.h:32
double mass
Mass (not mass * speed_of_light^2)
Definition: mparticle.h:26
virtual void print(std::ostream &file, int l) const
Definition: mparticle.cpp:242
void print_notation(std::ostream &file) const
Point.
Definition: vec.h:374
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:186
vfloat length() const
Definition: vec.h:205
void random_conic_vec(double theta)
Definition: vec.cpp:236
void down(const basis *fabas)
Definition: vec.cpp:168
Definition: BGMesh.cpp:5
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:1404
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:110
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