Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HistogramDefs.hh
Go to the documentation of this file.
1 #pragma clang diagnostic push
2 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
3 ///
4 /// @file HistogramDefs.hh
5 /// @brief Hammer histogram class template methods definitions
6 ///
7 #pragma clang diagnostic pop
8 
9 //**** This file is a part of the HAMMER library
10 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
11 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
12 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
13 
14 // -*- C++ -*-
15 
16 #include "Hammer/Exceptions.hh"
17 #include "Hammer/Tools/Logging.hh"
18 
19 namespace Hammer {
20 
21  template <typename... Args>
22  void Histogram::fillBin(const Tensor& value, Args... rest) {
23  try {
24  element({static_cast<IndexType>(rest)...}).addWeight(value);
25  } catch (RangeError& e) {
26  MSG_ERROR(std::string("Error setting element: ") + e.what() + std::string(" Element not set."));
27  }
28  }
29 
30  template <typename... Args>
31  const Tensor& Histogram::getWeight(Args... rest) const {
32  return element({static_cast<IndexType>(rest)...}).getWeight();
33  }
34 
35  template <typename... Args>
36  const Tensor& Histogram::getSquaredWeight(Args... rest) const {
37  return element({static_cast<IndexType>(rest)...}).getSquaredWeight();
38  }
39 
40  template <typename... Args>
41  size_t Histogram::getNumEvents(Args... rest) const {
42  return element({static_cast<IndexType>(rest)...}).getNumEvents();
43  }
44 
45 } // namespace Hammer
const Tensor & getWeight(Args...rest) const
get the value of a histogram bin based on an index of the bin
const Tensor & getSquaredWeight(Args...rest) const
get the value of a histogram bin based on an index of the bin
size_t getNumEvents(Args...rest) const
get the value of a histogram bin based on an index of the bin
size_t getNumEvents() const
the number of entries in the bin (number of times addWeight has been called)
Definition: Histogram.cc:71
Message logging routines.
uint16_t IndexType
const Tensor & getWeight() const
the sum of tensor weights contained in the bin
Definition: Histogram.cc:63
void addWeight(const Tensor &t)
add the values of a tensor to the current bin.
Definition: Histogram.cc:55
Hammer exception definitions.
Bin & element(const IndexList &indices)
convert the indices into the position in the flattened contents into vector organized as row-major ...
Definition: Histogram.cc:189
const Tensor & getSquaredWeight() const
the sum of (outer) squared tensor weights contained in the bin, or an empty tensor if the errors are ...
Definition: Histogram.cc:67
Multidimensional tensor class with complex numbers as elements.
Definition: Tensor.hh:33
#define MSG_ERROR(x)
Definition: Logging.hh:367
void fillBin(const Tensor &value, Args...rest)
set the value of a histogram bin based on the bin indices
Out-of-range error class.
Definition: Exceptions.hh:49