LCOV - code coverage report
Current view: top level - include/crpropa - Candidate.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 1 1 100.0 %
Date: 2024-04-29 14:43:01 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef CRPROPA_CANDIDATE_H
       2             : #define CRPROPA_CANDIDATE_H
       3             : 
       4             : #include "crpropa/ParticleState.h"
       5             : #include "crpropa/Referenced.h"
       6             : #include "crpropa/AssocVector.h"
       7             : #include "crpropa/Variant.h"
       8             : 
       9             : #include <vector>
      10             : #include <map>
      11             : #include <sstream>
      12             : #include <stdint.h>
      13             : 
      14             : namespace crpropa {
      15             : /**
      16             :  * \addtogroup Core
      17             :  * @{
      18             :  */
      19             : 
      20             : /**
      21             :  @class Candidate Candidate.h include/crpropa/Candidate.h
      22             :  @brief All information about the cosmic ray.
      23             : 
      24             :  The Candidate is a passive object, that holds the information about the state
      25             :  of the cosmic ray and the simulation itself.
      26             :  */
      27             : class Candidate: public Referenced {
      28             : public:
      29             :         ParticleState source; /**< Particle state at the source */
      30             :         ParticleState created; /**< Particle state of parent particle at the time of creation */
      31             :         ParticleState current; /**< Current particle state */
      32             :         ParticleState previous; /**< Particle state at the end of the previous step */
      33             : 
      34             :         std::vector<ref_ptr<Candidate> > secondaries; /**< Secondary particles from interactions */
      35             : 
      36             :         typedef Loki::AssocVector<std::string, Variant> PropertyMap;
      37             :         PropertyMap properties; /**< Map of property names and their values. */
      38             : 
      39             :         /** Parent candidate. 0 if no parent (initial particle). Must not be a ref_ptr to prevent circular referencing. */
      40             :         Candidate *parent;
      41             : 
      42             : private:
      43             :         bool active; /**< Active status */
      44             :         double weight; /**< Weight of the candidate */
      45             :         double redshift; /**< Current simulation time-point in terms of redshift z */
      46             :         double trajectoryLength; /**< Comoving distance [m] the candidate has traveled so far */
      47             :         double currentStep; /**< Size of the currently performed step in [m] comoving units */
      48             :         double nextStep; /**< Proposed size of the next propagation step in [m] comoving units */
      49             :         std::string tagOrigin; /**< Name of interaction/source process which created this candidate*/
      50             : 
      51             :         static uint64_t nextSerialNumber;
      52             :         uint64_t serialNumber;
      53             : 
      54             : public:
      55             :         Candidate(
      56             :                 int id = 0,
      57             :                 double energy = 0,
      58             :                 Vector3d position = Vector3d(0, 0, 0),
      59             :                 Vector3d direction = Vector3d(-1, 0, 0),
      60             :                 double z = 0,
      61             :                 double weight = 1., 
      62             :                 std::string tagOrigin = "PRIM"
      63             :         );
      64             : 
      65             :         /**
      66             :          Creates a candidate, initializing the Candidate::source, Candidate::created,
      67             :          Candidate::previous and Candidate::current state with the argument.
      68             :          */
      69             :         Candidate(const ParticleState &state);
      70             : 
      71             :         bool isActive() const;
      72             :         void setActive(bool b);
      73             : 
      74             :         void setTrajectoryLength(double length);
      75             :         double getTrajectoryLength() const;
      76             : 
      77             :         void setRedshift(double z);
      78             :         double getRedshift() const;
      79             : 
      80             :         /**
      81             :          Sets weight of each candidate.
      82             :          Weights are calculated for each tracked secondary.
      83             :          */
      84             :         void setWeight(double weight);
      85             :     void updateWeight(double weight);
      86             :         double getWeight() const;
      87             : 
      88             :         /**
      89             :          Sets the current step and increases the trajectory length accordingly.
      90             :          Only the propagation module should use this.
      91             :          */
      92             :         void setCurrentStep(double step);
      93             :         double getCurrentStep() const;
      94             : 
      95             :         /**
      96             :          Sets the proposed next step.
      97             :          Only the propagation module should use this.
      98             :          */
      99             :         void setNextStep(double step);
     100             :         double getNextStep() const;
     101             : 
     102             :         /**
     103             :          Sets the tagOrigin of the candidate. Can be used to trace back the interactions
     104             :          */
     105             :         void setTagOrigin(std::string tagOrigin);
     106             :         std::string getTagOrigin() const;
     107             : 
     108             :         /**
     109             :          Make a bid for the next step size: the lowest wins.
     110             :          */
     111             :         void limitNextStep(double step);
     112             : 
     113             :         void setProperty(const std::string &name, const Variant &value);
     114             :         const Variant &getProperty(const std::string &name) const;
     115             :         bool removeProperty(const std::string &name);
     116             :         bool hasProperty(const std::string &name) const;
     117             : 
     118             :         /**
     119             :          Add a new candidate to the list of secondaries.
     120             :          @param c Candidate
     121             : 
     122             :          Adds a new candidate to the list of secondaries of this candidate.
     123             :          The secondaries Candidate::source and Candidate::previous state are set to the _source_ and _previous_ state of its parent.
     124             :          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.
     125             :          Trajectory length and redshift are copied from the parent.
     126             :          */
     127             :         void addSecondary(Candidate *c);
     128           4 :         inline void addSecondary(ref_ptr<Candidate> c) { addSecondary(c.get()); };
     129             :         /**
     130             :          Add a new candidate to the list of secondaries.
     131             :          @param id                      particle ID of the secondary
     132             :          @param energy          energy of the secondary
     133             :          @param w                       weight of the secondary
     134             :          @param tagOrigin       tag of the secondary
     135             :          */
     136             :         void addSecondary(int id, double energy, double w = 1., std::string tagOrigin = "SEC");
     137             :         /**
     138             :          Add a new candidate to the list of secondaries.
     139             :          @param id                      particle ID of the secondary
     140             :          @param energy          energy of the secondary
     141             :          @param position        start position of the secondary
     142             :          @param w                       weight of the secondary
     143             :          @param tagOrigin       tag of the secondary
     144             :          */
     145             :         void addSecondary(int id, double energy, Vector3d position, double w = 1., std::string tagOrigin = "SEC");
     146             :         void clearSecondaries();
     147             : 
     148             :         std::string getDescription() const;
     149             : 
     150             :         /** Unique (inside process) serial number (id) of candidate */
     151             :         uint64_t getSerialNumber() const;
     152             :         void setSerialNumber(const uint64_t snr);
     153             : 
     154             :         /** Serial number of candidate at source*/
     155             :         uint64_t getSourceSerialNumber() const;
     156             : 
     157             :         /** Serial number of candidate at creation */
     158             :         uint64_t getCreatedSerialNumber() const;
     159             : 
     160             :         /** Set the next serial number to use */
     161             :         static void setNextSerialNumber(uint64_t snr);
     162             : 
     163             :         /** Get the next serial number that will be assigned */
     164             :         static uint64_t getNextSerialNumber();
     165             : 
     166             :         /**
     167             :          Create an exact clone of candidate
     168             :          @param recursive       recursively clone and add the secondaries
     169             :          */
     170             :         ref_ptr<Candidate> clone(bool recursive = false) const;
     171             : 
     172             :         /**
     173             :          Copy the source particle state to the current state
     174             :          and activate it if inactive, e.g. restart it
     175             :         */
     176             :         void restart();
     177             : };
     178             : 
     179             : /** @}*/
     180             : } // namespace crpropa
     181             : 
     182             : #endif // CRPROPA_CANDIDATE_H

Generated by: LCOV version 1.14