HistAxis.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <cassert>
6 #include <string>
7 
8 namespace ana
9 {
10  [[noreturn]] void HistAxisDimensionError(int dim);
11 
12  /// \brief Collect information describing the x-axis of an analysis histogram
13  ///
14  /// That is, what it should be labelled, what the binning should be, and what
15  /// variable will be being filled into it.
16  template<class T> class _HistAxis: public LabelsAndBins
17  {
18  public:
19  // The one constructor to rule them all
20  _HistAxis(const std::vector<std::string>& labels,
21  const std::vector<Binning>& bins,
22  const std::vector<T>& vars = {})
23  : LabelsAndBins(labels, bins), fVars(vars)
24  {
25  assert(fBins.size() == fVars.size() || fVars.empty());
26  }
27 
28  // Forwards
30  const Binning& bins,
31  const T& var)
32  : _HistAxis(std::vector<std::string>(1, label),
33  std::vector<Binning>(1, bins),
34  std::vector<T>(1, var))
35  {
36  }
37 
39  const Binning& bins)
40  : _HistAxis(std::vector<std::string>(1, label),
41  std::vector<Binning>(1, bins))
42  {
43  }
44 
45  _HistAxis(const std::string& labelX,
46  const Binning& binsX,
47  const T& varX,
48  const std::string& labelY,
49  const Binning& binsY,
50  const T& varY)
51  : _HistAxis({labelX, labelY}, {binsX, binsY}, {varX, varY})
52  {
53  }
54 
55  /// Shortcut for simple binnings
57  int nx, double x0, double x1,
58  const T& var)
59  : _HistAxis(label, Binning::Simple(nx, x0, x1), var)
60  {
61  }
62 
63  /// Shortcut for simple binnings
64  _HistAxis(const std::string& labelX,
65  int nx, double x0, double x1,
66  const T& varX,
67  const std::string& labelY,
68  int ny, double y0, double y1,
69  const T& varY)
70  : _HistAxis(labelX, Binning::Simple(nx, x0, x1), varX,
71  labelY, Binning::Simple(ny, y0, y1), varY)
72  {
73  }
74 
75  _HistAxis(const _HistAxis<T>& ax) = default;
76 
77  // MultiD binning expressed as a composition of existing axes
78  _HistAxis(const std::vector<_HistAxis<T>>& axes)
79  : LabelsAndBins(std::vector<std::string>(), std::vector<Binning>())
80  {
81  for(const auto& a: axes){
82  fLabels.insert(fLabels.end(), a.fLabels.begin(), a.fLabels.end());
83  fBins.insert(fBins.end(), a.fBins.begin(), a.fBins.end());
84  fVars.insert(fVars.end(), a.fVars.begin(), a.fVars.end());
85  }
86 
87  assert(fLabels.size() == fBins.size());
88  assert(fBins.size() == fVars.size() || fVars.empty());
89  }
90 
91  _HistAxis(const _HistAxis<T>& xax,
92  const _HistAxis<T>& yax)
93  : _HistAxis(std::vector<_HistAxis<T>>{xax, yax})
94  {
95  }
96 
97  _HistAxis(const _HistAxis<T>& xax,
98  const _HistAxis<T>& yax,
99  const _HistAxis<T>& zax)
100  : _HistAxis(std::vector<_HistAxis<T>>{xax, yax, zax})
101  {
102  }
103 
104  bool HasVars() const {return !fVars.empty();}
105 
106  const std::vector<T>& GetVars() const {return fVars;}
107 
108  /// A variable "flattening" all the dimensions into one 1D value. Use
109  /// sparingly.
110  T GetVar1D() const
111  {
112  switch(fVars.size()){
113  case 1: return fVars[0];
114  case 2: return T(fVars[0], fBins[0], fVars[1], fBins[1]);
115  case 3: return T(fVars[0], fBins[0], fVars[1], fBins[1], fVars[2], fBins[2]);
116  default: HistAxisDimensionError(fVars.size());
117  }
118  }
119 
120  protected:
121  std::vector<T> fVars;
122  };
123 
124  // Typedefs
125  // typedef _HistAxis<Var> HistAxis;
126  // typedef _HistAxis<MultiVar> MultiVarHistAxis;
127  // typedef _HistAxis<SpillVar> SpillHistAxis;
128  // typedef _HistAxis<NuTruthVar> NuTruthHistAxis;
129 }
bool HasVars() const
Definition: HistAxis.h:104
_HistAxis(const std::string &labelX, const Binning &binsX, const T &varX, const std::string &labelY, const Binning &binsY, const T &varY)
Definition: HistAxis.h:45
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const std::vector< T > & GetVars() const
Definition: HistAxis.h:106
Float_t y1[n_points_granero]
Definition: compare.C:5
Float_t x1[n_points_granero]
Definition: compare.C:5
void HistAxisDimensionError(int dim)
Definition: HistAxis.cxx:8
std::vector< T > fVars
Definition: HistAxis.h:121
LabelsAndBins(const std::vector< std::string > &labels, const std::vector< Binning > &bins)
std::vector< Binning > fBins
Definition: LabelsAndBins.h:77
var_value< double > var
Definition: StanTypedefs.h:14
const char * label
_HistAxis(const std::string &label, const Binning &bins)
Definition: HistAxis.h:38
_HistAxis(const std::string &label, const Binning &bins, const T &var)
Definition: HistAxis.h:29
const double a
const std::map< std::pair< std::string, std::string >, Variable > vars
_HistAxis(const std::string &labelX, int nx, double x0, double x1, const T &varX, const std::string &labelY, int ny, double y0, double y1, const T &varY)
Shortcut for simple binnings.
Definition: HistAxis.h:64
_HistAxis(const std::vector< std::string > &labels, const std::vector< Binning > &bins, const std::vector< T > &vars={})
Definition: HistAxis.h:20
const Binning bins
Definition: NumuCC_CPiBin.h:8
_HistAxis(const _HistAxis< T > &xax, const _HistAxis< T > &yax)
Definition: HistAxis.h:91
Collect information describing the x-axis of an analysis histogram.
Definition: HistAxis.h:16
assert(nhit_max >=nhit_nbins)
double T
Definition: Xdiff_gwt.C:5
_HistAxis(const _HistAxis< T > &xax, const _HistAxis< T > &yax, const _HistAxis< T > &zax)
Definition: HistAxis.h:97
_HistAxis(const std::string &label, int nx, double x0, double x1, const T &var)
Shortcut for simple binnings.
Definition: HistAxis.h:56
std::vector< std::string > fLabels
Definition: LabelsAndBins.h:76
_HistAxis(const std::vector< _HistAxis< T >> &axes)
Definition: HistAxis.h:78
T GetVar1D() const
Definition: HistAxis.h:110
enum BeamMode string