RooParticle
Particle scattering simulator with ROOT
Loading...
Searching...
No Matches
asymptote.cpp
Go to the documentation of this file.
1#include "asymptote.hpp"
2
3#include "iostream"
4
5#include "TMath.h"
6
7#include "particle.hpp"
8
9// Two states closer than this (relative to the scale) are treated as equal.
10static const Double_t kHeadOnTol = 1e-12; // |r x v| <= tol |r||v| : L = 0
11static const Double_t kParabolaTol = 1e-13; // |E| <= tol (KE + |PE|) : E = 0
12static const Double_t kAtRestTol = 1e-9; // |v_self| <= tol |v_other| : at rest
13
14asymptote::asymptote(particle* p1, particle* p2, Double_t kappa_){
15 Compute(p1, p2, kappa_);
16}
17
18asymptote::asymptote(TVector3 x1, TVector3 v1, Double_t m1_, Bool_t fixed1_,
19 TVector3 x2, TVector3 v2, Double_t m2_, Bool_t fixed2_,
20 Double_t kappa_){
21 Compute(x1, v1, m1_, fixed1_, x2, v2, m2_, fixed2_, kappa_);
22}
23
24asymptote::asymptote(TVector3 r_, TVector3 v_, Double_t mu_, Double_t kappa_){
25 Compute(r_, v_, mu_, kappa_);
26}
27
29 st = kInvalid;
30 fixedCentre = fixed1 = fixed2 = kFALSE;
31 m1 = m2 = mu = kappa = 0.;
32 r = v = vcm = TVector3();
33 energy = 0.;
34 lvec = avec = evec = phat = TVector3();
35 ecc = rmin = 0.;
36 vinf = 0.;
37 vinRel = voutRel = TVector3();
38 thetaCM = bimp = 0.;
39 v1in = v1out = v2in = v2out = TVector3();
40 thetaLab1 = thetaLab2 = 0.;
41}
42
43Bool_t asymptote::Compute(particle* p1, particle* p2, Double_t kappa_){
44 if(p1==nullptr || p2==nullptr || p1==p2){
45 Reset();
46 return kFALSE;
47 }
48 return Compute(p1->GetX(), p1->GetV(), p1->GetM0(), p1->IsInvincible(),
49 p2->GetX(), p2->GetV(), p2->GetM0(), p2->IsInvincible(),
50 kappa_);
51}
52
53Bool_t asymptote::Compute(TVector3 x1, TVector3 v1, Double_t m1_, Bool_t fixed1_,
54 TVector3 x2, TVector3 v2, Double_t m2_, Bool_t fixed2_,
55 Double_t kappa_){
56 Reset();
57 fixed1 = fixed1_;
58 fixed2 = fixed2_;
60 m1 = m1_;
61 m2 = m2_;
62 kappa = kappa_;
63 if(fixed1 && fixed2) return kFALSE;
64 if((!fixed1 && !(m1>0.)) || (!fixed2 && !(m2>0.))) return kFALSE;
65
66 // a fixed centre is at rest whatever its stored velocity is
67 if(fixed1) v1 = TVector3();
68 if(fixed2) v2 = TVector3();
69
70 r = x1 - x2;
71 v = v1 - v2;
72 if(fixed2) { mu = m1; vcm = TVector3(); }
73 else if(fixed1) { mu = m2; vcm = TVector3(); }
74 else { mu = m1*m2/(m1+m2); vcm = (v1*m1 + v2*m2)*(1./(m1+m2)); }
75
76 Solve();
77 SetLab();
78 return HasAsymptote();
79}
80
81Bool_t asymptote::Compute(TVector3 r_, TVector3 v_, Double_t mu_, Double_t kappa_){
82 // a body of mass mu around a fixed particle 2 at the origin
83 return Compute(r_, v_, mu_, kFALSE, TVector3(), TVector3(), 0., kTRUE, kappa_);
84}
85
87 st = kInvalid;
88 const Double_t rmag = r.Mag();
89 if(!(rmag>0.) || !(mu>0.)) return;
90
91 const Double_t v2 = v.Mag2();
92 const Double_t vmag = TMath::Sqrt(v2);
93 const TVector3 rhat = r*(1./rmag);
94 const TVector3 h = r.Cross(v); // specific angular momentum
95 const Double_t hmag = h.Mag();
96 const Double_t ke = 0.5*mu*v2;
97 const Double_t pe = kappa/rmag;
98
99 energy = ke + pe;
100 lvec = h*mu;
101 avec = v.Cross(h)*(mu*mu) + rhat*(mu*kappa);
102
103 // ---- no interaction : straight line
104 if(kappa==0.){
105 if(!(vmag>0.)){ st = kParabolic; rmin = rmag; return; } // at rest forever
106 st = kFree;
107 vinf = vmag;
108 vinRel = v;
109 voutRel = v;
110 thetaCM = 0.;
111 bimp = hmag/vmag;
112 rmin = bimp;
113 TVector3 perp = r - v*(r.Dot(v)/v2); // centre -> closest point of the line
114 phat = (perp.Mag()>0.) ? perp.Unit() : TVector3();
115 return;
116 }
117
118 // gm = -kappa/mu (> 0 attractive). e^2 - 1 = 2 eps h^2 / gm^2, eps = E/mu,
119 // computed directly to avoid the cancellation of e^2 - 1 near e = 1.
120 const Double_t gm = -kappa/mu;
121 const Double_t agm = TMath::Abs(gm);
122 const Double_t eps = energy/mu;
123 Double_t e2m1 = 2.*eps*hmag*hmag/(gm*gm);
124 if(e2m1 < -1.) e2m1 = -1.; // round-off of a circular orbit
125 ecc = TMath::Sqrt(1. + e2m1);
126 evec = avec*(1./(mu*TMath::Abs(kappa)));
127 phat = (avec.Mag2()>0.) ? avec.Unit() : TVector3();
128
129 const Bool_t radial = (hmag <= kHeadOnTol*rmag*vmag);
130
131 // ---- bound and parabolic orbits (attractive only)
132 if(TMath::Abs(energy) <= kParabolaTol*(ke + TMath::Abs(pe))){
133 st = radial ? kRadialAttractive : kParabolic;
134 rmin = radial ? 0. : hmag*hmag/(2.*agm);
135 return;
136 }
137 if(energy < 0.){
138 st = radial ? kRadialAttractive : kBound;
139 rmin = radial ? 0. : (hmag*hmag/agm)/(1.+ecc);
140 return;
141 }
142
143 // ---- unbound
144 vinf = TMath::Sqrt(2.*eps);
145 const Double_t a = agm/(vinf*vinf); // semi-axis of the hyperbola
146
147 if(radial){
148 if(kappa < 0.){ // falls into the centre
150 vinf = 0.;
151 rmin = 0.;
152 return;
153 }
154 // head-on repulsive : comes in and goes out along the line of r
155 st = kHeadOn;
156 phat = rhat;
157 voutRel = rhat*vinf;
158 vinRel = rhat*(-vinf);
159 thetaCM = TMath::Pi();
160 bimp = 0.;
161 rmin = kappa/energy; // = 2a
162 return;
163 }
164
165 st = kUnbound;
166 // Orbital frame : phat (centre -> periapsis), qhat (direction of motion at periapsis).
167 // Asymptotic directions, sigma = +1 repulsive, -1 attractive, s = sqrt(e^2-1):
168 // out = ( sigma phat + s qhat) / e, in = (-sigma phat + s qhat) / e.
169 const TVector3 nhat = h*(1./hmag);
170 const TVector3 qhat = nhat.Cross(phat);
171 const Double_t sigma = (kappa > 0.) ? 1. : -1.;
172 const Double_t s = TMath::Sqrt(e2m1);
173 voutRel = (phat*( sigma) + qhat*s)*(vinf/ecc);
174 vinRel = (phat*(-sigma) + qhat*s)*(vinf/ecc);
175 thetaCM = 2.*TMath::ATan2(1., s); // sin(theta/2) = 1/e
176 bimp = hmag/vinf;
177 if(kappa > 0.) rmin = a*(1.+ecc);
178 else rmin = (hmag*hmag/agm)/(1.+ecc);
179}
180
181static Double_t LabAngleOf(const TVector3 & vin, const TVector3 & vout, const TVector3 & vinOther){
182 if(vin.Mag() > kAtRestTol*vinOther.Mag() && vin.Mag2()>0.) return asymptote::Angle(vin, vout);
183 if(vinOther.Mag2()>0.) return asymptote::Angle(vinOther, vout);
184 return 0.;
185}
186
188 if(!HasAsymptote()) return;
189 // velocity of each particle = Vcm +- (share of the relative velocity)
190 Double_t c1, c2;
191 if(fixed2) { c1 = 1.; c2 = 0.; }
192 else if(fixed1) { c1 = 0.; c2 = 1.; }
193 else { c1 = m2/(m1+m2); c2 = m1/(m1+m2); }
194
195 v1in = vcm + vinRel*c1;
196 v1out = vcm + voutRel*c1;
197 v2in = vcm - vinRel*c2;
198 v2out = vcm - voutRel*c2;
199 if(fixed1){ v1in = v1out = TVector3(); }
200 if(fixed2){ v2in = v2out = TVector3(); }
201
204}
205
207 switch(st){
208 case kUnbound: return TString("UNBOUND");
209 case kHeadOn: return TString("HEADON");
210 case kFree: return TString("FREE");
211 case kRadialAttractive: return TString("RADIAL_ATTRACTIVE");
212 case kParabolic: return TString("PARABOLIC");
213 case kBound: return TString("BOUND");
214 case kInvalid: return TString("INVALID");
215 }
216 return TString("");
217}
218
219TString asymptote::Print(Bool_t mute) const{
220 TString out;
221 out += Form("asymptote : %s (%s)\n", GetStatusName().Data(), fixedCentre ? "fixed centre" : "two free bodies");
222 out += Form(" kappa %.6e mu %.6e E %.9e |L| %.9e e %.12f\n", kappa, mu, energy, lvec.Mag(), ecc);
223 out += Form(" rmin %.9f b %.9f vinf %.12e thetaCM %.12f deg\n",
224 rmin, bimp, vinf, thetaCM*TMath::RadToDeg());
225 out += Form(" vout(rel) (%.12e, %.12e, %.12e)\n", voutRel.X(), voutRel.Y(), voutRel.Z());
226 out += Form(" v1out (%.12e, %.12e, %.12e) theta1 %.9f deg\n", v1out.X(), v1out.Y(), v1out.Z(), thetaLab1*TMath::RadToDeg());
227 out += Form(" v2out (%.12e, %.12e, %.12e) theta2 %.9f deg\n", v2out.X(), v2out.Y(), v2out.Z(), thetaLab2*TMath::RadToDeg());
228 if(!mute) std::cout<<out;
229 return out;
230}
231
232// ---- closed-form relations
233
234Double_t asymptote::RutherfordAngle(Double_t b, Double_t vinf, Double_t mu, Double_t kappa){
235 return 2.*TMath::ATan2(kappa, mu*vinf*vinf*TMath::Abs(b));
236}
237
238Double_t asymptote::RutherfordImpactParameter(Double_t theta, Double_t vinf, Double_t mu, Double_t kappa){
239 return TMath::Abs(kappa)/(mu*vinf*vinf*TMath::Tan(0.5*TMath::Abs(theta)));
240}
241
242Double_t asymptote::RutherfordClosestApproach(Double_t b, Double_t vinf, Double_t mu, Double_t kappa){
243 const Double_t a = kappa/(mu*vinf*vinf);
244 const Double_t sq = TMath::Sqrt(a*a + b*b);
245 if(a >= 0.) return a + sq;
246 return b*b/(sq - a); // = sq + a, without cancellation
247}
248
249Double_t asymptote::HeadOnClosestApproach(Double_t vinf, Double_t mu, Double_t kappa){
250 return 2.*kappa/(mu*vinf*vinf);
251}
252
253Double_t asymptote::LabAngle(Double_t thetaCM, Double_t m1, Double_t m2){
254 return TMath::ATan2(TMath::Sin(thetaCM), TMath::Cos(thetaCM) + m1/m2);
255}
256
257Double_t asymptote::RecoilAngle(Double_t thetaCM){
258 return 0.5*(TMath::Pi() - thetaCM);
259}
260
261Double_t asymptote::Angle(const TVector3 & a, const TVector3 & b){
262 return TMath::ATan2(a.Cross(b).Mag(), a.Dot(b));
263}
static Double_t LabAngleOf(const TVector3 &vin, const TVector3 &vout, const TVector3 &vinOther)
static const Double_t kParabolaTol
Definition asymptote.cpp:11
static const Double_t kHeadOnTol
Definition asymptote.cpp:10
static const Double_t kAtRestTol
Definition asymptote.cpp:12
Analytic two-body 1/r asymptote calculator (asymptote), used to validate the integrators.
TVector3 lvec
TVector3 v2out
lab asymptotic velocities
TVector3 v
TVector3 phat
angular momentum, Laplace-Runge-Lenz, eccentricity vector, periapsis direction
Double_t thetaLab2
lab angle of particle 2
TVector3 vinRel
static Double_t RecoilAngle(Double_t thetaCM)
Lab angle of the recoiling target at rest, .
Double_t energy
orbital energy
Bool_t fixed2
particle 2 is a fixed centre
Double_t rmin
closest approach
Double_t ecc
eccentricity
Double_t vinf
relative speed at infinity
TString GetStatusName() const
Name of the status as text: "UNBOUND", "HEADON", "FREE", "RADIAL_ATTRACTIVE", "PARABOLIC",...
Double_t kappa
interaction constant
static Double_t RutherfordClosestApproach(Double_t b, Double_t vinf, Double_t mu, Double_t kappa)
Closest approach for impact parameter b.
Double_t bimp
effective impact parameter
Bool_t Compute(particle *p1, particle *p2, Double_t kappa)
Recompute from two particles (arguments as the matching constructor); all previous results are discar...
Definition asymptote.cpp:43
Bool_t fixed1
particle 1 is a fixed centre
@ kHeadOn
, , : straight back-scattering, , ,
@ kBound
: ellipse, no asymptote (E, L, A, e, are set)
@ kInvalid
zero distance, non-positive mass (of a moving particle), both particles fixed, or null/identical part...
@ kRadialAttractive
, (whatever the sign of E): falls into the singularity, no asymptote ( )
@ kUnbound
, : hyperbola, every asymptotic quantity is set
@ kFree
: straight line, , (with the relative velocity zero too it is reported as kParabolic with )
@ kParabolic
(within round-off): , no direction
TVector3 v1out
TVector3 vcm
relative position, relative velocity, centre-of-mass velocity
Double_t m1
mass of particle 1 (amu)
Double_t mu
reduced (or moving) mass (amu)
TVector3 v1in
TVector3 voutRel
incoming / outgoing relative velocity
Double_t m2
mass of particle 2 (amu)
TVector3 avec
Double_t thetaCM
CM scattering angle.
Bool_t HasAsymptote() const
true for kUnbound, kHeadOn, kFree
static Double_t HeadOnClosestApproach(Double_t vinf, Double_t mu, Double_t kappa)
Head-on ( ) closest approach, repulsive.
TVector3 v2in
TVector3 r
asymptote()
Empty object; the status is kInvalid until Compute() is called.
static Double_t Angle(const TVector3 &a, const TVector3 &b)
Angle between two vectors, , accurate at 0 and .
Bool_t fixedCentre
exactly one body fixed
status st
orbit classification
static Double_t RutherfordImpactParameter(Double_t theta, Double_t vinf, Double_t mu, Double_t kappa)
Inverse of RutherfordAngle().
Double_t thetaLab1
lab angle of particle 1
static Double_t RutherfordAngle(Double_t b, Double_t vinf, Double_t mu, Double_t kappa)
Rutherford scattering angle in the CM frame.
void Reset()
set every result and input to its empty value (status kInvalid)
Definition asymptote.cpp:28
TString Print(Bool_t mute=kFALSE) const
Text summary (status, kappa, mu, E, |L|, e, rmin, b, vinf, theta, outgoing velocities).
void Solve()
from r, v, mu, kappa (set by Compute)
Definition asymptote.cpp:86
static Double_t LabAngle(Double_t thetaCM, Double_t m1, Double_t m2)
Lab angle of the projectile (mass m1) on a target (mass m2) at rest, from the CM angle.
void SetLab()
lab velocities and angles from the relative asymptotes
TVector3 evec
A point body with mass, position, velocity, step count, time and an optional recorded path.
Definition particle.hpp:36
TVector3 GetV()
Velocity in c (a copy).
Definition particle.hpp:164
Bool_t IsInvincible()
Whether the particle is fixed (invincible).
Definition particle.hpp:208
Double_t GetM0()
Rest mass in amu.
Definition particle.hpp:179
TVector3 GetX()
Position in fm (a copy).
Definition particle.hpp:161