Skip to content

Commit

Permalink
Merge branch 'master' into jovoy-mirror_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jovoy authored Dec 15, 2023
2 parents d45f68f + e421bf2 commit 6c11abb
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 291 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ python3 pull-submodules.py --onlylibs

### Prerequisites

As any REST library, this library requires a running installion of REST-for-Physics Framework. But on top of that, some calculations require higher precision arithmetics and we need to use a external library named `mpfr`. We use a c++ wrapper that is available at the [following site](http://www.holoborodko.com/pavel/mpfr/#intro). This wrapper (mpreal.h) is already available/uploaded to this repository.
As any REST library, this library requires a running installion of REST-for-Physics Framework. But on top of that, some calculations require higher precision arithmetics and we need to use a external library named `mpfr`.

All you need to be able to compile `axionlib` is to install the [mpfr](https://www.mpfr.org) and [mpir](http://mpir.org) libraries. Download the source, compile, and install.
Usually as simple as running `./configure`, `make` and `make install` at the downloaded source directory.
All you need to be able to compile `axionlib` is to install the [mpfr](https://www.mpfr.org) library. Download the source, compile, and install. Usually as simple as running `./configure`, `make` and `make install` at the downloaded source directory.

#### mpfr installation:

Expand Down Expand Up @@ -52,6 +51,14 @@ cmake -DRESTLIB_AXION=ON -DREST_MPFR=ON ../
make -j4 install
```

If you have installed MPFR from source you may need to specify the path where the installation files are located at the `cmake` stage:

```
cd framework/build
cmake -DRESTLIB_AXION=ON -DREST_MPFR=ON -DMPFR_PATH=/full/path/to/mpfr/ ../
make -j4 install
```

In case of problems it is recommended to have a look at the following complete [download](https://rest-for-physics.github.io/downloading.html) and [installation](https://rest-for-physics.github.io/installation) instructions.

It is necessary to enable the `REST_MPFR` cmake option in order to benefit from the MPFR routines integration. If not, classes that use MPFR will not be compiled. `REST_MPFR` might be optionally disabled in case MPFR libraries are not available. However, this will lead to a non-complete installation of axionlib.
Expand Down
4 changes: 3 additions & 1 deletion inc/TRestAxionBufferGas.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TRestAxionBufferGas : public TRestMetadata {
void SetGasDensity(TString gasName, Double_t density);
Double_t GetGasDensity(TString gasName);

void SetGasMixture(TString gasMixture, TString gasDensities);
void SetGasMixture(TString gasMixture, TString gasDensities = "0");

/// It returns the number of gases in the mixture
Int_t GetNumberOfGases() { return (Int_t)fBufferGasName.size(); }
Expand All @@ -75,6 +75,8 @@ class TRestAxionBufferGas : public TRestMetadata {

Double_t GetPhotonMass(double en);

Double_t GetDensityForMass(double m_gamma, double en = 4.2);

void PrintAbsorptionGasData(TString gasName);
void PrintFormFactorGasData(TString gasName);

Expand Down
82 changes: 0 additions & 82 deletions inc/TRestAxionDetectorResponseProcess.h

This file was deleted.

31 changes: 29 additions & 2 deletions inc/TRestAxionField.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,29 @@ class TRestAxionField : public TObject {
private:
Bool_t fDebug = false; //!

/// The magnetic field in Teslas
Double_t fBmag = 2.5;

/// The coherence lenght (in mm) where the magnetic field is defined
Double_t fLcoh = 10000;

/// The energy of the axion in keV
Double_t fEa = 4.2;

void Initialize();

/// A pointer to the buffer gas definition
TRestAxionBufferGas* fBufferGas = NULL; //!

public:
void SetMagneticField(Double_t b) { fBmag = b; }
void SetCoherenceLength(Double_t l) { fLcoh = l; }
void SetAxionEnergy(Double_t e) { fEa = e; }

Double_t GetMagneticField() const { return fBmag; }
Double_t GetCoherenceLength() const { return fLcoh; }
Double_t GetAxionEnergy() const { return fEa; }

Double_t BL(Double_t Bmag, Double_t Lcoh);
Double_t BLHalfSquared(Double_t Bmag, Double_t Lcoh);

Expand All @@ -48,15 +65,25 @@ class TRestAxionField : public TObject {
/// It assigns a gas buffer medium to the calculation
void SetBufferGas(TRestAxionBufferGas* buffGas) { fBufferGas = buffGas; }

Double_t GammaTransmissionProbability(Double_t ma, Double_t mg = 0, Double_t absLength = 0);

Double_t GammaTransmissionProbability(Double_t Bmag, Double_t Lcoh, Double_t Ea, Double_t ma,
Double_t mg = 0, Double_t absLength = 0);

Double_t GammaTransmissionProbability(std::vector<Double_t> Bmag, Double_t deltaL, Double_t Ea,
Double_t ma, Double_t mg = 0, Double_t absLength = 0);
Double_t AxionAbsorptionProbability(Double_t ma, Double_t mg = 0, Double_t absLength = 0);

Double_t AxionAbsorptionProbability(Double_t Bmag, Double_t Lcoh, Double_t Ea, Double_t ma,
Double_t mg = 0, Double_t absLength = 0);

Double_t GammaTransmissionProbability(std::vector<Double_t> Bmag, Double_t deltaL, Double_t Ea,
Double_t ma, Double_t mg = 0, Double_t absLength = 0);

Double_t GammaTransmissionFWHM(Double_t step = 0.00001);

std::vector<std::pair<Double_t, Double_t>> GetMassDensityScanning(std::string gasName = "He",
Double_t maMax = 0.15,
Double_t rampDown = 5.0);

TRestAxionField();
~TRestAxionField();

Expand Down
136 changes: 136 additions & 0 deletions macros/REST_Axion_PlotResonances.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include "TCanvas.h"
#include "TGraph.h"
#include "TLatex.h"
#include "TLegend.h"
#include "TLine.h"
#include "TRestAxionBufferGas.h"
#include "TRestAxionField.h"
//*******************************************************************************************************
//*** Description: This script plots the transmission probability as a function of the axion mass for a given
// gas and an
//*** axion energy until a maximum axion mass.
//***
//*** Arguments by default are (in order):
//*** - *ma_max* = 0.1: Maximum axion mass (in eV) to be plotted.
//*** - *ma_min* = 0: Minimum axion mass (in eV) to be plotted.
//*** - *Ea* = 4.2: Axion energy (in keV).
//*** - *Bmag* = 2.5: Magnetic field (in T).
//*** - *Lcoh* = 10000: Coherence length (in mm).
//*** - *gasName* = "He": Gas name.
//*** - *vacuum* = true: If true, the vacuum probability is added to the sum of all the probabilities.
//*** - *n_ma* = 10000: Number of points to be plotted.
//***
//*** The generated plots are the results from `TRestAxionField::GetMassDensityScanning`,
//*** `TRestAxionField::GammaTransmissionFWHM` and `TRestAxionBufferGas::GetMassDensity`.
//***
//*** --------------
//*** Usage: restManager PlotResonances [ma_max=0.1] [ma_min=0] [Ea=4.2] [Bmag=2.5] [Lcoh=10000] [gasName=He]
//*** [vacuum=true] [n_ma=10000]
//***
//*** Being all of them optional arguments.
//*** --------------
//*** Author: Fran Candón
//*******************************************************************************************************

int REST_Axion_PlotResonances(double ma_max = 0.1, double ma_min = 0, double Ea = 4.2, double Bmag = 2.5,
double Lcoh = 10000, std::string gasName = "He", Bool_t vacuum = true,
int n_ma = 10000) {
TRestAxionField* ax = new TRestAxionField();
ax->SetMagneticField(Bmag);
ax->SetCoherenceLength(Lcoh);
ax->SetAxionEnergy(Ea);

vector<std::pair<Double_t, Double_t>> pair = ax->GetMassDensityScanning(gasName, ma_max, 20);
std::vector<double> m_a;
std::vector<double> sum_prob;

// Creates the vector of axion masses
double ma_step = (ma_max - ma_min) / n_ma;
for (int i = 0; i < n_ma; i++) {
m_a.push_back(ma_min + i * ma_step);
sum_prob.push_back(0);
}

TCanvas* c1 = new TCanvas("c1", "c1", 800, 600);
std::vector<TGraph*> grp;

TRestAxionBufferGas* gas = new TRestAxionBufferGas();

for (const auto& p : pair) {
// Creates the gas and the axion field
gas->SetGasDensity(gasName, p.second);
ax->AssignBufferGas(gas);

// Obtain the probability for each axion mass
std::vector<double> prob;
for (int j = 0; j < n_ma; j++) {
prob.push_back(ax->GammaTransmissionProbability(m_a[j]));
sum_prob[j] += prob[j];
}

TGraph* gr = new TGraph(n_ma, &m_a[0], &prob[0]);
grp.push_back(gr);
}

// Computes the Vacuum probability
TRestAxionField* ax_vac = new TRestAxionField();
std ::vector<double> prob_vac;
for (int j = 0; j < n_ma; j++) {
prob_vac.push_back(ax_vac->GammaTransmissionProbability(m_a[j]));
}

// Computes the sum of all the probabilities
if (vacuum == true) {
for (int i = 0; i < n_ma; i++) {
sum_prob[i] += prob_vac[i];
}
}

///// PLOTS /////

// Plot the density scan
grp[0]->SetLineColor(kBlue - 3);
grp[0]->SetTitle("Transmission probability as a function of the axion mass");
grp[0]->GetXaxis()->SetTitle("m_{a} [eV]");
grp[0]->GetYaxis()->SetTitle("P_{ag}");
grp[0]->GetXaxis()->SetLimits(ma_min, ma_max);
double ylim = 3.5e-18;
grp[0]->GetYaxis()->SetRangeUser(0, ylim);
grp[0]->Draw("AL");

for (const auto g : grp) {
g->SetLineColor(kBlue - 3);
g->Draw("SAME");
}

// PLot of the sum of all the probabilities
TGraph* sum = new TGraph(n_ma, &m_a[0], &sum_prob[0]);
sum->SetLineColor(kBlue + 3);
sum->SetLineWidth(3);
sum->Draw("SAME");

// Plot of the vacuum probability
TGraph* vac = new TGraph(n_ma, &m_a[0], &prob_vac[0]);
vac->SetLineColor(kCyan + 1);
vac->SetLineWidth(2);
vac->Draw("SAME");

// Plot of the vertical line
TLine* verticalLine = new TLine(pair[0].first, c1->GetUymin(), pair[0].first, ylim);
verticalLine->SetLineColor(kGreen - 3);
verticalLine->SetLineWidth(2);
verticalLine->Draw("same");

// Plot of the legend
TLegend* legend = new TLegend(0.9, 0.7, 0.48, 0.9);
legend->AddEntry(grp[0], "P_{ag} for each mass", "l");
legend->AddEntry(vac, "P_{ag} for vacuum", "l");
legend->AddEntry(sum, "Sum of all the probs.", "l");
legend->AddEntry(verticalLine, "m_{a} where P_{ag}^{vac} = max(P_{ag}^{vac}/2) ", "l");
legend->Draw("same");
c1->Draw();

c1->Print("/tmp/resonances.png");

return 0;
}
Loading

0 comments on commit 6c11abb

Please sign in to comment.