[yoda-svn] r356 - in trunk: include/YODA tests/Histo1D tests/Profile1D tests/Scatter2D

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Thu Aug 25 09:39:48 BST 2011


Author: mkawalec
Date: Thu Aug 25 09:39:47 2011
New Revision: 356

Log:
Some buxfixes, repaired some constructors, added more tests. Basically everything fone yesterday from 3pm onwards (broken svn).

Deleted:
   trunk/tests/Histo1D/Constructors.cc
   trunk/tests/Histo1D/Create.cc
   trunk/tests/Histo1D/Fill.cc
   trunk/tests/Histo1D/Modify.cc
Modified:
   trunk/include/YODA/Axis1D.h
   trunk/include/YODA/Point2D.h
   trunk/include/YODA/Profile1D.h
   trunk/include/YODA/Scatter2D.h
   trunk/tests/Profile1D/P1DFill.cc
   trunk/tests/Profile1D/P1DModify.cc
   trunk/tests/Scatter2D/S2DCreate.cc
   trunk/tests/Scatter2D/S2DModify.cc

Modified: trunk/include/YODA/Axis1D.h
==============================================================================
--- trunk/include/YODA/Axis1D.h	Thu Aug 25 09:05:22 2011	(r355)
+++ trunk/include/YODA/Axis1D.h	Thu Aug 25 09:39:47 2011	(r356)
@@ -407,7 +407,9 @@
 
     /// Check if a hypothetical bin to be added, starting at from and
     /// ending at to will partially overlap any of the existing bins.
-    bool _findCuts(const double& from, const double& to) const {
+    bool _findCuts(double from, double to) const {
+      from += 0.00000001;
+      to   -= 0.00000001;
       size_t index1 = _binaryS(from, 0, _binHashSparse.size());
       size_t index2 = _binaryS(to, 0, _binHashSparse.size());
       return !(index1 == index2);

Modified: trunk/include/YODA/Point2D.h
==============================================================================
--- trunk/include/YODA/Point2D.h	Thu Aug 25 09:05:22 2011	(r355)
+++ trunk/include/YODA/Point2D.h	Thu Aug 25 09:39:47 2011	(r356)
@@ -45,7 +45,7 @@
       : _x(x), _y(y)
     {
       _ex = std::make_pair(exminus, explus);
-      _ey = std::make_pair(eyplus, eyplus);
+      _ey = std::make_pair(eyminus, eyplus);
     }
 
 

Modified: trunk/include/YODA/Profile1D.h
==============================================================================
--- trunk/include/YODA/Profile1D.h	Thu Aug 25 09:05:22 2011	(r355)
+++ trunk/include/YODA/Profile1D.h	Thu Aug 25 09:39:47 2011	(r356)
@@ -140,15 +140,15 @@
     }
 
     /// Bin addition operator
-    void addBin(size_t& from, size_t& to) {
+    void addBin(size_t from, size_t to) {
       _axis.addBin(from, to);
     }
 
-    void addBin(const std::vector<double>& binedges) {
+    void addBin(const std::vector<double> binedges) {
       _axis.addBin(binedges);
     }
 
-    void addBin(const std::vector<std::pair<double,double> >& edges) {
+    void addBin(const std::vector<std::pair<double,double> > edges) {
       _axis.addBin(edges);
     }
 

Modified: trunk/include/YODA/Scatter2D.h
==============================================================================
--- trunk/include/YODA/Scatter2D.h	Thu Aug 25 09:05:22 2011	(r355)
+++ trunk/include/YODA/Scatter2D.h	Thu Aug 25 09:39:47 2011	(r356)
@@ -243,9 +243,9 @@
     }
 
     /// Insert a new point, defined as the x/y value pair and asymmetric errors
-    Scatter2D& addPoint(double x, double exminus, double explus,
-                        double y, double eyminus, double eyplus) {
-      _points.insert(Point2D(x, exminus, explus, y, eyminus, eyplus));
+    Scatter2D& addPoint(double x, double y, double exminus, double explus,
+                        double eyminus, double eyplus) {
+      _points.insert(Point2D(x, y, exminus, explus, eyminus, eyplus));
       return *this;
     }
 

Modified: trunk/tests/Profile1D/P1DFill.cc
==============================================================================
--- trunk/tests/Profile1D/P1DFill.cc	Thu Aug 25 09:05:22 2011	(r355)
+++ trunk/tests/Profile1D/P1DFill.cc	Thu Aug 25 09:39:47 2011	(r356)
@@ -7,7 +7,7 @@
 int main() {
   Profile1D p(100, 0, 100);
 
-  cout << "Testing fill operator                    ";
+  cout << "Testing fill operator:                   ";
   p.fill(1,1,2);
   if(p.sumW() != 2 || p.sumW2() != 4) {
     cout << "FAIL" << endl;
@@ -15,5 +15,37 @@
   }
   cout << "PASS" << endl;
 
+  cout << "Testing the fill of the underflow:       ";
+  p.fill(-10,2,3);
+  if(p.underflow().xMean() != -10){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(p.underflow().yMean() != 2){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(p.underflow().sumW() != 3 || p.underflow().sumW2() != 9){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+  
+  cout << "Testing the fill of the underflow:       ";
+  p.fill(110,2,3);
+  if(p.overflow().xMean() != 110){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(p.overflow().yMean() != 2){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(p.overflow().sumW() != 3 || p.overflow().sumW2() != 9){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
   return EXIT_SUCCESS;
 }

Modified: trunk/tests/Profile1D/P1DModify.cc
==============================================================================
--- trunk/tests/Profile1D/P1DModify.cc	Thu Aug 25 09:05:22 2011	(r355)
+++ trunk/tests/Profile1D/P1DModify.cc	Thu Aug 25 09:39:47 2011	(r356)
@@ -5,5 +5,78 @@
 using namespace YODA;
 
 int main() {
+  Profile1D p(100,0,100);
+  p.fill(1,1,2);
+
+  cout << "Scaling the height:                      ";
+  p.scaleW(3);
+  if(p.sumW() != 6 || p.sumW2() != 36) {
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Resetting the profile:                   ";
+  p.reset();
+  if(p.sumW() != 0 || p.sumW2() != 0){  
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Merging the bins:                        ";
+  p.mergeBins(0,10);
+  if(p.bin(0).xMin() != 0 || p.bin(0).xMax() != 11){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(p.numBins() != 90){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Testing rebinning:                       ";
+  p.rebin(2);
+  for(size_t i = 1; i < p.bins().size() - 1; ++i){
+    if(2 != p.bin(i).width()){
+      cout << "FAIL" << endl;
+      return -1;
+    }
+  }
+  if(p.numBins() != 45){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Trying to add a bin (first method):      ";
+  p.addBin(110, 120);
+  if(p.numBins() != 46){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Trying to add a bin (second method):     ";
+  vector<double> test;
+  test.push_back(120); test.push_back( 140); test.push_back(145);
+  p.addBin(test);
+  if(p.numBins() != 48){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Trying to add a bin (third method):      ";
+  vector<pair<double,double> > test2;
+  test2.push_back(make_pair(180,190));
+  p.addBin(test2);
+  if(p.numBins() != 49){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
   return EXIT_SUCCESS;
 }

Modified: trunk/tests/Scatter2D/S2DCreate.cc
==============================================================================
--- trunk/tests/Scatter2D/S2DCreate.cc	Thu Aug 25 09:05:22 2011	(r355)
+++ trunk/tests/Scatter2D/S2DCreate.cc	Thu Aug 25 09:39:47 2011	(r356)
@@ -1,9 +1,61 @@
 #include "YODA/Scatter2D.h"
+#include "YODA/Point2D.h"
 
 #include <iostream>
 using namespace std;
 using namespace YODA;
 
 int main() {
+  cout << "Constructing a scatter (empty const):    ";
+  Scatter2D s1();
+  cout << "PASS" << endl;
+  
+  
+  cout << "Constructing a scatter (vector of points)";
+  vector<Point2D> points;
+  Point2D apoint(0,0,0);
+  points.push_back(apoint);
+
+  Scatter2D s2(points);
+  cout << "PASS" << endl;
+
+  cout << "Constructing a scatter (values, no errs) ";
+  vector<double> values;
+  values.push_back(0);
+  Scatter2D s3(values, values);
+  cout << "PASS" << endl;
+
+  cout << "Constructing a scatter (values, sym errs)";
+  Scatter2D s4(values, values, values, values);
+  cout << "PASS" << endl;
+
+  cout << "Constructing a scatter (sym err x,asym y)";
+  vector<pair<double, double> > valuesS;
+  valuesS.push_back(make_pair(0,0));
+  Scatter2D s5(values, values, values, valuesS);
+  cout << "PASS" << endl;
+
+  cout << "Constructing a scatter (asym x, asym y)  ";
+  Scatter2D s6(values, values, valuesS, valuesS);
+  cout << "PASS" << endl;
+
+  cout << "Constructing a scatter (axym x, sym y)   ";
+  Scatter2D s7(values, values, valuesS, values);
+  cout << "PASS" << endl;
+
+  cout << "Constructing a scatter (explicit asym)   ";
+  Scatter2D s8(values, values, values, values, values, values);
+  cout << "PASS" << endl;
+
+  cout << "Testing a copy operator:                 ";
+  Scatter2D s9(s8);
+  cout << "PASS" << endl;
+
+  cout << "Testing an assignment operator:          ";
+  Scatter2D s10(s9);
+  s10 = s7;
+  cout << "PASS" << endl;
+
+  
   return EXIT_SUCCESS;
 }

Modified: trunk/tests/Scatter2D/S2DModify.cc
==============================================================================
--- trunk/tests/Scatter2D/S2DModify.cc	Thu Aug 25 09:05:22 2011	(r355)
+++ trunk/tests/Scatter2D/S2DModify.cc	Thu Aug 25 09:39:47 2011	(r356)
@@ -5,5 +5,142 @@
 using namespace YODA;
 
 int main() {
+  vector<double> coords;
+  coords.push_back(0); coords.push_back(1);
+  Scatter2D s1(coords, coords);
+  
+  cout << "Scaling the scatter:                     ";
+  s1.scale(2,3);
+  if(s1.point(1).x() != 2 || s1.point(1).y() != 3){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Adding a point (first method):           ";
+  Point2D point(1,1);
+  s1.addPoint(point);
+  if(s1.numPoints() != 3){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(s1.point(1).x() != 1 || s1.point(1).y() != 1){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Adding a point (second method):          ";
+  s1.addPoint(-1, -1);
+  if(s1.numPoints() != 4){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(s1.point(0).x() != -1 || s1.point(0).y() != -1){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Adding a point (third method):           ";
+  s1.addPoint(5,4,6,3);
+  if(s1.numPoints() != 5){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(s1.point(4).x() != 5 || s1.point(4).y() != 4 || 
+     s1.point(4).xErrMinus() != 6 || s1.point(4).xErrPlus() != 6 ||
+     s1.point(4).yErrMinus() != 3 || s1.point(4).yErrPlus() != 3){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Adding a point (fourth method):          ";
+  pair<double, double> errs;
+  errs = make_pair(1,2);
+  s1.addPoint(10,11, errs, 2);
+  if(s1.numPoints() != 6){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(s1.point(5).x() != 10 || s1.point(5).y() != 11 || 
+     s1.point(5).xErrMinus() != 1 || s1.point(5).xErrPlus() != 2 ||
+     s1.point(5).yErrMinus() != 2 || s1.point(5).yErrPlus() != 2){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Adding a point (fifth method):           ";
+  s1.addPoint(12,14,6,errs);
+  if(s1.numPoints() != 7){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(s1.point(6).x() != 12 || s1.point(6).y() != 14 || 
+     s1.point(6).xErrMinus() != 6 || s1.point(6).xErrPlus() != 6 ||
+     s1.point(6).yErrMinus() != 1 || s1.point(6).yErrPlus() != 2){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Adding a point (sixth method):           ";
+  pair<double, double> errsy;
+  errsy = make_pair(100, 200);
+  s1.addPoint(300, 400, errs, errsy);
+  if(s1.numPoints() != 8){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(s1.point(7).x() != 300 || s1.point(7).y() != 400 || 
+     s1.point(7).xErrMinus() != 1 || s1.point(7).xErrPlus() != 2 ||
+     s1.point(7).yErrMinus() != 100 || s1.point(7).yErrPlus() != 200){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Adding a point (seventh method):         ";
+  s1.addPoint(300, 400, 1, 2, 3, 4);
+  if(s1.numPoints() != 9){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+
+  if(s1.point(8).x() != 300 || s1.point(8).y() != 400 || 
+     s1.point(8).xErrMinus() != 1 || s1.point(8).xErrPlus() != 2 ||
+     s1.point(8).yErrMinus() != 3 || s1.point(8).yErrPlus() != 4){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Adding a point (eighth method):          ";
+  Point2D p2(800, 900); Point2D p3(1000, 1000);
+  vector<Point2D> p5; p5.push_back(p2); p5.push_back(p3);
+  s1.addPoints(p5);
+  if(s1.numPoints() != 11){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  if(s1.point(9).x() != 800 || s1.point(9).y() != 900 || 
+     s1.point(9).xErrMinus() != 0 || s1.point(9).xErrPlus() != 0 ||
+     s1.point(9).yErrMinus() != 0 || s1.point(9).yErrPlus() != 0 ||
+     s1.point(10).x() != 1000 || s1.point(10).y() != 1000){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Trying to reset the scatter:             ";
+  s1.reset();
+  if(s1.numPoints() != 0){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+  
   return EXIT_SUCCESS;
 }


More information about the yoda-svn mailing list