Skip to content

Commit

Permalink
Merge pull request #3 from vetlewi/master
Browse files Browse the repository at this point in the history
New features
  • Loading branch information
vetlewi committed Jan 13, 2016
2 parents 37f6663 + 0a60b0e commit 2f5b19e
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 272 deletions.
2 changes: 2 additions & 0 deletions Qkinz.pro
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ SOURCES += source/main.cpp \
source/kinematics/src/FileSP.cpp \
source/kinematics/src/Iterative.cpp \
source/kinematics/src/Scattering.cpp \
source/kinematics/src/LNScattering.cpp \
source/kinematics/src/StoppingPower.cpp \
source/kinematics/src/Ziegler1985.cpp \
source/kinematics/src/ZieglerComp.cpp \
Expand Down Expand Up @@ -85,6 +86,7 @@ HEADERS += source/gui/include/mainwindow.h \
source/kinematics/include/FileSP.h \
source/kinematics/include/Iterative.h \
source/kinematics/include/Scattering.h \
source/kinematics/include/LNScattering.h \
source/kinematics/include/StoppingPower.h \
source/kinematics/include/Ziegler1985.h \
source/kinematics/include/ZieglerComp.h \
Expand Down
269 changes: 0 additions & 269 deletions Qkinz.pro.user

This file was deleted.

10 changes: 9 additions & 1 deletion source/gui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void MainWindow::on_actionExport_plot_triggered()

void MainWindow::on_actionExport_table_triggered()
{
QString Filters("PDF (*.pdf);;HTML (*.html)");
QString Filters("PDF (*.pdf);;HTML (*.html);;Text file (*.txt)");
QString DefaultFilter("PDF (*.pdf)");
QFileDialog *SaveTabDialog = new QFileDialog(this);

Expand All @@ -571,6 +571,14 @@ void MainWindow::on_actionExport_table_triggered()
out << htmlCode;
}
file.close();
} else if (FilePath.endsWith("txt", Qt::CaseInsensitive)){
QString txt = table.getTXT();
QFile file(FilePath);
if (file.open(QIODevice::WriteOnly|QIODevice::Text)){
QTextStream out(&file);
out << txt;
}
file.close();
}

delete SaveTabDialog;
Expand Down
24 changes: 24 additions & 0 deletions source/kinematics/include/LNScattering.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef LNSCATTERING_H
#define LNSCATTERING_H

#include "Scattering.h"

class LNScattering : public Scattering
{
public:
//! Constructor.
LNScattering(Particle *pA, /*!< Incident particle. */
Particle *pX, /*!< Target particle. */
Particle *pY, /*!< Light product. */
Particle *pB /*!< Heavy product. */);

//! Destructor.
~LNScattering();

//! Calculate energy of light product.
double EvaluateY(const double &E, /*!< Incident energy. */
const double &theta, /*!< Scattering angle of light product. */
const double &Ex /*!< Excitation energy of the heavy product. */) const;
};

#endif // LNSCATTERING_H
27 changes: 27 additions & 0 deletions source/kinematics/src/LNScattering.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "LNScattering.h"

#include "Particle.h"

#include <cmath>

LNScattering::LNScattering(Particle *pA, Particle *pX, Particle *pY, Particle *pB)
: Scattering(pA, pX, pY, pB){ }

LNScattering::~LNScattering(){ }

double LNScattering::EvaluateY(const double &E, const double &theta, const double &Ex) const
{
double Ma = A->GetM_MeV(), MA = X->GetM_MeV(), Mb = Y->GetM_MeV(), MB = B->GetM_MeV();
double Q = Ma + MA - Mb - MB - Ex;
double ET = E + Q;

//double RaB = Ma*MB*E/(ET*(Ma + MA)*(Mb + MB));
//double RAb = MA*Mb*(1 + Ma*Q/(MA*ET))/((Ma + MA)*(Mb + MB));
double Rab = Ma*Mb*E/(ET*(Ma + MA)*(Mb + MB));
double RAB = MA*MB*(1 + Ma*Q/(MA*ET))/((Ma + MA)*(Mb + MB));

if (RAB > Rab)
return Rab*pow(cos(theta) + sqrt(RAB/Rab - sin(theta)*sin(theta)), 2)*ET;
else
return Rab*pow(cos(theta) - sqrt(RAB/Rab - sin(theta)*sin(theta)), 2)*ET;
}
16 changes: 16 additions & 0 deletions source/support/include/tablemakerhtml.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


#ifndef TABLEMAKERHTML_H
#define TABLEMAKERHTML_H

Expand Down Expand Up @@ -51,6 +53,10 @@ class TableMakerHTML

//! Returns the created page as HTML code.
QString getHTMLCode();

//! Returns the created page as txt file table.
QString getTXT();

private:
//! Internal structure to hold data recived by the class.
struct Result_t {
Expand Down Expand Up @@ -123,10 +129,20 @@ class TableMakerHTML
*/
QString makeTable(Result_t what /*!< Strucure containing the data to write to table. */);

//! Fuction to make a table from a result structure.
/*! \return the txt string used for the table.
*/
QString makeTableTXT(Result_t what /*!< Structure containing the data to write to table. */);

//! Function to make html code from the coefficients.
/*! \return the html code for nice output of the coefficients.
*/
QString makeCoeff(QVector<double> coeff /*!< Vector containing the coefficients. */);

//! Function to make txt code from the coefficients.
/*! \return the txt string for nice output of the coefficients.
*/
QString makeCoeffTXT(QVector<double> coeff /*!< Vector containing the coefficients. */);
};

#endif // TABLEMAKERHTML_H
87 changes: 87 additions & 0 deletions source/support/src/tablemakerhtml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,90 @@ QString TableMakerHTML::makeCoeff(QVector<double> coeff)
output += " MeV^-1</p>\n";
return output;
}

QString TableMakerHTML::getTXT()
{
QString value = "";

value += "This file was generated by QKinz.\n\n\n";

if (protons.is_set){
value += "Protons:\n";
value += makeTableTXT(protons);
if (!cProtons.empty())
value += makeCoeffTXT(cProtons);
value += "\n\n\n";
}
if (deutrons.is_set){
value += QString("Deutrons:\n");
value += makeTableTXT(deutrons);
if (!cDeutrons.empty())
value += makeCoeffTXT(cDeutrons);
value += "\n\n\n";
}
if (tritons.is_set){
value += QString("Tritons:\n");
value += makeTableTXT(tritons);
if (!cTritons.empty())
value += makeCoeffTXT(cTritons);
value += "\n\n\n";
}
if (He3s.is_set){
value += QString("Helium-3:\n");
value += makeTableTXT(He3s);
if (!cHe3s.empty())
value += makeCoeffTXT(cHe3s);
value += "\n\n\n";
}
if (alphas.is_set){
value += QString("Alphas:\n");
value += makeTableTXT(alphas);
if (!cAlphas.empty())
value += makeCoeffTXT(cAlphas);
value += "\n\n\n";
}

return value;
}

QString TableMakerHTML::makeTableTXT(Result_t data)
{
QString output = "";
output += "Excitation energy (keV): ";
output += "Energy dE-detector (keV): ";
output += "dEnergy dE-detector (keV): ";
output += "Energy E-detector (keV): ";
output += "dEnergy dE-detector (keV): ";
output += "Total particle energy (keV): \n";
for (int i = 0 ; i < data.Ex.size() ; ++i){
output += std::to_string(data.Ex[i]*1000).c_str();
output += " ";
output += std::to_string(data.dE[i]*1000).c_str();
output += " ";
output += std::to_string(data.d_dE[i]*1000).c_str();
output += " ";
output += std::to_string(data.E[i]*1000).c_str();
output += " ";
output += std::to_string(data.d_E[i]*1000).c_str();
output += " ";
output += std::to_string(data.E[i]*1000 + data.dE[i]*1000).c_str();
output += "\n";
}
return output;
}

QString TableMakerHTML::makeCoeffTXT(QVector<double> coeff)
{
QString output = "";
output += "Ex(e+de) = a0 + a1(e+de) + a2(e+de)^2\n";
output += "chi-squared: ";
output += std::to_string(coeff[3]).c_str();
output += ", a0 = ";
output += std::to_string(coeff[0]).c_str();
output += "MeV, a1 = ";
output += std::to_string(coeff[1]).c_str();
output += ", a2 = ";
output += std::to_string(coeff[2]).c_str();
output += "(MeV)^-1\n";
return output;
}
5 changes: 3 additions & 2 deletions source/support/src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Scattering.h"
#include "DickNorbury.h"
#include "Iterative.h"
#include "LNScattering.h"

#include "StoppingPower.h"
#include "Ziegler1985.h"
Expand Down Expand Up @@ -111,7 +112,7 @@ bool Worker::Curve(QVector<double> &Ex, QVector<double> &dE, QVector<double> &E,
Material *dEdet = new Material(theTelescope->dEdetector.Z, Get_mm2(theTelescope->dEdetector.Z), theTelescope->dEdetector.width/cos(incAngle), Unit2MatUnit(theTelescope->dEdetector.unit));
Material *Edet = new Material(theTelescope->Edetector.Z, Get_mm2(theTelescope->Edetector.Z), theTelescope->Edetector.width/cos(incAngle), Unit2MatUnit(theTelescope->Edetector.unit));

Scattering *scat = new Iterative(beam, scatIso, fragment, residual);
Scattering *scat = new LNScattering(beam, scatIso, fragment, residual);//new Iterative(beam, scatIso, fragment, residual);

// Setting up stopping power for the target.
StoppingPower *stopTargetB;
Expand Down Expand Up @@ -363,7 +364,7 @@ bool Worker::Known(QVector<double> &Ex, QVector<double> &dE, QVector<double> &E,
Material *dEdet = new Material(theTelescope->dEdetector.Z, Get_mm2(theTelescope->dEdetector.Z), theTelescope->dEdetector.width/cos(incAngle), Unit2MatUnit(theTelescope->dEdetector.unit));
Material *Edet = new Material(theTelescope->Edetector.Z, Get_mm2(theTelescope->Edetector.Z), theTelescope->Edetector.width/cos(incAngle), Unit2MatUnit(theTelescope->Edetector.unit));

Scattering *scat = new Iterative(beam, scatIso, fragment, residual);
Scattering *scat = new LNScattering(beam, scatIso, fragment, residual);//new Iterative(beam, scatIso, fragment, residual);

// Setting up stopping power for the target.
StoppingPower *stopTargetB;
Expand Down

0 comments on commit 2f5b19e

Please sign in to comment.