def get_simulation(params, add_masks=True): """ Create and return GISAXS simulation with beam and detector defined """ simulation = ba.GISASSimulation() simulation.setDetectorParameters(100, -1.0*deg, 1.0*deg, 100, 0.0*deg, 2.0*deg) simulation.setBeamParameters(1.0*angstrom, 0.2*deg, 0.0*deg) simulation.setBeamIntensity(1e+08) simulation.setSample(get_sample(params)) if add_masks: """ At this point we mask all the detector and then unmask two areas corresponding to the vertical and horizontal lines. This will make simulation/fitting to be performed along slices only. """ simulation.maskAll() simulation.addMask(ba.HorizontalLine(alpha_slice_value*deg), False) simulation.addMask(ba.VerticalLine(phi_slice_value*deg), False) return simulation
def run_fitting(): """ main function to run fitting """ real_data = create_real_data() sample = get_sample() simulation = get_simulation() simulation.setSample(sample) # At this point we mask all the detector and then unmask two areas # corresponding to the vertical and horizontal lines. This will make # simulation/fitting to be performed along slices only. simulation.maskAll() simulation.addMask(ba.HorizontalLine(alpha_slice_value * deg), False) simulation.addMask(ba.VerticalLine(phi_slice_value * deg), False) fit_suite = ba.FitSuite() fit_suite.addSimulationAndRealData(simulation, real_data) fit_suite.initPrint(5) draw_observer = DrawObserver(draw_every_nth=5) fit_suite.attachObserver(draw_observer) # setting fitting parameters with starting values fit_suite.addFitParameter("*/Cylinder/Radius", 6. * nm).setLimited(4., 8.) fit_suite.addFitParameter("*/Cylinder/Height", 9. * nm).setLimited(8., 12.) # running fit fit_suite.runFit() print("Fitting completed.") print("chi2:", fit_suite.getChi2()) for fitPar in fit_suite.fitParameters(): print(fitPar.name(), fitPar.value(), fitPar.error())