RooParticle
Particle scattering simulator with ROOT
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1#ifndef H_EVENT
2#define H_EVENT 1;
3
4#include "iostream"
5#include "stdio.h"
6#include "list"
7#include "vector"
8
9#include "TROOT.h"
10#include "TString.h"
11#include "TMath.h"
12#include "TVector3.h"
13
14#include "RPConfig.hpp"
15
16#include "particle.hpp"
17#include "force.hpp"
18#include "eventVolume.hpp"
19#include "inspector.hpp"
20#include "recorder.hpp"
21
22class inspector;
23
93class event{
94public:
120
129
139
144 event();
145
153 event(event &e);
154
156 virtual ~event();
157
159 event & operator=(const event &) = delete;
160
161 //Setup Methods
162
168 particle* AddParticle(particle* particle_){particles.push_back(particle_); nparticle++; return particle_;}
169
175 void AddForce(force * force_){forces.push_back(force_); nforce++; accCacheX.clear();}
176
179 void AddInspector(inspector* inspector_){inspectors.push_back(inspector_);}
180
183 void SetVolume(eventVolume * volume_){volume = volume_;}
184
189 void SetIntegrator(integrator integ_){integ = integ_; accCacheX.clear();}
190
195 Bool_t SetIntegrator(TString name);
196
199
201 TString GetIntegratorName();
202
214 void SetTolerance(Double_t rel, Double_t abs);
215
217 Double_t GetRelTolerance(){return rk45Rel;}
218
220 Double_t GetAbsTolerance(){return rk45Abs;}
221
223 Double_t GetRK45Substep(){return rk45H;}
224
227
230
242 void SetPairSymmetric(Bool_t sym_=kTRUE){pairSymmetric = sym_; accCacheX.clear();}
243
246
262 void SetRelativistic(Bool_t rel_=kTRUE){relativistic = rel_; accCacheX.clear();}
263
265 Bool_t IsRelativistic(){return relativistic;}
266
268 void SetInspectMode(inspectMode mode_){imode = mode_;}
269
272
277
280
283
285 TString GetStopReasonName();
286
294
306 void CalibrateVelocity();
307
308 //DerivingMethod
309
317 virtual void DeriveDT(Double_t dt = 1);
318
322 void DeriveDTN(Int_t n = 1, Double_t dt = 1);
323
326 void DeriveMAX(Double_t dt = 1);
327
347 Bool_t DeriveInspect(Int_t iperiod=1, Double_t dt = 1);
348
349 //GetMethod
350
356 particle * getParticle(Int_t index);
357
359 force * getForce(Int_t index);
360
362 inspector * getInspector(Int_t index);
363
365 Int_t getNParticle(){return nparticle;}
366
368 Int_t getNForce(){return nforce;}
369
371 Int_t getNInspector(){return inspectors.size();}
372
377 Long_t GetDeriveN(const Bool_t minima=kFALSE);
378
379 //Calculation
380
389 Double_t GetPE(Int_t index, Bool_t OnlyInvincibles=kFALSE);
390
394 Double_t GetPE(particle* p, Bool_t OnlyInvincibles=kFALSE);
395
401 Double_t GetNetKE(const Bool_t SR=kFALSE);
402
408 Double_t GetNetPE();
409
411 Double_t GetNetE(const Bool_t SR=kFALSE){return GetNetKE(SR)+GetNetPE();}
412
416 Double_t GetNetKERel();
417
419 Double_t GetNetERel(){return GetNetKERel()+GetNetPE();}
420
427 TVector3 GetNetMomentum();
428
434 TVector3 GetNetAngularMomentum(TVector3 origin = TVector3());
435
438 Double_t GetTime();
439
442 Double_t GetMinDistance();
443
448 Double_t GetMaxAcceleration();
449
453 Bool_t IsInsideVolume(Bool_t all=kTRUE);
454
455
456 //Inspection Deriving and Pre-Deriving.
457
462 void preDerive();
463
466 void preDeriveSetup();
467
470 Bool_t resetPreDerive();
471
480 Bool_t Inspect();
481
487 TString Print(Bool_t onlymechanic=kFALSE, Bool_t mute=kFALSE, Bool_t pprint=kFALSE);
488
492 Bool_t SetInitial();
493
494protected:
495 std::vector<particle*> particles;
496 std::vector<force*> forces;
497
498 Int_t nparticle = 0;
499 Int_t nforce = 0;
500
501 //Integrators
502
508 void DeriveTaylor(Double_t dt);
509
512 void DeriveSymplecticEuler(Double_t dt);
513
522 void DeriveVelocityVerlet(Double_t dt);
523
526 void DeriveRK4(Double_t dt);
527
536 void DeriveRK45(Double_t dt);
537
540 void ComputeForce(std::vector<TVector3> & frc);
541
544 void ComputeAcceleration(std::vector<TVector3> & acc);
545
548 void FinishStep(Double_t dt);
549
550 // The Runge-Kutta integrators work on a state (x, u) of every particle, with
551 // u = v (non-relativistic) or u = p = gamma m0 v (relativistic).
552 // Invincible particles are kept in the vectors but never changed.
553
557 virtual Bool_t UseRelativistic(){return relativistic && integ!=kTaylor;}
558
560 TVector3 MomentumOf(particle * p, const TVector3 & v);
561
563 TVector3 VelocityOf(particle * p, const TVector3 & u);
564
566 void GetState(std::vector<TVector3> & x, std::vector<TVector3> & u);
567
569 void SetState(const std::vector<TVector3> & x, const std::vector<TVector3> & u);
570
572 void ComputeDerivative(std::vector<TVector3> & dx, std::vector<TVector3> & du);
573
574private:
575 eventVolume * volume = nullptr;
576 event * pEvent = nullptr;
577 Bool_t preDerived = kFALSE;
578
579 std::vector<inspector*> inspectors;
580
585
586 Bool_t pairSymmetric = kTRUE;
587 Bool_t relativistic = kFALSE;
588
589 // kRK45 : tolerances, substep suggested for the next call, statistics
590 Double_t rk45Rel = RK45RELTOL;
591 Double_t rk45Abs = RK45ABSTOL;
592 Double_t rk45H = 0.;
593 Long_t rk45NAccept = 0;
594 Long_t rk45NReject = 0;
595 Bool_t rk45Warned = kFALSE;
596 Bool_t integFailed = kFALSE;
597
598 // Velocity Verlet reuses the acceleration (the force in the relativistic mode)
599 // of the previous step, as long as no particle was moved from outside in the meantime.
600 std::vector<TVector3> accCache;
601 std::vector<TVector3> accCacheX;
602};
603
604#endif
Compile-time limits and default tolerances (macros).
#define MAXINSPECTSTEPS
Definition RPConfig.hpp:12
#define RK45RELTOL
Definition RPConfig.hpp:17
#define RK45ABSTOL
Definition RPConfig.hpp:21
Base class of event volumes: the region in which an event is "alive".
One simulated system: particles, pairwise forces, inspectors and the time integration.
Definition event.hpp:93
void ComputeForce(std::vector< TVector3 > &frc)
Net force on every particle at the present state, in amu c^2/fm (zero for invincibles).
Definition event.cpp:184
Double_t GetMaxAcceleration()
The largest acceleration (force / rest mass) of the non-invincible particles (amu c^2/fm/amu = c^2/fm...
Definition event.cpp:929
Double_t rk45Abs
absolute tolerance
Definition event.hpp:591
TVector3 GetNetAngularMomentum(TVector3 origin=TVector3())
Total angular momentum of the non-invincible particles (amu c fm).
Definition event.cpp:738
void CalibrateVelocity()
Correct the speed of every non-invincible particle so that the given velocity is the velocity far fro...
Definition event.cpp:119
Bool_t integFailed
the integrator gave up (see HasIntegratorFailed())
Definition event.hpp:596
eventVolume * volume
not owned
Definition event.hpp:575
std::vector< TVector3 > accCacheX
positions for which accCache is valid
Definition event.hpp:601
Bool_t rk45Warned
the minimum-substep warning was printed
Definition event.hpp:595
inspectMode GetInspectMode()
The way the non-abort inspectors are combined.
Definition event.hpp:271
void AddForce(force *force_)
Add a force that acts on every pair of particles of the event.
Definition event.hpp:175
Bool_t preDerived
whether pEvent is valid
Definition event.hpp:577
Bool_t IsInsideVolume(Bool_t all=kTRUE)
Whether the non-invincible particles are inside the volume (SetVolume()).
Definition event.cpp:940
void SetTolerance(Double_t rel, Double_t abs)
Set the tolerances of kRK45.
Definition event.cpp:108
Bool_t pairSymmetric
Newton's third law in use.
Definition event.hpp:586
void SetInspectMode(inspectMode mode_)
Set how the non-abort inspectors are combined in Inspect() (default kInspectAND).
Definition event.hpp:268
Double_t GetNetKERel()
Relativistic kinetic energy, the sum of over the non-invincible particles (amu c^2).
Definition event.cpp:711
inspector * getInspector(Int_t index)
Get an inspector by the order of addition (index as in getParticle(); owned by the event).
Definition event.cpp:664
void SetRelativistic(Bool_t rel_=kTRUE)
Switch the dynamics to special relativity (default off).
Definition event.hpp:262
Double_t GetRelTolerance()
Relative tolerance of kRK45.
Definition event.hpp:217
Double_t GetNetPE()
Potential energy of the whole event (amu c^2).
Definition event.cpp:779
TString GetStopReasonName()
Name of the last stop reason: "NONE", "INSPECTOR", "ABORT", "MAXSTEPS", "INVALID" or "FAILED".
Definition event.cpp:161
void DeriveVelocityVerlet(Double_t dt)
Velocity-Verlet step (kick-drift-kick on the momentum in the relativistic mode).
Definition event.cpp:320
Double_t rk45Rel
relative tolerance
Definition event.hpp:590
std::vector< inspector * > inspectors
owned
Definition event.hpp:579
Int_t getNParticle()
Number of particles.
Definition event.hpp:365
Double_t rk45H
substep suggested for the next call
Definition event.hpp:592
void SetVolume(eventVolume *volume_)
Set the volume used by IsInsideVolume() and the "VOUT"/"VOUTA" inspectors.
Definition event.hpp:183
void preDeriveSetup()
Placeholder for the set-up after preDerive().
Definition event.cpp:958
Bool_t HasIntegratorFailed()
True once the integrator has given up.
Definition event.hpp:293
force * getForce(Int_t index)
Get a force by the order of addition (index as in getParticle(); the force is not owned).
Definition event.cpp:645
integrator integ
selected integrator
Definition event.hpp:581
void AddInspector(inspector *inspector_)
Add an inspector (a terminating condition for DeriveInspect()).
Definition event.hpp:179
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
inspectMode imode
how the inspectors are combined
Definition event.hpp:582
TVector3 GetNetMomentum()
Total momentum of the non-invincible particles (amu c).
Definition event.cpp:725
event * pEvent
pre-derived copy (owned)
Definition event.hpp:576
void SetPairSymmetric(Bool_t sym_=kTRUE)
Use Newton's third law to evaluate each pair once (default on).
Definition event.hpp:242
void DeriveMAX(Double_t dt=1)
Call DeriveDT() MAXSTEPS times (100,000, RPConfig.hpp), ignoring the inspectors.
Definition event.cpp:617
void SetMaxInspectSteps(Long_t n)
Set the safety cap of DeriveInspect().
Definition event.hpp:276
Long_t GetRK45NSubsteps()
Number of accepted kRK45 substeps so far.
Definition event.hpp:226
Long_t GetDeriveN(const Bool_t minima=kFALSE)
Number of derived steps (particle::GetECNT()) over all particles, invincible ones included.
Definition event.cpp:684
stopReason
Why the last DeriveInspect() returned.
Definition event.hpp:131
@ kStopFailed
the integrator gave up (kRK45 on a singular force, see HasIntegratorFailed())
Definition event.hpp:137
@ kStopInspector
the inspectors were satisfied (normal end)
Definition event.hpp:133
@ kStopAbort
an abort inspector fired
Definition event.hpp:134
@ kStopNone
DeriveInspect() was not called yet (or is running)
Definition event.hpp:132
@ kStopInvalid
an inspector has an undefined method; nothing was derived
Definition event.hpp:136
@ kStopMaxSteps
the safety cap of steps (SetMaxInspectSteps()) was reached
Definition event.hpp:135
TString GetIntegratorName()
Name of the integrator in use, as accepted by SetIntegrator(TString).
Definition event.cpp:150
particle * AddParticle(particle *particle_)
Add a particle to the event.
Definition event.hpp:168
Long_t GetRK45NRejected()
Number of rejected kRK45 substeps so far.
Definition event.hpp:229
Bool_t resetPreDerive()
Delete the pre-derived copy.
Definition event.cpp:828
Double_t GetMinDistance()
The smallest distance between two particles, invincible ones included (fm). The largest double for fe...
Definition event.cpp:918
virtual Bool_t UseRelativistic()
Whether the relativistic option is really in effect: set, and not kTaylor.
Definition event.hpp:557
event()
Make an empty event: no particles, forces, inspectors nor volume.
Definition event.cpp:20
void FinishStep(Double_t dt)
Close one step: every particle counts the step, the moving ones advance their time,...
Definition event.cpp:284
stopReason lastStop
reason of the last DeriveInspect()
Definition event.hpp:584
integrator
Integration scheme used by DeriveDT().
Definition event.hpp:113
@ kRK45
"RK45", adaptive Dormand-Prince
Definition event.hpp:118
@ kVelocityVerlet
"VERLET", velocity Verlet
Definition event.hpp:116
@ kRK4
"RK4", classical Runge-Kutta
Definition event.hpp:117
@ kSymplecticEuler
"SEULER", symplectic Euler
Definition event.hpp:115
@ kTaylor
"TAYLOR", original scheme (default)
Definition event.hpp:114
void GetState(std::vector< TVector3 > &x, std::vector< TVector3 > &u)
Read the positions x and state variables u of all particles.
Definition event.cpp:249
particle * getParticle(Int_t index)
Get a particle by the order of addition.
Definition event.cpp:625
void ComputeDerivative(std::vector< TVector3 > &dx, std::vector< TVector3 > &du)
Time derivatives dx/dt = v and du/dt (F/m0, or F when relativistic) at the present state.
Definition event.cpp:269
stopReason GetStopReason()
Why the last DeriveInspect() ended (kStopNone before the first call).
Definition event.hpp:282
virtual ~event()
Delete the particles, the inspectors and the pre-derived copy (not the forces nor the volume).
Definition event.cpp:89
Int_t nforce
number of forces
Definition event.hpp:499
integrator GetIntegrator()
The integrator in use (default kTaylor).
Definition event.hpp:198
std::vector< particle * > particles
the particles, in the order of addition (owned)
Definition event.hpp:495
Int_t getNForce()
Number of forces.
Definition event.hpp:368
Double_t GetNetE(const Bool_t SR=kFALSE)
GetNetKE(SR) + GetNetPE(); conserved in the non-relativistic mode only (see GetNetERel()).
Definition event.hpp:411
virtual void DeriveDT(Double_t dt=1)
Advance the event by one time step with the selected integrator.
Definition event.cpp:173
void SetIntegrator(integrator integ_)
Select the integrator by enumerator (see integrator).
Definition event.hpp:189
Bool_t IsPairSymmetric()
Whether the pair symmetry is in use (default kTRUE).
Definition event.hpp:245
Bool_t Inspect()
Evaluate the terminating condition once, without deriving.
Definition event.cpp:875
Long_t rk45NReject
rejected substeps
Definition event.hpp:594
void ComputeAcceleration(std::vector< TVector3 > &acc)
Acceleration F/m0 of every particle at the present state, in c^2/fm (zero for invincibles).
Definition event.cpp:228
Double_t GetNetKE(const Bool_t SR=kFALSE)
Kinetic energy of the non-invincible particles (amu c^2).
Definition event.cpp:697
TString Print(Bool_t onlymechanic=kFALSE, Bool_t mute=kFALSE, Bool_t pprint=kFALSE)
Describe the event (particles and inspectors) as text.
Definition event.cpp:966
Bool_t relativistic
relativistic flag
Definition event.hpp:587
Long_t rk45NAccept
accepted substeps
Definition event.hpp:593
event & operator=(const event &)=delete
Deleted: the default assignment would copy the pointers and delete them twice.
Double_t GetRK45Substep()
Substep suggested for the next kRK45 DeriveDT, in fm/c (0 : none yet).
Definition event.hpp:223
void SetState(const std::vector< TVector3 > &x, const std::vector< TVector3 > &u)
Write positions and state variables back to the non-invincible particles.
Definition event.cpp:260
void DeriveSymplecticEuler(Double_t dt)
Symplectic Euler step, v += a dt then x += v dt (momentum in the relativistic mode).
Definition event.cpp:291
void DeriveTaylor(Double_t dt)
The original scheme: all forces are evaluated for the present state of every moving particle (every o...
Definition event.cpp:566
void DeriveRK4(Double_t dt)
Classical 4th order Runge-Kutta step.
Definition event.cpp:386
TVector3 MomentumOf(particle *p, const TVector3 &v)
The state variable u of the velocity v: v itself, or when relativistic.
Definition event.cpp:238
std::vector< force * > forces
the forces (not owned)
Definition event.hpp:496
Long_t GetMaxInspectSteps()
The safety cap of steps of DeriveInspect() (0 : unlimited).
Definition event.hpp:279
TVector3 VelocityOf(particle *p, const TVector3 &u)
The velocity v of the state variable u (inverse of MomentumOf()).
Definition event.cpp:243
void preDerive()
Make a copy of the event and derive it until its inspectors are satisfied (pre-derivation).
Definition event.cpp:815
Long_t maxInspectSteps
safety cap of DeriveInspect()
Definition event.hpp:583
Double_t GetTime()
The largest evolved time among the particles (fm/c). Invincible particles do not advance their time,...
Definition event.cpp:909
void DeriveRK45(Double_t dt)
Dormand-Prince 5(4) with adaptive substeps, advancing exactly dt (see integrator).
Definition event.cpp:429
Bool_t IsRelativistic()
Whether the relativistic flag is set (the flag only; kTaylor ignores it).
Definition event.hpp:265
Double_t GetAbsTolerance()
Absolute tolerance of kRK45 (fm for positions, c for velocities).
Definition event.hpp:220
Double_t GetNetERel()
GetNetKERel() + GetNetPE(); the conserved energy of the relativistic mode.
Definition event.hpp:419
Bool_t DeriveInspect(Int_t iperiod=1, Double_t dt=1)
Derive until Inspect() is satisfied.
Definition event.cpp:839
Int_t getNInspector()
Number of inspectors.
Definition event.hpp:371
std::vector< TVector3 > accCache
acceleration (or force) at the end of the last step
Definition event.hpp:600
Int_t nparticle
number of particles
Definition event.hpp:498
void DeriveDTN(Int_t n=1, Double_t dt=1)
Call DeriveDT() n times.
Definition event.cpp:609
Bool_t SetInitial()
Set the initial condition from the present one.
inspectMode
How the non-abort inspectors are combined in Inspect().
Definition event.hpp:125
@ kInspectAND
stop when all of them are satisfied (default)
Definition event.hpp:126
@ kInspectOR
stop when any of them is satisfied
Definition event.hpp:127
Base class of the pairwise forces.
Definition force.hpp:24
Inspector : one terminating condition of event::DeriveInspect().
Definition inspector.hpp:28
A point body with mass, position, velocity, step count, time and an optional recorded path.
Definition particle.hpp:36
Spatial region attached to an event (eventVolume, eventVGeneral).
const char * name
Definition inspector.cpp:25
Small value holder that remembers one number, optionally read from a variable (recorder).