Skip to content
Snippets Groups Projects
Commit 5031a7c5 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Layout

parent e202d1ef
No related branches found
No related tags found
No related merge requests found
...@@ -55,12 +55,14 @@ TestFittingModule2::TestFittingModule2() ...@@ -55,12 +55,14 @@ TestFittingModule2::TestFittingModule2()
// setting up fitSuite // setting up fitSuite
m_fitSuite = new FitSuite(); m_fitSuite = new FitSuite();
m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Minuit2", "Combined") ); m_fitSuite->setMinimizer(
//m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Fumili") ); MinimizerFactory::createMinimizer("Minuit2", "Combined") );
m_fitSuite->attachObserver( FitSuiteObserverFactory::createPrintObserver() ); m_fitSuite->attachObserver(
m_fitSuite->attachObserver( FitSuiteObserverFactory::createDrawObserver() ); FitSuiteObserverFactory::createPrintObserver() );
m_fitSuite->attachObserver( FitSuiteObserverFactory::createTreeObserver() ); m_fitSuite->attachObserver(
FitSuiteObserverFactory::createDrawObserver() );
m_fitSuite->attachObserver(
FitSuiteObserverFactory::createTreeObserver() );
} }
...@@ -89,90 +91,94 @@ void TestFittingModule2::execute() ...@@ -89,90 +91,94 @@ void TestFittingModule2::execute()
//fit_example_mask(); //fit_example_mask();
} }
//! Basic fit example.
/* ************************************************************************* */
// basic fit example
/* ************************************************************************* */
void TestFittingModule2::fit_example_basics() void TestFittingModule2::fit_example_basics()
{ {
initializeSimulation(); initializeSimulation();
initializeRealData(); initializeRealData();
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_height", 5*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_height",
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_radius", 6*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); 5*Units::nanometer, 1*Units::nanometer,
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_half_side", 5*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_height", 6*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_radius",
// m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_height", 12*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); 6*Units::nanometer, 1*Units::nanometer,
// m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_radius", 2*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); AttLimits::lowerLimited(0.01) );
// m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_half_side", 12*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_half_side",
// m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_height", 2*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); 5*Units::nanometer, 1*Units::nanometer,
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_ratio", 0.2, 0.1, AttLimits::fixed()); AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_height",
6*Units::nanometer, 1*Units::nanometer,
AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_ratio",
0.2, 0.1,
AttLimits::fixed());
m_fitSuite->addSimulationAndRealData(*mp_simulation, *mp_real_data); m_fitSuite->addSimulationAndRealData(*mp_simulation, *mp_real_data);
m_fitSuite->runFit(); m_fitSuite->runFit();
} }
//! Fit example with chi2 module adjustment.
/* ************************************************************************* */
// fit example with chi2 module adjustment
/* ************************************************************************* */
void TestFittingModule2::fit_example_chimodule() void TestFittingModule2::fit_example_chimodule()
{ {
initializeSimulation(); initializeSimulation();
initializeRealData(); initializeRealData();
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_height", 4*Units::nanometer, 0.01*Units::nanometer, AttLimits::lowerLimited(0.01) ); m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_height",
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_radius", 6*Units::nanometer, 0.01*Units::nanometer, AttLimits::lowerLimited(0.01) ); 4*Units::nanometer, 0.01*Units::nanometer,
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_half_side", 4*Units::nanometer, 0.01*Units::nanometer, AttLimits::lowerLimited(0.01) ); AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_height", 6*Units::nanometer, 0.01*Units::nanometer, AttLimits::lowerLimited(0.01) ); m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_radius",
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_ratio", 0.2, 0.1, AttLimits::fixed()); 6*Units::nanometer, 0.01*Units::nanometer,
//m_fitSuite->addFitParameter("*Normalizer/scale", 1, 0.01*Units::nanometer, AttLimits::limited(0.9,1.1) ); AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_half_side",
4*Units::nanometer, 0.01*Units::nanometer,
AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_height",
6*Units::nanometer, 0.01*Units::nanometer,
AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_ratio",
0.2, 0.1,
AttLimits::fixed());
// setting up fitSuite // setting up fitSuite
ChiSquaredModule chiModule; ChiSquaredModule chiModule;
//chiModule.setChiSquaredFunction( SquaredFunctionDefault() );
// chiModule.setChiSquaredFunction( SquaredFunctionWhichOnlyWorks() ); // it works only with resolution function, without it fit doesn't converge
chiModule.setChiSquaredFunction( SquaredFunctionWithSystematicError() ); chiModule.setChiSquaredFunction( SquaredFunctionWithSystematicError() );
chiModule.setOutputDataNormalizer( OutputDataSimpleNormalizer() ); chiModule.setOutputDataNormalizer( OutputDataSimpleNormalizer() );
//chiModule.setIntensityFunction( IntensityFunctionLog() ); m_fitSuite->addSimulationAndRealData(
m_fitSuite->addSimulationAndRealData(*mp_simulation, *mp_real_data, chiModule); *mp_simulation, *mp_real_data, chiModule);
for(FitSuiteParameters::iterator it = m_fitSuite->getFitParameters()->begin(); it!=m_fitSuite->getFitParameters()->end(); ++it) { for(FitSuiteParameters::iterator it =
m_fitSuite->getFitParameters()->begin();
it!=m_fitSuite->getFitParameters()->end(); ++it)
std::cout << (*it) << std::endl; std::cout << (*it) << std::endl;
}
m_fitSuite->runFit(); m_fitSuite->runFit();
} }
/* ************************************************************************* */ //! Fit example with strategies.
// fit example with strategies
/* ************************************************************************* */
void TestFittingModule2::fit_example_strategies() void TestFittingModule2::fit_example_strategies()
{ {
initializeSimulation(); initializeSimulation();
initializeRealData(); initializeRealData();
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_height", 12*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_height",
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_radius", 2*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); 12*Units::nanometer, 1*Units::nanometer,
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_half_side", 12*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_height", 2*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_radius",
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_ratio", 0.2, 0.1, AttLimits::fixed()); 2*Units::nanometer, 1*Units::nanometer,
AttLimits::lowerLimited(0.01) );
// Applying fit strategy: fixing/releasing parameters m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_half_side",
// FitSuiteStrategyAdjustParameters *strategy0 = new FitSuiteStrategyAdjustParameters("strategy0"); 12*Units::nanometer, 1*Units::nanometer,
// strategy0->fix_all().release("*SampleBuilder/m_cylinder_ratio"); AttLimits::lowerLimited(0.01) );
// m_fitSuite->addFitStrategy(strategy0); m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_height",
// FitSuiteStrategyAdjustParameters *strategy1 = new FitSuiteStrategyAdjustParameters("strategy1"); 2*Units::nanometer, 1*Units::nanometer,
// strategy1->release_all().fix("*SampleBuilder/m_cylinder_ratio"); AttLimits::lowerLimited(0.01) );
// m_fitSuite->addFitStrategy(strategy1); m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_ratio",
// FitSuiteStrategyAdjustParameters *strategy2 = new FitSuiteStrategyAdjustParameters("strategy2"); 0.2, 0.1,
// strategy2->release_all(); AttLimits::fixed());
// m_fitSuite->addFitStrategy(strategy2);
// Applying fit strategy: resizing real data // Applying fit strategy: resizing real data
m_fitSuite->addFitStrategy(new FitSuiteStrategyAdjustData(3)); m_fitSuite->addFitStrategy(new FitSuiteStrategyAdjustData(3));
...@@ -180,26 +186,25 @@ void TestFittingModule2::fit_example_strategies() ...@@ -180,26 +186,25 @@ void TestFittingModule2::fit_example_strategies()
m_fitSuite->addFitStrategy(new FitSuiteStrategyAdjustData(1)); m_fitSuite->addFitStrategy(new FitSuiteStrategyAdjustData(1));
m_fitSuite->addFitStrategy(new FitSuiteStrategyDefault()); m_fitSuite->addFitStrategy(new FitSuiteStrategyDefault());
// Applying fit strategy: disturbing data to get out of local minima
//m_fitSuite->addFitStrategy(new FitSuiteStrategyBootstrap());
m_fitSuite->addSimulationAndRealData(*mp_simulation, *mp_real_data); m_fitSuite->addSimulationAndRealData(*mp_simulation, *mp_real_data);
m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Minuit2", "Migrad") ); m_fitSuite->setMinimizer(
MinimizerFactory::createMinimizer("Minuit2", "Migrad") );
m_fitSuite->runFit(); m_fitSuite->runFit();
} }
// ---------------------------------------------------------------------------- //! Fit example with data masking.
// fit example with data masking
// ----------------------------------------------------------------------------
void TestFittingModule2::fit_example_mask() void TestFittingModule2::fit_example_mask()
{ {
initializeSimulation(); initializeSimulation();
initializeRealData(); initializeRealData();
mp_simulation->setDetectorResolutionFunction(new ResolutionFunction2DSimple(0.0002, 0.0002)); mp_simulation->setDetectorResolutionFunction(
new ResolutionFunction2DSimple(0.0002, 0.0002));
TCanvas *c1 = DrawHelper::createAndRegisterCanvas("c1_test_meso_crystal", "mesocrystal"); TCanvas *c1 = DrawHelper::createAndRegisterCanvas(
"c1_test_meso_crystal", "mesocrystal");
c1->cd(); gPad->SetLogz(); c1->cd(); gPad->SetLogz();
c1->Divide(2,2); c1->Divide(2,2);
...@@ -214,7 +219,8 @@ void TestFittingModule2::fit_example_mask() ...@@ -214,7 +219,8 @@ void TestFittingModule2::fit_example_mask()
const double minima[]={0.003, 0.003}; const double minima[]={0.003, 0.003};
const double maxima[]={0.03, 0.03}; const double maxima[]={0.03, 0.03};
Mask *mask1 = OutputDataFunctions::CreateRectangularMask(*mp_real_data, minima, maxima); Mask *mask1 = OutputDataFunctions::CreateRectangularMask(
*mp_real_data, minima, maxima);
mp_real_data->setMask(*mask1); mp_real_data->setMask(*mask1);
c1->cd(2); c1->cd(2);
...@@ -224,61 +230,66 @@ void TestFittingModule2::fit_example_mask() ...@@ -224,61 +230,66 @@ void TestFittingModule2::fit_example_mask()
IsGISAXSTools::drawOutputDataInPad(*mp_real_data, "COLZ", "real_data"); IsGISAXSTools::drawOutputDataInPad(*mp_real_data, "COLZ", "real_data");
c1->Update(); c1->Update();
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_height", 4*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_height",
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_radius", 4*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); 4*Units::nanometer, 1*Units::nanometer,
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_half_side", 4*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_height", 4*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_radius",
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_ratio", 0.2, 0.1, AttLimits::fixed()); 4*Units::nanometer, 1*Units::nanometer,
// m_fitSuite->addFitParameter("*Normalizer/scale", 1e10, 1, AttLimits::limited(0.1*1e10, 2.*1e10)); AttLimits::lowerLimited(0.01) );
// m_fitSuite->addFitParameter("*Normalizer/scale", 1e10, 1, AttLimits::limited(1e8, 1e12)); m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_half_side",
4*Units::nanometer, 1*Units::nanometer,
AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_prism3_height",
4*Units::nanometer, 1*Units::nanometer,
AttLimits::lowerLimited(0.01) );
m_fitSuite->addFitParameter("*SampleBuilder/m_cylinder_ratio",
0.2, 0.1,
AttLimits::fixed());
ChiSquaredModule chiModule; ChiSquaredModule chiModule;
//chiModule.setChiSquaredFunction( SquaredFunctionDefault() );
// chiModule.setChiSquaredFunction( SquaredFunctionWhichOnlyWorks() ); // it works only with resolution function, without it fit doesn't converge
//chiModule.setChiSquaredFunction( SquaredFunctionWithSystematicError() );
chiModule.setOutputDataNormalizer( OutputDataSimpleNormalizer(1.0,0) ); chiModule.setOutputDataNormalizer( OutputDataSimpleNormalizer(1.0,0) );
m_fitSuite->addSimulationAndRealData(
*mp_simulation, *mp_real_data, chiModule);
m_fitSuite->addSimulationAndRealData(*mp_simulation, *mp_real_data, chiModule);
m_fitSuite->runFit(); m_fitSuite->runFit();
} }
//! Initialize simulation.
/* ************************************************************************* */
// initializing simulation
/* ************************************************************************* */
void TestFittingModule2::initializeSimulation() void TestFittingModule2::initializeSimulation()
{ {
if( !mp_sample_builder ) { if( !mp_sample_builder )
throw NullPointerException("TestFittingModule2::initializeSimulation() -> No sample builder defined"); throw NullPointerException(
} "TestFittingModule2::initializeSimulation() -> "
"No sample builder defined");
delete mp_simulation; delete mp_simulation;
mp_simulation = new Simulation(mp_options); mp_simulation = new Simulation(mp_options);
mp_simulation->setSampleBuilder(mp_sample_builder); mp_simulation->setSampleBuilder(mp_sample_builder);
mp_simulation->setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree,100 , 0.0*Units::degree, 2.0*Units::degree); mp_simulation->setDetectorParameters(
mp_simulation->setBeamParameters(1.0*Units::angstrom, -0.2*Units::degree, 0.0*Units::degree); 100, 0.0*Units::degree, 2.0*Units::degree,
//mp_simulation->setBeamIntensity(1e10); 100, 0.0*Units::degree, 2.0*Units::degree);
mp_simulation->setBeamParameters(
1.0*Units::angstrom,
-0.2*Units::degree,
0.0*Units::degree);
} }
/* ************************************************************************* */ //! Create noisy data (simulated experiment).
// initializing real data
/* ************************************************************************* */
void TestFittingModule2::initializeRealData() void TestFittingModule2::initializeRealData()
{ {
if( !mp_simulation ) throw NullPointerException("TestFittingModule2::initializeRealData() -> Error! No simulation of sample defined "); if( !mp_simulation )
throw NullPointerException(
"TestFittingModule2::initializeRealData() -> "
"Error! No simulation of sample defined ");
// generating "real" data
mp_simulation->runSimulation(); mp_simulation->runSimulation();
// mp_simulation->normalize();
//m_fitSuite->getFitObjects()->setSimulationNormalize(true);
delete mp_real_data; delete mp_real_data;
mp_real_data = IsGISAXSTools::createNoisyData(*mp_simulation->getOutputData()); mp_real_data = IsGISAXSTools::createNoisyData(
*mp_simulation->getOutputData());
// drawing data // draw data
TCanvas *c1 = new TCanvas("c1","c1",640, 480); TCanvas *c1 = new TCanvas("c1","c1",640, 480);
c1->cd(); gPad->SetLogz(); c1->cd(); gPad->SetLogz();
TH2D *hist = IsGISAXSTools::getOutputDataTH2D( *mp_real_data, "real_data"); TH2D *hist = IsGISAXSTools::getOutputDataTH2D( *mp_real_data, "real_data");
...@@ -287,11 +298,10 @@ void TestFittingModule2::initializeRealData() ...@@ -287,11 +298,10 @@ void TestFittingModule2::initializeRealData()
} }
/* ************************************************************************* */
// simple sample - mixture of cylinders and prisms on top of substrate // simple sample - mixture of cylinders and prisms on top of substrate
// builder via ISampleBuilder // builder via ISampleBuilder
// 5 fit parameters // 5 fit parameters
/* ************************************************************************* */
TestFittingModule2::SampleBuilder::SampleBuilder() TestFittingModule2::SampleBuilder::SampleBuilder()
: m_cylinder_height(5.0*Units::nanometer) : m_cylinder_height(5.0*Units::nanometer)
, m_cylinder_radius(5.0*Units::nanometer) , m_cylinder_radius(5.0*Units::nanometer)
...@@ -309,15 +319,25 @@ ISample *TestFittingModule2::SampleBuilder::buildSample() const ...@@ -309,15 +319,25 @@ ISample *TestFittingModule2::SampleBuilder::buildSample() const
complex_t n_air(1.0, 0.0); complex_t n_air(1.0, 0.0);
complex_t n_substrate(1.0-6e-6, 2e-8); complex_t n_substrate(1.0-6e-6, 2e-8);
complex_t n_particle(1.0-6e-4, 2e-8); complex_t n_particle(1.0-6e-4, 2e-8);
const IMaterial *p_air_material = MaterialManager::getHomogeneousMaterial("Air", n_air); const IMaterial *p_air_material =
const IMaterial *p_substrate_material = MaterialManager::getHomogeneousMaterial("Substrate", n_substrate); MaterialManager::getHomogeneousMaterial("Air", n_air);
const IMaterial *p_substrate_material =
MaterialManager::getHomogeneousMaterial("Substrate", n_substrate);
Layer air_layer; Layer air_layer;
air_layer.setMaterial(p_air_material); air_layer.setMaterial(p_air_material);
Layer substrate_layer; Layer substrate_layer;
substrate_layer.setMaterial(p_substrate_material); substrate_layer.setMaterial(p_substrate_material);
ParticleDecoration particle_decoration; ParticleDecoration particle_decoration;
particle_decoration.addParticle(new Particle(n_particle, new FormFactorCylinder(m_cylinder_height, m_cylinder_radius)),0.0, m_cylinder_ratio); particle_decoration.addParticle(
particle_decoration.addParticle(new Particle(n_particle, new FormFactorPrism3(m_prism3_height, m_prism3_half_side)), 0.0, 1.0 - m_cylinder_ratio); new Particle(n_particle,
new FormFactorCylinder(m_cylinder_height,
m_cylinder_radius)),
0.0, m_cylinder_ratio);
particle_decoration.addParticle(
new Particle(n_particle,
new FormFactorPrism3(m_prism3_height,
m_prism3_half_side)),
0.0, 1.0 - m_cylinder_ratio);
particle_decoration.addInterferenceFunction(new InterferenceFunctionNone()); particle_decoration.addInterferenceFunction(new InterferenceFunctionNone());
LayerDecorator air_layer_decorator(air_layer, particle_decoration); LayerDecorator air_layer_decorator(air_layer, particle_decoration);
......
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