LabelsAndBins.cxx
Go to the documentation of this file.
2 
3 #include <cassert>
4 
5 namespace ana
6 {
7  //----------------------------------------------------------------------
8  LabelsAndBins::LabelsAndBins(const std::vector<std::string>& labels,
9  const std::vector<Binning>& bins)
10  : fLabels(labels), fBins(bins)
11  {
12  assert(fLabels.size() == fBins.size());
13  }
14 
15  //----------------------------------------------------------------------
16  LabelsAndBins::LabelsAndBins(const std::vector<LabelsAndBins>& axes)
17  {
18  for(const auto& a: axes){
19  fLabels.insert(fLabels.end(), a.fLabels.begin(), a.fLabels.end());
20  fBins.insert(fBins.end(), a.fBins.begin(), a.fBins.end());
21  }
22 
23  assert(fLabels.size() == fBins.size());
24  }
25 
26  //----------------------------------------------------------------------
28  {
29  if(fBins.size() == 1) return fBins[0];
30 
31  if(fBins1D) return *fBins1D;
32 
33  assert(!fBins.empty());
34 
35  int n = 1;
36  for(const Binning& b: fBins) n *= b.NBins();
37  fBins1D = Binning::Simple(n, 0, n);
38 
39  return *fBins1D;
40  }
41 
42  //----------------------------------------------------------------------
44  {
45  if(fLabels.size() == 1) return fLabels[0];
46 
47  if(fLabel1D) return *fLabel1D;
48 
49  fLabel1D = "";
50  for(const std::string& l: fLabels) *fLabel1D += l + " and ";
51  fLabel1D->resize(fLabel1D->size()-5); // drop extra "and"
52 
53  return *fLabel1D;
54  }
55 
56 }
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
std::optional< Binning > fBins1D
Definition: LabelsAndBins.h:79
LabelsAndBins(const std::vector< std::string > &labels, const std::vector< Binning > &bins)
std::vector< Binning > fBins
Definition: LabelsAndBins.h:77
std::optional< std::string > fLabel1D
Definition: LabelsAndBins.h:80
const std::string & GetLabel1D() const
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
std::void_t< T > n
const double a
const Binning bins
Definition: NumuCC_CPiBin.h:8
const hit & b
Definition: hits.cxx:21
assert(nhit_max >=nhit_nbins)
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
std::vector< std::string > fLabels
Definition: LabelsAndBins.h:76
enum BeamMode string