Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Heed::gparticle Class Reference

#include <gparticle.h>

+ Inheritance diagram for Heed::gparticle:

Public Member Functions

 gparticle ()=default
 Default constructor.
 
 gparticle (manip_absvol *primvol, const point &pt, const vec &vel, vfloat time)
 Constructor.
 
virtual ~gparticle ()
 Destructor.
 
virtual void fly (std::vector< gparticle * > &secondaries)
 Transport the particle.
 
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.
 
const vecposition () const
 Get the current position of the particle.
 
vfloat time () const
 Get the current time of the particle.
 
const vecdirection () const
 Get the current direction of the particle.
 
virtual void print (std::ostream &file, int l) const
 Print-out.
 
virtual gparticlecopy () const
 Clone the particle.
 

Protected Member Functions

virtual void step (std::vector< gparticle * > &secondaries)
 
virtual void change_vol ()
 Move from one volume to another.
 
virtual void curvature (bool &curved, vec &frelcen, vfloat &fmrange, vfloat prec)
 
virtual void physics_after_new_speed (std::vector< gparticle * > &)
 Apply any other processes (turn the trajectory, kill the particle, ...).
 
virtual void physics (std::vector< gparticle * > &)
 Apply any other processes (turn the trajectory, kill the particle, ...).
 
virtual void physics_mrange (double &fmrange)
 
virtual stvpoint calc_step_to_bord ()
 Determine next position.
 
stvpoint switch_new_vol ()
 Generate next position in new volume.
 

Protected Attributes

bool m_alive = false
 Status flag whether the particle is active.
 
long m_nstep = 0
 Step number.
 
long m_nzero_step = 0
 Number of previous steps with zero range (including this step).
 
stvpoint m_origin
 Original point.
 
double m_total_range_from_origin = 0.
 Range from origin to current position.
 
stvpoint m_prevpos
 Previous point.
 
stvpoint m_currpos
 Current point.
 
stvpoint m_nextpos
 Next point.
 

Static Protected Attributes

static constexpr long m_max_qzero_step = 100
 Max. number of zero-steps allowed.
 

Detailed Description

"Geometric particle" (particle that does not interact with materials). It moves along a polyline or circle from one volume to another. Classes for interacting particles should be derived from this base class.

Definition at line 143 of file gparticle.h.

Constructor & Destructor Documentation

◆ gparticle() [1/2]

Heed::gparticle::gparticle ( )
default

Default constructor.

Referenced by copy().

◆ gparticle() [2/2]

Heed::gparticle::gparticle ( manip_absvol primvol,
const point pt,
const vec vel,
vfloat  time 
)

Constructor.

Definition at line 40 of file gparticle.cpp.

42 : m_prevpos(),
43 m_nextpos() {
44 // As far as I can now understand, primvol will be at m_origin.tid.eid[0]
45 mfunname("gparticle::gparticle(...)");
46 primvol->m_find_embed_vol(pt, vel, &m_origin.tid);
47 m_origin.pt = pt;
48 if (vel == dv0) {
50 m_origin.speed = 0.0;
51 } else {
52 m_origin.dir = unit_vec(vel);
53 m_origin.speed = vel.length();
54 }
59 m_origin.time = ftime;
60 m_origin.sb = 0;
61 m_origin.s_ent = 1;
62 if (m_origin.tid.eid.empty()) return;
63 m_alive = true;
66 m_nextpos.s_ent = 0;
67}
#define mfunname(string)
Definition: FunNameStack.h:45
stvpoint m_nextpos
Next point.
Definition: gparticle.h:252
stvpoint m_prevpos
Previous point.
Definition: gparticle.h:248
stvpoint m_currpos
Current point.
Definition: gparticle.h:250
stvpoint m_origin
Original point.
Definition: gparticle.h:243
bool m_alive
Status flag whether the particle is active.
Definition: gparticle.h:233
void up_absref(absref *f)
Definition: volume.cpp:26
std::vector< manip_absvol * > eid
List of volumes.
Definition: volume.h:37
vfloat time
Definition: gparticle.h:47
vec dirloc
Unit vector, in the local system (last system in the tree).
Definition: gparticle.h:29
vec dir
Unit vector, in the first system in the tree.
Definition: gparticle.h:25
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
vec dv0(0, 0, 0)
Definition: vec.h:306

◆ ~gparticle()

virtual Heed::gparticle::~gparticle ( )
inlinevirtual

Destructor.

Definition at line 151 of file gparticle.h.

151{}

Member Function Documentation

◆ calc_step_to_bord()

stvpoint Heed::gparticle::calc_step_to_bord ( )
protectedvirtual

Determine next position.

Definition at line 111 of file gparticle.cpp.

111 {
112 // Calculate next point as step to border.
113 pvecerror("stvpoint gparticle::calc_step_to_bord()");
114 if (m_currpos.sb > 0) {
115 // Just switch to new volume.
116 return switch_new_vol();
117 }
118 bool curved = false;
119 vec relcen;
120 vfloat mrange;
121 curvature(curved, relcen, mrange, m_max_straight_arange);
122 if (mrange <= 0) {
123 // Preserve current point for modification by physics.
124 stvpoint temp(m_currpos);
125 temp.s_ent = 0;
126 return temp;
127 }
128 // Change to local system.
129 m_currpos.tid.up_absref(&relcen);
130 physics_mrange(mrange);
131 trajestep ts(m_max_range, m_rad_for_straight,
132 m_max_straight_arange, m_max_circ_arange,
133 m_currpos.ptloc, m_currpos.dirloc, curved, relcen, mrange,
134 m_currpos.tid.eid.back()->Gavol()->prec);
135 if (ts.mrange <= 0) {
136 stvpoint temp(m_currpos);
137 temp.s_ent = 0;
138 return temp;
139 }
140 // Here the range is calculated:
141 int sb;
142 manip_absvol* faeid = nullptr;
143 m_currpos.tid.G_lavol()->range(ts, 1, sb, faeid);
144 // 1 means inside the volume and makes
145 // the program checking embraced volumes
146 if (ts.s_prec == 0) {
147 // Point is crossed.
148 return stvpoint(m_currpos, ts, sb, 0, faeid);
149 }
150 return stvpoint(m_currpos, ts, ts.mrange, sb, 0, faeid);
151}
virtual int range(trajestep &fts, int s_ext, int &sb, manip_absvol *&faeid) const
Definition: volume.cpp:99
virtual void physics_mrange(double &fmrange)
Definition: gparticle.cpp:109
stvpoint switch_new_vol()
Generate next position in new volume.
Definition: gparticle.cpp:153
virtual void curvature(bool &curved, vec &frelcen, vfloat &fmrange, vfloat prec)
Definition: gparticle.cpp:90
absvol * G_lavol() const
Get last address of volume.
Definition: volume.cpp:17
double vfloat
Definition: vfloat.h:16
#define pvecerror(string)
Definition: vec.h:28

Referenced by step(), and Heed::mparticle::step().

◆ change_vol()

virtual void Heed::gparticle::change_vol ( )
inlineprotectedvirtual

Move from one volume to another.

Definition at line 197 of file gparticle.h.

197{ m_currpos.tid.G_lavol()->income(this); }
virtual void income(gparticle *)
Definition: volume.h:120

Referenced by step(), and Heed::mparticle::step().

◆ copy()

virtual gparticle * Heed::gparticle::copy ( ) const
inlinevirtual

Clone the particle.

Reimplemented in Heed::HeedDeltaElectron, Heed::HeedParticle, Heed::HeedParticle_BGM, Heed::HeedPhoton, Heed::mparticle, and Heed::eparticle.

Definition at line 183 of file gparticle.h.

183{ return new gparticle(*this); }
gparticle()=default
Default constructor.

◆ curvature()

void Heed::gparticle::curvature ( bool &  curved,
vec frelcen,
vfloat fmrange,
vfloat  prec 
)
protectedvirtual

Set curvature. Can also change the direction at the current position.

Parameters
curvedflag whether the trajectory is curved
frelcenposition of the centre of rotation relative to currpos.
fmrangestep range
prectolerance for checking if the force is parallel or antiparallel to dir. In the latter case, the range is restricted by the end point. In calc_step_to_bord() it is set to m_max_straight_arange.

Reimplemented in Heed::mparticle.

Definition at line 90 of file gparticle.cpp.

91 {
92 curved = false;
93 frelcen.x = 0.;
94 frelcen.y = 0.;
95 frelcen.z = 0.;
96 fmrange = max_vfloat;
97 /* The following is for debug
98 vec field(0,1,0);
99 vfloat rad = 10;
100 if (length(m_currpos.dir) > 0 && check_par(m_currpos.dir, field) == 0) {
101 curved = true;
102 vfloat coef = sin2vec(m_currpos.dir, field);
103 rad = rad / coef;
104 frelcen = unit_vec(m_currpos.dir || field) * rad;
105 }
106 */
107}

Referenced by calc_step_to_bord().

◆ direction()

const vec & Heed::gparticle::direction ( ) const
inline

Get the current direction of the particle.

Definition at line 178 of file gparticle.h.

178{ return m_currpos.dir; }

◆ fly()

virtual void Heed::gparticle::fly ( std::vector< gparticle * > &  secondaries)
inlinevirtual

Transport the particle.

Definition at line 154 of file gparticle.h.

154 {
155 mfunname("virtual void gparticle::fly()");
156 while (m_alive) {
157 step(secondaries);
158 physics(secondaries);
159 }
160 }
virtual void step(std::vector< gparticle * > &secondaries)
Definition: gparticle.cpp:69
virtual void physics(std::vector< gparticle * > &)
Apply any other processes (turn the trajectory, kill the particle, ...).
Definition: gparticle.h:218

Referenced by Garfield::TrackHeed::GetCluster(), Garfield::TrackHeed::NewTrack(), Garfield::TrackHeed::TransportDeltaElectron(), and Garfield::TrackHeed::TransportPhoton().

◆ physics()

virtual void Heed::gparticle::physics ( std::vector< gparticle * > &  )
inlineprotectedvirtual

Apply any other processes (turn the trajectory, kill the particle, ...).

Reimplemented in Heed::HeedParticle, Heed::HeedParticle_BGM, and Heed::HeedPhoton.

Definition at line 218 of file gparticle.h.

218{}

Referenced by fly().

◆ physics_after_new_speed()

virtual void Heed::gparticle::physics_after_new_speed ( std::vector< gparticle * > &  )
inlineprotectedvirtual

Apply any other processes (turn the trajectory, kill the particle, ...).

Reimplemented in Heed::HeedDeltaElectron, and Heed::HeedPhoton.

Definition at line 215 of file gparticle.h.

215{}

Referenced by step(), and Heed::mparticle::step().

◆ physics_mrange()

void Heed::gparticle::physics_mrange ( double &  fmrange)
protectedvirtual

Reduce the maximal possible range due to continuous processes. Called from calc_step_to_bord after the call of curvature. but before considering the crossing with volumes. Therefore mrange may be reduced after this.

Reimplemented in Heed::HeedDeltaElectron.

Definition at line 109 of file gparticle.cpp.

109{}

Referenced by calc_step_to_bord().

◆ position()

const vec & Heed::gparticle::position ( ) const
inline

Get the current position of the particle.

Definition at line 174 of file gparticle.h.

174{ return m_currpos.pt.v; }
vec v
Definition: vec.h:368

Referenced by Garfield::TrackHeed::GetCluster().

◆ print()

void Heed::gparticle::print ( std::ostream &  file,
int  l 
) const
virtual

Print-out.

Reimplemented in Heed::HeedDeltaElectron, Heed::HeedParticle, Heed::HeedParticle_BGM, Heed::HeedPhoton, Heed::mparticle, and Heed::eparticle.

Definition at line 193 of file gparticle.cpp.

193 {
194 if (l < 0) return;
195 Ifile << "gparticle(l=" << l << "): alive=" << m_alive << " nstep=" << m_nstep
196 << " total_range_from_origin=" << m_total_range_from_origin
197 << " nzero_step=" << m_nzero_step << '\n';
198 if (l == 1) {
199 file.flush();
200 return;
201 }
202 indn.n += 2;
203 if (l - 5 >= 0) {
204 Ifile << "origin point:\n";
205 indn.n += 2;
206 m_origin.print(file, l - 2);
207 indn.n -= 2;
208 }
209 if (l - 4 >= 0) {
210 Ifile << "previous point:\n";
211 indn.n += 2;
212 m_prevpos.print(file, l - 1);
213 indn.n -= 2;
214 }
215 if (l - 2 >= 0) {
216 Ifile << "current point:\n";
217 indn.n += 2;
218 m_currpos.print(file, l);
219 indn.n -= 2;
220 }
221 if (l - 3 >= 0) {
222 Ifile << "next point:\n";
223 indn.n += 2;
224 m_nextpos.print(file, l - 1);
225 indn.n -= 2;
226 }
227 indn.n -= 2;
228 file.flush();
229}
double m_total_range_from_origin
Range from origin to current position.
Definition: gparticle.h:245
long m_nzero_step
Number of previous steps with zero range (including this step).
Definition: gparticle.h:240
long m_nstep
Step number.
Definition: gparticle.h:236
void print(std::ostream &file, int l) const
Definition: gparticle.cpp:16
indentation indn
Definition: prstream.cpp:15
#define Ifile
Definition: prstream.h:196

Referenced by Heed::HeedPhoton::print(), and Heed::mparticle::print().

◆ set_step_limits()

void Heed::gparticle::set_step_limits ( const vfloat  fmax_range,
const vfloat  frad_for_straight,
const vfloat  fmax_straight_arange,
const vfloat  fmax_circ_arange 
)
inline

Set limits/parameters for trajectory steps.

Definition at line 163 of file gparticle.h.

166 {
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 }

Referenced by Garfield::TrackHeed::NewTrack().

◆ step()

void Heed::gparticle::step ( std::vector< gparticle * > &  secondaries)
protectedvirtual

Assign prevpos = currpos and currpos = nextpos, call change_vol if necessary and update nextpos = calc_step_to_bord(). Derived versions can also recalculate the direction at currpos right after updating currpos = nextpos. This is especially important in the case when the motion is approximated by straight-line steps, but there is a (magnetic) field which slightly
deflects the trajectory. In this case, the velocity is corrected at the end point of each interval, but the position is not.

Reimplemented in Heed::mparticle.

Definition at line 69 of file gparticle.cpp.

69 {
70 // Make step to next point and calculate new step to border.
71 mfunname("void gparticle::step()");
75 m_nstep++;
76 if (m_currpos.prange == 0) {
79 "too many zero steps, possible infinite loop\n", mcerr);
80 } else {
81 m_nzero_step = 0;
82 }
83 physics_after_new_speed(secondaries);
84 if (m_alive) {
87 }
88}
#define check_econd12a(a, sign, b, add, stream)
Definition: FunNameStack.h:181
virtual void physics_after_new_speed(std::vector< gparticle * > &)
Apply any other processes (turn the trajectory, kill the particle, ...).
Definition: gparticle.h:215
virtual stvpoint calc_step_to_bord()
Determine next position.
Definition: gparticle.cpp:111
static constexpr long m_max_qzero_step
Max. number of zero-steps allowed.
Definition: gparticle.h:238
virtual void change_vol()
Move from one volume to another.
Definition: gparticle.h:197
vfloat prange
Range from previous point.
Definition: gparticle.h:46
#define mcerr
Definition: prstream.h:128

Referenced by fly().

◆ switch_new_vol()

stvpoint Heed::gparticle::switch_new_vol ( )
protected

Generate next position in new volume.

Definition at line 153 of file gparticle.cpp.

153 {
154 // Generate next position in new volume.
155 mfunname("stvpoint gparticle::switch_new_vol(void)");
156 manip_absvol_treeid tidl;
157 manip_absvol* eidl = nullptr;
158 stvpoint nextp = m_currpos;
159 point pth = nextp.pt;
160 // Search from primary
161 // In this case it does not necessarily switch to encountered volume
162 // namely nextp.next_eid
163 // Borders of two volumes may coincide. Thus it should look for
164 // the deepest volume at this point.
165 bool ok = false;
166 while (!ok) {
167 nextp.tid.eid[0]->m_find_embed_vol(pth, nextp.dir, &tidl);
168 if (tidl.eid.empty()) {
169 m_alive = false;
170 break;
171 }
172 // By default, assume switching to new volume.
173 int s_e = 1;
174 if (tidl == nextp.tid) {
175 // Remains in the same old volume, may be numerical error
176 // Will probably repeat attempt to switch at the same steps until ok.
177 s_e = 0;
178 double curprec = nextp.tid.G_lavol()->prec;
179 if (m_currpos.prange <= curprec) {
180 // very bad case, to repeat the trial.
181 vec additional_dist = nextp.dir * curprec;
182 pth = pth + additional_dist;
183 tidl = manip_absvol_treeid();
184 continue;
185 }
186 }
187 return stvpoint(pth, nextp.dir, nextp.speed, tidl, 0.0, nextp.time, 0, s_e,
188 eidl);
189 }
190 return stvpoint();
191}

Referenced by calc_step_to_bord().

◆ time()

vfloat Heed::gparticle::time ( ) const
inline

Get the current time of the particle.

Definition at line 176 of file gparticle.h.

176{ return m_currpos.time; }

Referenced by Garfield::TrackHeed::GetCluster().

Member Data Documentation

◆ m_alive

bool Heed::gparticle::m_alive = false
protected

◆ m_currpos

◆ m_max_qzero_step

constexpr long Heed::gparticle::m_max_qzero_step = 100
staticconstexprprotected

Max. number of zero-steps allowed.

Definition at line 238 of file gparticle.h.

Referenced by step(), and Heed::mparticle::step().

◆ m_nextpos

stvpoint Heed::gparticle::m_nextpos
protected

Next point.

Definition at line 252 of file gparticle.h.

Referenced by gparticle(), Heed::HeedPhoton::physics(), print(), step(), and Heed::mparticle::step().

◆ m_nstep

long Heed::gparticle::m_nstep = 0
protected

Step number.

Definition at line 236 of file gparticle.h.

Referenced by print(), step(), and Heed::mparticle::step().

◆ m_nzero_step

long Heed::gparticle::m_nzero_step = 0
protected

Number of previous steps with zero range (including this step).

Definition at line 240 of file gparticle.h.

Referenced by print(), step(), and Heed::mparticle::step().

◆ m_origin

stvpoint Heed::gparticle::m_origin
protected

Original point.

Definition at line 243 of file gparticle.h.

Referenced by gparticle(), Heed::mparticle::mparticle(), and print().

◆ m_prevpos

stvpoint Heed::gparticle::m_prevpos
protected

◆ m_total_range_from_origin

double Heed::gparticle::m_total_range_from_origin = 0.
protected

Range from origin to current position.

Definition at line 245 of file gparticle.h.

Referenced by print(), step(), and Heed::mparticle::step().


The documentation for this class was generated from the following files: