Garfield++ 3.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};
138
139/// "Geometric particle" (particle that does not interact with materials).
140/// It moves along a polyline or circle from one volume to another.
141/// Classes for interacting particles should be derived from this base class.
142
144 public:
145 /// Default constructor.
146 gparticle() = default;
147 /// Constructor.
148 gparticle(manip_absvol* primvol, const point& pt, const vec& vel,
149 vfloat time);
150 /// Destructor.
151 virtual ~gparticle() {}
152
153 /// Transport the particle.
154 virtual void fly(std::vector<gparticle*>& secondaries) {
155 mfunname("virtual void gparticle::fly()");
156 while (m_alive) {
157 step(secondaries);
158 physics(secondaries);
159 }
160 }
161
162 /// Set limits/parameters for trajectory steps.
163 void set_step_limits(const vfloat fmax_range,
164 const vfloat frad_for_straight,
165 const vfloat fmax_straight_arange,
166 const vfloat fmax_circ_arange) {
167 m_max_range = fmax_range;
168 m_rad_for_straight = frad_for_straight;
169 m_max_straight_arange = fmax_straight_arange;
170 m_max_circ_arange = fmax_circ_arange;
171 }
172
173 /// Get the current position of the particle.
174 const vec& position() const { return m_currpos.pt.v; }
175 /// Get the current time of the particle.
176 vfloat time() const { return m_currpos.time; }
177 /// Get the current direction of the particle.
178 const vec& direction() const { return m_currpos.dir; }
179
180 /// Print-out.
181 virtual void print(std::ostream& file, int l) const;
182 /// Clone the particle.
183 virtual gparticle* copy() const { return new gparticle(*this); }
184
185 protected:
186 /// Assign prevpos = currpos and currpos = nextpos,
187 /// call change_vol if necessary and update nextpos = calc_step_to_bord().
188 /// Derived versions can also recalculate the direction at currpos
189 /// right after updating currpos = nextpos.
190 /// This is especially important in the case when the motion is approximated
191 /// by straight-line steps, but there is a (magnetic) field which slightly
192 /// deflects the trajectory. In this case, the velocity is corrected
193 /// at the end point of each interval, but the position is not.
194 virtual void step(std::vector<gparticle*>& secondaries);
195
196 /// Move from one volume to another.
197 virtual void change_vol() { m_currpos.tid.G_lavol()->income(this); }
198
199 /** Set curvature. Can also change the direction at the current position.
200 * \param curved
201 * flag whether the trajectory is curved
202 * \param frelcen
203 * position of the centre of rotation relative to currpos.
204 * \param fmrange
205 * step range
206 * \param prec
207 * tolerance for checking if the force is parallel or antiparallel to
208 * dir. In the latter case, the range is restricted by the end point.
209 * In calc_step_to_bord() it is set to m_max_straight_arange.
210 */
211 virtual void curvature(bool& curved, vec& frelcen, vfloat& fmrange,
212 vfloat prec);
213
214 /// Apply any other processes (turn the trajectory, kill the particle, ...).
215 virtual void physics_after_new_speed(std::vector<gparticle*>& /*secondaries*/) {}
216
217 /// Apply any other processes (turn the trajectory, kill the particle, ...).
218 virtual void physics(std::vector<gparticle*>& /*secondaries*/) {}
219
220 /// Reduce the maximal possible range due to continuous processes.
221 /// Called from calc_step_to_bord after the call of curvature.
222 /// but before considering the crossing with volumes.
223 /// Therefore mrange may be reduced after this.
224 virtual void physics_mrange(double& fmrange);
225
226 /// Determine next position.
227 virtual stvpoint calc_step_to_bord();
228
229 /// Generate next position in new volume.
231
232 /// Status flag whether the particle is active.
233 bool m_alive = false;
234
235 /// Step number.
236 long m_nstep = 0;
237 /// Max. number of zero-steps allowed.
238 static constexpr long m_max_qzero_step = 100;
239 /// Number of previous steps with zero range (including this step).
240 long m_nzero_step = 0;
241
242 /// Original point.
244 /// Range from origin to current position.
246
247 /// Previous point.
249 /// Current point.
251 /// Next point.
253
254 private:
255 /// Max. length of trajectory steps.
256 vfloat m_max_range = 100. * CLHEP::cm;
257 /// Bending radius beyond which to use straight-line steps.
258 vfloat m_rad_for_straight = 1000. * CLHEP::cm;
259 /// Angular step limit when using straight-line approximation.
260 vfloat m_max_straight_arange = 0.1 * CLHEP::rad;
261 /// Angular step limit for curved lines.
262 vfloat m_max_circ_arange = 0.2 * CLHEP::rad;
263};
264}
265
266#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:193
virtual ~gparticle()
Destructor.
Definition: gparticle.h:151
virtual void physics_mrange(double &fmrange)
Definition: gparticle.cpp:109
virtual void physics_after_new_speed(std::vector< gparticle * > &)
Apply any other processes (turn the trajectory, kill the particle, ...).
Definition: gparticle.h:215
stvpoint m_nextpos
Next point.
Definition: gparticle.h:252
double m_total_range_from_origin
Range from origin to current position.
Definition: gparticle.h:245
virtual stvpoint calc_step_to_bord()
Determine next position.
Definition: gparticle.cpp:111
stvpoint m_prevpos
Previous point.
Definition: gparticle.h:248
static constexpr long m_max_qzero_step
Max. number of zero-steps allowed.
Definition: gparticle.h:238
virtual void step(std::vector< gparticle * > &secondaries)
Definition: gparticle.cpp:69
vfloat time() const
Get the current time of the particle.
Definition: gparticle.h:176
gparticle()=default
Default constructor.
const vec & position() const
Get the current position of the particle.
Definition: gparticle.h:174
stvpoint m_currpos
Current point.
Definition: gparticle.h:250
virtual void change_vol()
Move from one volume to another.
Definition: gparticle.h:197
stvpoint switch_new_vol()
Generate next position in new volume.
Definition: gparticle.cpp:153
virtual void physics(std::vector< gparticle * > &)
Apply any other processes (turn the trajectory, kill the particle, ...).
Definition: gparticle.h:218
virtual gparticle * copy() const
Clone the particle.
Definition: gparticle.h:183
long m_nzero_step
Number of previous steps with zero range (including this step).
Definition: gparticle.h:240
stvpoint m_origin
Original point.
Definition: gparticle.h:243
bool m_alive
Status flag whether the particle is active.
Definition: gparticle.h:233
long m_nstep
Step number.
Definition: gparticle.h:236
const vec & direction() const
Get the current direction of the particle.
Definition: gparticle.h:178
virtual void fly(std::vector< gparticle * > &secondaries)
Transport the particle.
Definition: gparticle.h:154
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:163
virtual void curvature(bool &curved, vec &frelcen, vfloat &fmrange, vfloat prec)
Definition: gparticle.cpp:90
Service class (array of manip_absvol).
Definition: volume.h:32
void down_absref(absref *f)
Definition: volume.cpp:21
void up_absref(absref *f)
Definition: volume.cpp:26
absvol * G_lavol() const
Get last address of volume.
Definition: volume.cpp:17
Abstract base classs for volume "manipulators".
Definition: volume.h:128
Point.
Definition: vec.h:366
vec v
Definition: vec.h:368
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.
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:177
Definition: BGMesh.cpp:6
double vfloat
Definition: vfloat.h:16