//testing script for the spline stuff - needs to be compiled //Felix #include "tpc/spacecharge/BiCubSpline.h" #include "tpc/spacecharge/BSpline.h" #include #include #include "TF2.h" #include "TH2D.h" #include "TCanvas.h" #include "TRandom.h" // helper class ------------------------------------------------ class Function { public: void setCSP(BiCubSpline* csp) { _csp = csp; _kx = _csp->getKx(); _ky = _csp->getKy(); _xl = _kx->size(); _yl = _ky->size(); _coeffs = new std::vector*>; std::cout<<"ncoeffs="<<_coeffs->size()<setCoeffsByArray(p); double result = _csp->eval(x[0], x[1]); return result; } private: BiCubSpline* _csp; std::vector* _kx; std::vector* _ky; std::vector*>* _coeffs; int _xl, _yl; }; // ------------------------------------------------------------- void testBiCubSpline() { int NknotsX = 4; int NknotsY = 4; int NlamdaX = NknotsX+8; int NlamdaY = NknotsY+8; std::vector* _kx = new std::vector; std::vector* _ky = new std::vector; std::vector*>* coeff=new std::vector*>; double lLx = 0; double uLx = 15; double lLy = 0; double uLy = 15; double stepx = (uLx - lLx)/NknotsX; double stepy = (uLy - lLy)/NknotsY; double kx,ky; for(int i=0; ipush_back(kx); } for(int j=0; jpush_back(ky); } for(int i=0; ipush_back(new std::vector(NlamdaX, 0)); } TCanvas* c1 = new TCanvas(); // Cub-Spline testing ------------------------------------------ BiCubSpline* csp = new BiCubSpline(_kx, _ky, coeff); Function* func = new Function(); func->setCSP(csp); //TF1* sin = new TF1("blub", "sin(x)",0,10); TH2D* hist = new TH2D("blub","blub",40 ,0,15, 30,0,15); for ( Int_t i = 0; i<1000; i++ ) hist->Fill(gRandom->Gaus(5,1), gRandom->Gaus(3,1)); //for ( Int_t i = 0; i<1000; i++ ) hist->Fill(gRandom->Gaus(9,1), // gRandom->Gaus(10,1)); TF2* f2 =new TF2("f2",func,&Function::eval,0,15,0,15,NlamdaX*NlamdaY, "Function", "eval"); Double_t param[14*14] = {0}; for(int i=5; i<7;i++) param[i]=10; for(int i=17; i<19;i++) param[i]=10; f1->SetParameters(param); f1->DrawClone(); hist->Fit("f1","R"); hist->Draw("SURF"); // f1->Draw(); }