diff --git a/App/inc/IsGISAXSTools.h b/App/inc/IsGISAXSTools.h index 13f865539c5c382ee84c7d022a163e2523d77c24..691dc1daf8333a7f13e2e998d556d069623cefb6 100644 --- a/App/inc/IsGISAXSTools.h +++ b/App/inc/IsGISAXSTools.h @@ -13,27 +13,18 @@ //! @brief Definition of functions and classes for IsGISAXS validation //! @author herck //! @date 19.06.2012 -#include "Types.h" -#include "NamedVector.h" -#include "IDoubleToComplexFunction.h" +#include "OutputData.h" -complex_t transmission_fresnel(double alpha_i); -void initialize_angles_sine(NamedVector<double> *p_axis, double start, double end, size_t size); +#include <string> -class ReflectionFresnelFunctionWrapper : public IDoubleToComplexFunction -{ -public: - ReflectionFresnelFunctionWrapper(complex_t refraction_index) : m_refraction_index(refraction_index) {} - virtual ReflectionFresnelFunctionWrapper *clone() const; +namespace IsGISAXSTools { - virtual complex_t evaluate(double value) { return reflection_fresnel(value, m_refraction_index); } - -private: - complex_t reflection_fresnel(double alpha_i, complex_t refraction_index); - - complex_t m_refraction_index; -}; +void 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 = std::string()); +void writeOutputDataToFile(const OutputData<double> &output, const std::string &filename); +} /* namespace IsGISAXS Tools */ #endif /* ISGISAXSTOOLS_H_ */ diff --git a/App/inc/TestIsGISAXS10.h b/App/inc/TestIsGISAXS10.h index 6851ca087ed0f68d9f841f8811a34a26f3063f5e..c6388158304acf793e082add87b7f135aae332e2 100644 --- a/App/inc/TestIsGISAXS10.h +++ b/App/inc/TestIsGISAXS10.h @@ -28,8 +28,6 @@ public: TestIsGISAXS10(); virtual ~TestIsGISAXS10(); virtual void execute(); - void draw(); - void write(); private: void initializeSample(); diff --git a/App/inc/TestIsGISAXS3.h b/App/inc/TestIsGISAXS3.h index 3b3738ef4c3e1e50ecc0c34eb9bcd7deaa6a40d0..e2f5ff14ff2461549aa83c58a44e0a60a473a5a6 100644 --- a/App/inc/TestIsGISAXS3.h +++ b/App/inc/TestIsGISAXS3.h @@ -28,8 +28,6 @@ public: TestIsGISAXS3(); virtual ~TestIsGISAXS3(); virtual void execute(); - void draw(); - void write(); private: void initializeSample(); diff --git a/App/src/IsGISAXSTools.cpp b/App/src/IsGISAXSTools.cpp index 93280faf31e34f15f09ada1426279825681ed937..3b8dca7ff6daf2c990964b144bfd894778639bb5 100644 --- a/App/src/IsGISAXSTools.cpp +++ b/App/src/IsGISAXSTools.cpp @@ -1,34 +1,77 @@ #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; - return complex_t(1.0, 0.0); -} + OutputData<double> *p_output = output.clone(); + 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: -void initialize_angles_sine(NamedVector<double> *p_axis, double start, double end, size_t size) { - double start_sin = std::sin(start*M_PI/180); - double end_sin = std::sin(end*M_PI/180); - double step = (end_sin-start_sin)/(size-1); - for(size_t i=0; i<size; ++i) { - p_axis->push_back(std::asin(start_sin + step*i)*180/M_PI); - } - return; -} + p_output->resetIndex(); + NamedVector<double> *p_y_axis = dynamic_cast<NamedVector<double>*>(p_output->getAxes()[0]); + NamedVector<double> *p_z_axis = dynamic_cast<NamedVector<double>*>(p_output->getAxes()[1]); + std::string y_axis_name = p_y_axis->getName(); + std::string z_axis_name = p_z_axis->getName(); + size_t y_size = p_y_axis->getSize(); + size_t z_size = p_z_axis->getSize(); + double y_start = (*p_y_axis)[0]/Units::degree; + 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 -{ - return new ReflectionFresnelFunctionWrapper(m_refraction_index); + while (p_output->hasNext()) + { + 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); - complex_t f0 = std::sqrt(complex_t(1.0, 0.0) - cos_alpha_0_squared); - complex_t f1 = std::sqrt(refraction_index*refraction_index - cos_alpha_0_squared); - return (f0 - f1)/(f0 + f1); + OutputData<double> *p_output = output.clone(); + std::ofstream file; + file.open(filename.c_str(), std::ios::out); + 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; } - diff --git a/App/src/TestIsGISAXS10.cpp b/App/src/TestIsGISAXS10.cpp index 3ae729590c8d1728de14c4faaf24785cad7c7616..289c35112fb39b5725c17e85341ffd4e9d495fd8 100644 --- a/App/src/TestIsGISAXS10.cpp +++ b/App/src/TestIsGISAXS10.cpp @@ -37,65 +37,9 @@ void TestIsGISAXS10::execute() experiment.setBeamParameters(1.0*Units::angstrom, -0.2*Units::degree, 0.0*Units::degree); experiment.runSimulation(); mp_intensity_output = experiment.getOutputData(); - draw(); - write(); -} - -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; - } + IsGISAXSTools::drawLogOutputData(*mp_intensity_output, "c1_test_isgisaxs_10", "1D paracrystal islands", + "CONT4 Z"); + IsGISAXSTools::writeOutputDataToFile(*mp_intensity_output, "./IsGISAXS_examples/ex-10/para1dcyl.ima"); } void TestIsGISAXS10::initializeSample() diff --git a/App/src/TestIsGISAXS3.cpp b/App/src/TestIsGISAXS3.cpp index 7eb3b436aa9b68e988b0126470dfb0b7a824b915..4a50a3bb591846164ef1d3ec50f045e9f778ca42 100644 --- a/App/src/TestIsGISAXS3.cpp +++ b/App/src/TestIsGISAXS3.cpp @@ -39,65 +39,9 @@ void TestIsGISAXS3::execute() experiment.runSimulation(); if (mp_intensity_output) delete mp_intensity_output; mp_intensity_output = experiment.getOutputData(); - draw(); - write(); -} - -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; - } + IsGISAXSTools::drawLogOutputData(*mp_intensity_output, "c1_test_dwba_formfactor", "Cylinder DWBA Formfactor", + "CONT4 Z"); + IsGISAXSTools::writeOutputDataToFile(*mp_intensity_output, "./IsGISAXS_examples/ex-3/dwbacyl.ima"); } void TestIsGISAXS3::initializeSample() diff --git a/App/src/main.cpp b/App/src/main.cpp index 1d3962c0bd22abb01cabc5e96b6162537bc4c699..58c41a80974ae46ca2e326768b29224412ef4c9b 100644 --- a/App/src/main.cpp +++ b/App/src/main.cpp @@ -12,10 +12,6 @@ int main(int argc, char **argv) { 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 TApplication theApp("theApp", &argc, argv);