Index: src/Fragmentation/Histogram/Histogram.cpp
===================================================================
--- src/Fragmentation/Histogram/Histogram.cpp	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
+++ src/Fragmentation/Histogram/Histogram.cpp	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
@@ -0,0 +1,155 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Histogram.cpp
+ *
+ *  Created on: Jul 26, 2012
+ *      Author: heber
+ */
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "Histogram.hpp"
+
+#include <algorithm>
+#include <cmath>
+#include <sstream>
+
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+
+#include "CodePatterns/Assert.hpp"
+#include "CodePatterns/Log.hpp"
+
+/** Tiny helper struct to create equally spaced bins with count of zero.
+ *
+ */
+struct BinCreator_t {
+  BinCreator_t( const double lowerend, const double _width ) :
+    currentstart(lowerend),
+    width(_width)
+  {}
+  Histogram::Bin_t operator()() {
+    Histogram::Bin_t bin( make_pair( currentstart, 0.) );
+    currentstart+=width;
+    return bin;
+  }
+private:
+  double currentstart;
+  const double width;
+};
+
+// see http://stackoverflow.com/questions/634087/stdcopy-to-stdcout-for-stdpair
+// printing a pair is not easy, especially so with ostream_iterator as it cannot find
+// overload operator<<() as it is not in namespace std.
+template <class T>
+struct PrintPair : public std::unary_function<T, void>
+{
+    std::ostream& os;
+    PrintPair(std::ostream& strm) : os(strm) {}
+
+    void operator()(const T& elem) const
+    {
+      os << "(" << elem.first << "," << elem.second << ") ";
+    }
+};
+
+Histogram::Histogram(const samples_t &samples, const int _CountBins) :
+    binwidth(0.5),
+    CountBins(_CountBins)
+{
+  // build histogram from samples
+  if (!samples.empty()) {
+    if (CountBins == -1) {
+      CountBins = ceil(pow(samples.size(), 1./3.));
+    }
+    // 2. get min and max and determine width
+    samples_t::const_iterator maxiter = max_element(samples.begin(), samples.end());
+    samples_t::const_iterator miniter = min_element(samples.begin(), samples.end());
+    ASSERT((maxiter != samples.end()) || (miniter != samples.end()),
+        "Histogram::Histogram() - cannot find min/max despite non-empty range.");
+      LOG(1, "DEBUG: min is " << *miniter << " and max is " << *maxiter << ".");
+    binwidth = (*maxiter - *miniter)/(CountBins-1);
+
+    // 3. create each bin
+    BinCreator_t BinCreator( *miniter, binwidth );
+    std::vector<Bin_t> vectorbins;
+    // we need one extra bin for getBin()'s find to work properly
+    vectorbins.resize(CountBins+1, Bin_t( make_pair(0., 0.) ) );
+    std::generate( vectorbins.begin(), vectorbins.end(), BinCreator );
+    std::stringstream output;
+    std::for_each( vectorbins.begin(), vectorbins.end(), PrintPair<Bin_t>(output));
+    LOG(2, "DEBUG: Bins are " << output.str() << ".");
+    bins.insert(vectorbins.begin(), vectorbins.end());
+
+    // 4. place each sample into bin
+    BOOST_FOREACH( double value, samples) {
+      const Bins_t::iterator biniter = getBin(value);
+      ASSERT( biniter != bins.end(),
+          "Histogram::Histogram() - cannot find bin for value from given samples.");
+      biniter->second += 1.;
+    }
+  } else {
+    LOG(1, "INFO: Given vector of samples is empty.");
+  }
+}
+
+Histogram& Histogram::operator+=(const Histogram &other)
+{
+  return *this;
+}
+
+Histogram& Histogram::operator-=(const Histogram &other)
+{
+  return *this;
+}
+
+bool Histogram::isEmpty() const
+{
+  bool status = true;
+  for (Bins_t::const_iterator iter = bins.begin(); iter != bins.end(); ++iter)
+    status &= iter->second == 0;
+  return status;
+}
+
+Histogram::Bins_t::iterator Histogram::getBin(const double _value)
+{
+  // \note we may use equal_range as our bins are always sorted
+  Bins_t::iterator iter = bins.lower_bound(_value);
+  // if we are not on the boundary we have to step back by one
+  if (iter != bins.end()) {
+    if (_value != iter->first)
+      --iter;
+  }
+  // if we actually are on boundary of "last bin", set to end
+  if ((_value == iter->first) && (iter == --bins.end()))
+      iter = bins.end();
+
+  return iter;
+}
Index: src/Fragmentation/Histogram/Histogram.hpp
===================================================================
--- src/Fragmentation/Histogram/Histogram.hpp	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
+++ src/Fragmentation/Histogram/Histogram.hpp	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
@@ -0,0 +1,93 @@
+/*
+ * Histogram.hpp
+ *
+ *  Created on: Jul 26, 2012
+ *      Author: heber
+ */
+
+#ifndef HISTOGRAM_HPP_
+#define HISTOGRAM_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <map>
+#include <vector>
+
+class HistogramTest;
+
+/** This class generates a histogram from a given vector of sampled values.
+ *
+ * Most importantly, it also contains operator+=() and operator-=() to perform
+ * sum on the \b histograms.
+ *
+ * This is to be used with the OrthogonalSummation which requires these specific
+ * operator implementations.
+ *
+ */
+class Histogram
+{
+  //!> grant unit test access to private parts
+  friend class HistogramTest;
+public:
+  //!> named type for a vector of sample values
+  typedef std::vector<double> samples_t;
+  //!> named type for the start of a bin
+  typedef double BinLowerEnd;
+  //!> named type for the count of a bin, may be fractional
+  typedef double BinWeight;
+  //!> named type for the pair identifying a bin by its lower end and count
+  typedef std::pair< BinLowerEnd, BinWeight> Bin_t;
+private:
+  //!> named type for a vector of bins
+  typedef std::map< BinLowerEnd, BinWeight > Bins_t;
+public:
+  /** Constructor for class Histogram.
+   *
+   * @param samples samples to put in the histogram.
+   * @param CountBins number of bins (if negative, we choose number by statistical means)
+   */
+  Histogram(const samples_t &samples, const int _CountBins=-1);
+
+  /** Adding another histogram onto this one.
+   *
+   * @param other other histogram
+   * @return ref to this instance
+   */
+  Histogram& operator+=(const Histogram &other);
+
+  /** Subtracting another histogram from this one.
+   *
+   * @param other other histogram
+   * @return ref to this instance
+   */
+  Histogram& operator-=(const Histogram &other);
+
+  /** States whether each bin of this histogram has count of zero.
+   *
+   * @return true - all bins are zero, false - else
+   */
+  bool isEmpty() const;
+
+private:
+  /** Returns the iterator to the bin into which the \a value fits.
+   *
+   * @param _value value to fit.
+   * @return iterator to bin or to bins.end() if not matching
+   */
+  Bins_t::iterator getBin(const double _value);
+
+private:
+  //!> vector of bins containing the histogram
+  Bins_t bins;
+  //!> width of bin
+  double binwidth;
+  //!> number of bins
+  int CountBins;
+};
+
+
+#endif /* HISTOGRAM_HPP_ */
Index: src/Fragmentation/Histogram/Makefile.am
===================================================================
--- src/Fragmentation/Histogram/Makefile.am	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
+++ src/Fragmentation/Histogram/Makefile.am	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
@@ -0,0 +1,55 @@
+# PLEASE adhere to the alphabetical ordering in this Makefile!
+# Also indentation by a single tab
+
+FRAGMENTATIONHISTOGRAMSOURCE = \
+	Fragmentation/Histogram/Histogram.cpp
+
+FRAGMENTATIONHISTOGRAMHEADER = \
+	Fragmentation/Histogram/Histogram.hpp
+
+
+noinst_LTLIBRARIES += libMolecuilderFragmentationHistogram.la
+libMolecuilderFragmentationHistogram_la_includedir = $(includedir)/MoleCuilder/Fragmentation/Histogram/
+libMolecuilderFragmentationHistogram_la_CPPFLAGS = ${BOOST_CPPFLAGS} ${CodePatterns_CFLAGS}
+libMolecuilderFragmentationHistogram_la_LDFLAGS = -ldl ${BOOST_LDFLAGS}
+libMolecuilderFragmentationHistogram_la_LIBADD = \
+	${CodePatterns_LIBS}
+
+
+nobase_libMolecuilderFragmentationHistogram_la_include_HEADERS = ${FRAGMENTATIONHISTOGRAMHEADER}
+
+## Define the source file list for the "libexample-@MOLECUILDER_API_VERSION@.la"
+## target.  Note that @MOLECUILDER_API_VERSION@ is not interpreted by Automake and
+## will therefore be treated as if it were literally part of the target name,
+## and the variable name derived from that.
+## The file extension .cc is recognized by Automake, and makes it produce
+## rules which invoke the C++ compiler to produce a libtool object file (.lo)
+## from each source file.  Note that it is not necessary to list header files
+## which are already listed elsewhere in a _HEADERS variable assignment.
+libMolecuilderFragmentationHistogram_la_SOURCES = ${FRAGMENTATIONHISTOGRAMSOURCE}
+
+## Instruct libtool to include ABI version information in the generated shared
+## library file (.so).  The library ABI version is defined in configure.ac, so
+## that all version information is kept in one place.
+#libMolecuilderFragmentationHistogram_la_LDFLAGS = -version-info $(MOLECUILDER_SO_VERSION)
+
+## The generated configuration header is installed in its own subdirectory of
+## $(libdir).  The reason for this is that the configuration information put
+## into this header file describes the target platform the installed library
+## has been built for.  Thus the file must not be installed into a location
+## intended for architecture-independent files, as defined by the Filesystem
+## Hierarchy Standard (FHS).
+## The nodist_ prefix instructs Automake to not generate rules for including
+## the listed files in the distribution on 'make dist'.  Files that are listed
+## in _HEADERS variables are normally included in the distribution, but the
+## configuration header file is generated at configure time and should not be
+## shipped with the source tarball.
+#libMolecuilderFragmentationHistogram_libincludedir = $(libdir)/MoleCuilder/include
+#nodist_libMolecuilderFragmentationHistogram_libinclude_HEADERS = $(top_builddir)/libmolecuilder_config.h
+
+## Install the generated pkg-config file (.pc) into the expected location for
+## architecture-dependent package configuration information.  Occasionally,
+## pkg-config files are also used for architecture-independent data packages,
+## in which case the correct install location would be $(datadir)/pkgconfig.
+#pkgconfigdir = $(libdir)/pkgconfig
+#pkgconfig_DATA = $(top_builddir)/MoleCuilder.pc
Index: src/Fragmentation/Histogram/unittests/HistogramUnitTest.cpp
===================================================================
--- src/Fragmentation/Histogram/unittests/HistogramUnitTest.cpp	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
+++ src/Fragmentation/Histogram/unittests/HistogramUnitTest.cpp	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
@@ -0,0 +1,129 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * HistogramUnitTest.cpp
+ *
+ *  Created on: Jul 26, 2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+using namespace std;
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include "Fragmentation/Histogram/Histogram.hpp"
+
+#include "HistogramUnitTest.hpp"
+
+#include <boost/assign.hpp>
+
+#ifdef HAVE_TESTRUNNER
+#include "UnitTestMain.hpp"
+#endif /*HAVE_TESTRUNNER*/
+
+using namespace boost::assign;
+
+/********************************************** Test classes **************************************/
+
+// Registers the fixture into the 'registry'
+CPPUNIT_TEST_SUITE_REGISTRATION( HistogramTest );
+
+
+void HistogramTest::setUp()
+{
+  histogram = NULL;
+}
+
+
+void HistogramTest::tearDown()
+{
+  delete histogram;
+}
+
+/** UnitTest for getBin()
+ */
+void HistogramTest::getBin_Test()
+{
+  // generate non-empty histogramgram
+  Histogram::samples_t sampled_values;
+  sampled_values += 1.,2.,3.,4.;
+  CPPUNIT_ASSERT_EQUAL( (size_t)4, sampled_values.size() );
+  histogram = new Histogram(sampled_values, 4);
+  CPPUNIT_ASSERT_EQUAL( (size_t)4+1, histogram->bins.size() );
+  CPPUNIT_ASSERT( histogram->bins.end() != histogram->bins.begin() );
+  CPPUNIT_ASSERT_EQUAL( 1., histogram->bins.begin()->first );
+
+  // check values inside
+  CPPUNIT_ASSERT( histogram->bins.end() != histogram->getBin(1.) );
+  CPPUNIT_ASSERT_EQUAL( 1., histogram->getBin(1.)->first );
+  CPPUNIT_ASSERT( histogram->bins.end() != histogram->getBin(2.) );
+  CPPUNIT_ASSERT_EQUAL( 2., histogram->getBin(2.)->first );
+  CPPUNIT_ASSERT( histogram->bins.end() != histogram->getBin(3.) );
+  CPPUNIT_ASSERT_EQUAL( 3., histogram->getBin(3.)->first );
+  CPPUNIT_ASSERT( histogram->bins.end() != histogram->getBin(4.) );
+  CPPUNIT_ASSERT_EQUAL( 4., histogram->getBin(4.)->first );
+  CPPUNIT_ASSERT( histogram->bins.end() != histogram->getBin(1.5) );
+  CPPUNIT_ASSERT_EQUAL( 1., histogram->getBin(1.5)->first );
+  CPPUNIT_ASSERT( histogram->bins.end() != histogram->getBin(2.5) );
+  CPPUNIT_ASSERT_EQUAL( 2., histogram->getBin(2.5)->first );
+  CPPUNIT_ASSERT( histogram->bins.end() != histogram->getBin(3.5) );
+  CPPUNIT_ASSERT_EQUAL( 3., histogram->getBin(3.5)->first );
+  CPPUNIT_ASSERT( histogram->bins.end() != histogram->getBin(4.5) );
+  CPPUNIT_ASSERT_EQUAL( 4., histogram->getBin(4.5)->first );
+
+  // check values outside
+  CPPUNIT_ASSERT( histogram->bins.end() == histogram->getBin(.9) );
+  CPPUNIT_ASSERT( histogram->bins.end() == histogram->getBin(5.01) );
+  CPPUNIT_ASSERT( histogram->bins.end() == histogram->getBin(5.) );
+}
+
+/** UnitTest for isEmpty
+ */
+void HistogramTest::isEmpty_Test()
+{
+  histogram = new Histogram(std::vector<double>());
+  // test on empty histogramgram
+  CPPUNIT_ASSERT( histogram->isEmpty() );
+
+  // create non-empty histogram and test
+  Histogram::samples_t sampled_values;
+  sampled_values += 1.,2.,3.,4.;
+  delete histogram;
+  histogram = new Histogram(sampled_values, 4);
+  CPPUNIT_ASSERT( !histogram->isEmpty() );
+
+}
+
+/** UnitTest for operator+=(), operator-=()
+ */
+void HistogramTest::operator_Test()
+{
+}
+
Index: src/Fragmentation/Histogram/unittests/HistogramUnitTest.hpp
===================================================================
--- src/Fragmentation/Histogram/unittests/HistogramUnitTest.hpp	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
+++ src/Fragmentation/Histogram/unittests/HistogramUnitTest.hpp	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
@@ -0,0 +1,43 @@
+/*
+ * HistogramUnitTest.hpp
+ *
+ *  Created on: Jul 26, 2012
+ *      Author: heber
+ */
+
+#ifndef HISTOGRAMUNITTEST_HPP_
+#define HISTOGRAMUNITTEST_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <cppunit/extensions/HelperMacros.h>
+
+class Histogram;
+
+/********************************************** Test classes **************************************/
+
+class HistogramTest : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE( HistogramTest) ;
+    CPPUNIT_TEST ( getBin_Test );
+    CPPUNIT_TEST ( isEmpty_Test );
+    CPPUNIT_TEST ( operator_Test );
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+      void setUp();
+      void tearDown();
+      void getBin_Test();
+      void isEmpty_Test();
+      void operator_Test();
+
+private:
+      Histogram *histogram;
+
+};
+
+#endif /* HISTOGRAMUNITTEST_HPP_ */
Index: src/Fragmentation/Histogram/unittests/Makefile.am
===================================================================
--- src/Fragmentation/Histogram/unittests/Makefile.am	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
+++ src/Fragmentation/Histogram/unittests/Makefile.am	(revision c4fd03029d3c59c8aa32a73a4e4e4afd60d9e7d4)
@@ -0,0 +1,28 @@
+# PLEASE adhere to the alphabetical ordering in this Makefile!
+# Also indentation by a single tab
+
+FRAGMENTATIONHISTOGRAMTESTSSOURCES = \
+	../Fragmentation/Histogram/unittests/HistogramUnitTest.cpp
+
+FRAGMENTATIONHISTOGRAMTESTSHEADERS = \
+	../Fragmentation/Histogram/unittests/HistogramUnitTest.hpp
+
+FRAGMENTATIONHISTOGRAMTESTS = \
+  HistogramUnitTest
+
+TESTS += $(FRAGMENTATIONHISTOGRAMTESTS)
+check_PROGRAMS += $(FRAGMENTATIONHISTOGRAMTESTS) 
+noinst_PROGRAMS += $(FRAGMENTATIONHISTOGRAMTESTS)
+
+FRAGMENTATIONHISTOGRAMLIBS = \
+	../libMolecuilderFragmentationHistogram.la \
+	${CodePatterns_LIBS} \
+	$(BOOST_LIB)
+
+
+HistogramUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
+	../Fragmentation/Histogram/unittests/HistogramUnitTest.cpp \
+	../Fragmentation/Histogram/unittests/HistogramUnitTest.hpp
+HistogramUnitTest_LDADD = ${FRAGMENTATIONHISTOGRAMLIBS}
+
+#AUTOMAKE_OPTIONS = parallel-tests
