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

Small bugfixes in energy loss table and test. Added testonly flag in main

This commit is contained in:
Gordon McCann 2022-06-16 11:12:35 -04:00
parent b2539965c5
commit 9bb87e999e
4 changed files with 15 additions and 14 deletions

View File

@ -76,23 +76,23 @@ namespace PunchTable {
m_isValid = true; m_isValid = true;
} }
double ElossTable::GetEnergyLoss(double finalEnergy, double theta_incident) double ElossTable::GetEnergyLoss(double thetaIncident, double finalEnergy)
{ {
theta_incident /= s_deg2rad; thetaIncident /= s_deg2rad;
if(!m_isValid) if(!m_isValid)
{ {
std::cerr<<"ElossTable not initialized at GetEnergyLoss()"<<std::endl; std::cerr<<"ElossTable not initialized at GetEnergyLoss()"<<std::endl;
return 0.0; return 0.0;
} }
else if(theta_incident < m_thetaMin || theta_incident > m_thetaMax) else if(thetaIncident < m_thetaMin || thetaIncident > m_thetaMax)
{ {
std::cerr<<"Theta incident outside of range of calculated values for ElossTable::GetEnergyLoss()"<<std::endl; std::cerr<<"Theta incident outside of range of calculated values for ElossTable::GetEnergyLoss()"<<std::endl;
return 0.0; return 0.0;
} }
int theta_bin = (theta_incident - m_thetaMin)/m_thetaStep; int theta_bin = (thetaIncident - m_thetaMin)/m_thetaStep;
//std::cout<<"theta bin: "<<theta_bin<<" theta_inc: "<<theta_incident<<std::endl; //std::cout<<"theta bin: "<<theta_bin<<" theta_inc: "<<thetaIncident<<std::endl;
if(m_splines[theta_bin].IsValid()) if(m_splines[theta_bin].IsValid())
{ {

View File

@ -21,7 +21,7 @@ namespace PunchTable {
~ElossTable(); ~ElossTable();
void ReadFile(const std::string& filename); void ReadFile(const std::string& filename);
double GetEnergyLoss(double finalEnergy, double theta_incident); double GetEnergyLoss(double thetaIncident, double finalEnergy);
inline const bool IsValid() const { return m_isValid; } inline const bool IsValid() const { return m_isValid; }

View File

@ -270,7 +270,7 @@ namespace PunchTable {
flush_count++; flush_count++;
std::cout<<"\rPercent of data generated: "<<flush_count*flush_percent*100.0<<"%"<<std::flush; std::cout<<"\rPercent of data generated: "<<flush_count*flush_percent*100.0<<"%"<<std::flush;
} }
ke = params.maxKE - j*params.stepKE; ke = params.minKE + j*params.stepKE;
projectile.T = ke/projectile.A; projectile.T = ke/projectile.A;
eloss = 0.0; eloss = 0.0;
for(size_t k=0; k<nlayers; k++) for(size_t k=0; k<nlayers; k++)

View File

@ -14,6 +14,7 @@ int main(int argc, char** argv)
{ {
bool test = true; bool test = true;
bool testonly = false;
if(argc != 2) if(argc != 2)
{ {
std::cerr<<"PunchTable requires an input file!"<<std::endl; std::cerr<<"PunchTable requires an input file!"<<std::endl;
@ -22,21 +23,21 @@ int main(int argc, char** argv)
PunchTable::TableParameters params = PunchTable::GetTableParameters(argv[1]); PunchTable::TableParameters params = PunchTable::GetTableParameters(argv[1]);
if(params.tableType == "PunchTable") if(!testonly && params.tableType == "PunchTable")
{ {
PunchTable::GeneratePunchTable(params); PunchTable::GeneratePunchTable(params);
} }
else if(params.tableType == "ElossTable") else if(!testonly && params.tableType == "ElossTable")
{ {
PunchTable::GenerateElossTable(params); PunchTable::GenerateElossTable(params);
} }
else else if(!testonly)
{ {
std::cerr<<"Unrecognized table type "<<params.tableType<<std::endl; std::cerr<<"Unrecognized table type "<<params.tableType<<std::endl;
return 1; return 1;
} }
if(test && params.tableType == "PunchTable") if((test || testonly) && params.tableType == "PunchTable")
{ {
std::cout<<std::endl; std::cout<<std::endl;
std::cout<<"-------------Testing---------"<<std::endl; std::cout<<"-------------Testing---------"<<std::endl;
@ -51,17 +52,17 @@ int main(int argc, char** argv)
<<" and the deposited energy is "<<ke_dep<<" MeV"<<std::endl; <<" and the deposited energy is "<<ke_dep<<" MeV"<<std::endl;
std::cout<<"-----------------------------"<<std::endl; std::cout<<"-----------------------------"<<std::endl;
} }
if(test && params.tableType == "ElossTable") if((test || testonly) && params.tableType == "ElossTable")
{ {
std::cout<<std::endl; std::cout<<std::endl;
std::cout<<"-------------Testing---------"<<std::endl; std::cout<<"-------------Testing---------"<<std::endl;
PunchTable::ElossTable table(params.filename); PunchTable::ElossTable table(params.filename);
std::cout<<"Is the table valid? "<<table.IsValid()<<std::endl; std::cout<<"Is the table valid? "<<table.IsValid()<<std::endl;
double ke_test = 14.5; //MeV double ke_test = 0.5; //MeV
double theta_test = 35.5*M_PI/180.0; double theta_test = 35.5*M_PI/180.0;
double eloss = table.GetEnergyLoss(theta_test, ke_test); double eloss = table.GetEnergyLoss(theta_test, ke_test);
std::cout<<"For a "<<PunchTable::MassLookup::GetInstance().FindSymbol(params.projectileZ, params.projectileA)<<" with kinetic energy "<<ke_test<<" MeV " std::cout<<"For a "<<PunchTable::MassLookup::GetInstance().FindSymbol(params.projectileZ, params.projectileA)<<" with kinetic energy "<<ke_test<<" MeV "
<<"calculate an energy loss of "<<eloss<<" MeV. Please compare to favorite tool (LISE, SRIM, etc.)"<<std::endl; <<"calculate an energy loss of "<<eloss<<" MeV for an incident angle of "<<theta_test*180.0/M_PI<<" degrees. Please compare to favorite tool (LISE, SRIM, etc.)"<<std::endl;
std::cout<<"-----------------------------"<<std::endl; std::cout<<"-----------------------------"<<std::endl;
} }