212 #include "TRestAxionSolarQCDFlux.h"
273 RESTDebug <<
"TRestAxionSolarflux::LoadContinuumFluxTable. No solar flux table was defined"
280 RESTDebug <<
"Loading table from file : " <<
RESTendl;
281 RESTDebug <<
"File : " << fullPathName <<
RESTendl;
283 std::vector<std::vector<Float_t>> fluxTable;
285 std::vector<std::vector<Double_t>> doubleTable;
287 RESTError <<
"TRestAxionSolarQCDFlux::LoadContinuumFluxTable. " <<
RESTendl;
291 for (
const auto& row : doubleTable) {
292 std::vector<Float_t> floatVec(row.begin(), row.end());
293 fluxTable.push_back(floatVec);
299 RESTError <<
"Filename extension was not recognized!" <<
RESTendl;
300 RESTError <<
"Solar flux table will not be populated" <<
RESTendl;
304 if (fluxTable.size() != 100 && fluxTable[0].size() != 200) {
306 RESTError <<
"LoadContinuumFluxTable. The table does not contain the right number of rows or columns"
308 RESTError <<
"Table will not be populated" <<
RESTendl;
311 for (
unsigned int n = 0; n < fluxTable.size(); n++) {
312 TH1F* h =
new TH1F(Form(
"%s_ContinuumFluxAtRadius%d", GetName(), n),
"", 200, 0, 20);
313 for (
unsigned int m = 0; m < fluxTable[n].size(); m++) h->SetBinContent(m + 1, fluxTable[n][m]);
324 RESTDebug <<
"TRestAxionSolarflux::LoadMonoChromaticFluxTable. No solar flux monochromatic table was "
332 RESTDebug <<
"Loading monochromatic lines from file : " <<
RESTendl;
333 RESTDebug <<
"File : " << fullPathName <<
RESTendl;
335 std::vector<std::vector<Double_t>> doubleTable;
337 RESTError <<
"TRestAxionSolarQCDFlux::LoadMonoChromaticFluxTable." <<
RESTendl;
342 std::vector<std::vector<Float_t>> asciiTable;
343 for (
const auto& row : doubleTable) {
344 std::vector<Float_t> floatVec(row.begin(), row.end());
345 asciiTable.push_back(floatVec);
350 if (asciiTable.size() != 101) {
351 RESTError <<
"LoadMonoChromaticFluxTable. The table does not contain the right number of rows"
353 RESTError <<
"Table will not be populated" <<
RESTendl;
357 for (
unsigned int en = 0; en < asciiTable[0].size(); en++) {
358 Float_t energy = asciiTable[0][en];
359 TH1F* h =
new TH1F(Form(
"%s_MonochromeFluxAtEnergy%6.4lf", GetName(), energy),
"", 100, 0, 1);
360 for (
unsigned int r = 1; r < asciiTable.size(); r++) h->SetBinContent(r, asciiTable[r][en]);
371 RESTError <<
"TRestAxionSolarflux::ReadFluxFile. Energy bin size of .flux file must be specified."
373 RESTError <<
"Please, define binSize parameter in eV." <<
RESTendl;
378 RESTWarning <<
"TRestAxionSolarflux::ReadFluxFile. Peak sigma must be specified to generate "
379 "monochromatic spectrum."
381 RESTWarning <<
"Only continuum table will be generated. If this was intentional, please, ignore this "
389 RESTDebug <<
"Loading flux table ... " <<
RESTendl;
390 RESTDebug <<
"File : " << fullPathName <<
RESTendl;
391 std::vector<std::vector<Double_t>> fluxData;
394 RESTDebug <<
"Table loaded" <<
RESTendl;
395 TH2F* originalHist =
new TH2F(
"FullTable",
"", 100, 0., 1., (Int_t)(20. /
fBinSize), 0., 20.);
396 TH2F* continuumHist =
new TH2F(
"ContinuumTable",
"", 100, 0., 1., (Int_t)(20. /
fBinSize), 0., 20.);
397 TH2F* spectrumHist =
new TH2F(
"LinesTable",
"", 100, 0., 1., (Int_t)(20. /
fBinSize), 0., 20.);
401 for (
const auto& data : fluxData) {
402 Float_t r = 0.005 + data[0];
403 Float_t en = data[1] - 0.005;
404 Float_t flux = data[2] * fluxBinSize;
406 originalHist->Fill(r, en, (Float_t)flux);
407 continuumHist->Fill(r, en, (Float_t)flux);
409 RESTDebug <<
"Histograms filled" <<
RESTendl;
415 const int smearPoints = (Int_t)(5 / (
fBinSize * 100));
416 const int excludePoints = smearPoints / 5;
417 for (
const auto& data : fluxData) {
418 Float_t r = 0.005 + data[0];
419 Float_t en = data[1] - 0.005;
421 Int_t binR = continuumHist->GetXaxis()->FindBin(r);
422 Int_t binE = continuumHist->GetYaxis()->FindBin(en);
424 Double_t avgFlux = 0;
426 for (
int e = binE - smearPoints; e <= binE + smearPoints; e++) {
427 if (e < 1 || (e < binE + excludePoints && e > binE - excludePoints))
continue;
429 avgFlux += continuumHist->GetBinContent(binR, e);
433 Float_t targetBinFlux = continuumHist->GetBinContent(binR, binE);
434 Float_t thrFlux = avgFlux +
fPeakSigma * TMath::Sqrt(avgFlux);
435 if (targetBinFlux > 0 && targetBinFlux > thrFlux) {
436 continuumHist->SetBinContent(binR, binE, avgFlux);
442 for (
int n = 0; n < originalHist->GetNbinsX(); n++)
443 for (
int m = 0; m < originalHist->GetNbinsY(); m++) {
444 Float_t orig = originalHist->GetBinContent(n + 1, m + 1);
445 Float_t cont = continuumHist->GetBinContent(n + 1, m + 1);
447 spectrumHist->SetBinContent(n + 1, m + 1, orig - cont);
450 continuumHist->Rebin2D(1, (Int_t)(0.1 /
fBinSize));
451 continuumHist->Scale(10);
455 for (
int n = 0; n < continuumHist->GetNbinsX(); n++) {
457 (TH1F*)continuumHist->ProjectionY(Form(
"%s_ContinuumFluxAtRadius%d", GetName(), n), n + 1, n + 1);
462 for (
int n = 0; n < spectrumHist->GetNbinsY(); n++) {
463 if (spectrumHist->ProjectionX(
"", n + 1, n + 1)->Integral() > 0) {
464 Double_t energy = spectrumHist->ProjectionY()->GetBinCenter(n + 1);
465 TH1F* hm = (TH1F*)spectrumHist->ProjectionX(
466 Form(
"%s_MonochromeFluxAtEnergy%5.3lf", GetName(), energy), n + 1, n + 1);
471 cout <<
"Number of peaks identified: " <<
fFluxLines.size() << endl;
510 fMonoHist =
new TH1F(
"MonochromaticHist",
"", 20000, 0, 20);
512 fMonoHist->Fill(x.first, x.second->Integral());
516 fMonoHist->GetXaxis()->SetTitle(
"Energy [keV]");
517 fMonoHist->GetXaxis()->SetTitleSize(0.05);
518 fMonoHist->GetXaxis()->SetLabelSize(0.05);
519 fMonoHist->GetYaxis()->SetTitle(
"Flux [cm-2 s-1 eV-1]");
520 fMonoHist->GetYaxis()->SetTitleSize(0.05);
521 fMonoHist->GetYaxis()->SetLabelSize(0.05);
540 fTotalHist =
new TH1F(
"fTotalHist",
"", 20000, 0, 20);
541 for (
int n = 0; n < hc->GetNbinsX(); n++) {
542 for (
int m = 0; m < 100; m++) {
543 fTotalHist->SetBinContent(n * 100 + 1 + m, hc->GetBinContent(n + 1));
547 for (
int n = 0; n < hm->GetNbinsX(); n++)
549 fTotalHist->SetBinContent(n + 1,
fTotalHist->GetBinContent(n + 1) + 100 * hm->GetBinContent(n + 1));
552 fTotalHist->GetXaxis()->SetTitle(
"Energy [keV]");
555 fTotalHist->GetYaxis()->SetTitle(
"Flux [cm-2 s-1 keV-1]");
570 fCanvas =
new TCanvas(
"canv",
"This is the canvas title", 1200, 500);
573 TPad* pad1 =
new TPad(
"pad1",
"This is pad1", 0.01, 0.02, 0.99, 0.97);
578 pad1->cd(1)->SetLogy();
579 pad1->cd(1)->SetRightMargin(0.09);
580 pad1->cd(1)->SetLeftMargin(0.15);
581 pad1->cd(1)->SetBottomMargin(0.15);
584 ht->SetLineColor(kBlack);
585 ht->SetFillStyle(4050);
586 ht->SetFillColor(kBlue - 10);
589 hm->SetLineColor(kBlack);
593 hm->Draw(
"hist same");
596 pad1->cd(2)->SetRightMargin(0.09);
597 pad1->cd(2)->SetLeftMargin(0.15);
598 pad1->cd(2)->SetBottomMargin(0.15);
601 hm->Draw(
"hist same");
623 for (
unsigned int n = 0; n <
fFluxTable.size(); n++) {
638 if (eRange.X() == -1 && eRange.Y() == -1) {
645 if (line.first > eRange.X() && line.first < eRange.Y()) flux += line.second->Integral();
648 for (
unsigned int n = 0; n <
fFluxTable.size(); n++) {
663 std::pair<Double_t, Double_t> result = {0, 0};
664 if (!AreTablesLoaded())
return result;
665 Double_t rnd =
fRandom->Rndm();
671 if (eRange.X() != -1 && eRange.Y() != -1) {
674 Double_t radius = ((Double_t)r +
fRandom->Rndm()) * 0.01;
675 std::pair<Double_t, Double_t> p = {energy, radius};
684 std::pair<Double_t, Double_t> p = {line.first, line.second->GetRandom()};
697 cout <<
"Continuum solar flux table: " << endl;
698 cout <<
"--------------------------- " << endl;
699 for (
unsigned int n = 0; n <
fFluxTable.size(); n++) {
700 for (
int m = 0; m <
fFluxTable[n]->GetNbinsX(); m++)
701 cout <<
fFluxTable[n]->GetBinContent(m + 1) <<
"\t";
712 cout <<
"Integrated solar flux per solar ring: " << endl;
713 cout <<
"--------------------------- " << endl;
726 cout <<
"+++++++++++++++++++++++++++++++++++" << endl;
728 cout <<
"Energy : " << line.first <<
" keV" << endl;
729 cout <<
"-----------------" << endl;
730 for (
int n = 0; n < line.second->GetNbinsX(); n++)
731 cout <<
"R : " << line.second->GetBinCenter(n + 1)
732 <<
" flux : " << line.second->GetBinContent(n + 1) <<
" cm-2 s-1" << endl;
746 RESTMetadata <<
"-------" <<
RESTendl;
749 RESTMetadata <<
"++++++++++++++++++" <<
RESTendl;
765 string path = REST_USER_PATH +
"/export/";
768 std::cout <<
"Creating path: " << path << std::endl;
769 int z = system((
"mkdir -p " + path).c_str());
770 if (z != 0) RESTError <<
"Could not create directory " << path <<
RESTendl;
774 std::vector<std::vector<Float_t>> table;
776 std::vector<Float_t> row;
777 for (
int n = 0; n < x->GetNbinsX(); n++) row.push_back(x->GetBinContent(n + 1));
779 table.push_back(row);
789 std::vector<std::vector<Float_t>> table;
791 std::vector<Float_t> row;
792 row.push_back(x.first);
793 for (
int n = 0; n < x.second->GetNbinsX(); n++) row.push_back(x.second->GetBinContent(n + 1));
795 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.
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