|
[yoda-svn] r365 - in trunk: . include/YODA tests tests/Histo2Dblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Aug 25 14:47:01 BST 2011
Author: mkawalec Date: Thu Aug 25 14:47:01 2011 New Revision: 365 Log: Added some tests to Histo2D, fixed some bugs (a serious one in Axis2D::scaleXY())and general TODO tweaking. Modified: trunk/TODO trunk/include/YODA/Axis2D.h trunk/include/YODA/Histo2D.h trunk/tests/Histo2D/H2DCreate.cc trunk/tests/Histo2D/H2DFill.cc trunk/tests/Histo2D/H2DModify.cc trunk/tests/Makefile.am trunk/tests/TestHisto2D.cc Modified: trunk/TODO ============================================================================== --- trunk/TODO Thu Aug 25 13:21:34 2011 (r364) +++ trunk/TODO Thu Aug 25 14:47:01 2011 (r365) @@ -11,6 +11,7 @@ * Comment, clean, and explain the Axis caching mechanisms and the very complex functions that manipulate them. (MK) + MK: Done? * Unify the API, especially the order of X/Y parameters in various constructors! (MK) Modified: trunk/include/YODA/Axis2D.h ============================================================================== --- trunk/include/YODA/Axis2D.h Thu Aug 25 13:21:34 2011 (r364) +++ trunk/include/YODA/Axis2D.h Thu Aug 25 14:47:01 2011 (r365) @@ -126,6 +126,7 @@ /// A constructor with specified x and y axis bin limits. Axis2D(const std::vector<double>& xedges, const std::vector<double>& yedges) { std::vector<Segment> binLimits; + /// Generate bin limits for (int i = 0; i < yedges.size() - 1; ++i) { for (int j = 0; j < xedges.size() - 1; ++j) { binLimits.push_back(std::make_pair(std::make_pair(xedges[j], yedges[i]), @@ -526,18 +527,18 @@ void scaleXY(double scaleX, double scaleY) { // Two loops are put on purpose, just to protect // against improper _binHashSparse - foreach(EdgeCollection ec, _binHashSparse.first) { - ec.first *= scaleY; - foreach(Edge edge, ec.second) { - edge.second.first *= scaleX; - edge.second.second *= scaleX; + for(size_t i = 0; i < _binHashSparse.first.size(); ++i){ + _binHashSparse.first[i].first *= scaleY; + for(size_t j = 0; j < _binHashSparse.first[i].second.size(); ++j){ + _binHashSparse.first[i].second[j].second.first *= scaleX; + _binHashSparse.first[i].second[j].second.second *= scaleX; } } - foreach(EdgeCollection ec, _binHashSparse.second) { - ec.first *= scaleX; - foreach(Edge edge, ec.second) { - edge.second.first *= scaleY; - edge.second.second *= scaleY; + for(size_t i = 0; i < _binHashSparse.second.size(); ++i){ + _binHashSparse.second[i].first *= scaleX; + for(size_t j = 0; j < _binHashSparse.second[i].second.size(); ++j){ + _binHashSparse.second[i].second[j].second.first *= scaleY; + _binHashSparse.second[i].second[j].second.second *= scaleY; } } Modified: trunk/include/YODA/Histo2D.h ============================================================================== --- trunk/include/YODA/Histo2D.h Thu Aug 25 13:21:34 2011 (r364) +++ trunk/include/YODA/Histo2D.h Thu Aug 25 14:47:01 2011 (r365) @@ -144,21 +144,37 @@ double lowEdgeX() const { return _axis.lowEdgeX(); } + /// Alias for lowEdgeX() + double xMin() const { + return lowEdgeX(); + } /// Low y edge of this histo's axis double lowEdgeY() const { return _axis.lowEdgeY(); } + /// Alias for lowEdgeY() + double yMin() const { + return lowEdgeY(); + } /// High x edge of this histo's axis double highEdgeX() const { return _axis.highEdgeX(); } + /// Alias for highEdgeX() + double xMax() const { + return highEdgeX(); + } /// High y edge of this histo's axis double highEdgeY() const { return _axis.highEdgeY(); } + /// Alias for highEdgeY() + double yMax() const { + return highEdgeY(); + } /// Access the bin vector (non-const version) std::vector<YODA::HistoBin2D>& bins() { Modified: trunk/tests/Histo2D/H2DCreate.cc ============================================================================== --- trunk/tests/Histo2D/H2DCreate.cc Thu Aug 25 13:21:34 2011 (r364) +++ trunk/tests/Histo2D/H2DCreate.cc Thu Aug 25 14:47:01 2011 (r365) @@ -5,5 +5,25 @@ using namespace YODA; int main() { + cout << "Creating histos to be operated on "; + + Histo2D first(10, 0, 100, 10, 0, 100); + first.fill(1,1,1); + first.fill(23,1,1); + Histo2D second(10, 0, 100, 10, 0, 100); + second.fill(1,1,1); + cout << "PASS" << endl; + + cout << "Testing the copy constructor: "; + Histo2D h(20, 0, 100, 20, 0, 100); + Histo2D copyTest(h); + cout << "PASS" << endl; + + cout << "Adding/substracting/dividing: "; + Histo2D added(first+second); + Histo2D subtracted(first-second); + Scatter3D divided(first/second); + cout << "PASS" << endl; + return EXIT_SUCCESS; } Modified: trunk/tests/Histo2D/H2DFill.cc ============================================================================== --- trunk/tests/Histo2D/H2DFill.cc Thu Aug 25 13:21:34 2011 (r364) +++ trunk/tests/Histo2D/H2DFill.cc Thu Aug 25 14:47:01 2011 (r365) @@ -1,9 +1,44 @@ #include "YODA/Histo2D.h" +#include "YODA/Scatter3D.h" +#include <cmath> #include <iostream> +#include <unistd.h> +#include <sys/time.h> using namespace std; using namespace YODA; int main() { + Histo2D h(200, 0, 100, 200, 0, 100); + + struct timeval startTime; + struct timeval endTime; + gettimeofday(&startTime, NULL); + cout << "Testing fill operation: "; + for (int i=0; i < 2000; i++) { + int out = h.fill(16.0123, 12.213, 2); + if (out == -1) { + cout << "FAIL" << endl; + return -1; + } + } + gettimeofday(&endTime, NULL); + + double tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000; + double tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000; + if ((tE - tS) > 50.0) { + cout << "Performance is not sufficient. Probably broken caches?" << endl; + return -1; + } + cout << "PASS (" << tE - tS << "s)" << endl; + + // Testing if fill() function does what it should + cout << "Does fill() do what it should? "; + if(-1 != h.fill(1123123,312312,1)){ + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + return EXIT_SUCCESS; } Modified: trunk/tests/Histo2D/H2DModify.cc ============================================================================== --- trunk/tests/Histo2D/H2DModify.cc Thu Aug 25 13:21:34 2011 (r364) +++ trunk/tests/Histo2D/H2DModify.cc Thu Aug 25 14:47:01 2011 (r365) @@ -1,9 +1,159 @@ #include "YODA/Histo2D.h" +#include "YODA/Scatter3D.h" +#include <cmath> #include <iostream> +#include <unistd.h> +#include <sys/time.h> + using namespace std; using namespace YODA; int main() { - return EXIT_SUCCESS; + + // Creating a histogram and measuring the time it takes to do it. + struct timeval startTime; + struct timeval endTime; + Histo2D h(200, 0, 100, 200, 0, 100); + + double tS; + double tE; + cout << "Adding bins "; + size_t before = h.numBins(); + h.addBin(0.1, 0.1, 0.2, 0.2); + h.addBin(110, 0, 200, 12.100); + h.addBin(16.0, 200, 17.0, 300); + + /// @todo Add position checking + if(before != h.numBins() - 3) { + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + cout << "Checking if filling does modify the grid:"; + size_t beforeAdd = h.numBins(); + h.fill(10000, 34234, 1); + if (h.numBins() != beforeAdd) { + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + // Checking if everything is still working as desired. + // It is a good thing to do, as at some earlier stages + // in development adding a broken bin destroyed the cache of edges. + cout << "Is the origin working correctly? "; + int originIndex = h.fill(0.0, 0.0, 1); + if (originIndex == -1) { + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + // Now, adding a square that is in a non-overlapping location: + cout << "Does bin addition work? "; + beforeAdd = h.numBins(); + h.addBin(150, 150, 200, 200); + if (beforeAdd == h.numBinsTotal()) { + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + // Checking if a broken bin triggers _dropEdge(). + cout << "Does a broken bin trigger _droEdge()? "; + beforeAdd = h.numBinsTotal(); + h.addBin(0.756, 0.213, 12.1234, 23); + if (beforeAdd != h.numBinsTotal()) { + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + // A check testing mostly _fixOrientation() + cout << "How about adding a bin in 3rd quadrant? "; + beforeAdd = h.numBinsTotal(); + h.addBin(-12, -12, -1, -1); + if (beforeAdd == h.numBinsTotal()) { + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + cout << "Trying to fill the newly created bin: "; + int fillTest = h.fill(-3, -3, 1); + if (fillTest == -1 || fillTest != (int)h.numBins() - 1) { + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + cout << "Scaling test: "; + gettimeofday(&startTime, NULL); + int xMin, xMax, yMin, yMax; + xMin = h.xMin(); xMax = h.xMax(); yMin = h.yMin(); yMax = h.yMax(); + h.scaleXY(2.0, 3.0); + if(h.xMin() != 2*xMin || h.xMax() != 2*xMax || + h.yMin() != 3*yMin || h.yMax() != 3*yMax) { + cout << "FAIL" << endl; + return -1; + } + gettimeofday(&endTime, NULL); + + fillTest = h.fill(180, 180, 1); + if (fillTest == -1) { + cout << "FAIL" << endl; + return -1; + } + tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000; + tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000; + cout << "PASS (" << tE - tS << "s)" << endl; + + cout << "Testing cuts: "; + Histo2D sampleHisto(50, 0, 100, 39, 0, 10); + sampleHisto.fill(0,0,123121); + if (!fuzzyEquals(sampleHisto.sumW(false), (double)123121)) { + cout << "FAIL" << endl; + return -1; + } + if (!fuzzyEquals(sampleHisto.sumW2(false), 1.51588e+10)) { + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + cout << "Testing cutterX: "; + Histo1D atY(sampleHisto.cutterX(0)); + if (!fuzzyEquals(atY.sumW(false), sampleHisto.sumW(false))){ + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + cout << "Another cutterX test: "; + Histo1D atX2(sampleHisto.cutterX(2)); + if (!fuzzyEquals(atX2.sumW(false), 0)){ + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + cout << "Testing cutterY: "; + Histo1D atX(sampleHisto.cutterY(0)); + if (!fuzzyEquals(atX.sumW(false), sampleHisto.sumW(false))){ + cout << "FAIL" << endl; + return -1; + } + cout << "PASS" << endl; + + cout << "Testing bin merger: "; + gettimeofday(&startTime, NULL); + h.mergeBins(0, 20000); + gettimeofday(&endTime, NULL); + tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000; + tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000; + cout << "PASS (" << tE - tS << ")" << endl; + + return EXIT_SUCCESS; } Modified: trunk/tests/Makefile.am ============================================================================== --- trunk/tests/Makefile.am Thu Aug 25 13:21:34 2011 (r364) +++ trunk/tests/Makefile.am Thu Aug 25 14:47:01 2011 (r365) @@ -2,8 +2,6 @@ testweights \ testhisto1Da testhisto1Db \ testprofile1Da \ - testhisto2D \ - testhisto2Da \ testhisto2De \ testpoint3D \ testscatter3D\ @@ -31,8 +29,6 @@ testprofile1Da_SOURCES = TestProfile1Da.cc testindexedset_SOURCES = TestIndexedSet.cc testsortedvector_SOURCES = TestSortedVector.cc -testhisto2D_SOURCES = TestHisto2D.cc -testhisto2Da_SOURCES = TestHisto2Da.cc testhisto2De_SOURCES = TestHisto2Derase.cc testpoint3D_SOURCES = TestPoint3D.cc testscatter3D_SOURCES = TestScatter3D.cc @@ -61,8 +57,6 @@ testweights \ testhisto1Da testhisto1Db \ testprofile1Da \ - testhisto2D \ - testhisto2Da \ testhisto2De \ testpoint3D \ testscatter3D \ Modified: trunk/tests/TestHisto2D.cc ============================================================================== --- trunk/tests/TestHisto2D.cc Thu Aug 25 13:21:34 2011 (r364) +++ trunk/tests/TestHisto2D.cc Thu Aug 25 14:47:01 2011 (r365) @@ -32,179 +32,3 @@ -int main() { - - // Creating a histogram and measuring the time it takes to do it. - struct timeval startTime; - struct timeval endTime; - gettimeofday(&startTime, NULL); - Histo2D h(200, 0, 100, 200, 0, 100); - gettimeofday(&endTime, NULL); - - double tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000; - double tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000; - cout << "Time to create 40K bins: " << tE - tS << "s" << endl; - printStats(h); - - - // Trying to fill a bin. - gettimeofday(&startTime, NULL); - for (int i=0; i < 2000; i++) { - int out = h.fill(16.0123, 12.213, 2); - if (out == -1) { - cout << "I wasn't able to find the bin, something must be incorrect in the search algorithm." << endl; - return -1; - } - } - gettimeofday(&endTime, NULL); - - tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000; - tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000; - cout << "Time taken to fill 2000 bins: " << tE - tS << "s" << endl; - if ((tE - tS) > 50.0) { - cout << "Performance is not sufficient. Probably broken caches?" << endl; - return -1; - } - cout << h.numBinsTotal() << endl; - h.addBin(0.1, 0.1, 0.2, 0.2); - h.addBin(110, 0, 200, 12.100); - h.addBin(16.0, 200, 17.0, 300); - - - - printStats(h, false); - cout << h.numBinsTotal() << endl; - - // Testing if fill() function does what it should - unsigned int beforeAdd = h.numBinsTotal(); - cout << "Does a too high bin exist? " << h.fill(10000, 34234, 1) << endl; - if (h.numBinsTotal() != beforeAdd) { - cout << "An incorrect bin seems to have been added. The other solution is an error in numBinsTotal()" << endl; - return -1; - } - - - // Checking if everything is still working as desired. - // It is actually a good thing to do, as at some earlier stages - // in development adding a broken bin destroyed the cache of edges. - int originIndex = h.fill(0.0, 0.0, 1); - cout << "And is the origin working in the right way? " << originIndex << endl; - if (originIndex == -1) { - cout << "The origin was not found!" << endl; - return -1; - } - - printStats(h, true); - - // Now, adding a square that is in a non-overlapping location: - beforeAdd = h.numBinsTotal(); - h.addBin(150, 150, 200, 200); - cout << "Added properly? " << h.fill(150.1, 150.1, 1) << " Size: " << h.numBinsTotal() << endl; - if (beforeAdd == h.numBinsTotal()) { - cout << "A bin that should be added wasn't added." << endl; - return -1; - } - - // Checking if a broken bin triggers _dropEdge(). - beforeAdd = h.numBinsTotal(); - h.addBin(0.756, 0.213, 12.1234, 23); - cout << "Size: " << h.numBinsTotal() << endl; - if (beforeAdd != h.numBinsTotal()) { - cout << "Detection of overlapping edges doesn't work!" << endl; - return -1; - } - - int fillTest = h.fill(0.0, 1.0, 1); - cout << "And a fill sanity check: " << fillTest << endl; - if (fillTest == -1) { - cout << "An undefined error with fill had occured." << endl; - return -1; - } - - // A check testing mostly _fixOrientation() - cout << "Now, how about another quadrant? " << endl; - beforeAdd = h.numBinsTotal(); - h.addBin(-12, -12, -1, -1); - if (beforeAdd == h.numBinsTotal()) { - cout << "A bin that should be added could not be added." << endl; - return -1; - } - - fillTest = h.fill(-3, -3, 1); - cout << "Trying to fill the newly created bin: " << fillTest << endl; - if (fillTest == -1 || fillTest != (int)h.numBinsTotal() - 1) { - cout << "Could not fill the bin that should be filled" << endl; - return -1; - } - - // And a scaling test. - printStats(h, true); - cout << "Scaling: " << endl; - - gettimeofday(&startTime, NULL); - h.scaleXY(2.0, 3.0); - gettimeofday(&endTime, NULL); - tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000; - tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000; - - cout << "Time to scale: " << tE - tS << "s" << endl; - printStats(h, true); - - fillTest = h.fill(180, 180, 1); - cout << "Was everything scaled as it should be? " << fillTest << endl; - if (fillTest == -1) { - cout << "Something went wrong while scaling." << endl; - return -1; - } - - - - // And now, test cuts: - - cout << endl << endl << endl << "Testing cuts: " << endl; - Histo2D sampleHisto(50, 0, 100, 39, 0, 10); - sampleHisto.fill(0,0,123121); - cout << sampleHisto.sumW(false) << " " << sampleHisto.sumW2(false) << endl; - printStats(sampleHisto); - if (!fuzzyEquals(sampleHisto.sumW(false), (double)123121)) { - cout << "Something is wrong with weight filling!!" << endl; - return -1; - } - if (!fuzzyEquals(sampleHisto.sumW2(false), 1.51588e+10)) { - cout << "Something is wrong with weight squared! It is: " << sampleHisto.sumW2(false)<< endl; - return -1; - } - - Histo1D atY(sampleHisto.cutterX(0)); - cout << atY.sumW(false) << " " <<sampleHisto.sumW(false) << endl; - if (!fuzzyEquals(atY.sumW(false), sampleHisto.sumW(false))){ - cout << "Something is wrong with weights when cut parallell to X axis." << endl; - return -1; - } - - Histo1D atX(sampleHisto.cutterY(0)); - cout << atX.sumW(false) << " " << atX.numBins() << endl; - if (!fuzzyEquals(atX.sumW(false), sampleHisto.sumW(false))){ - cout << "Something is wrong with weights when cut parallell to Y axis." << endl; - return -1; - } - - Histo1D atX2(sampleHisto.cutterX(2)); - cout << atX2.sumW(false) << " " << atX2.numBins() << endl; - if (!fuzzyEquals(atX2.sumW(false), 0)){ - cout << "Probably the cuts are not done properly!" << endl; - return -1; - } - - cout << "Testing bin merger:" << endl; - gettimeofday(&startTime, NULL); - h.mergeBins(0, 20000); - gettimeofday(&endTime, NULL); - tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000; - tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000; - - cout << "Time to merge 20k bins: " << tE - tS << "s" << endl; - - cout << "-----------------------------" << endl; - return EXIT_SUCCESS; -}
More information about the yoda-svn mailing list |