diff --git a/App/src/TestIsGISAXS10.cpp b/App/src/TestIsGISAXS10.cpp index d72f7579930193728513e8f9c65050b0ad29d8eb..993b037be08c71d84ed85466ce72fe1f6fb79cfa 100644 --- a/App/src/TestIsGISAXS10.cpp +++ b/App/src/TestIsGISAXS10.cpp @@ -32,8 +32,13 @@ void TestIsGISAXS10::execute() experiment.setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree , 100, 0.0*Units::degree, 2.0*Units::degree, true); experiment.setBeamParameters(1.0*Units::angstrom, -0.2*Units::degree, 0.0*Units::degree); +// experiment.setBeamIntensity(1e7); experiment.runSimulation(); +// experiment.normalize(); mp_intensity_output = experiment.getOutputDataClone(); + double total_count = mp_intensity_output->total(); + std::cout << "Total count in detector: " << total_count << std::endl; + std::cout << "Scattered percentage in detector: " << 100*total_count/experiment.getBeam().getIntensity() << std::endl; IsGISAXSTools::drawLogOutputData(*mp_intensity_output, "c1_test_isgisaxs_10", "1D paracrystal islands", "CONT4 Z"); IsGISAXSTools::writeOutputDataToFile(*mp_intensity_output, Utils::FileSystem::GetHomePath()+"./Examples/IsGISAXS_examples/ex-10/para1dcyl.ima"); @@ -57,6 +62,7 @@ void TestIsGISAXS10::initializeSample() NanoParticleDecoration particle_decoration( new NanoParticle(n_particle, new FormFactorCylinder(5*Units::nanometer, 5*Units::nanometer))); particle_decoration.addInterferenceFunction(p_interference_funtion); +// particle_decoration.setTotalParticleSurfaceDensity(1.0/(20.0*Units::nanometer*20.0*Units::nanometer)); LayerDecorator air_layer_decorator(air_layer, particle_decoration); p_multi_layer->addLayer(air_layer_decorator); diff --git a/App/src/TestMesoCrystal.cpp b/App/src/TestMesoCrystal.cpp index cc480c5f8f4734ab7fbf9de0a0eead018ff3af13..58942ae2d594355eaec4b231e9ca9adc79385240 100644 --- a/App/src/TestMesoCrystal.cpp +++ b/App/src/TestMesoCrystal.cpp @@ -46,12 +46,19 @@ void TestMesoCrystal::execute() experiment.setSample(mp_sample); experiment.setDetectorParameters(100, 0.3*Units::degree, 0.073 , 100 , -0.4*Units::degree, 0.066); +// experiment.setDetectorParameters(5, 2*Units::degree, 3*Units::degree +// , 5 , 1*Units::degree, 2*Units::degree); // experiment.setDetectorResolutionFunction(&testResolutionFunction); - experiment.setBeamParameters(1.54*Units::angstrom, -0.4*Units::degree, 0.0*Units::degree); - experiment.setBeamIntensity(1e3); + experiment.setBeamParameters(1.77*Units::angstrom, -0.4*Units::degree, 0.0*Units::degree); + experiment.setBeamIntensity(1e7); experiment.runSimulation(); + double count_before_normalize = experiment.getOutputData()->total(); experiment.normalize(); mp_intensity_output = experiment.getOutputDataClone(); + double total_count = mp_intensity_output->total(); + std::cout << "Total count in detector: " << total_count << std::endl; + std::cout << "Scattered percentage in detector: " << 100*total_count/experiment.getBeam().getIntensity() << std::endl; + std::cout << "Total count in detector before normalize: " << count_before_normalize << std::endl; IsGISAXSTools::drawLogOutputData(*mp_intensity_output, "c1_test_meso_crystal", "mesocrystal", "CONT4 Z"); IsGISAXSTools::writeOutputDataToFile(*mp_intensity_output, Utils::FileSystem::GetHomePath()+"./Examples/MesoCrystals/mesocrystal.ima"); @@ -105,8 +112,8 @@ void TestMesoCrystal::initializeSample() // IInterferenceFunction *p_interference_funtion = new InterferenceFunction1DParaCrystal(800.0*Units::nanometer, // 50*Units::nanometer, 1e7*Units::nanometer); NanoParticleDecoration particle_decoration; - size_t n_phi_rotation_steps = 11; - size_t n_alpha_rotation_steps =3; + size_t n_phi_rotation_steps = 1; + size_t n_alpha_rotation_steps =1; double phi_step = 2*M_PI/3.0/n_phi_rotation_steps; double alpha_step = 5*Units::degree/n_alpha_rotation_steps; for (size_t i=0; i<n_phi_rotation_steps; ++i) { @@ -125,4 +132,8 @@ void TestMesoCrystal::initializeSample() p_multi_layer->addLayer(avg_layer_decorator); p_multi_layer->addLayer(substrate_layer); mp_sample = p_multi_layer; + + std::cout << "Average layer index: " << n_avg << std::endl; + std::cout << "Adapted particle index: " << n_particle_adapted << std::endl; + std::cout << "Substrate layer index: " << n_substrate << std::endl; } diff --git a/Core/Algorithms/inc/DWBAFormFactor.h b/Core/Algorithms/inc/DWBAFormFactor.h index 3dc4296452b859d3b2532fad616dc698bc365dc9..14d8a14026b0244c3c87fba6ab3fceedfd419edb 100644 --- a/Core/Algorithms/inc/DWBAFormFactor.h +++ b/Core/Algorithms/inc/DWBAFormFactor.h @@ -18,7 +18,7 @@ #include "IDoubleToComplexFunction.h" -class DWBAFormFactor: public IFormFactor +class DWBAFormFactor: public IFormFactorDecorator { public: DWBAFormFactor(IFormFactor* p_form_factor); @@ -58,7 +58,6 @@ protected: void calculateTerms(kvector_t k_i, kvector_t k_f, complex_t k_iz, complex_t k_fz) const; - IFormFactor *mp_form_factor; IDoubleToComplexFunction *mp_T; IDoubleToComplexFunction *mp_R; diff --git a/Core/Algorithms/inc/FormFactorDecoratorFactor.h b/Core/Algorithms/inc/FormFactorDecoratorFactor.h index ac62f12831880c6d97a2dc97387fe662615e957b..da1650852ac2bce8b107e378ba4f192d3d6cd422 100644 --- a/Core/Algorithms/inc/FormFactorDecoratorFactor.h +++ b/Core/Algorithms/inc/FormFactorDecoratorFactor.h @@ -17,7 +17,7 @@ #include "IFormFactor.h" -class FormFactorDecoratorFactor : public IFormFactor +class FormFactorDecoratorFactor : public IFormFactorDecorator { public: FormFactorDecoratorFactor(IFormFactor *p_form_factor, complex_t factor); @@ -30,13 +30,12 @@ public: protected: complex_t m_factor; - IFormFactor *mp_form_factor; }; inline FormFactorDecoratorFactor::FormFactorDecoratorFactor( IFormFactor* p_form_factor, complex_t factor) -: m_factor(factor) -, mp_form_factor(p_form_factor) +: IFormFactorDecorator(p_form_factor) +, m_factor(factor) { } diff --git a/Core/Algorithms/inc/FormFactorDecoratorPositionFactor.h b/Core/Algorithms/inc/FormFactorDecoratorPositionFactor.h index e414e845e64e95993b8f0f07b161865be8056635..12fd15ae6ab885c662660bba67ce7bef7732563e 100644 --- a/Core/Algorithms/inc/FormFactorDecoratorPositionFactor.h +++ b/Core/Algorithms/inc/FormFactorDecoratorPositionFactor.h @@ -19,17 +19,13 @@ #include <cmath> -class FormFactorDecoratorPositionFactor : public IFormFactor +class FormFactorDecoratorPositionFactor : public IFormFactorDecorator { public: FormFactorDecoratorPositionFactor(const IFormFactor &form_factor, kvector_t position); virtual ~FormFactorDecoratorPositionFactor(); virtual FormFactorDecoratorPositionFactor *clone() const; - virtual void setAmbientRefractiveIndex(complex_t refractive_index) { - mp_form_factor->setAmbientRefractiveIndex(refractive_index); - } - virtual complex_t evaluate(kvector_t k_i, kvector_t k_f) const; virtual complex_t evaluateForComplexkz(kvector_t k_i, kvector_t k_f, complex_t k_iz, complex_t k_fz) const; @@ -39,14 +35,13 @@ public: } protected: kvector_t m_position; - IFormFactor *mp_form_factor; }; inline FormFactorDecoratorPositionFactor::FormFactorDecoratorPositionFactor( const IFormFactor& form_factor, kvector_t position) -: m_position(position) +: IFormFactorDecorator(form_factor.clone()) +, m_position(position) { - mp_form_factor = form_factor.clone(); } inline FormFactorDecoratorPositionFactor::~FormFactorDecoratorPositionFactor() diff --git a/Core/Algorithms/inc/FormFactorDecoratorTransformation.h b/Core/Algorithms/inc/FormFactorDecoratorTransformation.h index a672e4f7cb8bac99e6c698715f34b8df98af4fe6..359eb276e4372afcbf36d29218e3de0e3f3f0f2e 100644 --- a/Core/Algorithms/inc/FormFactorDecoratorTransformation.h +++ b/Core/Algorithms/inc/FormFactorDecoratorTransformation.h @@ -18,7 +18,7 @@ #include "Transform3D.h" -class FormFactorDecoratorTransformation : public IFormFactor +class FormFactorDecoratorTransformation : public IFormFactorDecorator { public: FormFactorDecoratorTransformation(IFormFactor *p_form_factor, Geometry::Transform3D *transform); @@ -32,14 +32,13 @@ public: protected: Geometry::Transform3D *mp_transform; Geometry::Transform3D *mp_inverse_transform; - IFormFactor *mp_form_factor; }; inline FormFactorDecoratorTransformation::FormFactorDecoratorTransformation( IFormFactor* p_form_factor, Geometry::Transform3D *transform) -: mp_transform(transform) +: IFormFactorDecorator(p_form_factor) +, mp_transform(transform) , mp_inverse_transform(0) -, mp_form_factor(p_form_factor) { mp_inverse_transform = new Geometry::Transform3D(mp_transform->inverse()); } diff --git a/Core/Algorithms/src/DWBAFormFactor.cpp b/Core/Algorithms/src/DWBAFormFactor.cpp index e3d17991212d6d721cac1be7b030925b714165e3..94c92934654f3d5eb4cf5ee182743a5207f12672 100644 --- a/Core/Algorithms/src/DWBAFormFactor.cpp +++ b/Core/Algorithms/src/DWBAFormFactor.cpp @@ -1,7 +1,7 @@ #include "DWBAFormFactor.h" DWBAFormFactor::DWBAFormFactor(IFormFactor *p_form_factor) - : mp_form_factor(p_form_factor) + : IFormFactorDecorator(p_form_factor) , mp_T(0), mp_R(0) { } diff --git a/Core/Samples/inc/IFormFactor.h b/Core/Samples/inc/IFormFactor.h index f326365774cadfa07f8a24c1aa64e90a16e0f6b7..df8673ba8fe9bb716a0bfd7c7ce4063bc3ec84a9 100644 --- a/Core/Samples/inc/IFormFactor.h +++ b/Core/Samples/inc/IFormFactor.h @@ -47,6 +47,18 @@ public: virtual int getNumberOfStochasticParameters() const { return 0; } }; +class IFormFactorDecorator : public IFormFactor +{ +public: + IFormFactorDecorator(IFormFactor *p_form_factor) : mp_form_factor(p_form_factor) {} + virtual ~IFormFactorDecorator() {} + virtual IFormFactorDecorator *clone() const=0; + + virtual void setAmbientRefractiveIndex(complex_t refractive_index) { if (mp_form_factor) mp_form_factor->setAmbientRefractiveIndex(refractive_index); } +protected: + IFormFactor *mp_form_factor; +}; + class IBornFormFactor : public IFormFactor { public: diff --git a/Core/Samples/inc/Lattice.h b/Core/Samples/inc/Lattice.h index fb020639baccbaf6fd07b3c11831051df302d4af..832ba3d5763a70592040398fba337a0cfb4e6c85 100644 --- a/Core/Samples/inc/Lattice.h +++ b/Core/Samples/inc/Lattice.h @@ -31,13 +31,16 @@ public: ~Lattice(); //! get basis vector a - kvector_t getBasisVectorA() { return m_a1; } + kvector_t getBasisVectorA() const { return m_a1; } //! get basis vector b - kvector_t getBasisVectorB() { return m_a2; } + kvector_t getBasisVectorB() const { return m_a2; } //! get basis vector c - kvector_t getBasisVectorC() { return m_a3; } + kvector_t getBasisVectorC() const { return m_a3; } + + //! get the volume of the unit cell + double getVolume() const; //! get the reciprocal basis vectors void getReciprocalLatticeBasis(kvector_t &b1, kvector_t &b2, kvector_t &b3) const; diff --git a/Core/Samples/inc/NanoParticleCrystalFormFactor.h b/Core/Samples/inc/NanoParticleCrystalFormFactor.h index 80a896d0c7dde8ff7b0fc5a7ef73d6f750ec24e7..00fcfe34a9d7d0b47be3f2ee0568a8c5dba57d8b 100644 --- a/Core/Samples/inc/NanoParticleCrystalFormFactor.h +++ b/Core/Samples/inc/NanoParticleCrystalFormFactor.h @@ -40,6 +40,7 @@ private: void calculateLargestReciprocalDistance(); Lattice m_lattice; NanoParticle *mp_nano_particle; + IFormFactor *mp_basis_form_factor; IFormFactor *mp_meso_form_factor; complex_t m_ambient_refractive_index; double m_max_rec_length; diff --git a/Core/Samples/src/Lattice.cpp b/Core/Samples/src/Lattice.cpp index a97677ac647ea10fc8e49a06fdfa9ebdd94d5e19..79156afe04297573324c02607de27b3df1a1c629 100644 --- a/Core/Samples/src/Lattice.cpp +++ b/Core/Samples/src/Lattice.cpp @@ -21,6 +21,11 @@ Lattice::~Lattice() { } +double Lattice::getVolume() const +{ + return std::abs(DotProduct(m_a1, CrossProduct(m_a2, m_a3))); +} + void Lattice::getReciprocalLatticeBasis(kvector_t& b1, kvector_t& b2, kvector_t& b3) const { diff --git a/Core/Samples/src/LatticeBasis.cpp b/Core/Samples/src/LatticeBasis.cpp index 742d3530e39d8f2d67c94f02ed4469c7f492914a..a52daeec51a41f52c1447e2a55091a2abb189536 100644 --- a/Core/Samples/src/LatticeBasis.cpp +++ b/Core/Samples/src/LatticeBasis.cpp @@ -39,6 +39,7 @@ LatticeBasis* LatticeBasis::clone() const p_new->addParticle(*m_particles[index], m_positions[index]); } p_new->setName(getName()); + p_new->m_ambient_refractive_index = this->m_ambient_refractive_index; return p_new; } diff --git a/Core/Samples/src/NanoParticleCrystalFormFactor.cpp b/Core/Samples/src/NanoParticleCrystalFormFactor.cpp index 9f564f5c4996b1e6946ddb4adacf1abd8044d47f..6300658d066496afb841f4e577c66b72c1cd5fd1 100644 --- a/Core/Samples/src/NanoParticleCrystalFormFactor.cpp +++ b/Core/Samples/src/NanoParticleCrystalFormFactor.cpp @@ -10,6 +10,7 @@ NanoParticleCrystalFormFactor::NanoParticleCrystalFormFactor( { m_lattice = p_crystal->getLattice(); mp_nano_particle = p_crystal->createNanoParticle(); + mp_basis_form_factor = mp_nano_particle->createFormFactor(); mp_meso_form_factor = meso_crystal_form_factor.clone(); setAmbientRefractiveIndex(ambient_refractive_index); calculateLargestReciprocalDistance(); @@ -33,6 +34,7 @@ void NanoParticleCrystalFormFactor::setAmbientRefractiveIndex( complex_t refractive_index) { mp_nano_particle->setAmbientRefractiveIndex(refractive_index); + mp_basis_form_factor->setAmbientRefractiveIndex(refractive_index); } complex_t NanoParticleCrystalFormFactor::evaluate_for_complex_qz(kvector_t q, @@ -49,18 +51,18 @@ complex_t NanoParticleCrystalFormFactor::evaluate_for_complex_qz(kvector_t q, // perform convolution on these lattice vectors // std::cout << "Number of reciprocal vectors used for convolution: " << rec_vectors.size() << std::endl; complex_t result(0.0, 0.0); - IFormFactor *p_basis_form_factor = mp_nano_particle->createFormFactor(); for (std::vector<kvector_t>::const_iterator it = rec_vectors.begin(); it != rec_vectors.end(); ++it) { kvector_t q_i = *it; kvector_t q_min_q_i = q_real - q_i; complex_t q_min_q_i_z = qz - q_i.z(); - result += p_basis_form_factor->evaluate(q_i, k_zero) - *mp_meso_form_factor->evaluateForComplexkz(q_min_q_i, k_zero, q_min_q_i_z, complex_t(0.0, 0.0)); + complex_t basis_factor = mp_basis_form_factor->evaluate(q_i, k_zero); + complex_t meso_factor = mp_meso_form_factor->evaluateForComplexkz(q_min_q_i, k_zero, q_min_q_i_z, complex_t(0.0, 0.0)); + result += basis_factor*meso_factor; } - delete p_basis_form_factor; - // the transformed delta train gets a factor of (2pi)^3 : + // the transformed delta train gets a factor of (2pi)^3/V : double pi3 = M_PI*M_PI*M_PI; - return 8.0*pi3*result; + double volume = m_lattice.getVolume(); + return 8.0*pi3*result/volume; } void NanoParticleCrystalFormFactor::calculateLargestReciprocalDistance() diff --git a/Core/Samples/src/WeightedFormFactor.cpp b/Core/Samples/src/WeightedFormFactor.cpp index 1be2d2644bda291c0b0dfb10e9183e6ef238a79c..61068906436a5d5f312ecefe94da9ab063ae442d 100644 --- a/Core/Samples/src/WeightedFormFactor.cpp +++ b/Core/Samples/src/WeightedFormFactor.cpp @@ -38,7 +38,8 @@ complex_t WeightedFormFactor::evaluate(kvector_t k_i, kvector_t k_f) const { complex_t result(0.0, 0.0); for (size_t index=0; index<m_form_factors.size(); ++index) { - result += m_weights[index]*m_form_factors[index]->evaluate(k_i, k_f); + complex_t ff_evaluate = m_form_factors[index]->evaluate(k_i, k_f); + result += m_weights[index]*ff_evaluate; } return result; } diff --git a/Core/Tools/inc/OutputData.h b/Core/Tools/inc/OutputData.h index 5e28b4a103c49029f596eb5bcdc4d3bfc3576bc2..6a9c9c100c3ee495ec6ed6327bcb3057fcb829dd 100644 --- a/Core/Tools/inc/OutputData.h +++ b/Core/Tools/inc/OutputData.h @@ -126,6 +126,9 @@ public: //! return current value of axis with given name template <class U> U getCurrentValueOfAxis(std::string axis_name) const; + //! get sum of all values in the data structure + T total() const; + // --------- // modifiers // --------- @@ -311,6 +314,16 @@ template <class U> inline U OutputData<T>::getCurrentValueOfAxis(std::string axi } +template<class T> +inline T OutputData<T>::total() const +{ + T total = 0; + for (size_t i=0; i<m_data_size; ++i) { + total += m_data_vector[i]; + } + return total; +} + // set object into initial state (no dimensions, data) template <class T> void OutputData<T>::clear() { @@ -362,5 +375,4 @@ template<class T> inline void OutputData<T>::setRawDataVector(const std::vector< m_data_vector = data_vector; } - #endif // OUTPUTDATA_H