cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.3
A generic central exclusive processes event generator
Loading...
Searching...
No Matches
Value.cpp
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2023 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
19#include <cmath>
20#include <iostream>
21
22#include "CepGen/Utils/Math.h"
23#include "CepGen/Utils/Value.h"
24
25namespace cepgen {
26 Value::Value(double val, double unc) : val_(val), unc_(unc) {}
27
28 double Value::relativeUncertainty() const { return val_ == 0. ? 0. : unc_ / val_; }
29
30 Value Value::operator+(const Value& oth) const { return Value{val_ + oth.val_, utils::fastHypot(unc_, oth.unc_)}; }
31
32 Value Value::operator-(const Value& oth) const { return Value{val_ - oth.val_, utils::fastHypot(unc_, oth.unc_)}; }
33
34 Value Value::operator*(const Value& oth) const {
35 const auto prod = val_ * oth.val_;
37 }
38
39 Value Value::operator/(const Value& oth) const {
40 const auto ratio = val_ / oth.val_;
41 return Value{ratio, ratio * utils::fastHypot(relativeUncertainty(), oth.relativeUncertainty())};
42 }
43
44 std::ostream& operator<<(std::ostream& os, const Value& value) { return os << value.val_ << " +/- " << value.unc_; }
45} // namespace cepgen
A scalar value with its uncertainty.
Definition Value.h:26
Value operator+(const Value &) const
Definition Value.cpp:30
Value operator*(const Value &) const
Definition Value.cpp:34
Value operator/(const Value &) const
Definition Value.cpp:39
double relativeUncertainty() const
Relative uncertainty around the central value.
Definition Value.cpp:28
Value operator-(const Value &) const
Definition Value.cpp:32
Value(double val=0., double unc=0.)
Definition Value.cpp:26
double fastHypot(double x, double y)
Definition Math.cpp:33
Common namespace for this Monte Carlo generator.
std::ostream & operator<<(std::ostream &os, const Exception::Type &type)
Definition Exception.cpp:59