#include "Geometry/geo.h"
#include <iostream>
#include <cmath>
#include <cassert>
Go to the source code of this file.
Functions | |
| int | main (void) |
Definition in file testgeo.cc.
|
|
Definition at line 12 of file testgeo.cc. References geo::DsqrToLine(), and geo::LinFitMinDperp(). 00013 {
00014 double d;
00015
00016 //....................................................................
00017 std::cout << "testing DsqrToLine";
00018 double p1[2] = { 1.0, 1.0};
00019 double p2[2] = { 1.0, -1.0};
00020 double p3[2] = {-1.0, 1.0};
00021
00022 d = geo::DsqrToLine(p1[0],p1[1],p2[0],p2[1],p3[0],p3[1]);
00023 assert((d-2.0)<1.0E-9);
00024 std::cout << ".";
00025
00026 d = geo::DsqrToLine(p2[0],p2[1],p3[0],p3[1],p1[0],p1[1]);
00027 assert((d-4.0)<1.0E-9);
00028 std::cout << ".";
00029
00030 d = geo::DsqrToLine(p3[0],p3[1],p1[0],p1[1],p2[0],p2[1]);
00031 assert((d-4.0)<1.0E-9);
00032 std::cout << ".";
00033
00034 std::cout << " AOK" << std::endl;
00035
00036 //....................................................................
00037 std::cout << "testing LinFitMinDperp";
00038 double chi2;
00039 double x1, y1;
00040 double x2, y2;
00041 std::vector<double> x(100);
00042 std::vector<double> y(100);
00043 std::vector<double> w(100);
00044
00045 // Simple case, equal weights
00046 for (int i=0; i<100; ++i) {
00047 x[i] = (float)i;
00048 y[i] = (float)i;
00049 w[i] = 1.0;
00050 }
00051 chi2 = geo::LinFitMinDperp(x,y,w,&x1,&y1,&x2,&y2);
00052 assert(chi2<1.0E-6);
00053 assert(fabs(x1-0.0)<1.0E-6);
00054 assert(fabs(y1-0.0)<1.0E-6);
00055 assert(fabs(x2-99.0)<1.0E-6);
00056 assert(fabs(y2-99.0)<1.0E-6);
00057 std::cout << ".";
00058
00059 // Test one with very large slope
00060 for (int i=0; i<100; ++i) {
00061 x[i] = (float)i/100.0;
00062 y[i] = 100.0*(float)i;
00063 w[i] = 1.0;
00064 }
00065 chi2 = geo::LinFitMinDperp(x,y,w,&x1,&y1,&x2,&y2);
00066 assert(chi2<1.0E-6);
00067 assert(fabs(x1-0.0)<1.0E-6);
00068 assert(fabs(y1-0.0)<1.0E-6);
00069 assert(fabs(x2-0.99)<1.0E-6);
00070 assert(fabs(y2-9900.0)<1.0E-6);
00071 std::cout << ".";
00072
00073 // Test one with unequal weights
00074 for (int i=0; i<100; ++i) {
00075 x[i] = (float)i;
00076 y[i] = (float)i;
00077 w[i] = 1.0+(i%10);
00078 }
00079 chi2 = geo::LinFitMinDperp(x,y,w,&x1,&y1,&x2,&y2);
00080 assert(chi2<1.0E-6);
00081 assert((x1-0.0)<1.0E-6);
00082 assert((y1-0.0)<1.0E-6);
00083 assert((x2-99.0)<1.0E-6);
00084 assert((y2-99.0)<1.0E-6);
00085 std::cout << ".";
00086
00087 std::cout << " AOK" << std::endl;
00088
00089 return 0;
00090 }
|
1.3.9.1