REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestAxionSolarFlux.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
84
85#include "TRestAxionSolarFlux.h"
86using namespace std;
87
88ClassImp(TRestAxionSolarFlux);
89
94
109TRestAxionSolarFlux::TRestAxionSolarFlux(const char* cfgFileName, string name) : TRestMetadata(cfgFileName) {
110 RESTDebug << "Entering TRestAxionSolarFlux constructor( cfgFileName, name )" << RESTendl;
111 RESTDebug << "File: " << cfgFileName << " Name: " << name << RESTendl;
112}
113
118
123 SetLibraryVersion(LIBRARY_VERSION);
124
126
127 if (!fRandom) {
128 delete fRandom;
129 fRandom = nullptr;
130 }
131
132 if (fRandom != nullptr) {
133 delete fRandom;
134 fRandom = nullptr;
135 }
136
137 fRandom = new TRandom3(fSeed);
138 fSeed = fRandom->TRandom::GetSeed();
139}
140
145TH1F* TRestAxionSolarFlux::GetFluxHistogram(string fname, Double_t binSize) {
146 string fullPathName = SearchFile(fname);
147
148 std::vector<std::vector<Double_t>> fluxData;
149 TRestTools::ReadASCIITable(fullPathName, fluxData, 3);
150
151 TH2F* originalHist =
152 new TH2F(Form("FluxTable_%s", GetName()), "", 100, 0., 1., (Int_t)(20. / binSize), 0., 20.);
153
154 for (const auto& data : fluxData) {
155 Double_t r = 0.005 + data[0];
156 Double_t en = data[1] - 0.005;
157 Double_t flux = data[2] * binSize; // flux in cm-2 s-1 bin-1
158
159 originalHist->Fill(r, en, flux);
160 }
161
162 return (TH1F*)originalHist->ProjectionY();
163}
164
169TCanvas* TRestAxionSolarFlux::DrawFluxFile(string fname, Double_t binSize) {
170 if (fCanvas != nullptr) {
171 delete fCanvas;
172 fCanvas = nullptr;
173 }
174 fCanvas = new TCanvas("canv", "This is the canvas title", 1400, 1200);
175 fCanvas->Draw();
176
177 TPad* pad1 = new TPad("pad1", "This is pad1", 0.01, 0.02, 0.99, 0.97);
178 pad1->Draw();
179
180 fCanvas->cd();
181 pad1->cd();
182
183 GetFluxHistogram(fname, binSize)->Draw("hist");
184
185 return fCanvas;
186}
187
191Double_t TRestAxionSolarFlux::GetFluxAtEnergy(Double_t energy, Double_t m) {
192 TH1F* h = GetEnergySpectrum(m);
193 return h->GetBinContent(h->FindBin(energy));
194}
195
200 if (fCanvas != nullptr) {
201 delete fCanvas;
202 fCanvas = nullptr;
203 }
204 fCanvas = new TCanvas("canv", "This is the canvas title", 1200, 500);
205 fCanvas->Draw();
206
207 TPad* pad1 = new TPad("pad1", "This is pad1", 0.01, 0.02, 0.99, 0.97);
208 pad1->Draw();
209
210 pad1->cd();
211 pad1->SetLogy();
212 pad1->SetRightMargin(0.09);
213 pad1->SetLeftMargin(0.15);
214 pad1->SetBottomMargin(0.15);
215
216 TH1F* ht = GetEnergySpectrum();
217 ht->SetLineColor(kBlack);
218 ht->SetFillStyle(4050);
219 ht->SetFillColor(kBlue - 10);
220
221 ht->Draw("hist");
222
223 return fCanvas;
224}
225
231
232 RESTMetadata << " - Coupling type : " << fCouplingType << RESTendl;
233 RESTMetadata << " - Coupling strength : " << fCouplingStrength << RESTendl;
234 RESTMetadata << "--------" << RESTendl;
235 RESTMetadata << " - Random seed : " << fSeed << RESTendl;
236 RESTMetadata << "--------" << RESTendl;
237}
A metadata class to load tabulated solar axion fluxes.
void Initialize()
It is required in order to load solar flux tables into memory.
TRestAxionSolarFlux()
Default constructor.
Double_t GetFluxAtEnergy(Double_t energy, Double_t m=0)
It returns a flux in cm-2 s-1 keV-1 at the energy given by argument.
TCanvas * fCanvas
A canvas pointer for drawing.
~TRestAxionSolarFlux()
Default destructor.
virtual Bool_t LoadTables()=0
It defines how to read the solar tables at the inhereted class.
Double_t fCouplingStrength
Axion coupling strength.
TCanvas * DrawFluxFile(std::string fname, Double_t binSize=0.01)
It draws the contents of a .flux file. This method just receives the name of the ....
TH1F * GetFluxHistogram(std::string fname, Double_t binSize=0.01)
It builds a histogram using the contents of the .flux file given in the argument.
std::string fCouplingType
Axion coupling. Defines coupling type and strength.
Int_t fSeed
Seed used in random generator.
TRandom3 * fRandom
Random number generator.
void PrintMetadata()
Prints on screen the information about the metadata members of TRestAxionSolarFlux.
virtual TH1F * GetEnergySpectrum(Double_t m=0)=0
It returns an energy integrated spectrum in cm-2 s-1 keV-1.
Bool_t fTablesLoaded
A metadata member to control if this class has been initialized.
virtual TCanvas * DrawSolarFlux()
It draws the contents of a .flux file. This method just receives the.
A base class for any REST metadata class.
Definition: TRestMetadata.h:74
virtual void PrintMetadata()
Implemented it in the derived metadata class to print out specific metadata information.
endl_t RESTendl
Termination flag object for TRestStringOutput.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
std::string SearchFile(std::string filename)
Search files in current directory and directories specified in "searchPath" section.
static int ReadASCIITable(std::string fName, std::vector< std::vector< Double_t > > &data, Int_t skipLines=0, std::string separator="\t")
Reads an ASCII file containing a table with values.
Definition: TRestTools.cxx:577