LCOV - code coverage report
Current view: top level - include/crpropa - PhotonBackground.h (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 77.4 % 31 24
Test Date: 2026-07-13 06:03:10 Functions: 81.0 % 21 17

            Line data    Source code
       1              : #ifndef CRPROPA_PHOTONBACKGROUND_H
       2              : #define CRPROPA_PHOTONBACKGROUND_H
       3              : 
       4              : #include "crpropa/Common.h"
       5              : #include "crpropa/Referenced.h"
       6              : #include "crpropa/Vector3.h"
       7              : #include "crpropa/Geometry.h"
       8              : 
       9              : #include <vector>
      10              : #include <string>
      11              : #include <unordered_map>
      12              : 
      13              : namespace crpropa {
      14              : /**
      15              :  * \addtogroup PhotonFields
      16              :  * @{
      17              :  */
      18              : 
      19              : /**
      20              :  @class PhotonField
      21              :  @brief Abstract base class for photon fields.
      22              :  */
      23              : class PhotonField: public Referenced {
      24              :         
      25              : public:
      26              :         
      27              :         /** Constructor
      28              :          * Sets the following values per default:
      29              :          * @var fieldName = "AbstractPhotonField";
      30              :          * @var isRedshiftDependent = false;
      31              :          * @var isPositionDependent = false;
      32              :          * @var surface = nullptr;
      33              :          */
      34          144 :         PhotonField() {
      35          144 :                 this->fieldName = "AbstractPhotonField";
      36          144 :                 this->isRedshiftDependent = false;
      37          144 :                 this->isPositionDependent = false;
      38              :                 this->surface = nullptr;
      39          144 :         }
      40              :         
      41              :         /**
      42              :          returns comoving photon density [1/m^3].
      43              :          multiply with (1+z^3) for physical number density.
      44              :          @param ePhoton         photon energy [J]
      45              :          @param z                       redshift (if redshift dependent, default = 0.)
      46              :          @param pos                     position (if position dependent, default = Vector3d(0,0,0))
      47              :          */
      48              :         virtual double getPhotonDensity(double ePhoton, double z = 0., const Vector3d &pos = Vector3d(0.,0.,0.)) const = 0;
      49              :         /** Returns the minimum photon energy
      50              :          * @param z  Redshift
      51              :          * @param pos  Position 
      52              :          */
      53              :         virtual double getMinimumPhotonEnergy(double z, const Vector3d &pos = Vector3d(0.,0.,0.)) const = 0;
      54              :         /** Returns the maximum photon energy
      55              :          * @param z  Redshift
      56              :          * @param pos  Position 
      57              :          */
      58              :         virtual double getMaximumPhotonEnergy(double z, const Vector3d &pos = Vector3d(0.,0.,0.)) const = 0;
      59              :         /// Returns name of the current used photon field
      60          159 :         virtual inline std::string getFieldName() const {
      61          159 :                 return this->fieldName;
      62              :         }
      63              :         
      64              :         /**
      65              :          returns overall comoving scaling factor
      66              :          (cf. CRPropa3-data/calc_scaling.py)
      67              :          @param z               redshift
      68              :          */
      69         3741 :         virtual inline double getRedshiftScaling(double z) const {
      70         3741 :                 return 1.;
      71              :         };
      72              :         
      73              :         /// Returns if the derived field has a redshift dependency or not
      74              :         inline bool hasRedshiftDependence() const {
      75            0 :                 return this->isRedshiftDependent;
      76              :         }
      77              :         /// Returns if the derived field has a position dependency or not
      78              :         inline bool hasPositionDependence() const {
      79           80 :                 return this->isPositionDependent;
      80              :         }
      81              :         /// Returns the set surface
      82              :         inline ref_ptr<Surface> getSurface() const {
      83              :                 return this->surface;
      84              :         }
      85              :         /** Sets the name of the currently used photon field
      86              :          * @param fieldName  Name of the currently used photon field
      87              :          */
      88              :         void setFieldName(std::string fieldName) {
      89            0 :                 this->fieldName = fieldName;
      90            0 :         }
      91              :         
      92              : protected:
      93              :         std::string fieldName;  /**< Name of the currently used field */
      94              :         bool isRedshiftDependent;  /**< If photon field is redshift dependent */
      95              :         bool isPositionDependent;  /**< If photon field is position dependent */
      96              :         ref_ptr<Surface> surface;  /**< Currently used Surface */
      97              :         
      98              : };
      99              : 
     100              : /**
     101              :  @class TabularPhotonField
     102              :  @brief Photon field decorator for tabulated photon fields.
     103              : 
     104              :  This class reads photon field data from files;
     105              :  The first file must be a list of photon energies [J], named fieldName_photonEnergy.txt
     106              :  The second file must be a list of comoving photon field densities [1/m^3], named fieldName_photonDensity.txt
     107              :  Optionally, a third file contains redshifts, named fieldName_redshift.txt.
     108              :  */
     109              : class TabularPhotonField: public PhotonField {
     110              :         public:
     111              :                 /** Constructor
     112              :                  * @param fieldName  String field identifier
     113              :                  * @param isRedshiftDependent  Whether or not the given field is redshift dependent
     114              :                  */
     115              :                 TabularPhotonField(const std::string fieldName, const bool isRedshiftDependent = true);
     116              : 
     117              :                 /** Returns photon density dependend on energy, redshift and position
     118              :                  * Returns the photon density for a specific photon energy, redshift and position
     119              :                  * @param ePhoton  Photon energy
     120              :                  * @param z  Redshift
     121              :                  * @param pos  Position
     122              :                  */
     123              :                 double getPhotonDensity(double ePhoton, double z = 0., const Vector3d &pos = Vector3d(0.,0.,0.)) const;
     124              :                 double getRedshiftScaling(double z) const;
     125              :                 /** Returns the minimum possible photon energy
     126              :                  * Returns the minimum possible photon energy for a given redshift and position.
     127              :                  * @param z  Redshift
     128              :                  * @param pos Position
     129              :                  */
     130              :                 double getMinimumPhotonEnergy(double z, const Vector3d &pos = Vector3d(0.,0.,0.)) const;
     131              :                 /** Returns the maximum possible photon energy
     132              :                  * Returns the maximum possible photon energy for a given redshift and position.
     133              :                  * @param z  Redshift
     134              :                  * @param pos Position
     135              :                  */
     136              :                 double getMaximumPhotonEnergy(double z, const Vector3d &pos = Vector3d(0.,0.,0.)) const;
     137              : 
     138              :         protected:
     139              :                 /** Reads the photon energies from the given folder
     140              :                  * @param filePath  Path containing photon energy files
     141              :                  */
     142              :                 void readPhotonEnergy(std::string filePath);
     143              :                 /** Reads the photon densities from the given folder
     144              :                  * @param filePath  Path containing photon densitiy files
     145              :                  */
     146              :                 void readPhotonDensity(std::string filePath);
     147              :                 /** Reads the photon redshift from the given folder
     148              :                  * @param filePath  Path containing photon redshift files
     149              :                  */
     150              :                 void readRedshift(std::string filePath);
     151              :                 /// Initializes the redshift scaling from the read photon redshift
     152              :                 void initRedshiftScaling();
     153              :                 /// Checks if read data is valid
     154              :                 void checkInputData() const;
     155              : 
     156              :                 std::vector<double> photonEnergies;
     157              :                 std::vector<double> photonDensity;
     158              :                 std::vector<double> redshifts;
     159              :                 std::vector<double> redshiftScalings;
     160              : };
     161              : 
     162              : /**
     163              :  @class TabularSpatialPhotonField
     164              :  @brief Position dependent photon field decorator for tabulated photon fields.
     165              : 
     166              :  This class reads photon field data from files in the appropriate directory;
     167              :  The first files must be lists of photon energies [J], named fieldName_photonEnergy.txt and contained in the subdirectory /photonEnegy/;
     168              :  The second files must be lists of comoving photon field densities [1/m^3], named fieldName_photonDensity.txt and contained in the subdirectory /photonDensity/;
     169              :  The generated files through the CRPropa procedure (https://crpropa.github.io/CRPropa3/pages/example_notebooks/custom_photonfield/custom-photon-field.html) have a different ordering: the energy bins from the larger to the lower.
     170              :  No redshift dependence is available.
     171              :  The surface is defined to include the nodes of the grid contained within.
     172              :  */
     173              : class TabularSpatialPhotonField: public PhotonField {
     174              :         public:
     175              :                 TabularSpatialPhotonField(const std::string fieldName, ref_ptr<Surface> surface = nullptr);
     176              :                 
     177              :                 /** Returns photon density dependend on energy, redshift and position
     178              :                  * Returns the photon density for a specific photon energy, redshift and position
     179              :                  * @param ePhoton  Photon energy
     180              :                  * @param z  Redshift
     181              :                  * @param pos  Position
     182              :                  */
     183              :                 double getPhotonDensity(double ePhoton = 0., double z = 0., const Vector3d &pos = Vector3d(0.,0.,0.)) const;
     184              :                 /** Returns the minimum possible photon energy
     185              :                  * Returns the minimum possible photon energy for a given redshift and position.
     186              :                  * @param z  Redshift
     187              :                  * @param pos Position
     188              :                  */
     189              :                 double getMinimumPhotonEnergy(double z, const Vector3d &pos = Vector3d(0.,0.,0.)) const;
     190              :                 /** Returns the maximum possible photon energy
     191              :                  * Returns the maximum possible photon energy for a given redshift and position.
     192              :                  * @param z  Redshift
     193              :                  * @param pos Position
     194              :                  */
     195              :                 double getMaximumPhotonEnergy(double z, const Vector3d &pos = Vector3d(0.,0.,0.)) const;
     196              : 
     197              :         protected:
     198              :                 /** Reads the photon energies from the given folder
     199              :                  * @param filePath  Path containing photon energy files
     200              :                  */
     201              :                 std::vector<double> readPhotonEnergy(std::string filePath);
     202              :                 /** Reads the photon densities from the given folder
     203              :                  * @param filePath  Path containing photon densitiy files
     204              :                  */
     205              :                 std::vector<double> readPhotonDensity(std::string filePath);
     206              :                 /// Checks if read data is valid
     207              :                 void checkInputData() const;
     208              :                 
     209              :                 /** Apply a surface that confine the position dependent photon field
     210              :                  * @param surface closed surface to confine the nodes of grid to be uploaded */
     211              :                 void setSurface(ref_ptr<Surface> surface);
     212              :                 
     213              :                 // assuming all the nodes in the grid have the same energy binning
     214              :                 std::vector<double> photonEnergies;
     215              :                 std::vector<std::vector<double>> photonDensity;
     216              :                 std::unordered_map<int, Vector3d> photonDict;
     217              : };
     218              : 
     219              : /**
     220              :  @class IRB_Kneiske04
     221              :  @brief Extragalactic background light model from Kneiske et al. 2004
     222              : 
     223              :  Source info:
     224              :  DOI:10.1051/0004-6361:20031542,
     225              :  https://www.aanda.org/articles/aa/pdf/2004/03/aa3848.pdf, figure 1 ("Best-fit" model)
     226              :  */
     227              : class IRB_Kneiske04: public TabularPhotonField {
     228              : public:
     229           26 :         IRB_Kneiske04() : TabularPhotonField("IRB_Kneiske04", true) {}
     230              : };
     231              : 
     232              : /**
     233              :  @class IRB_Stecker05
     234              :  @brief Extragalactic background light model by Stecker at al. 2005
     235              : 
     236              :  Source info:
     237              :  DOI:10.1086/506188, astro-ph/0510449
     238              :  https://iopscience.iop.org/article/10.1086/506188/pdf
     239              :  */
     240              : class IRB_Stecker05: public TabularPhotonField {
     241              : public:
     242           14 :         IRB_Stecker05() : TabularPhotonField("IRB_Stecker05", true) {}
     243              : };
     244              : 
     245              : /**
     246              :  @class IRB_Franceschini08
     247              :  @brief Extragalactic background light model from Franceschini et al. 2008
     248              : 
     249              :  Source info:
     250              :  DOI:10.1051/0004-6361:200809691
     251              :  https://arxiv.org/pdf/0805.1841.pdf, tables 1 and 2
     252              :  */
     253              : class IRB_Franceschini08: public TabularPhotonField {
     254              : public:
     255           14 :         IRB_Franceschini08() : TabularPhotonField("IRB_Franceschini08", true) {}
     256              : };
     257              : 
     258              : /**
     259              :  @class IRB_Finke10
     260              :  @brief Extragalactic background light model from Finke et al. 2010
     261              : 
     262              :  Source info:
     263              :  DOI:10.1088/0004-637X/712/1/238
     264              :  https://iopscience.iop.org/article/10.1088/0004-637X/712/1/238/pdf
     265              :  */
     266              : class IRB_Finke10: public TabularPhotonField {
     267              : public:
     268           14 :         IRB_Finke10() : TabularPhotonField("IRB_Finke10", true) {}
     269              : };
     270              : 
     271              : /**
     272              :  @class IRB_Dominguez11
     273              :  @brief Extragalactic background light model from Dominguez et al. 2011
     274              : 
     275              :  Source info:
     276              :  DOI:10.1111/j.1365-2966.2010.17631.x
     277              :  https://academic.oup.com/mnras/article/410/4/2556/1008012
     278              :  */
     279              : class IRB_Dominguez11: public TabularPhotonField {
     280              : public:
     281           14 :         IRB_Dominguez11() : TabularPhotonField("IRB_Dominguez11", true) {}
     282              : };
     283              : 
     284              : /**
     285              :  @class IRB_Gilmore12
     286              :  @brief Extragalactic background light model from Gilmore et al. 2012
     287              : 
     288              :  Source info:
     289              :  DOI:10.1111/j.1365-2966.2012.20841.x
     290              :  https://academic.oup.com/mnras/article/422/4/3189/1050758
     291              :  */
     292              : class IRB_Gilmore12: public TabularPhotonField {
     293              : public:
     294           16 :         IRB_Gilmore12() : TabularPhotonField("IRB_Gilmore12", true) {}
     295              : };
     296              : 
     297              : /**
     298              :  @class IRB_Stecker16_upper
     299              :  @brief Extragalactic background light model from Stecker et al. 2016 (upper-bound model)
     300              : 
     301              :  Source info:
     302              :  DOI:10.3847/0004-637X/827/1/6
     303              :  https://iopscience.iop.org/article/10.3847/0004-637X/827/1/6
     304              :  */
     305              : class IRB_Stecker16_upper: public TabularPhotonField {
     306              : public:
     307           14 :         IRB_Stecker16_upper() : TabularPhotonField("IRB_Stecker16_upper", true) {}
     308              : };
     309              : 
     310              : /**
     311              :  @class IRB_Stecker16_lower
     312              :  @brief Extragalactic background light model from Stecker et al. 2016 (lower-bound model)
     313              : 
     314              :  Source info:
     315              :  DOI:10.3847/0004-637X/827/1/6
     316              :  https://iopscience.iop.org/article/10.3847/0004-637X/827/1/6
     317              :  */
     318              : class IRB_Stecker16_lower: public TabularPhotonField {
     319              : public:
     320           14 :         IRB_Stecker16_lower() : TabularPhotonField("IRB_Stecker16_lower", true) {}
     321              : };
     322              : 
     323              : /**
     324              :  @class IRB_Saldana21
     325              :  @brief Extragalactic background light model from Saldana-Lopez et al. 2021
     326              : 
     327              :  Source info:
     328              :  DOI:10.1093/mnras/stab2393
     329              :  https://ui.adsabs.harvard.edu/abs/2021MNRAS.507.5144S/abstract
     330              :  */
     331              : class IRB_Saldana21: public TabularPhotonField {
     332              : public:
     333            8 :         IRB_Saldana21() : TabularPhotonField("IRB_Saldana21", true) {}
     334              : };
     335              : 
     336              : /**
     337              :  @class IRB_Saldana21_upper
     338              :  @brief Extragalactic background light model from Saldana-Lopez et al. 2021 (upper-bound model)
     339              : 
     340              :  Source info:
     341              :  DOI:10.1093/mnras/stab2393
     342              :  https://ui.adsabs.harvard.edu/abs/2021MNRAS.507.5144S/abstract
     343              :  */
     344              : class IRB_Saldana21_upper: public TabularPhotonField {
     345              : public:
     346            0 :         IRB_Saldana21_upper() : TabularPhotonField("IRB_Saldana21_upper", true) {}
     347              : };
     348              : 
     349              : /**
     350              :  @class IRB_Saldana21_lower
     351              :  @brief Extragalactic background light model from Saldana-Lopez et al. 2021 (lower-bound model)
     352              : 
     353              :  Source info:
     354              :  DOI:10.1093/mnras/stab2393
     355              :  https://ui.adsabs.harvard.edu/abs/2021MNRAS.507.5144S/abstract
     356              :  */
     357              : class IRB_Saldana21_lower: public TabularPhotonField {
     358              : public:
     359            0 :         IRB_Saldana21_lower() : TabularPhotonField("IRB_Saldana21_lower", true) {}
     360              : };
     361              : 
     362              : /**
     363              :  @class IRB_Finke22
     364              :  @brief Extragalactic background light model from Finke et al. 2022
     365              : 
     366              :  Source info:
     367              :  DOI:10.3847/1538-4357/ac9843
     368              :  https://iopscience.iop.org/article/10.3847/1538-4357/ac9843/pdf
     369              :  */
     370              : class IRB_Finke22: public TabularPhotonField {
     371              : public:
     372           14 :         IRB_Finke22() : TabularPhotonField("IRB_Finke22", true) {}
     373              : };
     374              : 
     375              : /**
     376              :  @class URB
     377              :  @brief Extragalactic background light model from Protheroe & Biermann 1996
     378              : 
     379              :  Source info:
     380              :  DOI:10.1016/S0927-6505(96)00041-2
     381              :  https://www.sciencedirect.com/science/article/abs/pii/S0927650596000412
     382              :  */
     383              : class URB_Protheroe96: public TabularPhotonField {
     384              : public:
     385           12 :         URB_Protheroe96() : TabularPhotonField("URB_Protheroe96", false) {}
     386              : };
     387              : 
     388              : /**
     389              :  @class URB
     390              :  @brief Extragalactic background light model based on ARCADE2 observations, by Fixsen et al.
     391              :  Note that this model does not cover the same energy range as other URB models. Here, only ~10 MHz - 10 GHz is considered.
     392              :  Therefore, it only makes sense to use this model in very specific studies.
     393              : 
     394              :  Source info:
     395              :  DOI:10.1088/0004-637X/734/1/5
     396              :  https://iopscience.iop.org/article/10.1088/0004-637X/734/1/5
     397              :  */
     398              : class URB_Fixsen11: public TabularPhotonField {
     399              : public:
     400            8 :         URB_Fixsen11() : TabularPhotonField("URB_Fixsen11", false) {}
     401              : };
     402              : 
     403              : /**
     404              :  @class URB
     405              :  @brief Extragalactic background light model by Nitu et al.
     406              : 
     407              :  Source info:
     408              :  DOI:10.1016/j.astropartphys.2020.102532
     409              :  https://www.sciencedirect.com/science/article/pii/S0927650520301043?
     410              :  */
     411              : class URB_Nitu21: public TabularPhotonField {
     412              : public:
     413           22 :         URB_Nitu21() : TabularPhotonField("URB_Nitu21", false) {}
     414              : };
     415              : 
     416              : /**
     417              :  @class ISRF
     418              :  @brief Interstellar radiation field model by Freudenreich et al. (1998) implemented in Porter et al. (2017)
     419              :  
     420              :  Source info:
     421              :  DOI:
     422              :  https://iopscience.iop.org/article/10.3847/1538-4357/aa844d
     423              :  */
     424              : class ISRF_Freudenreich98: public TabularSpatialPhotonField {
     425              : public:
     426            0 :         ISRF_Freudenreich98(ref_ptr<Surface> surface) : TabularSpatialPhotonField("ISRF_Freudenreich98", surface) {}
     427              : };
     428              : 
     429              : /**
     430              :  @class ISRF
     431              :  @brief Interstellar radiation field model by Robitaille et al. (2012) implemented in Porter et al. (2017)
     432              :  
     433              :  Source info:
     434              :  DOI:
     435              :  https://iopscience.iop.org/article/10.3847/1538-4357/aa844d
     436              :  */
     437              : class ISRF_Robitaille12: public TabularSpatialPhotonField {
     438              : public:
     439            0 :         ISRF_Robitaille12(ref_ptr<Surface> surface) : TabularSpatialPhotonField("ISRF_Robitaille12", surface) {}
     440              : };
     441              : 
     442              : /**
     443              :  @class BlackbodyPhotonField
     444              :  @brief Photon field decorator for black body photon fields.
     445              :  */
     446              : class BlackbodyPhotonField: public PhotonField {
     447              : public:
     448              :         /** Constructor
     449              :          * @param fieldName  String identifier of the desired field
     450              :          * @param blackbodyTemperatur  Blackbody temperature
     451              :          */
     452              :         BlackbodyPhotonField(const std::string fieldName, const double blackbodyTemperature);
     453              : 
     454              :         /** Returns photon density dependend on energy, redshift and position
     455              :          * Returns the photon density for a specific photon energy, redshift and position
     456              :          * @param ePhoton  Photon energy
     457              :          * @param z  Redshift
     458              :          * @param pos  Position
     459              :          */
     460              :         double getPhotonDensity(double ePhoton, double z = 0., const Vector3d &pos = Vector3d(0.,0.,0.)) const;
     461              :         /** Returns the minimum possible photon energy
     462              :          * Returns the minimum possible photon energy for a given redshift and position.
     463              :          * @param z  Redshift
     464              :          * @param pos Position
     465              :          */
     466              :         double getMinimumPhotonEnergy(double z, const Vector3d &pos = Vector3d(0.,0.,0.)) const;
     467              :         /** Returns the maximum possible photon energy
     468              :          * Returns the maximum possible photon energy for a given redshift and position.
     469              :          * @param z  Redshift
     470              :          * @param pos Position
     471              :          */
     472              :         double getMaximumPhotonEnergy(double z, const Vector3d &pos = Vector3d(0.,0.,0.)) const;
     473              :         void setQuantile(double q);
     474              : 
     475              : protected:
     476              :         double blackbodyTemperature;
     477              :         double quantile;
     478              : };
     479              : 
     480              : /**
     481              :  @class CMB
     482              :  @brief Cosmic mircowave background photon field
     483              : 
     484              :  Source info:
     485              :  This field is an isotropic blackbody photon field with temperature T = 2.73 K
     486              :  */
     487              : class CMB: public BlackbodyPhotonField {
     488              : public:
     489           94 :         CMB() : BlackbodyPhotonField("CMB", 2.73) {}
     490              : };
     491              : 
     492              : 
     493              : } // namespace crpropa
     494              : 
     495              : #endif // CRPROPA_PHOTONBACKGROUND_H
        

Generated by: LCOV version 2.0-1