Class Candidate

Inheritance Relationships

Base Type

Class Documentation

class Candidate : public Referenced

All information about the cosmic ray.

The Candidate is a passive object, that holds the information about the state of the cosmic ray and the simulation itself.

Public Types

typedef Loki::AssocVector<std::string, Variant> PropertyMap

Public Functions

Candidate(int id = 0, double energy = 0, Vector3d position = Vector3d(0, 0, 0), Vector3d direction = Vector3d(-1, 0, 0), double z = 0, double weight = 1., std::string tagOrigin = "PRIM")

Constructor

Parameters:
  • id – Particle ID after the 2012 Monte Carlo nuclear code scheme, use nuleusId(A,Z) for nuclei

  • energy – Particle energy

  • position – Start position

  • direction – Start direction

  • zRedshift

  • weight – Statistical weight (important property for some modules, usally just 1)

  • tagOrigin – Usually either “PRIM” for primary particle or “SEC” for secondary particle, but can be anything

Candidate(const ParticleState &state)

Creates a candidate, initializing the Candidate::source, Candidate::created, Candidate::previous and Candidate::current state with the argument.

Parameters:

stateParticleState for source, created, previous and current. Makes copies.

bool isActive() const

Checks if particle is still active

void setActive(bool b)

Sets particle active or unactive When the particle is set unactive it will first finish its current step, only at the beginning of the next step the particle will be recognized as unactive and the simulation for that particle will stop. It might be possible that some modules additionally check if the particle is still active, if that happens, it might allready be ignored in those modules during the same step, this depends on the order the modules are added to ModuleList.

Parameters:

b – Activate state of particle, false=deactivated

void setTrajectoryLength(double length)

Sets trajectory length Mostly used by propagators over setCurrentStep, but usefull if particle should start at a later position.

Parameters:

length – Trajectory length in meter

double getTrajectoryLength() const

Returns current trajectory length

double getVelocity() const

Returns absolute of current velocity To get the current velocity vector you can use Candidate.current.getVelocity()

void setRedshift(double z)
double getRedshift() const
void setWeight(double weight)

Sets weight of each candidate. Weights are calculated for each tracked secondary.

void updateWeight(double weight)

Updates Weight Multiplies the current weight with the given weight

double getWeight() const
void setCurrentStep(double step)

Sets the current step and increases the trajectory length and time accordingly. Only the propagation module should use this.

Parameters:

step – Current step in meter

double getCurrentStep() const
Returns:

Current stepsize in meter

void setNextStep(double step)

Sets the proposed next step. Only the propagation module should use this.

Parameters:

step – Proposed next stepsize in meter

double getNextStep() const
Returns:

Proposed next stepsize in meter

void setTagOrigin(std::string tagOrigin)

Sets the tagOrigin of the candidate. Can be used to trace back the interactions

std::string getTagOrigin() const
void setTime(double t)

Sets the time of the candidate. This is done automatically together with the increase of TrajectoryLength, since CRPropa assumes lightspeed in every case both TrajectoryLength and Time are equal.

Parameters:

t – Time in seconds

double getTime() const

Returns the time of the candidate. The time is tracked alongside TrajectoryLength by dividing the current TrajecoryLength by c

Returns:

Current time in seconds

void limitNextStep(double step)

Make a bid for the next step size: the lowest wins.

Parameters:

step – The bid in meter

void setProperty(const std::string &key, const Variant &value)

Sets a arbitrary property This function either creates a property if it does not exist or updates it.

Parameters:
  • key – Key to put into unordered_map

  • value – Any Variant object, Variant can represent a variety of data types so that a property can have any basic datatype

const Variant &getProperty(const std::string &key) const

Returns the value of the Property with given key This function loops through the unordered_map and returns the first property fitting to the provided key. If no key value pair is found it throws an error

Parameters:

key – Key to search for

bool removeProperty(const std::string &key)

Tries to remove property that has given key

Returns:

Returns true if property was removed successfully or false if not

bool hasProperty(const std::string &key) const
Returns:

Returns true if property exists, false otherwise

void addSecondary(Candidate *c)

Add a new candidate to the list of secondaries. Adds a new candidate to the list of secondaries of this candidate. The secondaries Candidate::source and Candidate::previous state are set to the source and previous state of its parent. The secondaries Candidate::created and Candidate::current state are set to the current state of its parent, except for the secondaries current energy and particle id. Trajectory length and redshift are copied from the parent.

Parameters:

cCandidate

inline void addSecondary(ref_ptr<Candidate> c)
void addSecondary(int id, double energy, double w = 1., std::string tagOrigin = "SEC")

Add a new candidate to the list of secondaries.

Parameters:
  • id – particle ID of the secondary after the 2012 Monte Carlo nuclear code scheme

  • energy – energy of the secondary

  • w – weight of the secondary

  • tagOrigin – tag of the secondary

void addSecondary(int id, double energy, Vector3d position, double w = 1., std::string tagOrigin = "SEC")

Add a new candidate to the list of secondaries.

Parameters:
  • id – particle ID of the secondary after the 2012 Monte Carlo nuclear code scheme

  • energy – energy of the secondary

  • position – start position of the secondary

  • w – weight of the secondary

  • tagOrigin – tag of the secondary

void clearSecondaries()

Clears all stored secondaries (deletes them)

std::string getDescription() const
uint64_t getSerialNumber() const
Returns:

Returns a the unique serial number of the particle

void setSerialNumber(const uint64_t snr)

Sets a custom serial number

Parameters:

snr – Custom serial number

uint64_t getSourceSerialNumber() const
Returns:

Serial number of candidate at source

uint64_t getCreatedSerialNumber() const
Returns:

Serial number of candidate at creation

ref_ptr<Candidate> clone(bool recursive = false) const

Create an exact clone of candidate

Parameters:

recursive – recursively clone and add the secondaries

void restart()

Copy the source particle state to the current state and activate it if inactive, e.g. restart it

inline size_t addReference() const
inline size_t removeReference() const
inline int removeReferenceNoDelete() const
inline size_t getReferenceCount() const

Public Members

ParticleState source

Particle state at the source

ParticleState created

Particle state of parent particle at the time of creation

ParticleState current

Current particle state

ParticleState previous

Particle state at the end of the previous step

std::vector<ref_ptr<Candidate>> secondaries

Secondary particles from interactions

PropertyMap properties

Map of property names and their values.

Candidate *parent

Parent candidate. 0 if no parent (initial particle). Must not be a ref_ptr to prevent circular referencing.

Public Static Functions

static void setNextSerialNumber(uint64_t snr)

Set the next serial number to use

static uint64_t getNextSerialNumber()
Returns:

Get the next serial number that will be assigned

Protected Attributes

mutable size_t _referenceCount