[yoda-svn] r316 - in trunk: include/YODA src

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Aug 22 11:50:44 BST 2011


Author: mkawalec
Date: Mon Aug 22 11:50:43 2011
New Revision: 316

Log:
Moved cutter/mkProfile functions from Histo2D.h to Histo2D.cc.

Modified:
   trunk/include/YODA/Histo2D.h
   trunk/src/Histo2D.cc

Modified: trunk/include/YODA/Histo2D.h
==============================================================================
--- trunk/include/YODA/Histo2D.h	Mon Aug 22 11:41:12 2011	(r315)
+++ trunk/include/YODA/Histo2D.h	Mon Aug 22 11:50:43 2011	(r316)
@@ -301,28 +301,7 @@
     /// Note that the created histogram will not have correctly filled underflow and overflow bins.
     /// @todo It's not really *at* the specified y coord: it's for the corresponding bin row.
     /// @todo Change the name!
-    Histo1D cutterX(double atY, const std::string& path="", const std::string& title="") {
-      if (!_axis.isGrid()) throw GridError("Attempt to cut a Histo2D that is not a grid!");
-
-      if (atY < lowEdgeY() || atY > highEdgeY()) throw RangeError("Y is outside the grid");
-      vector<HistoBin1D> tempBins;
-
-      for (double i = binByCoord(lowEdgeX(), atY).xMin(); i < highEdgeX(); i += binByCoord(i, atY).widthX()) {
-        const HistoBin2D& b2 = binByCoord(i, atY);
-        const Dbn1D dbn2(b2.numEntries(), b2.sumW(), b2.sumW2(), b2.sumWX(), b2.sumWX2());
-        tempBins.push_back(HistoBin1D(b2.lowEdgeX(), b2.highEdgeX(), dbn2));
-      }
-
-      /// Setting under/over flows
-      Dbn2D underflow;
-      underflow += _axis.outflows()[7][_axis.getBinRow(_axis.getBinIndex(lowEdgeX(), atY))];
-
-      Dbn2D overflow;
-      overflow += _axis.outflows()[3][_axis.getBinRow(_axis.getBinIndex(lowEdgeX(), atY))];
-
-      return Histo1D(tempBins, _axis.totalDbn().transformX(), underflow.transformX(), overflow.transformX(), path, title);
-
-    }
+    Histo1D cutterX(double atY, const std::string& path="", const std::string& title="");
 
 
     /// @brief Create a Histo1D for the bin slice parallel to the y axis at the specified x coordinate
@@ -330,111 +309,14 @@
     /// Note that the created histogram will not have correctly filled underflow and overflow bins.
     /// @todo It's not really *at* the specified x coord: it's for the corresponding bin row.
     /// @todo Change the name!
-    Histo1D cutterY(double atX, const std::string& path="", const std::string& title="") {
-      if (!_axis.isGrid()) throw GridError("Attempt to cut a Histo2D that is not a grid!");
-
-      if (atX < lowEdgeX() || atX > highEdgeX()) throw RangeError("X is outside the grid");
-      vector<HistoBin1D> tempBins;
-
-      for (double i = binByCoord(atX, lowEdgeY()).yMin(); i < highEdgeY(); i += binByCoord(atX, i).widthY()) {
-        const HistoBin2D& b2 = binByCoord(atX, i);
-        const Dbn1D dbn2(b2.numEntries(), b2.sumW(), b2.sumW2(), b2.sumWX(), b2.sumWX2());
-        tempBins.push_back(HistoBin1D(b2.lowEdgeY(), b2.highEdgeY(), dbn2));
-      }
-
-      /// Setting under/over flows
-      Dbn2D underflow;
-      underflow += _axis.outflows()[1][_axis.getBinColumn(_axis.getBinIndex(atX, lowEdgeY()))];
-
-      Dbn2D overflow;
-      overflow += _axis.outflows()[5][_axis.getBinColumn(_axis.getBinIndex(atX, lowEdgeY()))];
-      Dbn2D total = _axis.totalDbn();
-
-      /// Making sure that we rotate our distributions, as we are cutting paralell to Y axis now
-      total.flipXY();
-      underflow.flipXY();
-      overflow.flipXY();
-
-      return Histo1D(tempBins, total.transformX(), underflow.transformX(), overflow.transformX(), path, title);
-    }
+    Histo1D cutterY(double atX, const std::string& path="", const std::string& title=""); 
 
 
     /// @brief X-wise Profile1D creator from Histo2D
-    Profile1D mkProfileX() {
-      if (!_axis.isGrid()) throw GridError("Profile1D cannot be made from a histogram that is not a grid!");
-
-      vector<ProfileBin1D> prof;
-      for(int i = lowEdgeX() + _axis.bin(0).midpoint().first; i < highEdgeX(); i+= _axis.bin(0).widthX()) {
-        HistoBin2D& bin(_axis.binByCoord(i, lowEdgeY()));
-        HistoBin2D composite(bin.xMin(), bin.xMax(), bin.yMin(), bin.yMax()) ;
-        for(int j = lowEdgeY() + _axis.bin(0).midpoint().second; j < highEdgeY(); j += _axis.bin(0).widthY()) {
-          composite += _axis.binByCoord(i, j);
-        }
-      prof.push_back(composite.transformX());
-      }
-
-      vector<vector<Dbn2D> >& outflows = _axis.outflows();
-
-      /// Properly setting an underflow
-      Dbn2D underflow;
-      underflow += outflows[0][0]; underflow += outflows[6][0];
-      for(size_t i = 0; i < outflows[7].size(); ++i) {
-        underflow += outflows[7][i];
-      }
-
-      /// Setting an overflow
-      Dbn2D overflow;
-      overflow += outflows[2][0]; overflow += outflows[4][0];
-      for(size_t i = 0; i < outflows[3].size(); ++i) {
-        overflow += outflows[3][i];
-      }
-
-      /// And constructing a profile 1D from all this data
-      Profile1D ret(prof, _axis.totalDbn(), underflow, overflow);
-      return ret;
-
-    }
+    Profile1D mkProfileX();
 
     /// @brief Y-wise Profile1D creator from Histo2D
-    Profile1D mkProfileY() {
-      if (!_axis.isGrid()) throw GridError("Profile1D cannot be made from a histogram that is not a grid!");
-
-      vector<ProfileBin1D> prof;
-      for(int i = lowEdgeY() + _axis.bin(0).midpoint().second; i < highEdgeY(); i+= _axis.bin(0).widthY()) {
-        HistoBin2D& bin(_axis.binByCoord(i, lowEdgeY()));
-        HistoBin2D composite(bin.xMin(), bin.xMax(), bin.yMin(), bin.yMax()) ;
-        for(int j = lowEdgeX() + _axis.bin(0).midpoint().first; j < highEdgeX(); j += _axis.bin(0).widthX()) {
-          composite += _axis.binByCoord(i, j);
-        }
-      prof.push_back(composite.transformY());
-      }
-
-      vector<vector<Dbn2D> >& outflows = _axis.outflows();
-
-      /// Properly setting an underflow
-      Dbn2D underflow;
-      underflow += outflows[0][0]; underflow += outflows[2][0];
-      for(size_t i = 0; i < outflows[1].size(); ++i) {
-        underflow += outflows[1][i];
-      }
-
-      /// Setting an overflow
-      Dbn2D overflow;
-      overflow += outflows[6][0]; overflow += outflows[4][0];
-      for(size_t i = 0; i < outflows[5].size(); ++i) {
-        overflow += outflows[5][i];
-      }
-
-      /// Setting a flipped total distribution
-      Dbn2D td = _axis.totalDbn();
-      td.flipXY();
-
-      /// And constructing a profile 1D from all this data
-      Profile1D ret(prof, td, underflow, overflow);
-      return ret;
-
-    }
-
+    Profile1D mkProfileY(); 
     //@}
 
 

Modified: trunk/src/Histo2D.cc
==============================================================================
--- trunk/src/Histo2D.cc	Mon Aug 22 11:41:12 2011	(r315)
+++ trunk/src/Histo2D.cc	Mon Aug 22 11:50:43 2011	(r316)
@@ -82,6 +82,132 @@
     return sigma2/sumW();
   }
 
+
+    Histo1D Histo2D::cutterX(double atY, const std::string& path, const std::string& title) {
+      if (!_axis.isGrid()) throw GridError("Attempt to cut a Histo2D that is not a grid!");
+
+      if (atY < lowEdgeY() || atY > highEdgeY()) throw RangeError("Y is outside the grid");
+      vector<HistoBin1D> tempBins;
+
+      for (double i = binByCoord(lowEdgeX(), atY).xMin(); i < highEdgeX(); i += binByCoord(i, atY).widthX()) {
+        const HistoBin2D& b2 = binByCoord(i, atY);
+        const Dbn1D dbn2(b2.numEntries(), b2.sumW(), b2.sumW2(), b2.sumWX(), b2.sumWX2());
+        tempBins.push_back(HistoBin1D(b2.lowEdgeX(), b2.highEdgeX(), dbn2));
+      }
+
+      /// Setting under/over flows
+      Dbn2D underflow;
+      underflow += _axis.outflows()[7][_axis.getBinRow(_axis.getBinIndex(lowEdgeX(), atY))];
+
+      Dbn2D overflow;
+      overflow += _axis.outflows()[3][_axis.getBinRow(_axis.getBinIndex(lowEdgeX(), atY))];
+
+      return Histo1D(tempBins, _axis.totalDbn().transformX(), underflow.transformX(), overflow.transformX(), path, title);
+
+    }
+
+
+    Histo1D Histo2D::cutterY(double atX, const std::string& path, const std::string& title) {
+      if (!_axis.isGrid()) throw GridError("Attempt to cut a Histo2D that is not a grid!");
+
+      if (atX < lowEdgeX() || atX > highEdgeX()) throw RangeError("X is outside the grid");
+      vector<HistoBin1D> tempBins;
+
+      for (double i = binByCoord(atX, lowEdgeY()).yMin(); i < highEdgeY(); i += binByCoord(atX, i).widthY()) {
+        const HistoBin2D& b2 = binByCoord(atX, i);
+        const Dbn1D dbn2(b2.numEntries(), b2.sumW(), b2.sumW2(), b2.sumWX(), b2.sumWX2());
+        tempBins.push_back(HistoBin1D(b2.lowEdgeY(), b2.highEdgeY(), dbn2));
+      }
+
+      /// Setting under/over flows
+      Dbn2D underflow;
+      underflow += _axis.outflows()[1][_axis.getBinColumn(_axis.getBinIndex(atX, lowEdgeY()))];
+
+      Dbn2D overflow;
+      overflow += _axis.outflows()[5][_axis.getBinColumn(_axis.getBinIndex(atX, lowEdgeY()))];
+      Dbn2D total = _axis.totalDbn();
+
+      /// Making sure that we rotate our distributions, as we are cutting paralell to Y axis now
+      total.flipXY();
+      underflow.flipXY();
+      overflow.flipXY();
+
+      return Histo1D(tempBins, total.transformX(), underflow.transformX(), overflow.transformX(), path, title);
+    }
+
+    Profile1D Histo2D::mkProfileX() {
+      if (!_axis.isGrid()) throw GridError("Profile1D cannot be made from a histogram that is not a grid!");
+
+      vector<ProfileBin1D> prof;
+      for(int i = lowEdgeX() + _axis.bin(0).midpoint().first; i < highEdgeX(); i+= _axis.bin(0).widthX()) {
+        HistoBin2D& bin(_axis.binByCoord(i, lowEdgeY()));
+        HistoBin2D composite(bin.xMin(), bin.xMax(), bin.yMin(), bin.yMax()) ;
+        for(int j = lowEdgeY() + _axis.bin(0).midpoint().second; j < highEdgeY(); j += _axis.bin(0).widthY()) {
+          composite += _axis.binByCoord(i, j);
+        }
+      prof.push_back(composite.transformX());
+      }
+
+      vector<vector<Dbn2D> >& outflows = _axis.outflows();
+
+      /// Properly setting an underflow
+      Dbn2D underflow;
+      underflow += outflows[0][0]; underflow += outflows[6][0];
+      for(size_t i = 0; i < outflows[7].size(); ++i) {
+        underflow += outflows[7][i];
+      }
+
+      /// Setting an overflow
+      Dbn2D overflow;
+      overflow += outflows[2][0]; overflow += outflows[4][0];
+      for(size_t i = 0; i < outflows[3].size(); ++i) {
+        overflow += outflows[3][i];
+      }
+
+      /// And constructing a profile 1D from all this data
+      Profile1D ret(prof, _axis.totalDbn(), underflow, overflow);
+      return ret;
+
+    }
+
+    Profile1D Histo2D::mkProfileY() {
+      if (!_axis.isGrid()) throw GridError("Profile1D cannot be made from a histogram that is not a grid!");
+
+      vector<ProfileBin1D> prof;
+      for(int i = lowEdgeY() + _axis.bin(0).midpoint().second; i < highEdgeY(); i+= _axis.bin(0).widthY()) {
+        HistoBin2D& bin(_axis.binByCoord(i, lowEdgeY()));
+        HistoBin2D composite(bin.xMin(), bin.xMax(), bin.yMin(), bin.yMax()) ;
+        for(int j = lowEdgeX() + _axis.bin(0).midpoint().first; j < highEdgeX(); j += _axis.bin(0).widthX()) {
+          composite += _axis.binByCoord(i, j);
+        }
+      prof.push_back(composite.transformY());
+      }
+
+      vector<vector<Dbn2D> >& outflows = _axis.outflows();
+
+      /// Properly setting an underflow
+      Dbn2D underflow;
+      underflow += outflows[0][0]; underflow += outflows[2][0];
+      for(size_t i = 0; i < outflows[1].size(); ++i) {
+        underflow += outflows[1][i];
+      }
+
+      /// Setting an overflow
+      Dbn2D overflow;
+      overflow += outflows[6][0]; overflow += outflows[4][0];
+      for(size_t i = 0; i < outflows[5].size(); ++i) {
+        overflow += outflows[5][i];
+      }
+
+      /// Setting a flipped total distribution
+      Dbn2D td = _axis.totalDbn();
+      td.flipXY();
+
+      /// And constructing a profile 1D from all this data
+      Profile1D ret(prof, td, underflow, overflow);
+      return ret;
+
+    }
   
   /// @todo Check how finding the correct bins works in the case of 
   /// a sparse representation, and if it is decent, code it in here.


More information about the yoda-svn mailing list