Garfield++ 4.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.
 
virtual void fly (std::vector< gparticle * > &secondaries, const bool one_step)
 
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.
 
bool alive () const
 
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 144 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 mfunname("gparticle::gparticle(...)");
45 primvol->m_find_embed_vol(pt, vel, &m_origin.tid);
46 m_origin.pt = pt;
47 if (vel == dv0) {
49 m_origin.speed = 0.0;
50 } else {
51 m_origin.dir = unit_vec(vel);
52 m_origin.speed = vel.length();
53 }
58 m_origin.time = ftime;
59 m_origin.sb = 0;
60 m_origin.s_ent = 1;
61 if (m_origin.tid.eid.empty()) return;
62 m_alive = true;
65 m_nextpos.s_ent = 0;
66}
#define mfunname(string)
Definition: FunNameStack.h:45
stvpoint m_nextpos
Next point.
Definition: gparticle.h:266
stvpoint m_prevpos
Previous point.
Definition: gparticle.h:262
stvpoint m_currpos
Current point.
Definition: gparticle.h:264
stvpoint m_origin
Original point.
Definition: gparticle.h:257
bool m_alive
Status flag whether the particle is active.
Definition: gparticle.h:247
void up_absref(absref *f)
Definition: volume.cpp:27
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:308

◆ ~gparticle()

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

Destructor.

Definition at line 152 of file gparticle.h.

152{}

Member Function Documentation

◆ alive()

bool Heed::gparticle::alive ( ) const
inline

Definition at line 192 of file gparticle.h.

192{ return m_alive; }

Referenced by Heed::HeedParticle::physics(), and Heed::HeedParticle_BGM::physics().

◆ calc_step_to_bord()

stvpoint Heed::gparticle::calc_step_to_bord ( )
protectedvirtual

Determine next position.

Definition at line 110 of file gparticle.cpp.

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

211{ m_currpos.volume()->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 197 of file gparticle.h.

197{ 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 89 of file gparticle.cpp.

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

Referenced by calc_step_to_bord().

◆ direction()

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

Get the current direction of the particle.

Definition at line 190 of file gparticle.h.

190{ return m_currpos.dir; }

◆ fly() [1/2]

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

Transport the particle.

Definition at line 155 of file gparticle.h.

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

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

◆ fly() [2/2]

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

Definition at line 163 of file gparticle.h.

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

◆ 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 232 of file gparticle.h.

232{}

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 229 of file gparticle.h.

229{}

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 108 of file gparticle.cpp.

108{}

Referenced by calc_step_to_bord().

◆ position()

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

Get the current position of the particle.

Definition at line 186 of file gparticle.h.

186{ return m_currpos.pt.v; }
vec v
Definition: vec.h:370

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 192 of file gparticle.cpp.

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

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 175 of file gparticle.h.

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

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 68 of file gparticle.cpp.

68 {
69 // Make step to next point and calculate new step to border.
70 mfunname("void gparticle::step()");
74 m_nstep++;
75 if (m_currpos.prange == 0) {
78 "too many zero steps, possible infinite loop\n", mcerr);
79 } else {
80 m_nzero_step = 0;
81 }
82 physics_after_new_speed(secondaries);
83 if (m_alive) {
86 }
87}
#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:229
virtual stvpoint calc_step_to_bord()
Determine next position.
Definition: gparticle.cpp:110
static constexpr long m_max_qzero_step
Max. number of zero-steps allowed.
Definition: gparticle.h:252
virtual void change_vol()
Move from one volume to another.
Definition: gparticle.h:211
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 152 of file gparticle.cpp.

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

Referenced by calc_step_to_bord().

◆ time()

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

Get the current time of the particle.

Definition at line 188 of file gparticle.h.

188{ 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 252 of file gparticle.h.

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

◆ m_nextpos

stvpoint Heed::gparticle::m_nextpos
protected

Next point.

Definition at line 266 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 250 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 254 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 257 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 259 of file gparticle.h.

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


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