Skip to content
Snippets Groups Projects
Commit b41b6550 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

New ComplexBessel applicaiton test

parent b6000bff
No related branches found
No related tags found
No related merge requests found
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file App/inc/TestBessel.h
//! @brief Defines class TestBessel.
//
//! Homepage: apps.jcns.fz-juelich.de/BornAgain
//! License: GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2013
//! @authors Scientific Computing Group at MLZ Garching
//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#ifndef TESTBESSEL_H
#define TESTBESSEL_H
#include "IApplicationTest.h"
#include "Numeric.h"
class TestBessel : public IApplicationTest
{
public:
class Data {
public:
Data() : x(0), b1(0), b2(0) {}
double x;
double b1;
double b2;
};
TestBessel(){}
~TestBessel(){}
virtual void execute();
void run_benchmark();
// (x1-x2)/x2
double rel_diff(double x1, double x2)
{
double ratio(0);
double diff = x1 - x2;
if( std::abs(diff) <= Numeric::double_epsilon && std::abs(x2) <= Numeric::double_epsilon) {
ratio = 0.0;
} else if(std::abs(x2) <= Numeric::double_epsilon) {
ratio = diff/Numeric::double_epsilon;
} else {
ratio = diff/x2;
}
return ratio;
}
};
#endif // TESTBESSEL_H
......@@ -46,6 +46,7 @@
#include "TestFunctionalTests.h"
#include "TestRipple2.h"
#include "TestRipple1.h"
#include "TestBessel.h"
#include "TBenchmark.h"
......@@ -279,6 +280,11 @@ void RegisterApplicationTests(ApplicationTestFactory *p_test_factory)
IFactoryCreateFunction<TestRipple1, IApplicationTest>,
"test the new ripple1 formfactor");
p_test_factory->registerItem(
"bessel",
IFactoryCreateFunction<TestBessel, IApplicationTest>,
"test complex bessel functions");
}
#include "TestBessel.h"
#include "MathFunctions.h"
#include "TCanvas.h"
#include "TH2D.h"
#include "TBenchmark.h"
#include "TMath.h"
#include <iostream>
void TestBessel::execute()
{
std::cout << "TestBessel::execute() -> Hello World" << std::endl;
double xmin(0.0), xmax(20.0);
int nx(201);
double dx = (xmax-xmin)/(nx-1);
std::cout << "dx: " << dx << std::endl;
std::vector<Data> buff;
buff.resize(nx);
for(int i=0; i<nx; ++i) {
double x = xmin + dx*i;
buff[i].x = x;
buff[i].b1 = TMath::BesselJ1(x);
buff[i].b2 = MathFunctions::Bessel_J1(x);
std::cout << i << " " << x << " " << buff[i].b1 << std::endl;
}
TCanvas *c1 = new TCanvas("c1","c1",1024, 768);
TH1D *h2 = new TH1D("h2","h2", nx, xmin - dx/2., xmax+dx/2.);
for(int i=0; i<nx; ++i) {
h2->Fill(buff[i].x, rel_diff(buff[i].b1, buff[i].b2));
}
c1->Divide(2,2);
c1->cd(1);
h2->Draw();
}
void TestBessel::run_benchmark()
{
}
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