HistAxis.cxx
Go to the documentation of this file.
1 #include "CAFAna/Core/HistAxis.h"
2 
3 #include "CAFAna/Core/MultiVar.h"
4 #include "CAFAna/Core/Var.h"
5 
6 #include <cassert>
7 #include <iostream>
8 
9 namespace ana
10 {
11  // explicitly instantiate the template for the types we know we have
12  template class _HistAxis<Var>;
13  template class _HistAxis<MultiVar>;
14  template class _HistAxis<SpillVar>;
15  template class _HistAxis<NuTruthVar>;
16 
17  //----------------------------------------------------------------------
18  template<class T> _HistAxis<T>::
19  _HistAxis(const std::vector<std::string>& labels,
20  const std::vector<Binning>& bins,
21  const std::vector<T>& vars)
22  : LabelsAndBins(labels, bins), fVars(vars)
23  {
24  assert(fBins.size() == fVars.size() || fVars.empty());
25  }
26 
27  //----------------------------------------------------------------------
28  template<class T>_HistAxis<T>::
29  _HistAxis(const std::vector<_HistAxis<T>>& axes)
30  : LabelsAndBins(std::vector<std::string>(), std::vector<Binning>())
31  {
32  for(const auto& a: axes){
33  fLabels.insert(fLabels.end(), a.fLabels.begin(), a.fLabels.end());
34  fBins.insert(fBins.end(), a.fBins.begin(), a.fBins.end());
35  fVars.insert(fVars.end(), a.fVars.begin(), a.fVars.end());
36  }
37 
38  assert(fLabels.size() == fBins.size());
39  assert(fBins.size() == fVars.size() || fVars.empty());
40  }
41 
42  //----------------------------------------------------------------------
43  template<class T> T _HistAxis<T>::GetVar1D() const
44  {
45  switch(fVars.size()){
46  case 1:
47  return fVars[0];
48  case 2:
49  if constexpr(std::is_same_v<T, MultiVar>)
50  return MultiVar2D(fVars[0], fBins[0], fVars[1], fBins[1]);
51  else
52  return Var2D(fVars[0], fBins[0],
53  fVars[1], fBins[1]);
54  case 3:
55  if constexpr(!std::is_same_v<T, MultiVar>) // for MultiVar fall-through to the error
56  return Var3D(fVars[0], fBins[0],
57  fVars[1], fBins[1],
58  fVars[2], fBins[2]);
59  default:
60  std::cout << "Error: HistAxis::GetVar1D() doesn't support "
61  << fVars.size() << "-dimensional axes" << std::endl;
62  abort();
63  }
64  }
65 }
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
_Var< T > Var2D(const _Var< T > &a, const Binning &binsa, const _Var< T > &b, const Binning &binsb)
Variable formed from two input variables.
Definition: Var.cxx:247
std::vector< T > fVars
Definition: HistAxis.h:99
std::vector< Binning > fBins
Definition: LabelsAndBins.h:77
_Var< T > Var3D(const _Var< T > &a, const Binning &binsa, const _Var< T > &b, const Binning &binsb, const _Var< T > &c, const Binning &binsc)
This is just like a Var2D, but useful for 3D Spectra.
Definition: Var.cxx:273
MultiVar MultiVar2D(const MultiVar &a, const Binning &binsa, const MultiVar &b, const Binning &binsb)
Definition: MultiVar.cxx:68
const double a
const std::map< std::pair< std::string, std::string >, Variable > vars
_HistAxis(const std::vector< std::string > &labels, const std::vector< Binning > &bins, const std::vector< T > &vars={})
Definition: HistAxis.cxx:19
OStream cout
Definition: OStream.cxx:6
const Binning bins
Definition: NumuCC_CPiBin.h:8
Collect information describing the x-axis of an analysis histogram.
Definition: HistAxis.h:18
assert(nhit_max >=nhit_nbins)
double T
Definition: Xdiff_gwt.C:5
std::vector< std::string > fLabels
Definition: LabelsAndBins.h:76
T GetVar1D() const
Definition: HistAxis.cxx:43
enum BeamMode string