Line data Source code
1 : /********************************************************************/ 2 : /* SOFTWARE COPYRIGHT NOTIFICATION */ 3 : /* Cardinal */ 4 : /* */ 5 : /* (c) 2021 UChicago Argonne, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /* */ 8 : /* Prepared by UChicago Argonne, LLC */ 9 : /* Under Contract No. DE-AC02-06CH11357 */ 10 : /* With the U. S. Department of Energy */ 11 : /* */ 12 : /* Prepared by Battelle Energy Alliance, LLC */ 13 : /* Under Contract No. DE-AC07-05ID14517 */ 14 : /* With the U. S. Department of Energy */ 15 : /* */ 16 : /* See LICENSE for full restrictions */ 17 : /********************************************************************/ 18 : 19 : #include "BinUtility.h" 20 : 21 : namespace bin_utility { 22 : 23 287468093 : unsigned int linearBin(const Real & value, const std::vector<Real> & bounds) 24 : { 25 : // This finds the first entry in the vector that is larger than what we're looking for 26 287468093 : std::vector<Real>::const_iterator one_higher = std::upper_bound(bounds.begin(), bounds.end(), value); 27 : 28 287468093 : if (one_higher == bounds.end()) 29 8601320 : return static_cast<unsigned int>(bounds.size() - 2); 30 278866773 : else if (one_higher == bounds.begin()) 31 : return 0; 32 : else 33 278304596 : return static_cast<unsigned int>(std::distance(bounds.begin(), one_higher - 1)); 34 : } 35 : 36 5 : Real midpoint(const unsigned int & bin, const std::vector<Real> & bounds) 37 : { 38 5 : return 0.5 * (bounds[bin] + bounds[bin + 1]); 39 : } 40 : 41 : } // end namespace bin_utility