Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:14:58

0001 // lAger: General Purpose l/A-event Generator
0002 // Copyright (C) 2016-2021 Sylvester Joosten <sjoosten@anl.gov>
0003 // 
0004 // This file is part of lAger.
0005 // 
0006 // lAger is free software: you can redistribute it and/or modify
0007 // it under the terms of the GNU General Public License as published by
0008 // the Free Shoftware Foundation, either version 3 of the License, or
0009 // (at your option) any later version.
0010 // 
0011 // lAger is distributed in the hope that it will be useful,
0012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 // GNU General Public License for more details.
0015 // 
0016 // You should have received a copy of the GNU General Public License
0017 // along with lAger.  If not, see <https://www.gnu.org/licenses/>.
0018 // 
0019 
0020 #ifndef LAGER_CORE_INTERVAL_LOADED
0021 #define LAGER_CORE_INTERVAL_LOADED
0022 
0023 // =============================================================================
0024 // A simple interval for readible ranges such as cut parameters.
0025 // =============================================================================
0026 namespace lager {
0027 template <class T> struct interval {
0028   using value_type = T;
0029   value_type min;
0030   value_type max;
0031   constexpr interval() = default;
0032   constexpr interval(const value_type min, const value_type max)
0033       : min{min}, max{max} {}
0034   constexpr interval(const std::pair<value_type, value_type>& rhs)
0035       : min{rhs.first}, max{rhs.second} {}
0036   constexpr bool includes(const value_type value) const {
0037     return value > min && value < max;
0038   }
0039   constexpr bool excludes(const value_type value) const {
0040     return !includes(value);
0041   }
0042   constexpr T width() const { return max - min; }
0043   // Implicitly conversion to std::pair<T,T> when needed.
0044   constexpr operator std::pair<value_type, value_type>() const {
0045     return std::make_pair(min, max);
0046   }
0047   constexpr interval operator*(const double rhs) const {
0048     return {min * rhs, max * rhs};
0049   }
0050   constexpr interval operator/(const double rhs) const {
0051     return operator*(1 / rhs);
0052   }
0053   interval operator*=(const double rhs) { *this = operator*(rhs); }
0054   interval operator/=(const double rhs) { *this = operator/(rhs); }
0055 };
0056 } // namespace lager
0057 
0058 #endif