REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestAxionSpectrum.cxx
1/******************** REST disclaimer ***********************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
23/***************** DOXYGEN DOCUMENTATION ********************************
33 *************************************************************************/
34
35// See this header file for more info on the functions.
36#include "TRestAxionSpectrum.h"
37
38// Map for named approximations of the spectrum
39const std::map<std::string, std::vector<double>> avail_approximations = {
40 {"arXiv_0702006_Primakoff", {6.02e10, 1.0e-10, 2.481, 1.0 / 1.205}},
41 {"arXiv_1302.6283_Primakoff", {2.0e22 / (3600.0 * 24.0 * 365.25 * 1.0e4), 1.0e-10, 2.450, 0.829}},
42 {"arXiv_1302.6283_Compton", {4.2e24 / (3600.0 * 24.0 * 365.25 * 1.0e4), 1.0e-13, 2.987, 0.776}}};
43
44ClassImp(TRestAxionSpectrum);
45
46// Add basic TRest info
48 SetSectionName(this->ClassName());
49 SetLibraryVersion(LIBRARY_VERSION);
50}
51
53 Initialize();
54 sMode = GetParameter("mode");
55 if (sMode == "table") {
56 sTableFileName = GetParameter("spectrumTableFileName");
57 double g1ref = GetDblParameterWithUnits("g1ref", NAN);
58 double g2ref = GetDblParameterWithUnits("g2ref", NAN);
59 sTableFileName = SearchFile((std::string)sTableFileName);
60 if (sTableFileName == "") {
61 RESTError << "File not found : " << sTableFileName << RESTendl;
62 } else if (std::isnan(g1ref)) {
63 RESTError << "You need to supply at least one reference value 'g1ref' in 'table' mode of "
64 "TRestAxionSpectrum."
65 << RESTendl;
66 } else {
67 fDefaultG1 = g1ref;
68 if (not(std::isnan(g2ref))) {
69 std::cout << "Check!" << std::endl;
70 // N.B. If g2 > 0 has no effect, a warning will be issued by SolarAxionFluxLib.
71#ifdef USE_SolaxFlux
72 spectrum = AxionSpectrum(sTableFileName, g1ref, g2ref);
73#endif
74 fDefaultG2 = g2ref;
75 } else {
76 // N.B. If g2 is not supplied, we initialise with the default value from SolarAxionFluxLib and
77 // issue a warning if the table submode is wrong.
78 // This behaviour is probably not desired; force the user to always specify both
79 // couplings?
80#ifdef USE_SolaxFlux
81 spectrum = AxionSpectrum(sTableFileName, g1ref);
82 auto table_params = spectrum.get_table_parameters();
83 int table_submode = get<0>(table_params);
84 if (table_submode > 1) {
85 fDefaultG2 = get<2>(table_params);
86 std::cout
87 << "WARNING! Your table for TRestAxionSpectrum supports two separate spectra, but you did not specify a value for coupling 'g2'.\n\
88 TRestAxionSpectrum will assume a default value of "
89 << fDefaultG2 << " (in appropriate units)." << std::endl;
90 };
91#endif
92 };
93 };
94 } else if (sMode == "analytical") {
95 std::string named_approx = GetParameter("named_approx", "n/a");
96 double norm = GetDblParameterWithUnits("norm", NAN);
97 double g1ref = GetDblParameterWithUnits("g1ref", NAN);
98 double a = GetDblParameterWithUnits("a", NAN);
99 double b = GetDblParameterWithUnits("b", NAN);
100 bool check_named_approx = not(avail_approximations.find(named_approx) == avail_approximations.end());
101 bool check_numbers = not(std::isnan(norm) || std::isnan(a) || std::isnan(b) || std::isnan(g1ref));
102 if (check_named_approx) {
103 std::vector<double> p = avail_approximations.at(named_approx);
104#ifdef USE_SolaxFlux
105 spectrum = AxionSpectrum(p[0], p[1], p[2], p[3]);
106#endif
107 fDefaultG1 = p[1];
108 } else if (check_numbers) {
109#ifdef USE_SolaxFlux
110 spectrum = AxionSpectrum(norm, g1ref, a, b);
111#endif
112 fDefaultG1 = g1ref;
113 } else {
114 std::string avail_approximation_names = "";
115 for (auto el : avail_approximations) {
116 avail_approximation_names += " " + el.first;
117 };
118 RESTError << "You want to use the 'analytical' mode of TRestAxionSpectrum but neither supplied a "
119 "known 'named_approx' OR the four required parameters 'a', 'b', 'norm', "
120 "and 'g1ref'.\n The available known approximations are:" +
121 avail_approximation_names
122 << RESTendl;
123 }
124 } else if (sMode == "solar_model") {
125 // TODO: Ideally use TRestAxionSolarModel here...
126 std::string sSolarModelFile = GetParameter("solarAxionModel");
127 std::string fullPathName = SearchFile((std::string)sSolarModelFile);
128#ifdef USE_SolaxFlux
129 sol = SolarModel(fullPathName, OP, false);
130 fDefaultG1 = sol.get_gagg_ref_value_in_inverse_GeV();
131 fDefaultG2 = sol.get_gaee_ref_value();
132 spectrum = AxionSpectrum(&sol);
133#endif
134 } else {
135 RESTError << "Mode for TRestAxionSpectrum not known! Choose one of 'table', 'analytical', and "
136 "'solar_model'."
137 << RESTendl;
138 sMode = "none";
139 };
140}
141
142TRestAxionSpectrum::TRestAxionSpectrum() : TRestMetadata() { Initialize(); }
143
144TRestAxionSpectrum::TRestAxionSpectrum(const char* cfgFileName, std::string name)
145 : TRestMetadata(cfgFileName) {
146 RESTDebug << "Creating instance of TRestAxionSpectrum from file " + fConfigFileName + "..." << RESTendl;
147 Initialize();
150}
151
152TRestAxionSpectrum::~TRestAxionSpectrum() {}
153
156
157 RESTMetadata << "+++++++++++++++++++++++++++++++++++++++++++++++++" << RESTendl;
158 if (sMode != "none") {
159 RESTMetadata << " Solar spectrum created in mode '" << sMode << "'." << RESTendl;
160 } else {
161 RESTMetadata << " Solar spectrum has not yet been initialised, yet!" << RESTendl;
162 };
163 if (sMode == "solar_model") {
164#ifdef USE_SolaxFlux
165 RESTMetadata << " - Opacity code used : " << sol.get_solaxlib_name_and_version() << RESTendl;
166 RESTMetadata << " - Solar model file : " << sol.get_solar_model_name() << RESTendl;
167 RESTMetadata << " - Opacity code used : " << sol.get_opacitycode_name() << RESTendl;
168#endif
169 } else if (sMode == "table") {
170 RESTMetadata << " - Tabulated spectrum file used : "
171 << TRestTools::SeparatePathAndName(sTableFileName).second << RESTendl;
172 };
173 RESTMetadata << "-------------------------------------------------" << RESTendl;
174 RESTMetadata << " - Units of the solar axion flux from this class : axions / cm^2 s keV" << RESTendl;
175 if (not(std::isnan(fDefaultG1))) {
176 RESTMetadata << " - Numerical value of coupling g1 (in appropriate units): " << fDefaultG1
177 << RESTendl;
178 };
179 if (fDefaultG2 > 0) {
180 RESTMetadata << " - Numerical value of coupling g2 (in appropriate units): " << fDefaultG2
181 << RESTendl;
182 } else {
183 RESTMetadata << " - A second coupling, g2, is not available in this class instance." << RESTendl;
184 };
185 RESTMetadata << "+++++++++++++++++++++++++++++++++++++++++++++++++" << RESTendl;
186}
187
188double TRestAxionSpectrum::GetSolarAxionFlux(double erg_lo, double erg_hi, double erg_step_size) { return 0; }
189double TRestAxionSpectrum::GetDifferentialSolarAxionFlux(double erg) {
190#ifdef USE_SolaxFlux
191 return spectrum.axion_flux(erg, fDefaultG1, fDefaultG2);
192#endif
193 return 0.0;
194}
A metadata class to define a solar axion spectrum and functions to evaluate it.
void InitFromConfigFile()
To make settings from rml file. This method must be implemented in the derived class.
void PrintMetadata()
Implemented it in the derived metadata class to print out specific metadata information.
void Initialize()
Making default settings.
A base class for any REST metadata class.
Definition: TRestMetadata.h:70
virtual void PrintMetadata()
Implemented it in the derived metadata class to print out specific metadata information.
endl_t RESTendl
Termination flag object for TRestStringOutput.
Int_t LoadConfigFromFile(const std::string &configFilename, const std::string &sectionName="")
Give the file name, find out the corresponding section. Then call the main starter.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
void SetSectionName(std::string sName)
set the section name, clear the section content
std::string SearchFile(std::string filename)
Search files in current directory and directories specified in "searchPath" section.
std::string fConfigFileName
Full name of the rml file.
std::string GetParameter(std::string parName, TiXmlElement *e, TString defaultValue=PARAMETER_NOT_FOUND_STR)
Returns the value for the parameter named parName in the given section.
static std::pair< std::string, std::string > SeparatePathAndName(const std::string &fullname)
Separate path and filename in a full path+filename string, returns a pair of string.
Definition: TRestTools.cxx:813