Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HeedPhoton.cpp
Go to the documentation of this file.
5// to see last_particle_number
7#include "heed++/code/HeedDeltaElectron.h" // because it can be generated
12 /*
132003, I. Smirnov
14*/
15
16namespace Heed {
17
18HeedPhoton::HeedPhoton(manip_absvol* primvol, const point& pt, const vec& vel,
19 vfloat time, long fparent_particle_number,
20 double fenergy, int fs_print_listing)
21 : gparticle(primvol, pt, vel, time),
22 parent_particle_number(fparent_particle_number),
23 s_print_listing(fs_print_listing),
24 energy(fenergy),
25 s_photon_absorbed(0),
26#ifdef SFER_PHOTOEL
27 s_sfer_photoel(0),
28#endif
29 s_delta_generated(0) {
30 mfunname("HeedPhoton::HeedPhoton(...)");
32 //set_count_references();
34 double length_vel = length(vel);
35 check_econd11(fabs(length_vel - c_light) / (length_vel + c_light), > 1.0e-10,
36 mcerr);
37}
38
40 mfunname("void HeedPhoton::physics(void)");
41
42 if (s_print_listing == 1) {
43 mcout << "void HeedPhoton::physics(void) is starting\n";
44 }
45 if (s_photon_absorbed == 0) // still not absorbed
46 {
47 if (nextpos.prange > 0.0) {
48 const absvol* av = currpos.G_lavol(); // get least address of volume
49 HeedMatterDef* hmd = NULL;
50 const EnTransfCSType* etcst = dynamic_cast<const EnTransfCSType*>(av);
51 if (etcst != NULL) {
52 hmd = etcst->etcs->hmd.getver();
53 } else {
54 const HeedDeltaElectronCSType* hmecst =
55 dynamic_cast<const HeedDeltaElectronCSType*>(av);
56 if (hmecst != NULL) {
57 hmd = hmecst->hdecs->hmd.get();
58 }
59 }
60 if (hmd != NULL) {
61 // calculate cross section
62 // First to count shells
63 long qst = 0;
64 long qa = hmd->matter->qatom();
65 long na;
66 for (na = 0; na < qa; na++) {
67 long qs = hmd->apacs[na]->get_qshell();
68 qst += qs;
69 }
70 DynLinArr<double> cs(qst);
71 DynLinArr<long> nat(qst);
72 DynLinArr<long> nsh(qst);
73 double s = 0.0;
74 long nst = 0;
75 for (na = 0; na < qa; na++) {
76 long qs = hmd->apacs[na]->get_qshell();
77 long ns;
78 double at_weight_quan = hmd->matter->weight_quan(na);
79 for (ns = 0; ns < qs; ns++) {
80 cs[nst] = hmd->apacs[na]->get_ICS(ns, energy) * at_weight_quan;
81 // threshold is taken into account in apacs[na]->get_ACS(ns,..
82 nat[nst] = na;
83 nsh[nst] = ns;
84 s += cs[nst];
85 //Imcout<<"na="<<na<<" ns="<<ns<<" cs[nst]="<<cs[nst]<<'\n';
86 nst++;
87 }
88 }
89 if (s_print_listing == 1) {
90 Iprintn(mcout, s);
91 }
92 //s=s * hmd->eldens / hmd->matter->Z_mean() * C1_MEV_CM;
93 s = s * 1.0e-18 * AVOGADRO / (hmd->matter->A_mean() / (gram / mole)) *
94 hmd->matter->density() / (gram / cm3);
95 if (s_print_listing == 1) {
96 Iprintn(mcout, s);
97 }
98 double path_length = 1.0 / s; // cm
99 if (s_print_listing == 1) {
100 Iprint2n(mcout, energy, path_length);
101 }
102 double xleng = -path_length * log(1.0 - SRANLUX());
103 // computing randon length
104 if (s_print_listing == 1) {
105 Iprintn(mcout, xleng);
107 }
108 if (xleng * cm < nextpos.prange) {
110#ifdef SFER_PHOTOEL
111 s_sfer_photoel = 1; // assumes that virtual photons are already
112 // absorbed and s_sfer_photoel is 0 for them
113#endif
114
115 //s_life = 0;
116 chispre(cs);
117 double r = chisran(SRANLUX(), cs);
118 //Iprintn(mcout, r);
119 long n = long(r);
120 if (n < 0) n = 0;
121 if (n > nst - 1) n = nst - 1;
122 if (s_print_listing == 1) {
123 Iprintn(mcout, n);
124 }
125 na_absorbing = nat[n];
126 ns_absorbing = nsh[n];
127 nextpos.prange = xleng * cm;
131 }
132 }
133 }
134 }
135}
136
138 mfunname("void HeedPhoton::physics_after_new_speed(void)");
139 if (s_print_listing == 1) {
140 mcout << "HeedPhoton::physics_after_new_speed is started\n";
141 }
142 if (s_photon_absorbed == 1 && s_delta_generated == 0) {
143 const absvol* av = currpos.G_lavol(); // get least address of volume
144
145 HeedMatterDef* hmd = NULL;
146 const EnTransfCSType* etcst = dynamic_cast<const EnTransfCSType*>(av);
147 if (etcst != NULL) {
148 hmd = etcst->etcs->hmd.getver();
149 } else {
150 const HeedDeltaElectronCSType* hmecst =
151 dynamic_cast<const HeedDeltaElectronCSType*>(av);
152 if (hmecst != NULL) {
153 hmd = hmecst->hdecs->hmd.get();
154 }
155 }
156 check_econd11(hmd, == NULL, mcerr);
157 // generate delta-electrons
158 DynLinArr<double> el_energy;
159 DynLinArr<double> ph_energy;
160 hmd->apacs[na_absorbing]
161 ->get_escape_particles(ns_absorbing, energy, el_energy, ph_energy);
162 if (s_print_listing == 1) {
163 mcout << "The condition:\n";
165 mcout << "The decay products:\n";
166 Iprintn(mcout, el_energy);
167 Iprintn(mcout, ph_energy);
168 }
169 long qel = el_energy.get_qel();
170 long nel;
171 for (nel = 0; nel < qel; nel++) {
172 vec vel;
173 if (nel == 0) { // assumed it is photoelectron
174#ifdef SFER_PHOTOEL
175 if (s_sfer_photoel == 1) {
176 vel.random_sfer_vec();
177 } else {
178 vel = currpos.dir;
179 }
180#else
181 vel = currpos.dir; // direction is OK
182#endif
183 } else {
184 vel.random_sfer_vec();
185 }
186 double gam_1 = el_energy[nel] / ELMAS;
187 double betta = sqrt(1.0 - pow(1.0 / (gam_1 + 1.0), 2.0));
188 double mod_v = betta * c_light;
189 vel = vel * mod_v;
190 if (s_print_listing == 1) {
191 mcout << "Initializing delta electron\n";
192 Iprint4n(mcout, el_energy[nel], gam_1, betta, mod_v);
193 }
194 ActivePtr<gparticle> ac;
195 ac.pass(
198 particle_bank.insert_after(particle_bank.get_last_node(), ac);
199 }
200 long qph = ph_energy.get_qel();
201 long nph;
202 for (nph = 0; nph < qph; nph++) {
203 vec vel;
204 vel.random_sfer_vec();
205 vel *= c_light;
206 if (s_print_listing == 1) {
207 mcout << "Initializing photon\n";
208 Iprint2n(mcout, el_energy[nph], vel);
209 }
210 ActivePtr<gparticle> ac;
211 ac.pass(new HeedPhoton(currpos.tid.eid[0].amvol.getver(), currpos.pt, vel,
212 currpos.time, particle_number, ph_energy[nph]));
213 particle_bank.insert_after(particle_bank.get_last_node(), ac);
214 }
216 s_life = 0;
217 }
218 if (s_print_listing == 1) {
219 mcout << "HeedPhoton::physics_after_new_speed is exitted\n";
220 }
221}
222
223void HeedPhoton::print(std::ostream& file, int l) const {
224 if (l >= 0) {
225 Ifile << "HeedPhoton (l=" << l << "): particle_number=" << particle_number
226 << " energy=" << energy << "MeV\n";
227 if (l == 1) return;
228 indn.n += 2;
229 Ifile << "s_photon_absorbed=" << s_photon_absorbed
230 << " na_absorbing=" << na_absorbing
231 << " ns_absorbing=" << ns_absorbing
232 << " s_delta_generated=" << s_delta_generated
233#ifdef SFER_PHOTOEL
234 << " s_sfer_photoel=" << s_sfer_photoel
235#endif
236 << " parent_particle_number=" << parent_particle_number
237 << " s_print_listing=" << s_print_listing << '\n';
238 gparticle::print(file, l - 1);
239 indn.n -= 2;
240 }
241}
242
243}
DoubleAc pow(const DoubleAc &f, double p)
Definition: DoubleAc.cpp:336
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:616
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
#define mfunname(string)
Definition: FunNameStack.h:67
float chispre(float *x, float *p, float *f, long q)
Definition: chisran.cpp:7
float chisran(float flat_random_number, float *x, float *f, long q)
Definition: chisran.cpp:22
long get_qel(void) const
Definition: AbsArr.h:420
PassivePtr< EnTransfCS > etcs
Definition: EnTransfCS.h:151
PassivePtr< HeedDeltaElectronCS > hdecs
PassivePtr< MatterDef > matter
Definition: HeedMatterDef.h:39
DynLinArr< PassivePtr< const AtomPhotoAbsCS > > apacs
Definition: HeedMatterDef.h:40
virtual void physics(void)
Definition: HeedPhoton.cpp:39
long particle_number
Definition: HeedPhoton.h:19
virtual void print(std::ostream &file, int l) const
Definition: HeedPhoton.cpp:223
void physics_after_new_speed(void)
Definition: HeedPhoton.cpp:137
long parent_particle_number
Definition: HeedPhoton.h:20
Definition: volume.h:91
stvpoint currpos
Definition: gparticle.h:188
virtual void print(std::ostream &file, int l) const
Definition: gparticle.cpp:312
int s_life
Definition: gparticle.h:180
stvpoint nextpos
Definition: gparticle.h:189
PassivePtr< manip_absvol > amvol
Definition: volume.h:39
manip_absvol_eid eid[pqamvol]
Definition: volume.h:52
void up_absref(absref *f)
Definition: volume.cpp:37
Definition: vec.h:477
point pt
Definition: gparticle.h:33
point ptloc
Definition: gparticle.h:37
absvol * G_lavol() const
Definition: gparticle.h:63
vfloat prange
Definition: gparticle.h:54
manip_absvol_treeid tid
Definition: gparticle.h:43
vfloat time
Definition: gparticle.h:55
vec dir
Definition: gparticle.h:35
Definition: vec.h:248
void random_sfer_vec(void)
Definition: vec.cpp:334
Definition: BGMesh.cpp:3
long last_particle_number
Definition: HeedParticle.h:26
const double ELMAS
AbsList< ActivePtr< gparticle > > particle_bank
Definition: TrackHeed.cc:42
const double AVOGADRO
indentation indn
Definition: prstream.cpp:13
#define mcout
Definition: prstream.h:133
#define Ifile
Definition: prstream.h:207
#define mcerr
Definition: prstream.h:135
#define Iprintn(file, name)
Definition: prstream.h:216
#define Iprint2n(file, name1, name2)
Definition: prstream.h:236
#define Iprint4n(file, name1, name2, name3, name4)
Definition: prstream.h:260
ffloat SRANLUX(void)
Definition: ranluxint.h:262
double vfloat
Definition: vfloat.h:15