Crombie Tools
Types.h
Go to the documentation of this file.
1 #ifndef CROMBIE_TYPES_H
2 #define CROMBIE_TYPES_H
3 
4 #include <string>
5 #include <vector>
6 #include <map>
7 #include <list>
8 
9 /**
10  Defines a few types that are frequently used
11 */
12 
13 namespace crombie {
14  namespace Types {
15 
16  using strings = std::vector<std::string>;
17 
18  /**
19  Map with strings as the keys
20  @param V The mapped type
21  */
22  template<typename V> using map = std::map<const std::string, V>;
23 
24  /**
25  This generates and stores all of the edges needed in a histogram.
26  There are two types of Binning, same width, and variable width.
27  This is determined by the constructor.
28  */
29  class Binning {
30  public:
31  /**
32  @brief Initializes the binning for a histogram.
33 
34  If the initializer list is three numbers,
35  these are assumed to be the number of bins, minimum, and maximum,
36  unless the first number is not an integer.
37  (You can end the number with `'.'` or something to avoid this.)
38 
39  An initialization with one value is invalid.
40  */
41  Binning(std::initializer_list<std::string> bins);
42 
43  /**
44  @param value The value on the binned axis to make an insertion.
45  @returns `0` for an underflow bin, and `nbins + 1` for overflow bin.
46  */
47  unsigned find_bin(double value);
48 
49  private:
50  bool same_width {}; ///< Tracks if this Binning is same width, or variable width
51  unsigned nbins {}; ///< Number of bins
52  double min {}; ///< Minimum value
53  double max {}; ///< Maximum value
54  std::vector<double> edges {}; ///< If variable width, store all of the edges
55 
56  };
57 
58  }
59 }
60 
61 #endif