物理定数したい(G4PhysicalConstants.hh

 1using CLHEP::alpha_rcl2;
 2using CLHEP::amu;
 3using CLHEP::amu_c2;
 4using CLHEP::Avogadro;
 5using CLHEP::Bohr_radius;
 6using CLHEP::c_light;
 7using CLHEP::c_squared;
 8using CLHEP::classic_electr_radius;
 9using CLHEP::e_squared;
10using CLHEP::electron_charge;
11using CLHEP::electron_Compton_length;
12using CLHEP::electron_mass_c2;
13using CLHEP::elm_coupling;
14using CLHEP::epsilon0;
15using CLHEP::fine_structure_const;
16using CLHEP::h_Planck;
17using CLHEP::halfpi;
18using CLHEP::hbar_Planck;
19using CLHEP::hbarc;
20using CLHEP::hbarc_squared;
21using CLHEP::k_Boltzmann;
22using CLHEP::kGasThreshold;
23using CLHEP::mu0;
24using CLHEP::neutron_mass_c2;
25using CLHEP::pi;
26using CLHEP::pi2;
27using CLHEP::proton_mass_c2;
28using CLHEP::STP_Pressure;
29using CLHEP::STP_Temperature;
30using CLHEP::twopi;
31using CLHEP::twopi_mc2_rcl2;
32using CLHEP::Bohr_magneton;
33using CLHEP::nuclear_magneton;
34using CLHEP::universe_mean_density;

CLHEPライブラリの物理定数を読み込み、グローバル変数として使えるようになっています。

名前

単位

CLHEP::pi

3.141592653589793d

CLHEP::c_light

\(299.792458\)

km / s

CLHEP::h_Planck

\(4.135669239559144 \times 10^{-12}\)

eV s

CLHEP::hbar_Planck

\(6.582122024689376 \times 10^{-13}\)

eV s

CLHEP::hbarc

\(1.9732705406375647 \times 10^{-10}\)

eV m

波長をエネルギーに変換したい

 1#include "G4PhysicalConstants.hh"
 2#include "G4SystemOfUnit.hh"
 3
 4std::vector<G4double> WavelengthToEnergy(const std::vector<G4double>& wavelength)
 5{
 6    // wavelength [m]
 7    // energy [eV]
 8    // h_Planck = 4.135669239559144e-12 [eV s]
 9    // c_light  = 299.792458 [km / s]
10    const G4double h = CLHEP::h_Planck;
11    const G4double c = CLHEP::c_light / m;  // [m] に変換
12    std::vector<G4double> energy;
13    for (auto length : wavelength) {
14        length = length / m;     // [m] に変換
15        G4double e = h * c / length / eV;  // [eV] に変換
16        energy.push_back(e);
17    };
18    return energy;
19};
\[E = h\nu = \frac{hc}{\lambda} \]