Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
gparticle.h
Go to the documentation of this file.
1#ifndef GPARTICLE_H
2#define GPARTICLE_H
4
5/*
6Copyright (c) 2000 Igor B. Smirnov
7
8The file can be used, copied, modified, and distributed
9according to the terms of GNU Lesser General Public License version 2.1
10as published by the Free Software Foundation,
11and provided that the above copyright notice, this permission notice,
12and notices about any modifications of the original text
13appear in all copies and in supporting documentation.
14The file is provided "as is" without express or implied warranty.
15*/
16
17namespace Heed {
18
19/// Point in space, time and velocity
20class stvpoint {
21 public:
22 /// Coordinates in the first system in the tree.
24 /// Unit vector, in the first system in the tree.
26 /// Coordinates in the local system (last system in the tree).
28 /// Unit vector, in the local system (last system in the tree).
30 /// Longitudinal velocity
33
34 /// Position flag
35 /// 0 - inside volume, or unknown
36 /// 1 - on the border of the volume
37 /// 2 - on the border of an embraced volume
38 int sb = 0;
39 /// "Entering flag".
40 /// 1 - entering new volume, 0 otherwise.
41 /// Embraced volume is also considered new.
42 int s_ent = 0;
43
44 manip_absvol* next_eid = nullptr; // if nextpos.sb==2
45 /// Range from previous point.
48
49 /// Default constructor.
50 stvpoint() = default;
51 /// Constructor.
52 stvpoint(const point& fpt, const vec& fdir, vfloat fspeed,
53 manip_absvol_treeid& ftid, vfloat fprange, vfloat ftime, int fsb,
54 int fs_ent, manip_absvol* faeid)
55 : pt(fpt),
56 dir(unit_vec(fdir)),
57 speed(fspeed),
58 tid(ftid),
59 sb(fsb),
60 s_ent(fs_ent),
61 next_eid(faeid),
62 prange(fprange),
63 time(ftime) {
64 ptloc = pt;
66 dirloc = dir;
68 }
69 /** Constructor.
70 * \param pstv previous point
71 * \param ts trajectory step (in the local system)
72 * \param mrange step length (may be less than the one in ts)
73 * \param fsb position flag
74 * \param fs_ent "entering" flag
75 * \param faeid next volume
76 **/
77 stvpoint(const stvpoint& pstv, const trajestep& ts, vfloat mrange,
78 int fsb, int fs_ent, manip_absvol* faeid)
79 : pt(),
80 dir(),
81 ptloc(),
82 dirloc(),
83 speed(pstv.speed),
84 tid(pstv.tid),
85 sb(fsb),
86 s_ent(fs_ent),
87 next_eid(faeid),
88 prange(mrange) {
89 if (pstv.speed == 0) {
90 time = pstv.time; // just to put anything
91 } else {
92 // If speed is changed, this time is to be corrected in derivative class
93 time = pstv.time + mrange / pstv.speed;
94 }
95 ts.Gnextpoint(mrange, ptloc, dirloc);
96 pt = ptloc;
98 dir = dirloc;
100 }
101 /** Constructor.
102 * \param pstv previous point
103 * \param ts trajectory step (in the local system)
104 * \param fsb position flag
105 * \param fs_ent "entering" flag
106 * \param faeid next volume
107 **/
108 stvpoint(const stvpoint& pstv, const trajestep& ts,
109 int fsb, int fs_ent, manip_absvol* faeid)
110 : pt(),
111 dir(),
112 ptloc(),
113 dirloc(),
114 speed(pstv.speed),
115 tid(pstv.tid),
116 sb(fsb),
117 s_ent(fs_ent),
118 next_eid(faeid),
119 prange(ts.mrange) {
120 if (pstv.speed == 0) {
121 time = pstv.time; // just to put anything
122 } else {
123 // If speed is changed, this time is to be corrected in derivative class
124 time = pstv.time + ts.mrange / pstv.speed;
125 }
126 ptloc = ts.mpoint;
127 point temp;
128 ts.Gnextpoint(ts.mrange, temp, dirloc);
129 pt = ptloc;
131 dir = dirloc;
133 }
134 /// Copy constructor.
135 stvpoint(const stvpoint& fp) = default;
136 void print(std::ostream& file, int l) const;
137 absvol* volume() { return tid.G_lavol(); }
138};
139
140/// "Geometric particle" (particle that does not interact with materials).
141/// It moves along a polyline or circle from one volume to another.
142/// Classes for interacting particles should be derived from this base class.
143
145 public:
146 /// Default constructor.
147 gparticle() = default;
148 /// Constructor.
149 gparticle(manip_absvol* primvol, const point& pt, const vec& vel,
150 vfloat time);
151 /// Destructor.
152 virtual ~gparticle() {}
153
154 /// Transport the particle.
155 virtual void fly(std::vector<gparticle*>& secondaries) {
156 mfunname("virtual void gparticle::fly()");
157 while (m_alive) {
158 step(secondaries);
159 physics(secondaries);
160 }
161 }
162
163 virtual void fly(std::vector<gparticle*>& secondaries, const bool one_step) {
164 mfunname("virtual void gparticle::fly()");
165 int nstep = 0;
166 while (m_alive) {
167 step(secondaries);
168 physics(secondaries);
169 ++nstep;
170 if (one_step && nstep >= 2) break;
171 }
172 }
173
174 /// Set limits/parameters for trajectory steps.
175 void set_step_limits(const vfloat fmax_range,
176 const vfloat frad_for_straight,
177 const vfloat fmax_straight_arange,
178 const vfloat fmax_circ_arange) {
179 m_max_range = fmax_range;
180 m_rad_for_straight = frad_for_straight;
181 m_max_straight_arange = fmax_straight_arange;
182 m_max_circ_arange = fmax_circ_arange;
183 }
184
185 /// Get the current position of the particle.
186 const vec& position() const { return m_currpos.pt.v; }
187 /// Get the current time of the particle.
188 vfloat time() const { return m_currpos.time; }
189 /// Get the current direction of the particle.
190 const vec& direction() const { return m_currpos.dir; }
191 // Alive?
192 bool alive() const { return m_alive; }
193
194 /// Print-out.
195 virtual void print(std::ostream& file, int l) const;
196 /// Clone the particle.
197 virtual gparticle* copy() const { return new gparticle(*this); }
198
199 protected:
200 /// Assign prevpos = currpos and currpos = nextpos,
201 /// call change_vol if necessary and update nextpos = calc_step_to_bord().
202 /// Derived versions can also recalculate the direction at currpos
203 /// right after updating currpos = nextpos.
204 /// This is especially important in the case when the motion is approximated
205 /// by straight-line steps, but there is a (magnetic) field which slightly
206 /// deflects the trajectory. In this case, the velocity is corrected
207 /// at the end point of each interval, but the position is not.
208 virtual void step(std::vector<gparticle*>& secondaries);
209
210 /// Move from one volume to another.
211 virtual void change_vol() { m_currpos.volume()->income(this); }
212
213 /** Set curvature. Can also change the direction at the current position.
214 * \param curved
215 * flag whether the trajectory is curved
216 * \param frelcen
217 * position of the centre of rotation relative to currpos.
218 * \param fmrange
219 * step range
220 * \param prec
221 * tolerance for checking if the force is parallel or antiparallel to
222 * dir. In the latter case, the range is restricted by the end point.
223 * In calc_step_to_bord() it is set to m_max_straight_arange.
224 */
225 virtual void curvature(bool& curved, vec& frelcen, vfloat& fmrange,
226 vfloat prec);
227
228 /// Apply any other processes (turn the trajectory, kill the particle, ...).
229 virtual void physics_after_new_speed(std::vector<gparticle*>& /*secondaries*/) {}
230
231 /// Apply any other processes (turn the trajectory, kill the particle, ...).
232 virtual void physics(std::vector<gparticle*>& /*secondaries*/) {}
233
234 /// Reduce the maximal possible range due to continuous processes.
235 /// Called from calc_step_to_bord after the call of curvature.
236 /// but before considering the crossing with volumes.
237 /// Therefore mrange may be reduced after this.
238 virtual void physics_mrange(double& fmrange);
239
240 /// Determine next position.
241 virtual stvpoint calc_step_to_bord();
242
243 /// Generate next position in new volume.
245
246 /// Status flag whether the particle is active.
247 bool m_alive = false;
248
249 /// Step number.
250 long m_nstep = 0;
251 /// Max. number of zero-steps allowed.
252 static constexpr long m_max_qzero_step = 100;
253 /// Number of previous steps with zero range (including this step).
254 long m_nzero_step = 0;
255
256 /// Original point.
258 /// Range from origin to current position.
260
261 /// Previous point.
263 /// Current point.
265 /// Next point.
267
268 private:
269 /// Max. length of trajectory steps.
270 vfloat m_max_range = 100. * CLHEP::cm;
271 /// Bending radius beyond which to use straight-line steps.
272 vfloat m_rad_for_straight = 1000. * CLHEP::cm;
273 /// Angular step limit when using straight-line approximation.
274 vfloat m_max_straight_arange = 0.1 * CLHEP::rad;
275 /// Angular step limit for curved lines.
276 vfloat m_max_circ_arange = 0.2 * CLHEP::rad;
277};
278}
279
280#endif
#define mfunname(string)
Definition: FunNameStack.h:45
virtual void income(gparticle *)
Definition: volume.h:120
virtual void print(std::ostream &file, int l) const
Print-out.
Definition: gparticle.cpp:192
virtual ~gparticle()
Destructor.
Definition: gparticle.h:152
virtual void physics_mrange(double &fmrange)
Definition: gparticle.cpp:108
virtual void physics_after_new_speed(std::vector< gparticle * > &)
Apply any other processes (turn the trajectory, kill the particle, ...).
Definition: gparticle.h:229
virtual void fly(std::vector< gparticle * > &secondaries, const bool one_step)
Definition: gparticle.h:163
stvpoint m_nextpos
Next point.
Definition: gparticle.h:266
double m_total_range_from_origin
Range from origin to current position.
Definition: gparticle.h:259
virtual stvpoint calc_step_to_bord()
Determine next position.
Definition: gparticle.cpp:110
stvpoint m_prevpos
Previous point.
Definition: gparticle.h:262
static constexpr long m_max_qzero_step
Max. number of zero-steps allowed.
Definition: gparticle.h:252
virtual void step(std::vector< gparticle * > &secondaries)
Definition: gparticle.cpp:68
bool alive() const
Definition: gparticle.h:192
vfloat time() const
Get the current time of the particle.
Definition: gparticle.h:188
gparticle()=default
Default constructor.
const vec & position() const
Get the current position of the particle.
Definition: gparticle.h:186
stvpoint m_currpos
Current point.
Definition: gparticle.h:264
virtual void change_vol()
Move from one volume to another.
Definition: gparticle.h:211
stvpoint switch_new_vol()
Generate next position in new volume.
Definition: gparticle.cpp:152
virtual void physics(std::vector< gparticle * > &)
Apply any other processes (turn the trajectory, kill the particle, ...).
Definition: gparticle.h:232
virtual gparticle * copy() const
Clone the particle.
Definition: gparticle.h:197
long m_nzero_step
Number of previous steps with zero range (including this step).
Definition: gparticle.h:254
stvpoint m_origin
Original point.
Definition: gparticle.h:257
bool m_alive
Status flag whether the particle is active.
Definition: gparticle.h:247
long m_nstep
Step number.
Definition: gparticle.h:250
const vec & direction() const
Get the current direction of the particle.
Definition: gparticle.h:190
virtual void fly(std::vector< gparticle * > &secondaries)
Transport the particle.
Definition: gparticle.h:155
void set_step_limits(const vfloat fmax_range, const vfloat frad_for_straight, const vfloat fmax_straight_arange, const vfloat fmax_circ_arange)
Set limits/parameters for trajectory steps.
Definition: gparticle.h:175
virtual void curvature(bool &curved, vec &frelcen, vfloat &fmrange, vfloat prec)
Definition: gparticle.cpp:89
Service class (array of manip_absvol).
Definition: volume.h:32
void down_absref(absref *f)
Definition: volume.cpp:22
void up_absref(absref *f)
Definition: volume.cpp:27
absvol * G_lavol() const
Get last address of volume.
Definition: volume.cpp:18
Abstract base classs for volume "manipulators".
Definition: volume.h:128
Point.
Definition: vec.h:368
vec v
Definition: vec.h:370
Point in space, time and velocity.
Definition: gparticle.h:20
vfloat time
Definition: gparticle.h:47
void print(std::ostream &file, int l) const
Definition: gparticle.cpp:16
stvpoint(const stvpoint &fp)=default
Copy constructor.
absvol * volume()
Definition: gparticle.h:137
manip_absvol * next_eid
Definition: gparticle.h:44
vec dirloc
Unit vector, in the local system (last system in the tree).
Definition: gparticle.h:29
stvpoint(const point &fpt, const vec &fdir, vfloat fspeed, manip_absvol_treeid &ftid, vfloat fprange, vfloat ftime, int fsb, int fs_ent, manip_absvol *faeid)
Constructor.
Definition: gparticle.h:52
stvpoint(const stvpoint &pstv, const trajestep &ts, int fsb, int fs_ent, manip_absvol *faeid)
Definition: gparticle.h:108
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
stvpoint(const stvpoint &pstv, const trajestep &ts, vfloat mrange, int fsb, int fs_ent, manip_absvol *faeid)
Definition: gparticle.h:77
point pt
Coordinates in the first system in the tree.
Definition: gparticle.h:23
manip_absvol_treeid tid
Definition: gparticle.h:32
stvpoint()=default
Default constructor.
point ptloc
Coordinates in the local system (last system in the tree).
Definition: gparticle.h:27
vfloat mrange
Maximal possible range.
Definition: trajestep.h:93
void Gnextpoint(vfloat frange, point &fpos, vec &fdir) const
Move to the next point.
Definition: trajestep.cpp:80
Definition: vec.h:179
Definition: BGMesh.cpp:6
double vfloat
Definition: vfloat.h:16