RooParticle
Particle scattering simulator with ROOT
Loading...
Searching...
No Matches
particle.cpp
Go to the documentation of this file.
1#include "iostream"
2
3#include "TROOT.h"
4#include "TVectorT.h"
5#include "TVector3.h"
6
7#include "particle.hpp"
8#include "event.hpp"
9
10#include <math.h>
11
12using namespace std;
13
14
15// particle::particle(){
16// }
17
18particle::particle(Double_t m0_,
19 // Double_t q_ = 1,
20 TVector3 x0_,
21 TVector3 v0_,
22 Bool_t Invincible_,
23 Bool_t Record_){
24 m0 = m0_;
25 // q = q_;
26 x = x0_;
27 v = v0_;
28 hF = TVector3();
29 Invincible = Invincible_;
30 if(Record_){
31 ppath = new path();
32 Record = true;
33 }else{
34 Record = false;
35 }
36}
37
38//copy constructor
40 name = p.name;
41 x = p.x;
42 v = p.v;
43 m0 = p.m0;
45 Record = p.Record;
46 hold = p.hold;
47 hF = p.hF;
48 etime = p.etime;
49 ecount = p.ecount; // the copy continues the same step count (CNT inspectors)
51 q = p.q;
52 if(p.Record){
53 ppath = new path(*(p.ppath));
54 Record = kTRUE;
55 }else{
56 Record = kFALSE;
57 }
58}
59
60void particle::holdForce(const TVector3 f){
61 if(!hold){
62 hold = true;
63 hF = TVector3();
64 // std::cout<<"ZERO"<<endl;
65 // hF.Print();
66 }
67 hF+=f;
68}
69
70void particle::releaseForce(const Double_t dt){
71 applyForce(hF, dt);
72 resetHold();
73}
74
76 hold=false;
77 hF = TVector3();
78}
79
80void particle::finishStep(const Double_t dt){
81 // Same bookkeeping as applyForce(): invincible particles count the step
82 // but do not advance their own time.
83 ecount += 1;
84 if(!Invincible){
85 etime += dt;
86 }
87 recordStep();
88}
89
90TVector3 particle::calculateCalibrateVelocity(event* ev_, Bool_t ignoreInvincible){
91 TVector3 result;
92 Double_t resultmag;
93 Double_t Unet = ev_->GetPE(this, kFALSE);
94 Double_t UnetI = ev_->GetPE(this, kTRUE);
95 // std::cout<<"UNUT\t"<<Unet<<std::endl;
96 // std::cout<<"UNUTI\t"<<UnetI<<std::endl;
97 if ((!ignoreInvincible)&&IsInvincible())return TVector3();
98
99 resultmag = TMath::Sqrt( GetV().Mag2() - ((1/GetM())*Unet+(1/GetM())*UnetI) )-GetV().Mag();
100
101 result = resultmag*GetV().Unit();
102 // result.Print();
103
104 return result;
105}
106
107TVector3 particle::calibrateVelocity(event* ev_, Bool_t ignoreInvincible, Bool_t verbose){
108 TVector3 result = calculateCalibrateVelocity(ev_, ignoreInvincible);
109 // if ((!ignoreInvincible)&&IsInvincible())return TVector3();
110 Double_t e1 = GetKE();
111 v += result;
112 Double_t e2 = GetKE();
113 if(verbose) cout<<"BEFORE\t"<< e1 <<"\tAFTER\t" << e2 <<"\tDIFF\t" <<e2-e1<<std::endl;
114 return result;
115}
116
117void particle::applyForce(const TVector3 f, const Double_t dt, const Bool_t SR){
118 ecount+=1;
119 if(Invincible==true){
120 recordStep();
121 return;
122 }
123 Double_t m_ = GetM(!SR);
124 TVector3 a = f * (1/m_);
125 applyDX(
126 a * (0.5) * pow(dt,2) + v * dt
127 );
128 applyDV(
129 a * dt
130 );
131 etime += dt;
132 recordStep();
133 // cout<<"APPLYFORCE"<<endl;
134 // f.Print();
135 // cout<<dt<<" / "<<etime<<endl;
136}
137
138Double_t particle::GetM(Bool_t restmass){
139 if(restmass){
140 return m0;
141 }
142 Double_t v_ = v.Mag();
143 return ( 1/sqrt( 1-pow(v_,2) )) * m0;
144}
145
147 // Same expression as GetM(kFALSE), so that GetGamma()*GetM0() == GetM(kFALSE).
148 Double_t v_ = v.Mag();
149 return 1/sqrt( 1-pow(v_,2) );
150}
151
152TVector3 particle::GetMomentum(Bool_t relativistic){
153 if(relativistic){
154 return TVector3(v * (GetGamma() * m0));
155 }
156 return TVector3(v * m0);
157}
158
159TString onelineTVectorS(TVector3 vec){
160 TString result = TString("");
161 result += TString("[");
162 Int_t i;
163 for(i=0; i<2; ++i){
164 // cout<<i<<endl;
165 result+=vec(i);
166 result+=", ";
167 }
168 result += vec(i);
169 result += TString("]");
170 return result;
171}
172
173TString particle::Print(Bool_t onlymechanic, Bool_t mute){
174 TString result = TString("");
175 result += TString("[ Particle ");
176 if(!onlymechanic){
177 }
178 result += TString("x: ");
179 result += onelineTVectorS(GetX());
180 result += TString(", ");
181 result += TString("v: ");
182 result += onelineTVectorS(GetV());
183 result += TString(" ]");
184
185 if(!mute){
186 cout<<result<<endl;
187 }
188
189 return result;
190}
One simulated system: particles, pairwise forces, inspectors and the time integration.
Definition event.hpp:93
Double_t GetPE(Int_t index, Bool_t OnlyInvincibles=kFALSE)
Potential energy of one particle with the other particles (amu c^2).
Definition event.cpp:752
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 Invincible
fixed particle
Definition particle.hpp:230
TString name
name for printing
Definition particle.hpp:225
Double_t GetKE(const Bool_t SR=kFALSE)
Kinetic energy in amu c^2.
Definition particle.hpp:193
void releaseForce(const Double_t dt)
Apply the held force for one step of dt (see applyForce()) and clear it.
Definition particle.cpp:70
TVector3 x
position in fm
Definition particle.hpp:226
void holdForce(const TVector3 f)
Add a force to the pending force of this particle.
Definition particle.cpp:60
Bool_t Record
records the path
Definition particle.hpp:237
TVector3 v
velocity in c
Definition particle.hpp:227
Int_t recordPeriod
a step is recorded when ecount is a multiple of it
Definition particle.hpp:238
Bool_t IsInvincible()
Whether the particle is fixed (invincible).
Definition particle.hpp:208
void applyDV(const TVector3 dv)
Add dv (c) to the velocity.
Definition particle.hpp:135
Double_t m0
rest mass in amu
Definition particle.hpp:228
void applyForce(const TVector3 f, const Double_t dt=1., Bool_t SR=kFALSE)
Move the particle for one step under a constant force (the original Taylor step).
Definition particle.cpp:117
TVector3 GetMomentum(Bool_t relativistic=kFALSE)
Momentum in amu c.
Definition particle.cpp:152
TVector3 calibrateVelocity(event *ev_, Bool_t ignoreInvincible=kFALSE, Bool_t verbose=kFALSE)
Apply calculateCalibrateVelocity() to this particle.
Definition particle.cpp:107
path * ppath
the path (owned)
Definition particle.hpp:239
Long_t ecount
number of derived steps
Definition particle.hpp:235
Double_t etime
evolved time in fm/c
Definition particle.hpp:234
TString Print(Bool_t onlymechanic=kFALSE, Bool_t mute=kFALSE)
Describe the particle as text "[ Particle x: [..], v: [..] ]".
Definition particle.cpp:173
void finishStep(const Double_t dt)
Close one integration step whose x, v were already updated by the event (step count,...
Definition particle.cpp:80
TVector3 calculateCalibrateVelocity(event *ev_, Bool_t ignoreInvincible=kFALSE)
Velocity change which makes the given velocity the one far from the other bodies.
Definition particle.cpp:90
void resetHold()
Discard the held force.
Definition particle.cpp:75
void applyDX(const TVector3 dx)
Add dx (fm) to the position.
Definition particle.hpp:132
Double_t GetM(const Bool_t restmass=kTRUE)
Mass in amu.
Definition particle.cpp:138
Bool_t hold
a force is held
Definition particle.hpp:231
Double_t q
charge in e
Definition particle.hpp:222
void recordStep()
Definition particle.hpp:242
TVector3 hF
held force in amu c^2/fm
Definition particle.hpp:232
TVector3 GetX()
Position in fm (a copy).
Definition particle.hpp:161
particle(Double_t m0_=1, TVector3 x0_=TVector3(), TVector3 v0_=TVector3(), Bool_t Invincible_=false, Bool_t Record_=false)
Make a particle.
Definition particle.cpp:18
Double_t GetGamma()
Lorentz factor (v in c); NaN for speed above c.
Definition particle.cpp:146
Time-ordered list of (position, velocity, time) samples of one particle.
Definition path.hpp:37
TString onelineTVectorS(TVector3 vec)
Definition particle.cpp:159