Skip to content
Snippets Groups Projects
Commit 448ed63c authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

Move draw and write functions from IsGISAXS test cases to IsGISAXS tools

parent 59a51961
No related branches found
No related tags found
No related merge requests found
...@@ -13,27 +13,18 @@ ...@@ -13,27 +13,18 @@
//! @brief Definition of functions and classes for IsGISAXS validation //! @brief Definition of functions and classes for IsGISAXS validation
//! @author herck //! @author herck
//! @date 19.06.2012 //! @date 19.06.2012
#include "Types.h" #include "OutputData.h"
#include "NamedVector.h"
#include "IDoubleToComplexFunction.h"
complex_t transmission_fresnel(double alpha_i); #include <string>
void initialize_angles_sine(NamedVector<double> *p_axis, double start, double end, size_t size);
class ReflectionFresnelFunctionWrapper : public IDoubleToComplexFunction namespace IsGISAXSTools {
{
public:
ReflectionFresnelFunctionWrapper(complex_t refraction_index) : m_refraction_index(refraction_index) {}
virtual ReflectionFresnelFunctionWrapper *clone() const;
virtual complex_t evaluate(double value) { return reflection_fresnel(value, m_refraction_index); } void drawLogOutputData(const OutputData<double> &output, const std::string &canvas_name,
const std::string &canvas_title, const std::string &draw_options,
private: const std::string &histogram_title = std::string());
complex_t reflection_fresnel(double alpha_i, complex_t refraction_index);
complex_t m_refraction_index;
};
void writeOutputDataToFile(const OutputData<double> &output, const std::string &filename);
} /* namespace IsGISAXS Tools */
#endif /* ISGISAXSTOOLS_H_ */ #endif /* ISGISAXSTOOLS_H_ */
...@@ -28,8 +28,6 @@ public: ...@@ -28,8 +28,6 @@ public:
TestIsGISAXS10(); TestIsGISAXS10();
virtual ~TestIsGISAXS10(); virtual ~TestIsGISAXS10();
virtual void execute(); virtual void execute();
void draw();
void write();
private: private:
void initializeSample(); void initializeSample();
......
...@@ -28,8 +28,6 @@ public: ...@@ -28,8 +28,6 @@ public:
TestIsGISAXS3(); TestIsGISAXS3();
virtual ~TestIsGISAXS3(); virtual ~TestIsGISAXS3();
virtual void execute(); virtual void execute();
void draw();
void write();
private: private:
void initializeSample(); void initializeSample();
......
#include "IsGISAXSTools.h" #include "IsGISAXSTools.h"
#include "Units.h"
#include <cmath> #include "TCanvas.h"
#include "TH2.h"
#include "TStyle.h"
complex_t transmission_fresnel(double alpha_i) #include <fstream>
void IsGISAXSTools::drawLogOutputData(const OutputData<double>& output,
const std::string& canvas_name, const std::string& canvas_title,
const std::string& draw_options, const std::string &histogram_title)
{ {
(void)alpha_i; OutputData<double> *p_output = output.clone();
return complex_t(1.0, 0.0); if (p_output->getDimension() != 2) return;
} // creation of 2D histogram from calculated intensities
TCanvas *c1 = new TCanvas(canvas_name.c_str(), canvas_title.c_str(), 0, 0, 1024, 768);
(void)c1;
// For IsGISAXS comparison: p_output->resetIndex();
void initialize_angles_sine(NamedVector<double> *p_axis, double start, double end, size_t size) { NamedVector<double> *p_y_axis = dynamic_cast<NamedVector<double>*>(p_output->getAxes()[0]);
double start_sin = std::sin(start*M_PI/180); NamedVector<double> *p_z_axis = dynamic_cast<NamedVector<double>*>(p_output->getAxes()[1]);
double end_sin = std::sin(end*M_PI/180); std::string y_axis_name = p_y_axis->getName();
double step = (end_sin-start_sin)/(size-1); std::string z_axis_name = p_z_axis->getName();
for(size_t i=0; i<size; ++i) { size_t y_size = p_y_axis->getSize();
p_axis->push_back(std::asin(start_sin + step*i)*180/M_PI); size_t z_size = p_z_axis->getSize();
} double y_start = (*p_y_axis)[0]/Units::degree;
return; double y_end = (*p_y_axis)[y_size-1]/Units::degree;
} double z_start = (*p_z_axis)[0]/Units::degree;
double z_end = (*p_z_axis)[z_size-1]/Units::degree;
std::string histo_name = histogram_title;
if (histo_name.empty()) {
histo_name = canvas_title;
}
TH2D *p_hist2D = new TH2D("p_hist2D", histo_name.c_str(), y_size, y_start, y_end, z_size, z_start, z_end);
//p_hist2D->UseCurrentStyle();
p_hist2D->GetXaxis()->SetTitle(y_axis_name.c_str());
p_hist2D->GetYaxis()->SetTitle(z_axis_name.c_str());
ReflectionFresnelFunctionWrapper* ReflectionFresnelFunctionWrapper::clone() const while (p_output->hasNext())
{ {
return new ReflectionFresnelFunctionWrapper(m_refraction_index); size_t index_y = p_output->getCurrentIndexOfAxis(y_axis_name.c_str());
size_t index_z = p_output->getCurrentIndexOfAxis(z_axis_name.c_str());
double x_value = (*p_y_axis)[index_y]/Units::degree;
double y_value = (*p_z_axis)[index_z]/Units::degree;
double z_value = p_output->next();
p_hist2D->Fill(x_value, y_value, z_value);
}
p_hist2D->SetContour(50);
gStyle->SetPalette(1);
gStyle->SetOptStat(0);
gPad->SetLogz();
gPad->SetRightMargin(0.12);
p_hist2D->SetMinimum(1.0);
p_hist2D->Draw(draw_options.c_str());
delete p_output;
} }
complex_t ReflectionFresnelFunctionWrapper::reflection_fresnel(double alpha_i, complex_t refraction_index) void IsGISAXSTools::writeOutputDataToFile(const OutputData<double>& output,
const std::string &filename)
{ {
complex_t cos_alpha_0_squared = std::cos(alpha_i)*std::cos(alpha_i); OutputData<double> *p_output = output.clone();
complex_t f0 = std::sqrt(complex_t(1.0, 0.0) - cos_alpha_0_squared); std::ofstream file;
complex_t f1 = std::sqrt(refraction_index*refraction_index - cos_alpha_0_squared); file.open(filename.c_str(), std::ios::out);
return (f0 - f1)/(f0 + f1); p_output->resetIndex();
size_t row_length = p_output->getAxes()[0]->getSize();
int counter = 1;
while(p_output->hasNext()) {
double z_value = p_output->next();
file << z_value << " ";
if(counter%row_length==0) {
file << std::endl;
}
++counter;
}
delete p_output;
} }
...@@ -37,65 +37,9 @@ void TestIsGISAXS10::execute() ...@@ -37,65 +37,9 @@ void TestIsGISAXS10::execute()
experiment.setBeamParameters(1.0*Units::angstrom, -0.2*Units::degree, 0.0*Units::degree); experiment.setBeamParameters(1.0*Units::angstrom, -0.2*Units::degree, 0.0*Units::degree);
experiment.runSimulation(); experiment.runSimulation();
mp_intensity_output = experiment.getOutputData(); mp_intensity_output = experiment.getOutputData();
draw(); IsGISAXSTools::drawLogOutputData(*mp_intensity_output, "c1_test_isgisaxs_10", "1D paracrystal islands",
write(); "CONT4 Z");
} IsGISAXSTools::writeOutputDataToFile(*mp_intensity_output, "./IsGISAXS_examples/ex-10/para1dcyl.ima");
void TestIsGISAXS10::draw()
{
// creation of 2D histogram from calculated intensities
TCanvas *c1 = new TCanvas("c1_test_isgisaxs_10", "1D paracrystal islands", 0, 0, 1024, 768);
(void)c1;
MultiIndex& index = mp_intensity_output->getIndex();
index.reset();
NamedVector<double> *p_y_axis = dynamic_cast<NamedVector<double>*>(mp_intensity_output->getAxis("phi_f"));
NamedVector<double> *p_z_axis = dynamic_cast<NamedVector<double>*>(mp_intensity_output->getAxis("alpha_f"));
size_t y_size = p_y_axis->getSize();
size_t z_size = p_z_axis->getSize();
double y_start = (*p_y_axis)[0];
double y_end = (*p_y_axis)[y_size-1];
double z_start = (*p_z_axis)[0];
double z_end = (*p_z_axis)[z_size-1];
TH2D *p_hist2D = new TH2D("p_hist2D", "1D paracrystal islands", y_size, y_start, y_end, z_size, z_start, z_end);
//p_hist2D->UseCurrentStyle();
p_hist2D->GetXaxis()->SetTitle("phi_f");
p_hist2D->GetYaxis()->SetTitle("alpha_f");
while (!index.endPassed())
{
size_t index_y = index.getCurrentIndexOfAxis("phi_f");
size_t index_z = index.getCurrentIndexOfAxis("alpha_f");
double x_value = (*p_y_axis)[index_y];
double y_value = (*p_z_axis)[index_z];
double z_value = mp_intensity_output->currentValue();
p_hist2D->Fill(x_value, y_value, z_value);
++index;
}
p_hist2D->SetContour(50);
gStyle->SetPalette(1);
gStyle->SetOptStat(0);
gPad->SetLogz();
gPad->SetRightMargin(0.12);
p_hist2D->SetMinimum(1.0);
p_hist2D->Draw("CONT4 Z");
}
void TestIsGISAXS10::write()
{
std::ofstream file;
file.open("./IsGISAXS_examples/ex-10/para1dcyl.ima", std::ios::out);
mp_intensity_output->resetIndex();
size_t row_length = mp_intensity_output->getAxes()[0]->getSize();
int counter = 1;
while(mp_intensity_output->hasNext()) {
double z_value = mp_intensity_output->next();
file << z_value << " ";
if(counter%row_length==0) {
file << std::endl;
}
++counter;
}
} }
void TestIsGISAXS10::initializeSample() void TestIsGISAXS10::initializeSample()
......
...@@ -39,65 +39,9 @@ void TestIsGISAXS3::execute() ...@@ -39,65 +39,9 @@ void TestIsGISAXS3::execute()
experiment.runSimulation(); experiment.runSimulation();
if (mp_intensity_output) delete mp_intensity_output; if (mp_intensity_output) delete mp_intensity_output;
mp_intensity_output = experiment.getOutputData(); mp_intensity_output = experiment.getOutputData();
draw(); IsGISAXSTools::drawLogOutputData(*mp_intensity_output, "c1_test_dwba_formfactor", "Cylinder DWBA Formfactor",
write(); "CONT4 Z");
} IsGISAXSTools::writeOutputDataToFile(*mp_intensity_output, "./IsGISAXS_examples/ex-3/dwbacyl.ima");
void TestIsGISAXS3::draw()
{
// creation of 2D histogram from calculated intensities
TCanvas *c1 = new TCanvas("c1_test_dwba_formfactor", "Cylinder Formfactor", 0, 0, 1024, 768);
(void)c1;
MultiIndex& index = mp_intensity_output->getIndex();
index.reset();
NamedVector<double> *p_y_axis = dynamic_cast<NamedVector<double>*>(mp_intensity_output->getAxis("phi_f"));
NamedVector<double> *p_z_axis = dynamic_cast<NamedVector<double>*>(mp_intensity_output->getAxis("alpha_f"));
size_t y_size = p_y_axis->getSize();
size_t z_size = p_z_axis->getSize();
double y_start = (*p_y_axis)[0];
double y_end = (*p_y_axis)[y_size-1];
double z_start = (*p_z_axis)[0];
double z_end = (*p_z_axis)[z_size-1];
TH2D *p_hist2D = new TH2D("p_hist2D", "Cylinder DWBA Formfactor", y_size, y_start, y_end, z_size, z_start, z_end);
//p_hist2D->UseCurrentStyle();
p_hist2D->GetXaxis()->SetTitle("phi_f");
p_hist2D->GetYaxis()->SetTitle("alpha_f");
while (!index.endPassed())
{
size_t index_y = index.getCurrentIndexOfAxis("phi_f");
size_t index_z = index.getCurrentIndexOfAxis("alpha_f");
double x_value = (*p_y_axis)[index_y];
double y_value = (*p_z_axis)[index_z];
double z_value = mp_intensity_output->currentValue();
p_hist2D->Fill(x_value, y_value, z_value);
++index;
}
p_hist2D->SetContour(50);
gStyle->SetPalette(1);
gStyle->SetOptStat(0);
gPad->SetLogz();
gPad->SetRightMargin(0.12);
p_hist2D->SetMinimum(1.0);
p_hist2D->Draw("CONT4 Z");
}
void TestIsGISAXS3::write()
{
std::ofstream file;
file.open("./IsGISAXS_examples/ex-3/dwbacyl.ima", std::ios::out);
mp_intensity_output->resetIndex();
size_t row_length = mp_intensity_output->getAxes()[0]->getSize();
int counter = 1;
while(mp_intensity_output->hasNext()) {
double z_value = mp_intensity_output->next();
file << z_value << " ";
if(counter%row_length==0) {
file << std::endl;
}
++counter;
}
} }
void TestIsGISAXS3::initializeSample() void TestIsGISAXS3::initializeSample()
......
...@@ -12,10 +12,6 @@ int main(int argc, char **argv) ...@@ -12,10 +12,6 @@ int main(int argc, char **argv)
{ {
std::cout << "Hello Brave New World!" << std::endl; std::cout << "Hello Brave New World!" << std::endl;
// MaterialManager *mm = new MaterialManager;
// std::cout << *mm << std::endl;
return 0;
CommandLine args(argc, argv); // parsing command line arguments CommandLine args(argc, argv); // parsing command line arguments
TApplication theApp("theApp", &argc, argv); TApplication theApp("theApp", &argc, argv);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment