Garfield++ v2r0
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;
39 /// "Entering flag".
40 /// 1 - entering new volume, 0 otherwise. i
41 /// Embraced volume is also considered new.
42 int s_ent;
43
45 /// Range from previous point.
48
49 // constructors
51 : pt(),
52 dir(),
53 ptloc(),
54 dirloc(),
55 speed(0.0),
56 tid(),
57 sb(0),
58 s_ent(0),
59 next_eid(),
60 prange(0.0),
61 time(0) {}
62 stvpoint(const point& fpt, const vec& fdir, vfloat fspeed,
63 manip_absvol_treeid& ftid, vfloat fprange, vfloat ftime, int fsb,
64 int fs_ent, PassivePtr<manip_absvol>& faeid)
65 : pt(fpt),
66 dir(unit_vec(fdir)),
67 speed(fspeed),
68 tid(ftid),
69 sb(fsb),
70 s_ent(fs_ent),
71 next_eid(faeid),
72 prange(fprange),
73 time(ftime) {
74 ptloc = pt;
76 dirloc = dir;
78 }
79 stvpoint(const stvpoint& pstv, const trajestep& ts, // in the local system
80 vfloat mrange, // may be less than one in ts
81 int fsb, int fs_ent, PassivePtr<manip_absvol>& faeid)
82 : pt(),
83 dir(),
84 ptloc(),
85 dirloc(),
86 speed(pstv.speed),
87 tid(pstv.tid),
88 sb(fsb),
89 s_ent(fs_ent),
90 next_eid(faeid),
91 prange(mrange),
92 time(pstv.time + mrange / pstv.speed) {
93 if (pstv.speed == 0) {
94 time = pstv.time; // just to put anything
95 } else {
96 // If speed is changed, this time is to be corrected in derivative class
97 time = pstv.time + mrange / pstv.speed;
98 }
99 ts.Gnextpoint(mrange, ptloc, dirloc);
100 pt = ptloc;
102 dir = dirloc;
104 }
105
106 stvpoint(const stvpoint& pstv, const trajestep& ts, // in the local system
107 int fsb, int fs_ent, PassivePtr<manip_absvol>& faeid)
108 : pt(),
109 dir(),
110 ptloc(),
111 dirloc(),
112 speed(pstv.speed),
113 tid(pstv.tid),
114 sb(fsb),
115 s_ent(fs_ent),
116 next_eid(faeid),
117 prange(ts.mrange),
118 time(pstv.time + ts.mrange / pstv.speed) {
119 if (pstv.speed == 0) {
120 time = pstv.time; // just to put anything
121 } else {
122 // If speed is changed, this time is to be corrected in derivative class
123 time = pstv.time + ts.mrange / pstv.speed;
124 }
125 ptloc = ts.mpoint;
126 point temp;
127 ts.Gnextpoint(ts.mrange, temp, dirloc);
128 pt = ptloc;
130 dir = dirloc;
132 }
134 : pt(fp.pt),
135 dir(fp.dir),
136 ptloc(fp.ptloc),
137 dirloc(fp.dirloc),
138 speed(fp.speed),
139 tid(fp.tid),
140 sb(fp.sb),
141 s_ent(fp.s_ent),
142 next_eid(fp.next_eid),
143 prange(fp.prange),
144 time(fp.time) {}
145 void print(std::ostream& file, int l) const;
146};
147
148extern trajestep_limit gtrajlim;
149
150/// "Geometric particle" (particle which does not interact with materials).
151/// It moves along a polyline line or circle from one volume to another.
152/// The flying is represented by changing of class members representing
153/// particle position.
154/// Interacted particle should be derived class from this one.
155
156class gparticle : public RegPassivePtr {
157 public:
158 /// Default constructor.
159 gparticle() : s_life(false), nstep(0) {}
160 /// Constructor.
161 gparticle(manip_absvol* primvol, const point& pt, const vec& vel,
162 vfloat time);
163 /// Destructor.
164 virtual ~gparticle() {}
165
166 bool s_life;
167 /// Step number.
168 long nstep;
169 /// Range from origin to currpos.
171 /// Number of previous steps with zero range (including this step).
173
174 static long max_q_zero_step;
179 // current relcen computed
180 // at the last call of calc_step_to_bord(), only for debug print
182
183 /// Assign prevpos = currpos and currpos = nextpos,
184 /// calls change_vol if necessary and update nextpos =calc_step_to_bord().
185 // Derived versions can also recalculate direction of move currpos
186 // right after the call of currpos=nextpos;.
187 // This is especially important in the case when the move is done
188 // by straight steps, but there is a field (magnetic) of any
189 // force which deflects the trajectory slightly. In this case
190 // at the end point of each interval the velocity is corrected (but the
191 // point currpos is not).
192 virtual void step(std::vector<gparticle*>& secondaries);
193
194 virtual void change_vol(void) { currpos.tid.G_lavol()->income(this); }
195 virtual void curvature(int& fs_cf, vec& frelcen, vfloat& fmrange,
196 vfloat prec);
197 // Allows to set curvature.
198 // For flying particle it is expected to call another function
199 // so as to obtain value and direction of force.
200 // Can also change currpos.dir.
201 // prec is used to find out if the force is parallel or antiparallel to dir
202 // In the latter case the range is restricted by the stop point.
203 // Thus this prec does not depend on order of geometry sizes.
204 // In calc_step_to_bord() it is set to gtrajlim.max_straight_arange.
205 // vec& frelcen: position of the center of circumf. relatively currpos
206
207 virtual void physics_after_new_speed(std::vector<gparticle*>& /*secondaries*/) {}
208 // Allows to apply any other processes, to turn the trajectory, kill
209 // the particle and so on.
210 virtual void physics(std::vector<gparticle*>& /*secondaries*/) {}
211 // Allows to apply any other processes, to turn the trajectory, kill
212 // the particle and so on.
213 virtual void physics_mrange(double& fmrange);
214 // Allows to reduce maximal possible range due to continuous processes.
215 // Called from calc_step_to_bord() after the call of curvature(...)
216 // but before considering the crossing with volumes.
217 // Therefore mrange may be reduced after this.
218
219 /// Produces nextpos
220 virtual stvpoint calc_step_to_bord();
221
223
224 /// Transport the particle.
225 virtual void fly(std::vector<gparticle*>& secondaries) {
226 mfunname("virtual void gparticle::fly()");
227 while (s_life) {
228 step(secondaries);
229 physics(secondaries);
230 }
231 }
232 virtual void print(std::ostream& file, int l) const;
233 virtual gparticle* copy() const { return new gparticle(*this); }
234
235};
236}
237
238#endif
#define mfunname(string)
Definition: FunNameStack.h:45
virtual void income(gparticle *)
Definition: volume.h:122
virtual void print(std::ostream &file, int l) const
Definition: gparticle.cpp:200
virtual ~gparticle()
Destructor.
Definition: gparticle.h:164
virtual void physics_mrange(double &fmrange)
Definition: gparticle.cpp:116
static long max_q_zero_step
Definition: gparticle.h:174
stvpoint prevpos
Definition: gparticle.h:176
virtual void change_vol(void)
Definition: gparticle.h:194
virtual void physics_after_new_speed(std::vector< gparticle * > &)
Definition: gparticle.h:207
virtual void curvature(int &fs_cf, vec &frelcen, vfloat &fmrange, vfloat prec)
Definition: gparticle.cpp:99
stvpoint origin
Definition: gparticle.h:175
double total_range_from_origin
Range from origin to currpos.
Definition: gparticle.h:170
virtual stvpoint calc_step_to_bord()
Produces nextpos.
Definition: gparticle.cpp:119
long nstep
Step number.
Definition: gparticle.h:168
virtual void step(std::vector< gparticle * > &secondaries)
Definition: gparticle.cpp:77
stvpoint currpos
Definition: gparticle.h:177
gparticle()
Default constructor.
Definition: gparticle.h:159
stvpoint nextpos
Definition: gparticle.h:178
stvpoint switch_new_vol()
Definition: gparticle.cpp:160
virtual void physics(std::vector< gparticle * > &)
Definition: gparticle.h:210
virtual gparticle * copy() const
Definition: gparticle.h:233
long n_zero_step
Number of previous steps with zero range (including this step).
Definition: gparticle.h:172
virtual void fly(std::vector< gparticle * > &secondaries)
Transport the particle.
Definition: gparticle.h:225
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:178
Point.
Definition: vec.h:374
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 &pstv, const trajestep &ts, int fsb, int fs_ent, PassivePtr< manip_absvol > &faeid)
Definition: gparticle.h:106
stvpoint(const stvpoint &fp)
Definition: gparticle.h:133
vec dirloc
Unit vector, in the local system (last system in the tree).
Definition: gparticle.h:29
stvpoint(const stvpoint &pstv, const trajestep &ts, vfloat mrange, int fsb, int fs_ent, PassivePtr< manip_absvol > &faeid)
Definition: gparticle.h:79
vec dir
Unit vector, in the first system in the tree.
Definition: gparticle.h:25
PassivePtr< manip_absvol > next_eid
Definition: gparticle.h:44
stvpoint(const point &fpt, const vec &fdir, vfloat fspeed, manip_absvol_treeid &ftid, vfloat fprange, vfloat ftime, int fsb, int fs_ent, PassivePtr< manip_absvol > &faeid)
Definition: gparticle.h:62
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
point ptloc
Coordinates in the local system (last system in the tree).
Definition: gparticle.h:27
vfloat mrange
Maximal possible range.
Definition: trajestep.h:90
void Gnextpoint(vfloat frange, point &fpos, vec &fdir) const
Definition: trajestep.cpp:76
Definition: vec.h:186
Definition: BGMesh.cpp:5
double vfloat
Definition: vfloat.h:16
trajestep_limit gtrajlim
Definition: TrackHeed.cc:50