212#include "TRestAxionSolarQCDFlux.h"
277 RESTDebug <<
"TRestAxionSolarflux::LoadContinuumFluxTable. No solar flux table was defined"
284 RESTDebug <<
"Loading table from file : " <<
RESTendl;
285 RESTDebug <<
"File : " << fullPathName <<
RESTendl;
287 std::vector<std::vector<Float_t>> fluxTable;
289 std::vector<std::vector<Double_t>> doubleTable;
291 RESTError <<
"TRestAxionSolarQCDFlux::LoadContinuumFluxTable. " <<
RESTendl;
295 for (
const auto& row : doubleTable) {
296 std::vector<Float_t> floatVec(row.begin(), row.end());
297 fluxTable.push_back(floatVec);
303 RESTError <<
"Filename extension was not recognized!" <<
RESTendl;
304 RESTError <<
"Solar flux table will not be populated" <<
RESTendl;
308 if (fluxTable.size() != 100 && fluxTable[0].size() != 200) {
310 RESTError <<
"LoadContinuumFluxTable. The table does not contain the right number of rows or columns"
312 RESTError <<
"Table will not be populated" <<
RESTendl;
315 for (
unsigned int n = 0; n < fluxTable.size(); n++) {
316 TH1F* h =
new TH1F(Form(
"%s_ContinuumFluxAtRadius%d", GetName(), n),
"", 200, 0, 20);
317 for (
unsigned int m = 0; m < fluxTable[n].size(); m++) h->SetBinContent(m + 1, fluxTable[n][m]);
328 RESTDebug <<
"TRestAxionSolarflux::LoadMonoChromaticFluxTable. No solar flux monochromatic table was "
336 RESTDebug <<
"Loading monochromatic lines from file : " <<
RESTendl;
337 RESTDebug <<
"File : " << fullPathName <<
RESTendl;
339 std::vector<std::vector<Double_t>> doubleTable;
341 RESTError <<
"TRestAxionSolarQCDFlux::LoadMonoChromaticFluxTable." <<
RESTendl;
346 std::vector<std::vector<Float_t>> asciiTable;
347 for (
const auto& row : doubleTable) {
348 std::vector<Float_t> floatVec(row.begin(), row.end());
349 asciiTable.push_back(floatVec);
354 if (asciiTable.size() != 101) {
355 RESTError <<
"LoadMonoChromaticFluxTable. The table does not contain the right number of rows"
357 RESTError <<
"Table will not be populated" <<
RESTendl;
361 for (
unsigned int en = 0; en < asciiTable[0].size(); en++) {
362 Float_t energy = asciiTable[0][en];
363 TH1F* h =
new TH1F(Form(
"%s_MonochromeFluxAtEnergy%6.4lf", GetName(), energy),
"", 100, 0, 1);
364 for (
unsigned int r = 1; r < asciiTable.size(); r++) h->SetBinContent(r, asciiTable[r][en]);
375 RESTError <<
"TRestAxionSolarflux::ReadFluxFile. Energy bin size of .flux file must be specified."
377 RESTError <<
"Please, define binSize parameter in eV." <<
RESTendl;
382 RESTWarning <<
"TRestAxionSolarflux::ReadFluxFile. Peak sigma must be specified to generate "
383 "monochromatic spectrum."
385 RESTWarning <<
"Only continuum table will be generated. If this was intentional, please, ignore this "
393 RESTDebug <<
"Loading flux table ... " <<
RESTendl;
394 RESTDebug <<
"File : " << fullPathName <<
RESTendl;
395 std::vector<std::vector<Double_t>> fluxData;
398 RESTDebug <<
"Table loaded" <<
RESTendl;
399 TH2F* originalHist =
new TH2F(
"FullTable",
"", 100, 0., 1., (Int_t)(20. /
fBinSize), 0., 20.);
400 TH2F* continuumHist =
new TH2F(
"ContinuumTable",
"", 100, 0., 1., (Int_t)(20. /
fBinSize), 0., 20.);
401 TH2F* spectrumHist =
new TH2F(
"LinesTable",
"", 100, 0., 1., (Int_t)(20. /
fBinSize), 0., 20.);
405 for (
const auto& data : fluxData) {
406 Float_t r = 0.005 + data[0];
407 Float_t en = data[1] - 0.005;
408 Float_t flux = data[2] * fluxBinSize;
410 originalHist->Fill(r, en, (Float_t)flux);
411 continuumHist->Fill(r, en, (Float_t)flux);
413 RESTDebug <<
"Histograms filled" <<
RESTendl;
419 const int smearPoints = (Int_t)(5 / (
fBinSize * 100));
420 const int excludePoints = smearPoints / 5;
421 for (
const auto& data : fluxData) {
422 Float_t r = 0.005 + data[0];
423 Float_t en = data[1] - 0.005;
425 Int_t binR = continuumHist->GetXaxis()->FindBin(r);
426 Int_t binE = continuumHist->GetYaxis()->FindBin(en);
428 Double_t avgFlux = 0;
430 for (
int e = binE - smearPoints; e <= binE + smearPoints; e++) {
431 if (e < 1 || (e < binE + excludePoints && e > binE - excludePoints))
continue;
433 avgFlux += continuumHist->GetBinContent(binR, e);
437 Float_t targetBinFlux = continuumHist->GetBinContent(binR, binE);
438 Float_t thrFlux = avgFlux +
fPeakSigma * TMath::Sqrt(avgFlux);
439 if (targetBinFlux > 0 && targetBinFlux > thrFlux) {
440 continuumHist->SetBinContent(binR, binE, avgFlux);
446 for (
int n = 0; n < originalHist->GetNbinsX(); n++)
447 for (
int m = 0; m < originalHist->GetNbinsY(); m++) {
448 Float_t orig = originalHist->GetBinContent(n + 1, m + 1);
449 Float_t cont = continuumHist->GetBinContent(n + 1, m + 1);
451 spectrumHist->SetBinContent(n + 1, m + 1, orig - cont);
454 continuumHist->Rebin2D(1, (Int_t)(0.1 /
fBinSize));
455 continuumHist->Scale(10);
459 for (
int n = 0; n < continuumHist->GetNbinsX(); n++) {
461 (TH1F*)continuumHist->ProjectionY(Form(
"%s_ContinuumFluxAtRadius%d", GetName(), n), n + 1, n + 1);
466 for (
int n = 0; n < spectrumHist->GetNbinsY(); n++) {
467 if (spectrumHist->ProjectionX(
"", n + 1, n + 1)->Integral() > 0) {
468 Double_t energy = spectrumHist->ProjectionY()->GetBinCenter(n + 1);
469 TH1F* hm = (TH1F*)spectrumHist->ProjectionX(
470 Form(
"%s_MonochromeFluxAtEnergy%5.3lf", GetName(), energy), n + 1, n + 1);
475 cout <<
"Number of peaks identified: " <<
fFluxLines.size() << endl;
514 fMonoHist =
new TH1F(
"MonochromaticHist",
"", 20000, 0, 20);
516 fMonoHist->Fill(x.first, x.second->Integral());
520 fMonoHist->GetXaxis()->SetTitle(
"Energy [keV]");
521 fMonoHist->GetXaxis()->SetTitleSize(0.05);
522 fMonoHist->GetXaxis()->SetLabelSize(0.05);
523 fMonoHist->GetYaxis()->SetTitle(
"Flux [cm-2 s-1 eV-1]");
524 fMonoHist->GetYaxis()->SetTitleSize(0.05);
525 fMonoHist->GetYaxis()->SetLabelSize(0.05);
544 fTotalHist =
new TH1F(
"fTotalHist",
"", 20000, 0, 20);
545 for (
int n = 0; n < hc->GetNbinsX(); n++) {
546 for (
int m = 0; m < 100; m++) {
547 fTotalHist->SetBinContent(n * 100 + 1 + m, hc->GetBinContent(n + 1));
551 for (
int n = 0; n < hm->GetNbinsX(); n++)
553 fTotalHist->SetBinContent(n + 1,
fTotalHist->GetBinContent(n + 1) + 100 * hm->GetBinContent(n + 1));
556 fTotalHist->GetXaxis()->SetTitle(
"Energy [keV]");
559 fTotalHist->GetYaxis()->SetTitle(
"Flux [cm-2 s-1 keV-1]");
574 fCanvas =
new TCanvas(
"canv",
"This is the canvas title", 1200, 500);
577 TPad* pad1 =
new TPad(
"pad1",
"This is pad1", 0.01, 0.02, 0.99, 0.97);
582 pad1->cd(1)->SetLogy();
583 pad1->cd(1)->SetRightMargin(0.09);
584 pad1->cd(1)->SetLeftMargin(0.15);
585 pad1->cd(1)->SetBottomMargin(0.15);
588 ht->SetLineColor(kBlack);
589 ht->SetFillStyle(4050);
590 ht->SetFillColor(kBlue - 10);
593 hm->SetLineColor(kBlack);
597 hm->Draw(
"hist same");
600 pad1->cd(2)->SetRightMargin(0.09);
601 pad1->cd(2)->SetLeftMargin(0.15);
602 pad1->cd(2)->SetBottomMargin(0.15);
605 hm->Draw(
"hist same");
627 for (
unsigned int n = 0; n <
fFluxTable.size(); n++) {
642 if (eRange.X() == -1 && eRange.Y() == -1) {
649 if (line.first > eRange.X() && line.first < eRange.Y()) flux += line.second->Integral();
652 for (
unsigned int n = 0; n <
fFluxTable.size(); n++) {
667 std::pair<Double_t, Double_t> result = {0, 0};
668 if (!AreTablesLoaded())
return result;
669 Double_t rnd =
fRandom->Rndm();
675 if (eRange.X() != -1 && eRange.Y() != -1) {
678 Double_t radius = ((Double_t)r +
fRandom->Rndm()) * 0.01;
679 std::pair<Double_t, Double_t> p = {energy, radius};
688 std::pair<Double_t, Double_t> p = {line.first, line.second->GetRandom()};
701 cout <<
"Continuum solar flux table: " << endl;
702 cout <<
"--------------------------- " << endl;
703 for (
unsigned int n = 0; n <
fFluxTable.size(); n++) {
704 for (
int m = 0; m <
fFluxTable[n]->GetNbinsX(); m++)
705 cout <<
fFluxTable[n]->GetBinContent(m + 1) <<
"\t";
716 cout <<
"Integrated solar flux per solar ring: " << endl;
717 cout <<
"--------------------------- " << endl;
730 cout <<
"+++++++++++++++++++++++++++++++++++" << endl;
732 cout <<
"Energy : " << line.first <<
" keV" << endl;
733 cout <<
"-----------------" << endl;
734 for (
int n = 0; n < line.second->GetNbinsX(); n++)
735 cout <<
"R : " << line.second->GetBinCenter(n + 1)
736 <<
" flux : " << line.second->GetBinContent(n + 1) <<
" cm-2 s-1" << endl;
750 RESTMetadata <<
"-------" <<
RESTendl;
753 RESTMetadata <<
"++++++++++++++++++" <<
RESTendl;
769 string path = REST_USER_PATH +
"/export/";
772 std::cout <<
"Creating path: " << path << std::endl;
773 int z = system((
"mkdir -p " + path).c_str());
774 if (z != 0) RESTError <<
"Could not create directory " << path <<
RESTendl;
778 std::vector<std::vector<Float_t>> table;
780 std::vector<Float_t> row;
781 for (
int n = 0; n < x->GetNbinsX(); n++) row.push_back(x->GetBinContent(n + 1));
783 table.push_back(row);
793 std::vector<std::vector<Float_t>> table;
795 std::vector<Float_t> row;
796 row.push_back(x.first);
797 for (
int n = 0; n < x.second->GetNbinsX(); n++) row.push_back(x.second->GetBinContent(n + 1));
799 table.push_back(row);
A metadata class to load tabulated solar axion fluxes.
TCanvas * fCanvas
A canvas pointer for drawing.
TRandom3 * fRandom
Random number generator.
void PrintMetadata()
Prints on screen the information about the metadata members of TRestAxionSolarFlux.
Bool_t fTablesLoaded
A metadata member to control if this class has been initialized.
A metadata class to load tabulated solar axion fluxes. Mass independent.
void PrintMetadata() override
Prints on screen the information about the metadata members of TRestAxionSolarQCDFlux.
std::string fFluxSptFile
The filename containning the solar flux spectra for monochromatic spectrum.
Double_t fPeakSigma
It will be used when loading .flux files to define the threshold for peak identification.
TRestAxionSolarQCDFlux()
Default constructor.
~TRestAxionSolarQCDFlux()
Default destructor.
void ReadFluxFile()
It loads a .flux file. It will split continuum and monochromatic peaks, loading both internal flux ta...
TH1F * GetTotalSpectrum()
It builds a histogram adding the continuum and the monochromatic spectrum component....
TH1F * fMonoHist
A pointer to the monochromatic spectrum histogram.
TH1F * fTotalHist
A pointer to the superposed monochromatic and continuum spectrum histogram.
void LoadContinuumFluxTable()
A helper method to load the data file containning continuum spectra as a function of the solar radius...
void PrintIntegratedRingFlux()
It prints on screen the integrated solar flux per solar ring.
std::vector< Double_t > fFluxTableIntegrals
Accumulative integrated solar flux for each solar ring for continuum spectrum (renormalized to unity)
Double_t GetTotalFlux(Double_t mass=0) override
It returns the total integrated flux at earth in cm-2 s-1.
Double_t IntegrateFluxInRange(TVector2 eRange=TVector2(-1, -1), Double_t mass=0) override
It returns the integrated flux at earth in cm-2 s-1 for the given energy range.
Bool_t LoadTables() override
It defines how to read the solar tables at the inhereted class.
std::vector< TH1F * > fFluxTable
The tabulated solar flux continuum spectra TH1F(200,0,20)keV in cm-2 s-1 keV-1 versus solar radius.
TH1F * GetContinuumSpectrum()
It builds a histogram with the continuum spectrum component. The flux will be expressed in cm-2 s-1 k...
void IntegrateSolarFluxes()
A helper method to initialize the internal class data members with the integrated flux for each solar...
TH1F * fContinuumHist
A pointer to the continuum spectrum histogram.
void LoadMonoChromaticFluxTable()
A helper method to load the data file containning monochromatic spectral lines as a function of the s...
void ExportTables(Bool_t ascii=false) override
It will create files with the continuum and spectral flux components to be used in a later ocasion.
std::vector< Double_t > fFluxLineIntegrals
Accumulative integrated solar flux for each monochromatic energy (renormalized to unity)
TH1F * GetMonochromaticSpectrum()
It builds a histogram with the monochromatic spectrum component. The flux will be expressed in cm-2 s...
std::pair< Double_t, Double_t > GetRandomEnergyAndRadius(TVector2 eRange=TVector2(-1, -1), Double_t mass=0) override
It defines how to generate Monte Carlo energy and radius values to reproduce the flux.
std::map< Double_t, TH1F * > fFluxLines
The tabulated solar flux in cm-2 s-1 for a number of monochromatic energies versus solar radius.
virtual TCanvas * DrawSolarFlux() override
It draws the contents of a .flux file. This method just receives the.
void PrintMonoChromaticFlux()
It prints on screen the spectral lines loaded in memory.
std::string fFluxDataFile
The filename containning the solar flux table with continuum spectrum.
Double_t fFluxRatio
The ratio between monochromatic and total flux.
void PrintContinuumSolarTable()
It prints on screen the table that has been loaded in memory.
Double_t fBinSize
It will be used when loading .flux files to define the input file energy binsize in eV.
Double_t fTotalContinuumFlux
Total solar flux for monochromatic contributions.
Double_t fTotalMonochromaticFlux
Total solar flux for monochromatic contributions.
@ REST_Info
+show most of the information for each steps
@ REST_Debug
+show the defined debug messages