1
0
Fork 0
mirror of https://github.com/gwm17/Mask.git synced 2024-11-22 18:28:51 -05:00

Fixed some stylistic incosistencies. Incorporated all classes used for Mask into the Mask namespace. Updated some comments.

This commit is contained in:
Gordon McCann 2021-09-06 16:18:49 -04:00
parent 170cc7afb0
commit e96b29accf
31 changed files with 1490 additions and 1484 deletions

View File

@ -5,20 +5,22 @@
#include <vector>
#include <random>
namespace Mask {
class AngularDistribution {
public:
AngularDistribution();
AngularDistribution(const std::string& file);
~AngularDistribution();
void ReadDistributionFile(const std::string& file);
void AttachRandomNumberGenerator(std::mt19937* random) { generator = random; };
inline void AttachRandomNumberGenerator(std::mt19937* random) { generator = random; }
double GetRandomCosTheta();
int GetL() { return L; };
double GetBranchingRatio() { return branchingRatio; };
inline int GetL() { return L; }
inline double GetBranchingRatio() { return branchingRatio; }
private:
bool IsIsotropic();
bool IsGeneratorSet() {
inline bool IsIsotropic() { return isoFlag; }
inline bool IsGeneratorSet() {
if(generator) {
return true;
} else {
@ -36,4 +38,6 @@ private:
bool isoFlag;
};
}
#endif

View File

@ -1,6 +1,8 @@
#ifndef ELOSS_TABLES_H
#define ELOSS_TABLES_H
namespace Mask {
#define MAX_Z 93 //Maximum number of elements for which we have hydrogen coefficients
/*Atomic Masses for elements H through U. Taken from ELAST data*/
@ -127,4 +129,5 @@ static double HYDROGEN_COEFF[MAX_Z][12] = {
/*Pa*/{7.407, 8.336,1.901E4,586.3,0.002603,0.0464,1221,-20.11,6.981,-0.8749,0.04752,-0.0009512},
/*U*/{7.29, 8.204,1.918E4,586.3,0.002573,0.04691,1207,-20.18,6.995,-0.8757,0.04753,-0.0009508}
};
}
#endif

View File

@ -19,6 +19,7 @@ Written by G.W. McCann Aug. 2020
#include <cmath>
#include "MassLookup.h"
namespace Mask {
class EnergyLoss {
public:
@ -50,8 +51,8 @@ class EnergyLoss {
static constexpr double MAX_H_E_PER_U = 100000.0;
static constexpr double AVOGADRO = 0.60221367; //N_A times 10^(-24) for converting
static constexpr double MEV2U = 1.0/931.4940954;
static constexpr double PI = 3.14159265358979323846;
static constexpr double H_RESTMASS = 938.27231; //MeV, for beta calc
};
}
#endif

View File

@ -1,7 +1,7 @@
/*
LayeredTarget.h
Functional unit for targets in the SPANCRedux environment. Contains a
Functional unit for targets in the Mask environment. Contains a
set (read: vector) of Targets for use in reaction calculations. In this
way handles situations such as carbon backed targets
@ -15,9 +15,10 @@ Written by G.W. McCann Aug. 2020
#include <vector>
#include <string>
#include <iostream>
#include "Target.h"
namespace Mask {
class LayeredTarget {
public:
@ -27,15 +28,17 @@ class LayeredTarget {
double GetProjectileEnergyLoss(int zp, int ap, double startEnergy, int rxnLayer, double angle);
double GetEjectileEnergyLoss(int ze, int ae, double startEnergy, int rxnLayer, double angle);
double GetEjectileReverseEnergyLoss(int ze, int ae, double startEnergy, int rxnLayer, double angle);
int GetNumberOfLayers();
int FindLayerContaining(int Z, int A);
void SetName(std::string& n);
Target& GetLayerInfo(int index);
std::string& GetName();
inline int GetNumberOfLayers() { return layers.size(); }
inline void SetName(std::string& n) { name = n; }
inline const Target& GetLayerInfo(int index) { return layers[index]; }
inline const std::string& GetName() { return name; }
private:
std::vector<Target> layers;
std::string name;
};
}
#endif

View File

@ -1,6 +1,8 @@
#ifndef LEGENDREPOLY_H
#define LEGENDREPOLY_H
namespace Mask {
double P_l(int l, double x);
double P_l_ROOT(double* x, double* pars);
double Normed_P_l_sq(int l, double x);
@ -9,4 +11,6 @@ double P_0(double x);
double P_1(double x);
double P_2(double x);
}
#endif

View File

@ -12,18 +12,18 @@ Converted to true singleton to simplify usage -- Aug. 2021 GWM
#ifndef MASS_LOOKUP_H
#define MASS_LOOKUP_H
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdexcept>
namespace Mask {
class MassLookup {
public:
~MassLookup();
double FindMass(int Z, int A);
std::string FindSymbol(int Z, int A);
static MassLookup* GetInstance() {
if(s_instance == nullptr) {
s_instance = new MassLookup();
@ -44,4 +44,6 @@ class MassLookup {
};
}
#endif

View File

@ -25,7 +25,6 @@ public:
void SetBeamKE(double bke);
void SetEjectileThetaType(int type);
/*Setters and getters*/
inline void SetLayeredTarget(LayeredTarget* targ) { target = targ; };
inline void SetPolarRxnAngle(double theta) { m_theta = theta; };
inline void SetAzimRxnAngle(double phi) { m_phi = phi; };
@ -47,17 +46,17 @@ public:
inline const Nucleus& GetTarget() const { return reactants[0]; };
inline const Nucleus& GetEjectile() const { return reactants[2]; };
inline const Nucleus& GetResidual() const { return reactants[3]; };
inline void ResetTarget() { reactants[0].SetVectorCartesian(0,0,0,0); };
inline void ResetProjectile() { reactants[1].SetVectorCartesian(0,0,0,0); };
inline void ResetEjectile() { reactants[2].SetVectorCartesian(0,0,0,0); };
inline void ResetResidual() { reactants[3].SetVectorCartesian(0,0,0,0); };
inline int GetRxnLayer() { return rxnLayer; };
inline void ResetTarget() { reactants[0].SetVectorCartesian(0,0,0, reactants[0].GetGroundStateMass()); }
inline void ResetProjectile() { reactants[1].SetVectorCartesian(0,0,0, reactants[1].GetGroundStateMass()); }
inline void ResetEjectile() { reactants[2].SetVectorCartesian(0,0,0, reactants[2].GetGroundStateMass()); }
inline void ResetResidual() { reactants[3].SetVectorCartesian(0,0,0, reactants[3].GetGroundStateMass()); }
private:
void CalculateDecay(); //target -> light_decay (eject) + heavy_decay(resid)
void CalculateReaction(); //target + project -> eject + resid
void CalculateReactionThetaLab();
void CalculateReactionThetaCM();
void CalculateDecay(); //target -> light_decay (eject) + heavy_decay(resid)
Nucleus reactants[4]; //0=target, 1=projectile, 2=ejectile, 3=residual
LayeredTarget* target; //not owned by Reaction
@ -74,6 +73,6 @@ private:
};
};
}
#endif

View File

@ -16,14 +16,14 @@ public:
XRotation(double ang);
~XRotation();
Vec3 Rotate(const Vec3& vector);
inline void SetAngle(double ang) { m_angle = ang; GenerateMatrix(); };
inline XRotation GetInverse() { return XRotation(-m_angle); };
inline void SetAngle(double ang) { m_angle = ang; GenerateMatrix(); }
inline XRotation GetInverse() { return XRotation(-m_angle); }
inline Vec3 operator*(const Vec3& vector) {
double x = m_matrix[0][0]*vector[0] + m_matrix[0][1]*vector[1] + m_matrix[0][2]*vector[2];
double y = m_matrix[1][0]*vector[0] + m_matrix[1][1]*vector[1] + m_matrix[1][2]*vector[2];
double z = m_matrix[2][0]*vector[0] + m_matrix[2][1]*vector[1] + m_matrix[2][2]*vector[2];
return Vec3(x, y, z);
};
}
private:
void GenerateMatrix();
@ -37,14 +37,14 @@ public:
YRotation(double ang);
~YRotation();
Vec3 Rotate(const Vec3& vector);
inline void SetAngle(double ang) { m_angle = ang; GenerateMatrix(); };
inline YRotation GetInverse() { return YRotation(-m_angle); };
inline void SetAngle(double ang) { m_angle = ang; GenerateMatrix(); }
inline YRotation GetInverse() { return YRotation(-m_angle); }
inline Vec3 operator*(const Vec3& vector) {
double x = m_matrix[0][0]*vector[0] + m_matrix[0][1]*vector[1] + m_matrix[0][2]*vector[2];
double y = m_matrix[1][0]*vector[0] + m_matrix[1][1]*vector[1] + m_matrix[1][2]*vector[2];
double z = m_matrix[2][0]*vector[0] + m_matrix[2][1]*vector[1] + m_matrix[2][2]*vector[2];
return Vec3(x, y, z);
};
}
private:
void GenerateMatrix();
@ -58,14 +58,14 @@ public:
ZRotation(double ang);
~ZRotation();
Vec3 Rotate(const Vec3& vector);
inline void SetAngle(double ang) { m_angle = ang; GenerateMatrix();};
inline ZRotation GetInverse() { return ZRotation(-m_angle); };
inline void SetAngle(double ang) { m_angle = ang; GenerateMatrix(); }
inline ZRotation GetInverse() { return ZRotation(-m_angle); }
inline Vec3 operator*(const Vec3& vector) {
double x = m_matrix[0][0]*vector[0] + m_matrix[0][1]*vector[1] + m_matrix[0][2]*vector[2];
double y = m_matrix[1][0]*vector[0] + m_matrix[1][1]*vector[1] + m_matrix[1][2]*vector[2];
double z = m_matrix[2][0]*vector[0] + m_matrix[2][1]*vector[1] + m_matrix[2][2]*vector[2];
return Vec3(x, y, z);
};
}
private:
void GenerateMatrix();
@ -73,6 +73,6 @@ private:
double m_matrix[3][3];
};
};
}
#endif

View File

@ -171,4 +171,5 @@ private:
};
#endif

View File

@ -21,8 +21,8 @@ private:
std::vector<SabreDetector> detectors;
Target deadlayer;
Target sabre_eloss;
Mask::Target deadlayer;
Mask::Target sabre_eloss;
DeadChannelMap dmap;
//Sabre constants

View File

@ -1,7 +1,7 @@
/*
Target.h
A basic target unit for use in the SPANCRedux environment. A target
A basic target unit for use in the Mask environment. A target
is defined as a single compound with elements Z,A of a given stoichiometry
Holds an energy loss class
@ -15,8 +15,11 @@ Written by G.W. McCann Aug. 2020
#include <string>
#include <vector>
#include <cmath>
#include "EnergyLoss.h"
namespace Mask {
class Target {
public:
@ -28,19 +31,19 @@ class Target {
double getEnergyLossHalf(int zp, int ap, double startEnergy, double angle);
double getReverseEnergyLossTotal(int zp, int ap, double finalEnergy, double angle);
double getReverseEnergyLossHalf(int zp, int ap, double finalEnergy, double angle);
double& GetThickness();
int GetNumberOfElements();
int GetElementZ(int index);
int GetElementA(int index);
int GetElementStoich(int index);
inline const double& GetThickness() { return thickness; }
inline int GetNumberOfElements() { return Z.size(); }
inline int GetElementZ(int index) { return Z[index]; }
inline int GetElementA(int index) { return A[index]; }
inline int GetElementStoich(int index) { return Stoich[index]; }
private:
EnergyLoss eloss;
double thickness;
std::vector<int> Z, A, Stoich;
static constexpr double PI = 3.14159265358979323846;
};
}
#endif

View File

@ -19,22 +19,22 @@ public:
void SetVectorCartesian(double x, double y, double z);
void SetVectorSpherical(double r, double theta, double phi);
inline double GetX() const { return m_data[0]; };
inline double GetY() const { return m_data[1]; };
inline double GetZ() const { return m_data[2]; };
inline double GetRho() const { return std::sqrt(std::pow(m_data[0], 2.0) + std::pow(m_data[1], 2.0)); };
inline double GetX() const { return m_data[0]; }
inline double GetY() const { return m_data[1]; }
inline double GetZ() const { return m_data[2]; }
inline double GetRho() const { return std::sqrt(std::pow(m_data[0], 2.0) + std::pow(m_data[1], 2.0)); }
inline double GetR() const { return std::sqrt(std::pow(m_data[0], 2.0) + std::pow(m_data[1], 2.0) + std::pow(m_data[2], 2.0)); }
inline double GetTheta() const { return Atan2(GetRho(), GetZ()); };
inline double GetTheta() const { return Atan2(GetRho(), GetZ()); }
inline double GetPhi() const {
double phi = Atan2(GetY(), GetX());
if(phi < 0) phi += M_PI*2.0;
return phi;
};
}
inline const double operator[](int index) const { return index>2 || index<0 ? 0.0 : m_data[index]; };
inline Vec3& operator=(const Vec3& rhs) { SetVectorCartesian(rhs.GetX(), rhs.GetY(), rhs.GetZ()); return *this; };
inline Vec3 operator+(const Vec3& rhs) const { return Vec3(this->GetX()+rhs.GetX(), this->GetY()+rhs.GetY(), this->GetZ()+rhs.GetZ()); };
inline Vec3 operator-(const Vec3& rhs) const { return Vec3(this->GetX()-rhs.GetX(), this->GetY()-rhs.GetY(), this->GetZ()-rhs.GetZ()); };
inline const double operator[](int index) const { return index>2 || index<0 ? 0.0 : m_data[index]; }
inline Vec3& operator=(const Vec3& rhs) { SetVectorCartesian(rhs.GetX(), rhs.GetY(), rhs.GetZ()); return *this; }
inline Vec3 operator+(const Vec3& rhs) const { return Vec3(this->GetX()+rhs.GetX(), this->GetY()+rhs.GetY(), this->GetZ()+rhs.GetZ()); }
inline Vec3 operator-(const Vec3& rhs) const { return Vec3(this->GetX()-rhs.GetX(), this->GetY()-rhs.GetY(), this->GetZ()-rhs.GetZ()); }
double Dot(const Vec3& rhs) const;
@ -56,6 +56,6 @@ private:
};
};
}
#endif

View File

@ -19,31 +19,31 @@ public:
void SetVectorCartesian(double px, double py, double pz, double E);
void SetVectorSpherical(double theta, double phi, double p, double E);
inline double GetE() const {return m_data[3];};
inline double GetPx() const {return m_data[0];};
inline double GetPy() const {return m_data[1];};
inline double GetPz() const {return m_data[2];};
inline double GetP() const {return std::sqrt(m_data[0]*m_data[0] + m_data[1]*m_data[1] + m_data[2]*m_data[2]);};
inline double GetPxy() const {return std::sqrt(m_data[0]*m_data[0] + m_data[1]*m_data[1]); };
inline double GetTheta() const {return GetPxy() == 0.0 && GetPz() == 0.0 ? 0.0 : Atan2(GetPxy(), GetPz());};
inline double GetE() const { return m_data[3]; }
inline double GetPx() const { return m_data[0]; }
inline double GetPy() const { return m_data[1]; }
inline double GetPz() const { return m_data[2]; }
inline double GetP() const { return std::sqrt(m_data[0]*m_data[0] + m_data[1]*m_data[1] + m_data[2]*m_data[2]); }
inline double GetPxy() const { return std::sqrt(m_data[0]*m_data[0] + m_data[1]*m_data[1]); }
inline double GetTheta() const { return GetPxy() == 0.0 && GetPz() == 0.0 ? 0.0 : Atan2(GetPxy(), GetPz()); }
inline double GetPhi() const {
double phi = Atan2(GetPy(), GetPx());
if(phi<0) phi += 2.0*M_PI;
return GetPx() == 0.0 && GetPy() == 0.0 ? 0.0 : phi;
};
}
inline double GetInvMass() const {return std::sqrt(GetE()*GetE() - GetP()*GetP());};
inline double GetKE() const {return GetE() - GetInvMass();};
inline const double* GetBoost() const {return &m_boost[0];};
inline double GetInvMass() const { return std::sqrt(GetE()*GetE() - GetP()*GetP()); }
inline double GetKE() const { return GetE() - GetInvMass(); }
inline const double* GetBoost() const { return &m_boost[0]; }
void ApplyBoost(const double* boost);
//Only intended for use in looping access!
inline const double operator[] (int index) const {return index>3 || index < 0 ? 0.0 : m_data[index];};
inline const double operator[] (int index) const { return index>3 || index < 0 ? 0.0 : m_data[index]; }
inline Vec4& operator=(const Vec4& rhs) {SetVectorCartesian(rhs.GetPx(), rhs.GetPy(), rhs.GetPz(), rhs.GetE()); return *this;};
inline Vec4 operator+(const Vec4& rhs) const {return Vec4(rhs.GetPx()+GetPx(), rhs.GetPy()+GetPy(), rhs.GetPz()+GetPz(), rhs.GetE()+GetE());};
inline Vec4 operator-(const Vec4& rhs) const {return Vec4(rhs.GetPx()-GetPx(), rhs.GetPy()-GetPy(), rhs.GetPz()-GetPz(), rhs.GetE()-GetE());};
inline Vec4& operator=(const Vec4& rhs) { SetVectorCartesian(rhs.GetPx(), rhs.GetPy(), rhs.GetPz(), rhs.GetE()); return *this; }
inline Vec4 operator+(const Vec4& rhs) const { return Vec4(rhs.GetPx()+GetPx(), rhs.GetPy()+GetPy(), rhs.GetPz()+GetPz(), rhs.GetE()+GetE()); }
inline Vec4 operator-(const Vec4& rhs) const { return Vec4(rhs.GetPx()-GetPx(), rhs.GetPy()-GetPy(), rhs.GetPz()-GetPz(), rhs.GetE()-GetE()); }
double Dot(const Vec4& rhs) const;
Vec4 Cross(const Vec4& rhs) const;
@ -57,13 +57,13 @@ private:
else if( y > 0 ) return M_PI/2.0;
else if( y < 0 ) return -M_PI/2.0;
else return 0.0;
};
}
double m_data[4];
double m_boost[3];
};
};
}
#endif

View File

@ -1,5 +1,5 @@
----------Data Information----------
OutputFile: /data1/gwm17/mask_tests/7Bedp_600keV_beam_centered_target_targetgap_BackQQQ_rndmCM_test.mask
OutputFile: test/7Bedp_600keV_beam_centered_target_targetgap_BackQQQ_rndmCM_test.mask
SaveTree: yes
SavePlots: yes
----------Reaction Information----------

View File

@ -4,6 +4,8 @@
#include <iostream>
#include "LegendrePoly.h"
namespace Mask {
AngularDistribution::AngularDistribution() :
generator(nullptr), uniform_cosine_dist(-1.0, 1.0), uniform_prob_dist(0.0, 1.0), branchingRatio(1.0), L(0), isoFlag(true)
{
@ -102,3 +104,5 @@ double AngularDistribution::GetRandomCosTheta() {
return costheta;
}
}

View File

@ -59,7 +59,6 @@ namespace Mask {
LinkTarget();
}
if(step1.IsDecay()) {
double rxnTheta = std::acos(decay1dist.GetRandomCosTheta());
double rxnPhi = (*m_phi1Range)(*generator);
step1.SetPolarRxnAngle(rxnTheta);
@ -67,9 +66,7 @@ namespace Mask {
step1.TurnOnResidualEloss();
step1.Calculate();
} else {
return;
}
}
}

View File

@ -49,6 +49,7 @@
*/
#include "SabreDetector.h"
SabreDetector::SabreDetector() :

View File

@ -14,9 +14,11 @@ Written by G.W. McCann Aug. 2020
#include "KinematicsExceptions.h"
#include <iostream>
EnergyLoss::EnergyLoss() {
comp_denom = 0;
ZP = -1;
namespace Mask {
EnergyLoss::EnergyLoss() :
ZP(-1), AP(-1), MP(-1.0), comp_denom(0)
{
}
EnergyLoss::~EnergyLoss() {}
@ -28,15 +30,14 @@ void EnergyLoss::SetTargetComponents(std::vector<int>& Zt, std::vector<int>& At,
AT = At;
for(unsigned int i=0; i<Stoich.size(); i++) {
comp_denom += Stoich[i];
if(ZT[i] > MAX_Z) {
if(ZT[i] > MAX_Z)
throw ELossException("Maximum allowed target Z exceeded");
}
}
targ_composition.resize(Stoich.size());
for(unsigned int i=0; i<Stoich.size(); i++) {
for(unsigned int i=0; i<Stoich.size(); i++)
targ_composition[i] = Stoich[i]/comp_denom;
}
}
/*
Returns units of MeV; thickness in ug/cm^2; e_initial in units of MeV
@ -58,8 +59,8 @@ double EnergyLoss::GetEnergyLoss(int zp, int ap, double e_initial, double thickn
int depth=0;
if(thickness == 0.0) return 0;
else if(e_initial == 0.0) return 0;
if(thickness == 0.0 || e_initial == 0.0)
return 0;
bool go = true;
while(go) {
@ -72,21 +73,18 @@ double EnergyLoss::GetEnergyLoss(int zp, int ap, double e_initial, double thickn
go = false;
x_step = thickness - x_traversed; //get valid portion of last chunk
e_final -= GetTotalStoppingPower(e_final)*x_step/1000.0;
if(depth > 20)std::cout<<"depth: "<<depth<<std::endl;
if(e_final <= e_threshold) {
if(e_final <= e_threshold)
return e_initial;
}
} else if(depth == MAX_DEPTH) {
return e_initial;
} else {
x_traversed += x_step;
e_step = GetTotalStoppingPower(e_final)*x_step/1000.0;
e_final -= e_step;
if(e_final <= e_threshold) {
if(e_final <= e_threshold)
return e_initial;
}
}
}
return e_initial - e_final;
}
@ -138,30 +136,25 @@ double EnergyLoss::GetElectronicStoppingPower(double energy) {
if(e_per_u > MAX_H_E_PER_U) {
throw ELossException("Exceeded maximum allowed energy per nucleon");
} else if (e_per_u > 1000.0) {
for(auto& z: ZT) {
for(auto& z: ZT)
values.push_back(Hydrogen_dEdx_High(e_per_u, energy, z));
}
} else if (e_per_u > 10.0) {
for(auto& z: ZT) {
for(auto& z: ZT)
values.push_back(Hydrogen_dEdx_Med(e_per_u, z));
}
} else if (e_per_u > 0.0) {
for(auto& z: ZT) {
for(auto& z: ZT)
values.push_back(Hydrogen_dEdx_Low(e_per_u, z));
}
} else {
throw ELossException("Negative energy per nucleon");
}
if(values.size() == 0) {
if(values.size() == 0)
throw ELossException("Size of value array is 0. Unable to iterate over target components");
}
if(ZP > 1) { //not hydrogen, need to account for effective charge
for(unsigned int i=0; i<values.size(); i++) {
for(unsigned int i=0; i<values.size(); i++)
values[i] *= CalculateEffectiveChargeRatio(e_per_u, ZT[i]);
}
}
double stopping_total = 0;
double conversion_factor = 0;
@ -192,9 +185,9 @@ double EnergyLoss::GetNuclearStoppingPower(double energy) {
/*Wrapper function for aquiring total stopping (elec + nuc)*/
double EnergyLoss::GetTotalStoppingPower(double energy) {
if(ZP == 0) {
if(ZP == 0)
return GetNuclearStoppingPower(energy);
}
return GetElectronicStoppingPower(energy)+GetNuclearStoppingPower(energy);
}
@ -206,16 +199,16 @@ double EnergyLoss::CalculateEffectiveChargeRatio(double e_per_u, int z) {
double gamma = 1.0+(0.007+0.00005*z)*std::exp(-std::pow(7.6-ln_epu,2.0));
double alpha = 0.7446 + 0.1429*ln_epu + 0.01562*std::pow(ln_epu, 2.0) - 0.00267*std::pow(ln_epu,3.0)
+ 1.338E-6*std::pow(ln_epu,8.0);
z_ratio = gamma*(1.0-std::exp(-alpha))*2.0; //test this; SPANC has factor of 2. mult
z_ratio = gamma*(1.0-std::exp(-alpha))*2.0;
} else if (ZP == 3) {
double ln_epu = std::log(e_per_u);
double gamma = 1.0+(0.007+0.00005*z)*std::exp(-std::pow(7.6-ln_epu,2.0));
double alpha = 0.7138+0.002797*e_per_u+1.348E-6*std::pow(e_per_u, 2.0);
z_ratio = gamma*(1-std::exp(-alpha))*3.0; //test this; SPANC has factor of 3. mult
z_ratio = gamma*(1-std::exp(-alpha))*3.0;
} else {
double B = 0.886*std::pow(e_per_u/25.0, 0.5)/std::pow(ZP, 2.0/3.0);
double A = B + 0.0378*std::sin(PI/2.0*B);
z_ratio = 1.0 - std::exp(-A)*(1.034-0.1777*std::exp(-0.08114*ZP))*z; //test this; SPANC has factor of ZT[i] mult
double A = B + 0.0378*std::sin(M_PI/2.0*B);
z_ratio = 1.0 - std::exp(-A)*(1.034-0.1777*std::exp(-0.08114*ZP))*z;
}
return z_ratio*z_ratio; //for stopping power uses ratio sq.
}
@ -235,10 +228,16 @@ double EnergyLoss::Hydrogen_dEdx_High(double e_per_u, double energy, int z) {
double beta_sq = energy * (energy+2.0*MP/MEV2U)/std::pow(energy+MP/MEV2U, 2.0);
double alpha = HYDROGEN_COEFF[z][5]/beta_sq;
double epsilon = HYDROGEN_COEFF[z][6]*beta_sq/(1.0-beta_sq) - beta_sq - HYDROGEN_COEFF[z][7];
for(int i=1; i<5; i++) {
for(int i=1; i<5; i++)
epsilon += HYDROGEN_COEFF[z][7+i]*std::pow(std::log(e_per_u), i);
}
return alpha * std::log(epsilon);
}
double EnergyLoss::GetRange(double energy) {return 0.0;} //unimplemented
//unimplemented
double EnergyLoss::GetRange(double energy) {
std::cerr<<"EnergyLoss::GetRange is not implemented! Returning 0.0"<<std::endl;
return 0.0;
}
}

View File

@ -24,7 +24,6 @@ namespace Mask {
std::ifstream input(filename);
if(!input.is_open()) {
std::cerr<<"Unable to load configuration in "<<filename<<", check that it exists"<<std::endl;
return false;
}

View File

@ -1,7 +1,7 @@
/*
LayeredTarget.h
Functional unit for targets in the SPANCRedux environment. Contains a
Functional unit for targets in the Mask environment. Contains a
set (read: vector) of Targets for use in reaction calculations. In this
way handles situations such as carbon backed targets
@ -11,8 +11,14 @@ Written by G.W. McCann Aug. 2020
*/
#include "LayeredTarget.h"
#include <iostream>
LayeredTarget::LayeredTarget() {}
namespace Mask {
LayeredTarget::LayeredTarget() :
name("")
{
}
LayeredTarget::~LayeredTarget() {}
@ -100,28 +106,13 @@ double LayeredTarget::GetEjectileReverseEnergyLoss(int ze, int ae, double startE
return eloss;
}
/*Getters and Setters*/
int LayeredTarget::GetNumberOfLayers() {
return layers.size();
}
int LayeredTarget::FindLayerContaining(int Z, int A) {
for(unsigned int i=0; i<layers.size(); i++) {
if(layers[i].ContainsElement(Z, A)) return i;
}
for(unsigned int i=0; i<layers.size(); i++)
if(layers[i].ContainsElement(Z, A))
return i;
return -1;
}
void LayeredTarget::SetName(std::string& n) {
name = n;
}
Target& LayeredTarget::GetLayerInfo(int index) {
return layers[index];
}
std::string& LayeredTarget::GetName() {
return name;
}

View File

@ -1,6 +1,8 @@
#include "LegendrePoly.h"
#include <cmath>
namespace Mask {
double P_l(int l, double x) {
if(l == 0) {
return 1.0;
@ -30,3 +32,5 @@ double P_2(double x) {
double P_l_ROOT(double* x, double* pars) {
return P_l(pars[0], x[0]);
}
}

View File

@ -11,16 +11,13 @@ Written by G.W. McCann Aug. 2020
#include "MassLookup.h"
#include "KinematicsExceptions.h"
/*
Read in AMDC mass file, preformated to remove excess info. Here assumes that by default
the file is in a local directory etc/
*/
namespace Mask {
MassLookup* MassLookup::s_instance = nullptr;
MassLookup::MassLookup() {
std::ifstream massfile("./etc/mass.txt");
std::ifstream massfile("etc/mass.txt");
if(massfile.is_open()) {
std::string junk, A, element;
int Z;
@ -45,18 +42,20 @@ MassLookup::~MassLookup() {}
double MassLookup::FindMass(int Z, int A) {
std::string key = "("+std::to_string(Z)+","+std::to_string(A)+")";
auto data = massTable.find(key);
if(data == massTable.end()) {
if(data == massTable.end())
throw MassException();
}
return data->second;
}
//returns element symbol
std::string MassLookup::FindSymbol(int Z, int A) {
auto data = elementTable.find(Z);
if(data == elementTable.end()) {
if(data == elementTable.end())
throw MassException();
}
std::string fullsymbol = std::to_string(A) + data->second;
return fullsymbol;
}
}

View File

@ -44,4 +44,4 @@ bool Nucleus::SetIsotope(int Z, int A) {
return true;
}
};
}

View File

@ -55,7 +55,6 @@ namespace Mask {
LinkTarget();
}
if(!step1.IsDecay()) {
//Sample parameters
double bke = (*m_beamDist)(*generator);
double rxnTheta = std::acos((*m_theta1Range)(*generator));
@ -69,9 +68,6 @@ namespace Mask {
step1.TurnOnResidualEloss();
step1.Calculate();
} else {
return;
}
}
}

View File

@ -28,7 +28,8 @@ Reaction::~Reaction()
bool Reaction::Calculate() {
if(!nuc_initFlag) return false;
if(!nuc_initFlag)
return false;
if(decayFlag) {
CalculateDecay();
@ -72,10 +73,11 @@ void Reaction::SetNuclei(int zt, int at, int zp, int ap, int ze, int ae) {
}
void Reaction::SetBeamKE(double bke) {
if(!nuc_initFlag) return;
else if(decayFlag) return;
if(!nuc_initFlag || decayFlag)
return;
m_bke = bke - target->GetProjectileEnergyLoss(reactants[1].GetZ(), reactants[1].GetA(), bke, rxnLayer, 0);
};
}
void Reaction::SetEjectileThetaType(int type) {
if(decayFlag) return;
@ -238,7 +240,7 @@ void Reaction::CalculateDecay() {
}
}
};
}

View File

@ -12,13 +12,14 @@ Written by G.W. McCann Aug. 2020
*/
#include "Target.h"
namespace Mask {
/*Targets must be of known thickness*/
Target::Target(double thick) {
thickness = thick;
}
Target::~Target() {
}
Target::~Target() {}
/*Set target elements of given Z, A, S*/
void Target::SetElements(std::vector<int>& z, std::vector<int>& a, std::vector<int>& stoich) {
@ -31,58 +32,50 @@ void Target::SetElements(std::vector<int>& z, std::vector<int>& a, std::vector<i
/*Element verification*/
bool Target::ContainsElement(int z, int a) {
for(unsigned int i=0; i<Z.size(); i++) {
if( z == Z[i] && a == A[i]) return true;
}
for(unsigned int i=0; i<Z.size(); i++)
if( z == Z[i] && a == A[i])
return true;
return false;
}
/*Calculates energy loss for travelling all the way through the target*/
double Target::getEnergyLossTotal(int zp, int ap, double startEnergy, double theta) {
if(theta == PI/2.) return startEnergy;
else if (theta > PI/2.) theta = PI - theta;
if(theta == M_PI/2.)
return startEnergy;
else if (theta > M_PI/2.)
theta = M_PI - theta;
return eloss.GetEnergyLoss(zp, ap, startEnergy, thickness/fabs(cos(theta)));
}
/*Calculates energy loss for travelling halfway through the target*/
double Target::getEnergyLossHalf(int zp, int ap, double startEnergy, double theta) {
if(theta == PI/2.) return startEnergy;
else if (theta > PI/2.) theta = PI - theta;
if(theta == M_PI/2.)
return startEnergy;
else if (theta > M_PI/2.)
theta = M_PI - theta;
return eloss.GetEnergyLoss(zp, ap, startEnergy, thickness/(2.0*fabs(cos(theta))));
}
/*Calculates reverse energy loss for travelling all the way through the target*/
double Target::getReverseEnergyLossTotal(int zp, int ap, double finalEnergy, double theta) {
if(theta == PI/2.) return finalEnergy;
else if (theta > PI/2.) theta = PI - theta;
if(theta == M_PI/2.)
return finalEnergy;
else if (theta > M_PI/2.)
theta = M_PI - theta;
return eloss.GetReverseEnergyLoss(zp, ap, finalEnergy, thickness/fabs(cos(theta)));
}
/*Calculates reverse energy loss for travelling half way through the target*/
double Target::getReverseEnergyLossHalf(int zp, int ap, double finalEnergy, double theta) {
if(theta == PI/2.) return finalEnergy;
else if (theta > PI/2.) theta = PI - theta;
if(theta == M_PI/2.)
return finalEnergy;
else if (theta > M_PI/2.)
theta = M_PI - theta;
return eloss.GetReverseEnergyLoss(zp, ap, finalEnergy, thickness/(2.0*fabs(cos(theta))));
}
/*Getter functions*/
double& Target::GetThickness() {
return thickness;
}
int Target::GetNumberOfElements() {
return Z.size();
}
int Target::GetElementZ(int index) {
return Z[index];
}
int Target::GetElementA(int index) {
return A[index];
}
int Target::GetElementStoich(int index) {
return Stoich[index];
}

View File

@ -45,4 +45,4 @@ Vec3 Vec3::Cross(const Vec3& rhs) const {
return Vec3(x,y,z);
}
};
}

View File

@ -70,4 +70,4 @@ Vec4 Vec4::Cross(const Vec4& rhs) const {
return Vec4();
}
};
}

View File

@ -17,6 +17,7 @@ int main(int argc, char** argv) {
sw.Start();
try {
if(!calculator.LoadConfig(argv[1])) {
std::cerr<<"Unable to read input file!"<<std::endl;
return 1;
}
calculator.Run();