cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
Histogram.cpp
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2021-2024 Laurent Forthomme
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
21
22namespace cepgen {
23 namespace utils {
24 void Histogram::normalise(double integ) { scale(integ / integral()); }
25
26 std::set<double> Histogram::extractBins(BinMode mode,
27 size_t num_bins,
28 const std::function<Limits(size_t)>& bins_extractor) const {
29 std::set<double> bins;
30 for (size_t i = 0; i < num_bins; ++i) {
31 const auto range = bins_extractor(i);
32 if (mode == BinMode::low || mode == BinMode::both)
33 bins.insert(range.min());
34 if (mode == BinMode::high || mode == BinMode::both)
35 bins.insert(range.max());
36 }
37 const auto exp_bins = mode == BinMode::both ? num_bins + 1 : num_bins;
38 if (bins.size() != exp_bins)
39 CG_WARNING("Histogram:extractBins")
40 << "Invalid number of values to bin ranges: got " << bins.size() << ", expecting " << exp_bins << ".";
41 return bins;
42 }
43 } // namespace utils
44} // namespace cepgen
#define CG_WARNING(mod)
Definition Message.h:228
Validity interval for a variable.
Definition Limits.h:28
std::set< double > extractBins(BinMode mode, size_t num_bins, const std::function< Limits(size_t)> &bins_extractor) const
Extract the list of bin limits.
Definition Histogram.cpp:26
virtual void scale(double)=0
Rescale all histogram bins by a constant factor.
virtual double integral(bool include_out_of_range=false) const =0
Compute the histogram integral.
void normalise(double integ=1.)
Normalise the histogram to a given constant.
Definition Histogram.cpp:24
Common namespace for this Monte Carlo generator.