RooParticle
Particle scattering simulator with ROOT
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
event Class Reference

One simulated system: particles, pairwise forces, inspectors and the time integration. More...

#include <event.hpp>

Inheritance diagram for event:
oddevent

Public Types

enum  integrator {
  kTaylor = 0 , kSymplecticEuler , kVelocityVerlet , kRK4 ,
  kRK45
}
 Integration scheme used by DeriveDT(). More...
 
enum  inspectMode { kInspectAND = 0 , kInspectOR }
 How the non-abort inspectors are combined in Inspect(). More...
 
enum  stopReason {
  kStopNone = 0 , kStopInspector , kStopAbort , kStopMaxSteps ,
  kStopInvalid , kStopFailed
}
 Why the last DeriveInspect() returned. More...
 

Public Member Functions

 event ()
 Make an empty event: no particles, forces, inspectors nor volume.
 
 event (event &e)
 Make a copy of an event, to run many events from one template.
 
virtual ~event ()
 Delete the particles, the inspectors and the pre-derived copy (not the forces nor the volume).
 
event & operator= (const event &)=delete
 Deleted: the default assignment would copy the pointers and delete them twice.
 
particle * AddParticle (particle *particle_)
 Add a particle to the event.
 
void AddForce (force *force_)
 Add a force that acts on every pair of particles of the event.
 
void AddInspector (inspector *inspector_)
 Add an inspector (a terminating condition for DeriveInspect()).
 
void SetVolume (eventVolume *volume_)
 Set the volume used by IsInsideVolume() and the "VOUT"/"VOUTA" inspectors.
 
void SetIntegrator (integrator integ_)
 Select the integrator by enumerator (see integrator).
 
Bool_t SetIntegrator (TString name)
 Select the integrator by name.
 
integrator GetIntegrator ()
 The integrator in use (default kTaylor).
 
TString GetIntegratorName ()
 Name of the integrator in use, as accepted by SetIntegrator(TString).
 
void SetTolerance (Double_t rel, Double_t abs)
 Set the tolerances of kRK45.
 
Double_t GetRelTolerance ()
 Relative tolerance of kRK45.
 
Double_t GetAbsTolerance ()
 Absolute tolerance of kRK45 (fm for positions, c for velocities).
 
Double_t GetRK45Substep ()
 Substep suggested for the next kRK45 DeriveDT, in fm/c (0 : none yet).
 
Long_t GetRK45NSubsteps ()
 Number of accepted kRK45 substeps so far.
 
Long_t GetRK45NRejected ()
 Number of rejected kRK45 substeps so far.
 
void SetPairSymmetric (Bool_t sym_=kTRUE)
 Use Newton's third law to evaluate each pair once (default on).
 
Bool_t IsPairSymmetric ()
 Whether the pair symmetry is in use (default kTRUE).
 
void SetRelativistic (Bool_t rel_=kTRUE)
 Switch the dynamics to special relativity (default off).
 
Bool_t IsRelativistic ()
 Whether the relativistic flag is set (the flag only; kTaylor ignores it).
 
void SetInspectMode (inspectMode mode_)
 Set how the non-abort inspectors are combined in Inspect() (default kInspectAND).
 
inspectMode GetInspectMode ()
 The way the non-abort inspectors are combined.
 
void SetMaxInspectSteps (Long_t n)
 Set the safety cap of DeriveInspect().
 
Long_t GetMaxInspectSteps ()
 The safety cap of steps of DeriveInspect() (0 : unlimited).
 
stopReason GetStopReason ()
 Why the last DeriveInspect() ended (kStopNone before the first call).
 
TString GetStopReasonName ()
 Name of the last stop reason: "NONE", "INSPECTOR", "ABORT", "MAXSTEPS", "INVALID" or "FAILED".
 
Bool_t HasIntegratorFailed ()
 True once the integrator has given up.
 
void CalibrateVelocity ()
 Correct the speed of every non-invincible particle so that the given velocity is the velocity far from the others.
 
virtual void DeriveDT (Double_t dt=1)
 Advance the event by one time step with the selected integrator.
 
void DeriveDTN (Int_t n=1, Double_t dt=1)
 Call DeriveDT() n times.
 
void DeriveMAX (Double_t dt=1)
 Call DeriveDT() MAXSTEPS times (100,000, RPConfig.hpp), ignoring the inspectors.
 
Bool_t DeriveInspect (Int_t iperiod=1, Double_t dt=1)
 Derive until Inspect() is satisfied.
 
particle * getParticle (Int_t index)
 Get a particle by the order of addition.
 
force * getForce (Int_t index)
 Get a force by the order of addition (index as in getParticle(); the force is not owned).
 
inspector * getInspector (Int_t index)
 Get an inspector by the order of addition (index as in getParticle(); owned by the event).
 
Int_t getNParticle ()
 Number of particles.
 
Int_t getNForce ()
 Number of forces.
 
Int_t getNInspector ()
 Number of inspectors.
 
Long_t GetDeriveN (const Bool_t minima=kFALSE)
 Number of derived steps (particle::GetECNT()) over all particles, invincible ones included.
 
Double_t GetPE (Int_t index, Bool_t OnlyInvincibles=kFALSE)
 Potential energy of one particle with the other particles (amu c^2).
 
Double_t GetPE (particle *p, Bool_t OnlyInvincibles=kFALSE)
 Same as GetPE(Int_t, Bool_t) for a particle pointer.
 
Double_t GetNetKE (const Bool_t SR=kFALSE)
 Kinetic energy of the non-invincible particles (amu c^2).
 
Double_t GetNetPE ()
 Potential energy of the whole event (amu c^2).
 
Double_t GetNetE (const Bool_t SR=kFALSE)
 GetNetKE(SR) + GetNetPE(); conserved in the non-relativistic mode only (see GetNetERel()).
 
Double_t GetNetKERel ()
 Relativistic kinetic energy, the sum of \((\gamma-1) m_0\) over the non-invincible particles (amu c^2).
 
Double_t GetNetERel ()
 GetNetKERel() + GetNetPE(); the conserved energy of the relativistic mode.
 
TVector3 GetNetMomentum ()
 Total momentum of the non-invincible particles (amu c).
 
TVector3 GetNetAngularMomentum (TVector3 origin=TVector3())
 Total angular momentum \(\sum (\vec x - \vec o) \times \vec p\) of the non-invincible particles (amu c fm).
 
Double_t GetTime ()
 The largest evolved time among the particles (fm/c). Invincible particles do not advance their time, so it is 0 if all are invincible.
 
Double_t GetMinDistance ()
 The smallest distance between two particles, invincible ones included (fm). The largest double for fewer than two particles.
 
Double_t GetMaxAcceleration ()
 The largest acceleration (force / rest mass) of the non-invincible particles (amu c^2/fm/amu = c^2/fm).
 
Bool_t IsInsideVolume (Bool_t all=kTRUE)
 Whether the non-invincible particles are inside the volume (SetVolume()).
 
void preDerive ()
 Make a copy of the event and derive it until its inspectors are satisfied (pre-derivation).
 
void preDeriveSetup ()
 Placeholder for the set-up after preDerive().
 
Bool_t resetPreDerive ()
 Delete the pre-derived copy.
 
Bool_t Inspect ()
 Evaluate the terminating condition once, without deriving.
 
TString Print (Bool_t onlymechanic=kFALSE, Bool_t mute=kFALSE, Bool_t pprint=kFALSE)
 Describe the event (particles and inspectors) as text.
 
Bool_t SetInitial ()
 Set the initial condition from the present one.
 

Protected Member Functions

void DeriveTaylor (Double_t dt)
 The original scheme: all forces are evaluated for the present state of every moving particle (every ordered pair), then every particle is moved.
 
void DeriveSymplecticEuler (Double_t dt)
 Symplectic Euler step, v += a dt then x += v dt (momentum in the relativistic mode).
 
void DeriveVelocityVerlet (Double_t dt)
 Velocity-Verlet step (kick-drift-kick on the momentum in the relativistic mode).
 
void DeriveRK4 (Double_t dt)
 Classical 4th order Runge-Kutta step.
 
void DeriveRK45 (Double_t dt)
 Dormand-Prince 5(4) with adaptive substeps, advancing exactly dt (see integrator).
 
void ComputeForce (std::vector< TVector3 > &frc)
 Net force on every particle at the present state, in amu c^2/fm (zero for invincibles).
 
void ComputeAcceleration (std::vector< TVector3 > &acc)
 Acceleration F/m0 of every particle at the present state, in c^2/fm (zero for invincibles).
 
void FinishStep (Double_t dt)
 Close one step: every particle counts the step, the moving ones advance their time, paths are recorded.
 
virtual Bool_t UseRelativistic ()
 Whether the relativistic option is really in effect: set, and not kTaylor.
 
TVector3 MomentumOf (particle *p, const TVector3 &v)
 The state variable u of the velocity v: v itself, or \(\gamma m_0 v\) when relativistic.
 
TVector3 VelocityOf (particle *p, const TVector3 &u)
 The velocity v of the state variable u (inverse of MomentumOf()).
 
void GetState (std::vector< TVector3 > &x, std::vector< TVector3 > &u)
 Read the positions x and state variables u of all particles.
 
void SetState (const std::vector< TVector3 > &x, const std::vector< TVector3 > &u)
 Write positions and state variables back to the non-invincible particles.
 
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.
 

Protected Attributes

std::vector< particle * > particles
 the particles, in the order of addition (owned)
 
std::vector< force * > forces
 the forces (not owned)
 
Int_t nparticle = 0
 number of particles
 
Int_t nforce = 0
 number of forces
 

Private Attributes

eventVolume * volume = nullptr
 not owned
 
event * pEvent = nullptr
 pre-derived copy (owned)
 
Bool_t preDerived = kFALSE
 whether pEvent is valid
 
std::vector< inspector * > inspectors
 owned
 
integrator integ = kTaylor
 selected integrator
 
inspectMode imode = kInspectAND
 how the inspectors are combined
 
Long_t maxInspectSteps = MAXINSPECTSTEPS
 safety cap of DeriveInspect()
 
stopReason lastStop = kStopNone
 reason of the last DeriveInspect()
 
Bool_t pairSymmetric = kTRUE
 Newton's third law in use.
 
Bool_t relativistic = kFALSE
 relativistic flag
 
Double_t rk45Rel = RK45RELTOL
 relative tolerance
 
Double_t rk45Abs = RK45ABSTOL
 absolute tolerance
 
Double_t rk45H = 0.
 substep suggested for the next call
 
Long_t rk45NAccept = 0
 accepted substeps
 
Long_t rk45NReject = 0
 rejected substeps
 
Bool_t rk45Warned = kFALSE
 the minimum-substep warning was printed
 
Bool_t integFailed = kFALSE
 the integrator gave up (see HasIntegratorFailed())
 
std::vector< TVector3 > accCache
 acceleration (or force) at the end of the last step
 
std::vector< TVector3 > accCacheX
 positions for which accCache is valid
 

Detailed Description

One simulated system: particles, pairwise forces, inspectors and the time integration.

An event is filled with AddParticle(), AddForce() and AddInspector(), and is then advanced with DeriveDT(), DeriveDTN(), DeriveMAX() or DeriveInspect(). Units are fm, amu, c, e and time in fm/c (energies in amu c^2, momenta in amu c).

event * ev = new event();
ev->AddForce(new coulombForce());
particle * target = ev->AddParticle(new EMparticle(206, 79, TVector3(0,0,0), TVector3(0,0,0), true, false));
particle * alpha = ev->AddParticle(new EMparticle(4, 2, TVector3(-1000,50,0), TVector3(0.05,0,0), false, true));
ev->SetIntegrator("VERLET");
ev->AddInspector(new inspectorP(target, alpha, "DEG", 1));
ev->AddInspector(new inspectorP(target, alpha, "CNT", 50000));
ev->DeriveInspect();
A particle with a charge, for electromagnetic forces (coulombForce).
Definition particle.hpp:249
Electric (Coulomb) force between the charges of two particles.
Definition force.hpp:66
event()
Make an empty event: no particles, forces, inspectors nor volume.
Definition event.cpp:20
Inspector on a pair of particles.
A point body with mass, position, velocity, step count, time and an optional recorded path.
Definition particle.hpp:36
Forces
Every force added with AddForce() acts on every pair of particles of the event (there is no way to restrict a force to some particles), and the forces are summed. A force is evaluated as Evaluate(p1, p2), the force on p1 by p2.
Many bodies
The simulator is built for three or more bodies, not only one projectile on a fixed target. With N particles every pair interacts: the force on a particle is the sum over all other particles and all forces, so the cost grows as N^2 per force evaluation. All moving particles are moved together (except in oddevent). Inspectors on a pair (inspectorP) look at two chosen particles only, while inspectors on the event (inspectorE) look at all of them (net energies, smallest distance between any two particles, largest acceleration, ...). The total momentum and angular momentum of the moving particles are conserved only if no invincible particle is present and the integrator treats action and reaction symmetrically.
Invincible particles
An invincible particle (see particle::IsInvincible()) acts on the others but is never moved by any integrator and never receives a force. It is skipped in the kinetic energy, momentum, angular momentum, acceleration and volume checks, but it is counted in potential energies, in GetMinDistance() and in GetDeriveN(). It counts every step (particle::GetECNT()) but its own time does not advance.
Ownership
The event owns, and its destructor deletes,

So particles and inspectors must be made with new, and one of them must not be given to two events (a copied event makes its own copies). The event does NOT own the forces (AddForce()) nor the volume (SetVolume()): they are shared with the copies of the event and may live on the stack. The pointers returned by AddParticle(), getParticle() and getInspector() stay valid until the event is deleted.

Copying
event(event &e) makes a new event from a template event, to run many events with the same setup. It copies the particles (state, step count, time, charge, path, as plain particle objects), makes new inspectors of the same method, criterion and abort flag that watch the new particles (inspectorP) or the new event (inspectorE), and copies the settings: integrator, inspect mode, step cap, pair symmetry, relativistic flag, RK45 tolerances, and the volume and force pointers (shared, not duplicated). It does not copy the RK45 suggested substep and statistics, the last stop reason, the pre-derived copy, the Velocity-Verlet cache, the reference energy of the "EDG"/"EDL" inspectors, nor inspectors that are neither inspectorP nor inspectorE (they are dropped). The copy of an oddevent is a plain event with the default integrator, not an oddevent. The default assignment is deleted.
Integrators and dynamics settings
The integrator is selected by SetIntegrator(), see the table at integrator. The default is kTaylor. DeriveTaylor() (and so oddevent) ignores SetIntegrator(), SetRelativistic() and SetPairSymmetric(); every other integrator honors them.

Definition at line 93 of file event.hpp.

Member Enumeration Documentation

◆ inspectMode

How the non-abort inspectors are combined in Inspect().

The AND default is the design: a typical condition is "the particle reached the asymptote AND went through a minimum number of steps".

Enumerator
kInspectAND 

stop when all of them are satisfied (default)

kInspectOR 

stop when any of them is satisfied

Definition at line 125 of file event.hpp.

◆ integrator

Integration scheme used by DeriveDT().

All of them evaluate every force before any particle is moved (oddevent does not). They are non-relativistic (rest mass) unless SetRelativistic(kTRUE) is called, which kTaylor ignores. The default is kTaylor, the original scheme.

Enumerator Name Scheme Order
kTaylor "TAYLOR" x += v dt + a dt^2/2 ; v += a dt (original scheme, default) 1
kSymplecticEuler "SEULER" v += a dt ; x += v dt (symplectic) 1
kVelocityVerlet "VERLET" x += v dt + a dt^2/2 ; ‘v += (a + a’) dt/2(symplectic) \ilinebr </td> <td class="markdownTableBodyNone"> 2 \ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone"> kRK4 \ilinebr </td> <td class="markdownTableBodyNone">"RK4"\ilinebr </td> <td class="markdownTableBodyNone"> classical Runge-Kutta \ilinebr </td> <td class="markdownTableBodyNone"> 4 \ilinebr </td> </tr> <tr class="markdownTableRowOdd"> <td class="markdownTableBodyNone"> kRK45 \ilinebr </td> <td class="markdownTableBodyNone">"RK45"` Dormand-Prince 5(4), adaptive 5

kRK45: DeriveDT(dt) still advances exactly dt and counts one step; inside, it takes as many substeps as the tolerance needs (SetTolerance()) and remembers the last suggested substep for the next call. It costs 6 force evaluations per substep plus 1 per call, so give it a dt larger than the substep.

Enumerator
kTaylor 

"TAYLOR", original scheme (default)

kSymplecticEuler 

"SEULER", symplectic Euler

kVelocityVerlet 

"VERLET", velocity Verlet

kRK4 

"RK4", classical Runge-Kutta

kRK45 

"RK45", adaptive Dormand-Prince

Definition at line 113 of file event.hpp.

◆ stopReason

Why the last DeriveInspect() returned.

Enumerator
kStopNone 

DeriveInspect() was not called yet (or is running)

kStopInspector 

the inspectors were satisfied (normal end)

kStopAbort 

an abort inspector fired

kStopMaxSteps 

the safety cap of steps (SetMaxInspectSteps()) was reached

kStopInvalid 

an inspector has an undefined method; nothing was derived

kStopFailed 

the integrator gave up (kRK45 on a singular force, see HasIntegratorFailed())

Definition at line 131 of file event.hpp.

Constructor & Destructor Documentation

◆ event() [1/2]

event::event ( )

Make an empty event: no particles, forces, inspectors nor volume.

Defaults: kTaylor, AND mode, pair symmetry on, non-relativistic, step cap MAXINSPECTSTEPS, RK45 tolerances RK45RELTOL and RK45ABSTOL (see RPConfig.hpp).

Definition at line 20 of file event.cpp.

◆ event() [2/2]

event::event ( event &  e)

Make a copy of an event, to run many events from one template.

See "Copying" in the class description for what is copied (particles, inspectors, settings), what is shared (forces, volume) and what is not copied. The inspectors of the source must refer to particles of the source event; an inspectorP whose particle is not in the source event is linked to a wrong particle of the copy. The argument is a non-const reference, so a const event cannot be copied.

Definition at line 24 of file event.cpp.

◆ ~event()

event::~event ( )
virtual

Delete the particles, the inspectors and the pre-derived copy (not the forces nor the volume).

Definition at line 89 of file event.cpp.

Member Function Documentation

◆ AddForce()

void event::AddForce ( force *  force_)
inline

Add a force that acts on every pair of particles of the event.

Parameters
force_force object; NOT owned and NOT copied by the event (it must outlive the event, and is shared with copies of the event).

Several forces are summed. Invalidates the Velocity-Verlet cache.

Definition at line 175 of file event.hpp.

◆ AddInspector()

void event::AddInspector ( inspector *  inspector_)
inline

Add an inspector (a terminating condition for DeriveInspect()).

Parameters
inspector_inspector made with new; the event takes the ownership and deletes it.

Definition at line 179 of file event.hpp.

◆ AddParticle()

particle * event::AddParticle ( particle *  particle_)
inline

Add a particle to the event.

Parameters
particle_particle made with new; the event takes the ownership and deletes it.
Returns
the same pointer, for convenience.

The particles are indexed by the order of addition (getParticle()).

Definition at line 168 of file event.hpp.

◆ CalibrateVelocity()

void event::CalibrateVelocity ( )

Correct the speed of every non-invincible particle so that the given velocity is the velocity far from the others.

For every non-invincible particle the speed is changed along its present direction to \( v'^2 = v^2 - (U_{all} + U_{inv})/m_0 \), where \(U_{all}\) is the potential energy of the particle with all the other particles and \(U_{inv}\) the part with the invincible ones (see particle::calibrateVelocity()). So the interaction with an invincible particle is removed completely and the one with a moving particle by half (it is shared). Uses the rest mass and the non-relativistic kinetic energy. A particle at rest stays at rest. If the radicand is negative (the potential barrier is higher than the kinetic energy) the velocity becomes NaN.

Definition at line 119 of file event.cpp.

◆ ComputeAcceleration()

void event::ComputeAcceleration ( std::vector< TVector3 > &  acc)
protected

Acceleration F/m0 of every particle at the present state, in c^2/fm (zero for invincibles).

Parameters
accoutput, resized to the number of particles

Definition at line 228 of file event.cpp.

◆ ComputeDerivative()

void event::ComputeDerivative ( std::vector< TVector3 > &  dx,
std::vector< TVector3 > &  du 
)
protected

Time derivatives dx/dt = v and du/dt (F/m0, or F when relativistic) at the present state.

Definition at line 269 of file event.cpp.

◆ ComputeForce()

void event::ComputeForce ( std::vector< TVector3 > &  frc)
protected

Net force on every particle at the present state, in amu c^2/fm (zero for invincibles).

Parameters
frcoutput, resized to the number of particles

Definition at line 184 of file event.cpp.

◆ DeriveDT()

void event::DeriveDT ( Double_t  dt = 1)
virtual

Advance the event by one time step with the selected integrator.

Parameters
dttime step in fm/c (a negative value runs backwards in time)

Every non-invincible particle is moved and its time advances by dt. Every particle, invincible or not, counts one step (particle::GetECNT()) and records its path according to its record period. With kRK45 the call advances exactly dt and counts one step, but takes internal substeps. oddevent overrides this.

Reimplemented in oddevent.

Definition at line 173 of file event.cpp.

◆ DeriveDTN()

void event::DeriveDTN ( Int_t  n = 1,
Double_t  dt = 1 
)

Call DeriveDT() n times.

Parameters
nnumber of steps
dttime step in fm/c

Definition at line 609 of file event.cpp.

◆ DeriveInspect()

Bool_t event::DeriveInspect ( Int_t  iperiod = 1,
Double_t  dt = 1 
)

Derive until Inspect() is satisfied.

Parameters
iperiodthe inspectors are checked every iperiod steps, the first time before any step (values below 1 are taken as 1)
dttime step in fm/c
Returns
kTRUE on a normal end (the inspectors are satisfied), kFALSE otherwise; the reason is given by GetStopReason().
  • The non-abort inspectors are combined by the inspect mode, AND by default (SetInspectMode()). An abort inspector (inspector::SetAbort()) ends the event by itself, whatever the others say (stop reason kStopAbort, return kFALSE).
  • An event without any inspector ends at once without a step (kStopInspector, kTRUE). An event with only abort inspectors goes on until one of them fires.
  • The safety cap SetMaxInspectSteps() ends the event with kStopMaxSteps (return kFALSE) after that many steps, if the inspectors are not satisfied before. The cap is counted in steps, not in inspection periods.
  • If any inspector (abort or not) has an undefined method, nothing is derived, a message goes to stderr and kStopInvalid is returned with kFALSE.
  • Because inspection is every iperiod steps, the event may overshoot the condition by up to iperiod - 1 steps; abort inspectors are also checked only then.

Definition at line 839 of file event.cpp.

◆ DeriveMAX()

void event::DeriveMAX ( Double_t  dt = 1)

Call DeriveDT() MAXSTEPS times (100,000, RPConfig.hpp), ignoring the inspectors.

Parameters
dttime step in fm/c

Definition at line 617 of file event.cpp.

◆ DeriveRK4()

void event::DeriveRK4 ( Double_t  dt)
protected

Classical 4th order Runge-Kutta step.

Parameters
dttime step in fm/c

Definition at line 386 of file event.cpp.

◆ DeriveRK45()

void event::DeriveRK45 ( Double_t  dt)
protected

Dormand-Prince 5(4) with adaptive substeps, advancing exactly dt (see integrator).

Parameters
dttime step in fm/c ; may be negative

The 5th order solution is kept and the embedded 4th order one gives the error. The substep suggested at the end of a call is used as the first substep of the next call. If the substep reaches 1e-12 of dt without meeting the tolerance (for example at a singular force), the step is accepted anyway with a warning on stderr (once per event). Counts one step for every particle per call, whatever the number of substeps.

Definition at line 429 of file event.cpp.

◆ DeriveSymplecticEuler()

void event::DeriveSymplecticEuler ( Double_t  dt)
protected

Symplectic Euler step, v += a dt then x += v dt (momentum in the relativistic mode).

Parameters
dttime step in fm/c

Definition at line 291 of file event.cpp.

◆ DeriveTaylor()

void event::DeriveTaylor ( Double_t  dt)
protected

The original scheme: all forces are evaluated for the present state of every moving particle (every ordered pair), then every particle is moved.

Parameters
dttime step in fm/c

Non-relativistic; ignores the pair symmetry and the relativistic flag.

Definition at line 566 of file event.cpp.

◆ DeriveVelocityVerlet()

void event::DeriveVelocityVerlet ( Double_t  dt)
protected

Velocity-Verlet step (kick-drift-kick on the momentum in the relativistic mode).

Parameters
dttime step in fm/c

The acceleration (the force in the relativistic mode) at the end of the step is reused at the start of the next one, as long as every particle is at the position where the last step left it. Only the positions are compared: changing a force parameter or a particle velocity between two steps is not noticed. AddForce(), SetIntegrator(), SetPairSymmetric() and SetRelativistic() clear the cache.

Definition at line 320 of file event.cpp.

◆ FinishStep()

void event::FinishStep ( Double_t  dt)
protected

Close one step: every particle counts the step, the moving ones advance their time, paths are recorded.

Parameters
dttime step in fm/c

Definition at line 284 of file event.cpp.

◆ GetAbsTolerance()

Double_t event::GetAbsTolerance ( )
inline

Absolute tolerance of kRK45 (fm for positions, c for velocities).

Definition at line 220 of file event.hpp.

◆ GetDeriveN()

Long_t event::GetDeriveN ( const Bool_t  minima = kFALSE)

Number of derived steps (particle::GetECNT()) over all particles, invincible ones included.

Parameters
minimakFALSE : the largest count ; kTRUE : the smallest count.
Returns
the count; for an event without particles the extreme value of Long_t (the "DXG"/"DXL"/"DNG"/"DNL" inspectors use it).

Definition at line 684 of file event.cpp.

◆ getForce()

force * event::getForce ( Int_t  index)

Get a force by the order of addition (index as in getParticle(); the force is not owned).

Definition at line 645 of file event.cpp.

◆ GetInspectMode()

inspectMode event::GetInspectMode ( )
inline

The way the non-abort inspectors are combined.

Definition at line 271 of file event.hpp.

◆ getInspector()

inspector * event::getInspector ( Int_t  index)

Get an inspector by the order of addition (index as in getParticle(); owned by the event).

Definition at line 664 of file event.cpp.

◆ GetIntegrator()

integrator event::GetIntegrator ( )
inline

The integrator in use (default kTaylor).

Definition at line 198 of file event.hpp.

◆ GetIntegratorName()

TString event::GetIntegratorName ( )

Name of the integrator in use, as accepted by SetIntegrator(TString).

Definition at line 150 of file event.cpp.

◆ GetMaxAcceleration()

Double_t event::GetMaxAcceleration ( )

The largest acceleration (force / rest mass) of the non-invincible particles (amu c^2/fm/amu = c^2/fm).

Evaluates the forces at the present state without changing it. It uses the rest mass also in the relativistic mode, and honors SetPairSymmetric(). 0 if nobody moves.

Definition at line 929 of file event.cpp.

◆ GetMaxInspectSteps()

Long_t event::GetMaxInspectSteps ( )
inline

The safety cap of steps of DeriveInspect() (0 : unlimited).

Definition at line 279 of file event.hpp.

◆ GetMinDistance()

Double_t event::GetMinDistance ( )

The smallest distance between two particles, invincible ones included (fm). The largest double for fewer than two particles.

Definition at line 918 of file event.cpp.

◆ GetNetAngularMomentum()

TVector3 event::GetNetAngularMomentum ( TVector3  origin = TVector3())

Total angular momentum \(\sum (\vec x - \vec o) \times \vec p\) of the non-invincible particles (amu c fm).

Parameters
originthe point \(\vec o\) in fm (default the origin)

The momentum is the same as in GetNetMomentum().

Definition at line 738 of file event.cpp.

◆ GetNetE()

Double_t event::GetNetE ( const Bool_t  SR = kFALSE)
inline

GetNetKE(SR) + GetNetPE(); conserved in the non-relativistic mode only (see GetNetERel()).

Definition at line 411 of file event.hpp.

◆ GetNetERel()

Double_t event::GetNetERel ( )
inline

GetNetKERel() + GetNetPE(); the conserved energy of the relativistic mode.

Definition at line 419 of file event.hpp.

◆ GetNetKE()

Double_t event::GetNetKE ( const Bool_t  SR = kFALSE)

Kinetic energy of the non-invincible particles (amu c^2).

Parameters
SRkFALSE (default) : \(\frac12 m_0 v^2\) . kTRUE : \(\frac12 \gamma m_0 v^2\), which is not the relativistic kinetic energy and is not conserved (use GetNetKERel()).
Returns
the sum over the non-invincible particles.

Definition at line 697 of file event.cpp.

◆ GetNetKERel()

Double_t event::GetNetKERel ( )

Relativistic kinetic energy, the sum of \((\gamma-1) m_0\) over the non-invincible particles (amu c^2).

GetNetKE(kTRUE) is \(\frac12 \gamma m_0 v^2\), which is not conserved.

Definition at line 711 of file event.cpp.

◆ GetNetMomentum()

TVector3 event::GetNetMomentum ( )

Total momentum of the non-invincible particles (amu c).

The momentum is the one of the integrated dynamics: \(\gamma m_0 v\) when the relativistic mode is really in effect (SetRelativistic() with an integrator other than kTaylor, never in oddevent), \(m_0 v\) otherwise. With an invincible particle it is not conserved, because the invincible particle takes the recoil.

Definition at line 725 of file event.cpp.

◆ GetNetPE()

Double_t event::GetNetPE ( )

Potential energy of the whole event (amu c^2).

Every pair counts once, as half the sum of GetPE() over the particles (so the potential must be symmetric). The pairs with an invincible particle and between invincible particles are included (the latter is a constant).

Definition at line 779 of file event.cpp.

◆ getNForce()

Int_t event::getNForce ( )
inline

Number of forces.

Definition at line 368 of file event.hpp.

◆ getNInspector()

Int_t event::getNInspector ( )
inline

Number of inspectors.

Definition at line 371 of file event.hpp.

◆ getNParticle()

Int_t event::getNParticle ( )
inline

Number of particles.

Definition at line 365 of file event.hpp.

◆ getParticle()

particle * event::getParticle ( Int_t  index)

Get a particle by the order of addition.

Parameters
indexfrom 0 to getNParticle() - 1
Returns
the particle (owned by the event), or a null pointer with a message on stderr if index is too large. A negative index is not checked (it returns the last particle, or is undefined for an empty event).

Definition at line 625 of file event.cpp.

◆ GetPE() [1/2]

Double_t event::GetPE ( Int_t  index,
Bool_t  OnlyInvincibles = kFALSE 
)

Potential energy of one particle with the other particles (amu c^2).

Parameters
indexindex of the particle (as in getParticle(); it must be valid, otherwise the call dereferences a null pointer)
OnlyInvincibleskTRUE : count only the interaction with the invincible particles
Returns
sum over the other particles and all forces of Potential(p, other).

The energy of a pair appears in the value of both particles, so the sum over all particles counts every pair twice (GetNetPE() corrects it).

Definition at line 752 of file event.cpp.

◆ GetPE() [2/2]

Double_t event::GetPE ( particle *  p,
Bool_t  OnlyInvincibles = kFALSE 
)

Same as GetPE(Int_t, Bool_t) for a particle pointer.

Parameters
pparticle (it needs not be in the event; every particle of the event except p itself counts)
OnlyInvincibleskTRUE : count only the interaction with the invincible particles

Definition at line 756 of file event.cpp.

◆ GetRelTolerance()

Double_t event::GetRelTolerance ( )
inline

Relative tolerance of kRK45.

Definition at line 217 of file event.hpp.

◆ GetRK45NRejected()

Long_t event::GetRK45NRejected ( )
inline

Number of rejected kRK45 substeps so far.

Definition at line 229 of file event.hpp.

◆ GetRK45NSubsteps()

Long_t event::GetRK45NSubsteps ( )
inline

Number of accepted kRK45 substeps so far.

Definition at line 226 of file event.hpp.

◆ GetRK45Substep()

Double_t event::GetRK45Substep ( )
inline

Substep suggested for the next kRK45 DeriveDT, in fm/c (0 : none yet).

Definition at line 223 of file event.hpp.

◆ GetState()

void event::GetState ( std::vector< TVector3 > &  x,
std::vector< TVector3 > &  u 
)
protected

Read the positions x and state variables u of all particles.

Definition at line 249 of file event.cpp.

◆ GetStopReason()

stopReason event::GetStopReason ( )
inline

Why the last DeriveInspect() ended (kStopNone before the first call).

Definition at line 282 of file event.hpp.

◆ GetStopReasonName()

TString event::GetStopReasonName ( )

Name of the last stop reason: "NONE", "INSPECTOR", "ABORT", "MAXSTEPS", "INVALID" or "FAILED".

Definition at line 161 of file event.cpp.

◆ GetTime()

Double_t event::GetTime ( )

The largest evolved time among the particles (fm/c). Invincible particles do not advance their time, so it is 0 if all are invincible.

Definition at line 909 of file event.cpp.

◆ HasIntegratorFailed()

Bool_t event::HasIntegratorFailed ( )
inline

True once the integrator has given up.

kRK45 gives up when one call of DeriveDT() needs more than RK45MAXSUBSTEPS substeps, which happens when two bodies fall into an unsoftened attractive singularity. The particles are left at the last accepted state and DeriveInspect() ends with kStopFailed. The flag is never cleared: the state is not usable any more.

Definition at line 293 of file event.hpp.

◆ Inspect()

Bool_t event::Inspect ( )

Evaluate the terminating condition once, without deriving.

Returns
kTRUE if the event should stop.

The abort inspectors are checked first: if one is satisfied it returns kTRUE at once and sets the stop reason to kStopAbort. Otherwise the non-abort inspectors are combined by the inspect mode (AND or OR). With only abort inspectors it returns kFALSE (go on); with no inspector at all it returns kTRUE. The stop reason is only ever set to kStopAbort here; it is reset by DeriveInspect().

Definition at line 875 of file event.cpp.

◆ IsInsideVolume()

Bool_t event::IsInsideVolume ( Bool_t  all = kTRUE)

Whether the non-invincible particles are inside the volume (SetVolume()).

Parameters
allkTRUE : all of them are inside ; kFALSE : at least one is inside.
Returns
kTRUE without a volume, and also when there is no non-invincible particle.

Definition at line 940 of file event.cpp.

◆ IsPairSymmetric()

Bool_t event::IsPairSymmetric ( )
inline

Whether the pair symmetry is in use (default kTRUE).

Definition at line 245 of file event.hpp.

◆ IsRelativistic()

Bool_t event::IsRelativistic ( )
inline

Whether the relativistic flag is set (the flag only; kTaylor ignores it).

Definition at line 265 of file event.hpp.

◆ MomentumOf()

TVector3 event::MomentumOf ( particle *  p,
const TVector3 &  v 
)
protected

The state variable u of the velocity v: v itself, or \(\gamma m_0 v\) when relativistic.

Definition at line 238 of file event.cpp.

◆ operator=()

event & event::operator= ( const event &  )
delete

Deleted: the default assignment would copy the pointers and delete them twice.

◆ preDerive()

void event::preDerive ( )

Make a copy of the event and derive it until its inspectors are satisfied (pre-derivation).

Todo:
Unfinished feature (initial position set-up by pre-derivation, see TODO.md). The copy is private and has no accessor, so the only visible effect is the time spent. A previous pre-derived copy is deleted first. Do not rely on it.

Definition at line 815 of file event.cpp.

◆ preDeriveSetup()

void event::preDeriveSetup ( )

Placeholder for the set-up after preDerive().

Todo:
Unfinished feature: the body is empty.

Definition at line 958 of file event.cpp.

◆ Print()

TString event::Print ( Bool_t  onlymechanic = kFALSE,
Bool_t  mute = kFALSE,
Bool_t  pprint = kFALSE 
)

Describe the event (particles and inspectors) as text.

Parameters
onlymechanicpassed to particle::Print() (which ignores it)
mutekFALSE (default) also prints the text to stdout
pprintkTRUE puts line breaks
Returns
the text.

Definition at line 966 of file event.cpp.

◆ resetPreDerive()

Bool_t event::resetPreDerive ( )

Delete the pre-derived copy.

Returns
kTRUE if there was one, kFALSE otherwise.

Definition at line 828 of file event.cpp.

◆ SetInitial()

Bool_t event::SetInitial ( )

Set the initial condition from the present one.

Warning
Declared but NOT defined anywhere: calling it fails at link time.
Todo:
Unfinished feature (see TODO.md).

◆ SetInspectMode()

void event::SetInspectMode ( inspectMode  mode_)
inline

Set how the non-abort inspectors are combined in Inspect() (default kInspectAND).

Definition at line 268 of file event.hpp.

◆ SetIntegrator() [1/2]

void event::SetIntegrator ( integrator  integ_)
inline

Select the integrator by enumerator (see integrator).

Parameters
integ_new integrator. Invalidates the Velocity-Verlet cache.

The RK45 suggested substep and statistics are kept.

Definition at line 189 of file event.hpp.

◆ SetIntegrator() [2/2]

Bool_t event::SetIntegrator ( TString  name)

Select the integrator by name.

Parameters
name"TAYLOR", "SEULER", "VERLET", "RK4" or "RK45" (case is ignored).
Returns
kTRUE if the name was known. Otherwise a message goes to stderr, kFALSE is returned and the integrator is not changed.

Definition at line 130 of file event.cpp.

◆ SetMaxInspectSteps()

void event::SetMaxInspectSteps ( Long_t  n)
inline

Set the safety cap of DeriveInspect().

Parameters
nmaximum number of steps; 0 means unlimited. The default is MAXINSPECTSTEPS (100,000,000, RPConfig.hpp).

Definition at line 276 of file event.hpp.

◆ SetPairSymmetric()

void event::SetPairSymmetric ( Bool_t  sym_ = kTRUE)
inline

Use Newton's third law to evaluate each pair once (default on).

Parameters
sym_kTRUE : each pair is evaluated once, Evaluate(p1, p2), and the opposite force is given to p2. kFALSE : every ordered pair is evaluated; use it for a force whose Evaluate(p2, p1) is not -Evaluate(p1, p2).

With many bodies the force on particle i is the sum over all j of Evaluate(i, j); with the symmetry on, the pair (i, j) with i < j is evaluated once and its opposite is added to j, which halves the evaluations and makes the total force of the moving particles vanish exactly. Invincible particles never get a force either way. Used by kSymplecticEuler, kVelocityVerlet, kRK4, kRK45 and GetMaxAcceleration(). Ignored by kTaylor and by oddevent, which always evaluate every ordered pair. Invalidates the Velocity-Verlet cache.

Definition at line 242 of file event.hpp.

◆ SetRelativistic()

void event::SetRelativistic ( Bool_t  rel_ = kTRUE)
inline

Switch the dynamics to special relativity (default off).

Parameters
rel_kTRUE to switch on.

With c = 1:

\[ \vec p = \gamma m_0 \vec v, \qquad \frac{d\vec p}{dt} = \vec F, \qquad \vec v = \frac{\vec p}{\sqrt{m_0^2 + p^2}} \]

The integrators kSymplecticEuler, kVelocityVerlet, kRK4 and kRK45 then integrate the momentum. kTaylor (and oddevent) ignore it and stay non-relativistic. The speeds must stay below 1 (c); otherwise the result is NaN. Retardation (finite speed of the fields) is not included. Invalidates the Velocity-Verlet cache.

Only some quantities follow the setting: GetNetMomentum() and GetNetAngularMomentum() use \(\gamma m_0 v\) and the energy inspector "EDG"/"EDL" uses GetNetERel(). The others stay non-relativistic: GetNetKE() (default argument), GetNetE(), GetMaxAcceleration() (force / rest mass), the "KEG"/"KEL"/"PKG"/"PKL" inspectors, and particle::GetP().

Definition at line 262 of file event.hpp.

◆ SetState()

void event::SetState ( const std::vector< TVector3 > &  x,
const std::vector< TVector3 > &  u 
)
protected

Write positions and state variables back to the non-invincible particles.

Definition at line 260 of file event.cpp.

◆ SetTolerance()

void event::SetTolerance ( Double_t  rel,
Double_t  abs 
)

Set the tolerances of kRK45.

Parameters
relrelative tolerance (default RK45RELTOL = 1e-8 in RPConfig.hpp)
absabsolute tolerance, in fm for positions and in c for velocities (default RK45ABSTOL = 1e-10)

A substep is accepted when, for every moving particle, the estimated error is about below abs + rel * |value| (RMS over the moving particles and over position and velocity parts), where the value is the position (fm) and the velocity (c). In the relativistic mode the momentum divided by the rest mass is used instead of the velocity. Invalid values (negative, or both zero) are refused with a message on stderr and the previous tolerances are kept.

Definition at line 108 of file event.cpp.

◆ SetVolume()

void event::SetVolume ( eventVolume *  volume_)
inline

Set the volume used by IsInsideVolume() and the "VOUT"/"VOUTA" inspectors.

Parameters
volume_volume object; NOT owned (may be a null pointer, which means no volume).

Definition at line 183 of file event.hpp.

◆ UseRelativistic()

virtual Bool_t event::UseRelativistic ( )
inlineprotectedvirtual

Whether the relativistic option is really in effect: set, and not kTaylor.

Virtual: oddevent overrides it with kFALSE because it never uses the option.

Reimplemented in oddevent.

Definition at line 557 of file event.hpp.

◆ VelocityOf()

TVector3 event::VelocityOf ( particle *  p,
const TVector3 &  u 
)
protected

The velocity v of the state variable u (inverse of MomentumOf()).

Definition at line 243 of file event.cpp.

Member Data Documentation

◆ accCache

std::vector<TVector3> event::accCache
private

acceleration (or force) at the end of the last step

Definition at line 600 of file event.hpp.

◆ accCacheX

std::vector<TVector3> event::accCacheX
private

positions for which accCache is valid

Definition at line 601 of file event.hpp.

◆ forces

std::vector<force*> event::forces
protected

the forces (not owned)

Definition at line 496 of file event.hpp.

◆ imode

inspectMode event::imode = kInspectAND
private

how the inspectors are combined

Definition at line 582 of file event.hpp.

◆ inspectors

std::vector<inspector*> event::inspectors
private

owned

Definition at line 579 of file event.hpp.

◆ integ

integrator event::integ = kTaylor
private

selected integrator

Definition at line 581 of file event.hpp.

◆ integFailed

Bool_t event::integFailed = kFALSE
private

the integrator gave up (see HasIntegratorFailed())

Definition at line 596 of file event.hpp.

◆ lastStop

stopReason event::lastStop = kStopNone
private

reason of the last DeriveInspect()

Definition at line 584 of file event.hpp.

◆ maxInspectSteps

Long_t event::maxInspectSteps = MAXINSPECTSTEPS
private

safety cap of DeriveInspect()

Definition at line 583 of file event.hpp.

◆ nforce

Int_t event::nforce = 0
protected

number of forces

Definition at line 499 of file event.hpp.

◆ nparticle

Int_t event::nparticle = 0
protected

number of particles

Definition at line 498 of file event.hpp.

◆ pairSymmetric

Bool_t event::pairSymmetric = kTRUE
private

Newton's third law in use.

Definition at line 586 of file event.hpp.

◆ particles

std::vector<particle*> event::particles
protected

the particles, in the order of addition (owned)

Definition at line 495 of file event.hpp.

◆ pEvent

event* event::pEvent = nullptr
private

pre-derived copy (owned)

Definition at line 576 of file event.hpp.

◆ preDerived

Bool_t event::preDerived = kFALSE
private

whether pEvent is valid

Definition at line 577 of file event.hpp.

◆ relativistic

Bool_t event::relativistic = kFALSE
private

relativistic flag

Definition at line 587 of file event.hpp.

◆ rk45Abs

Double_t event::rk45Abs = RK45ABSTOL
private

absolute tolerance

Definition at line 591 of file event.hpp.

◆ rk45H

Double_t event::rk45H = 0.
private

substep suggested for the next call

Definition at line 592 of file event.hpp.

◆ rk45NAccept

Long_t event::rk45NAccept = 0
private

accepted substeps

Definition at line 593 of file event.hpp.

◆ rk45NReject

Long_t event::rk45NReject = 0
private

rejected substeps

Definition at line 594 of file event.hpp.

◆ rk45Rel

Double_t event::rk45Rel = RK45RELTOL
private

relative tolerance

Definition at line 590 of file event.hpp.

◆ rk45Warned

Bool_t event::rk45Warned = kFALSE
private

the minimum-substep warning was printed

Definition at line 595 of file event.hpp.

◆ volume

eventVolume* event::volume = nullptr
private

not owned

Definition at line 575 of file event.hpp.


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