Public Member Functions | Protected Attributes | List of all members
ana::_HistAxis< T > Class Template Reference

Collect information describing the x-axis of an analysis histogram. More...

#include "/cvmfs/nova.opensciencegrid.org/externals/cafanacore/v01.11/src/CAFAna/Core/HistAxis.h"

Inheritance diagram for ana::_HistAxis< T >:
ana::LabelsAndBins

Public Member Functions

 _HistAxis (const std::vector< std::string > &labels, const std::vector< Binning > &bins, const std::vector< T > &vars={})
 
 _HistAxis (const std::string &label, const Binning &bins, const T &var)
 
 _HistAxis (const std::string &label, const Binning &bins)
 
 _HistAxis (const std::string &labelX, const Binning &binsX, const T &varX, const std::string &labelY, const Binning &binsY, const T &varY)
 
 _HistAxis (const std::string &label, int nx, double x0, double x1, const T &var)
 Shortcut for simple binnings. More...
 
 _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. More...
 
 _HistAxis (const _HistAxis< T > &ax)=default
 
 _HistAxis (const std::vector< _HistAxis< T >> &axes)
 
 _HistAxis (const _HistAxis< T > &xax, const _HistAxis< T > &yax)
 
 _HistAxis (const _HistAxis< T > &xax, const _HistAxis< T > &yax, const _HistAxis< T > &zax)
 
bool HasVars () const
 
const std::vector< T > & GetVars () const
 
T GetVar1D () const
 
unsigned int NDimensions () const
 
const std::vector< std::string > & GetLabels () const
 
const std::vector< Binning > & GetBinnings () const
 
const BinningGetBins1D () const
 Appropriate binning and labelling for that 1D Var. More...
 
const std::stringGetLabel1D () const
 

Protected Attributes

std::vector< TfVars
 
std::vector< std::stringfLabels
 
std::vector< BinningfBins
 
std::optional< BinningfBins1D
 
std::optional< std::stringfLabel1D
 

Detailed Description

template<class T>
class ana::_HistAxis< T >

Collect information describing the x-axis of an analysis histogram.

That is, what it should be labelled, what the binning should be, and what variable will be being filled into it.

Definition at line 18 of file HistAxis.h.

Constructor & Destructor Documentation

template<class T>
ana::_HistAxis< T >::_HistAxis ( const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
const std::vector< T > &  vars = {} 
)

Definition at line 19 of file HistAxis.cxx.

References ana::assert(), ana::LabelsAndBins::fBins, and ana::_HistAxis< T >::fVars.

Referenced by ana::_HistAxis< Var >::_HistAxis().

23  {
24  assert(fBins.size() == fVars.size() || fVars.empty());
25  }
std::vector< T > fVars
Definition: HistAxis.h:99
LabelsAndBins(const std::vector< std::string > &labels, const std::vector< Binning > &bins)
std::vector< Binning > fBins
Definition: LabelsAndBins.h:77
const std::map< std::pair< std::string, std::string >, Variable > vars
const Binning bins
Definition: NumuCC_CPiBin.h:8
assert(nhit_max >=nhit_nbins)
template<class T>
ana::_HistAxis< T >::_HistAxis ( const std::string label,
const Binning bins,
const T var 
)
inline

Definition at line 27 of file HistAxis.h.

30  : _HistAxis(std::vector<std::string>(1, label),
31  std::vector<Binning>(1, bins),
32  std::vector<T>(1, var))
33  {
34  }
const char * label
_HistAxis(const std::vector< std::string > &labels, const std::vector< Binning > &bins, const std::vector< T > &vars={})
Definition: HistAxis.cxx:19
const Binning bins
Definition: NumuCC_CPiBin.h:8
template<class T>
ana::_HistAxis< T >::_HistAxis ( const std::string label,
const Binning bins 
)
inline

Definition at line 36 of file HistAxis.h.

38  : _HistAxis(std::vector<std::string>(1, label),
39  std::vector<Binning>(1, bins))
40  {
41  }
const char * label
_HistAxis(const std::vector< std::string > &labels, const std::vector< Binning > &bins, const std::vector< T > &vars={})
Definition: HistAxis.cxx:19
const Binning bins
Definition: NumuCC_CPiBin.h:8
template<class T>
ana::_HistAxis< T >::_HistAxis ( const std::string labelX,
const Binning binsX,
const T varX,
const std::string labelY,
const Binning binsY,
const T varY 
)
inline

Definition at line 43 of file HistAxis.h.

49  : _HistAxis({labelX, labelY}, {binsX, binsY}, {varX, varY})
50  {
51  }
_HistAxis(const std::vector< std::string > &labels, const std::vector< Binning > &bins, const std::vector< T > &vars={})
Definition: HistAxis.cxx:19
template<class T>
ana::_HistAxis< T >::_HistAxis ( const std::string label,
int  nx,
double  x0,
double  x1,
const T var 
)
inline

Shortcut for simple binnings.

Definition at line 54 of file HistAxis.h.

57  : _HistAxis(label, Binning::Simple(nx, x0, x1), var)
58  {
59  }
Float_t x1[n_points_granero]
Definition: compare.C:5
const char * label
_HistAxis(const std::vector< std::string > &labels, const std::vector< Binning > &bins, const std::vector< T > &vars={})
Definition: HistAxis.cxx:19
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
template<class T>
ana::_HistAxis< T >::_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 
)
inline

Shortcut for simple binnings.

Definition at line 62 of file HistAxis.h.

68  : _HistAxis(labelX, Binning::Simple(nx, x0, x1), varX,
69  labelY, Binning::Simple(ny, y0, y1), varY)
70  {
71  }
Float_t y1[n_points_granero]
Definition: compare.C:5
Float_t x1[n_points_granero]
Definition: compare.C:5
_HistAxis(const std::vector< std::string > &labels, const std::vector< Binning > &bins, const std::vector< T > &vars={})
Definition: HistAxis.cxx:19
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
template<class T>
ana::_HistAxis< T >::_HistAxis ( const _HistAxis< T > &  ax)
default
template<class T>
ana::_HistAxis< T >::_HistAxis ( const std::vector< _HistAxis< T >> &  axes)

Definition at line 29 of file HistAxis.cxx.

References a, ana::assert(), file_size_ana::axes, ana::LabelsAndBins::fBins, ana::LabelsAndBins::fLabels, and ana::_HistAxis< T >::fVars.

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  }
std::vector< T > fVars
Definition: HistAxis.h:99
LabelsAndBins(const std::vector< std::string > &labels, const std::vector< Binning > &bins)
std::vector< Binning > fBins
Definition: LabelsAndBins.h:77
const double a
assert(nhit_max >=nhit_nbins)
std::vector< std::string > fLabels
Definition: LabelsAndBins.h:76
template<class T>
ana::_HistAxis< T >::_HistAxis ( const _HistAxis< T > &  xax,
const _HistAxis< T > &  yax 
)
inline

Definition at line 77 of file HistAxis.h.

79  : _HistAxis(std::vector<_HistAxis<T>>{xax, yax})
80  {
81  }
_HistAxis(const std::vector< std::string > &labels, const std::vector< Binning > &bins, const std::vector< T > &vars={})
Definition: HistAxis.cxx:19
template<class T>
ana::_HistAxis< T >::_HistAxis ( const _HistAxis< T > &  xax,
const _HistAxis< T > &  yax,
const _HistAxis< T > &  zax 
)
inline

Definition at line 83 of file HistAxis.h.

86  : _HistAxis(std::vector<_HistAxis<T>>{xax, yax, zax})
87  {
88  }
_HistAxis(const std::vector< std::string > &labels, const std::vector< Binning > &bins, const std::vector< T > &vars={})
Definition: HistAxis.cxx:19

Member Function Documentation

const std::vector<Binning>& ana::LabelsAndBins::GetBinnings ( ) const
inlineinherited
const Binning & ana::LabelsAndBins::GetBins1D ( ) const
inherited

Appropriate binning and labelling for that 1D Var.

Definition at line 27 of file LabelsAndBins.cxx.

References ana::assert(), b, ana::LabelsAndBins::fBins, ana::LabelsAndBins::fBins1D, getGoodRuns4SAM::n, and ana::Binning::Simple().

Referenced by ana::ReweightableSpectrum::Fill(), ana::Spectrum::Fill(), ana::LabelsAndBins::GetBinnings(), ana::ReweightableSpectrum::LoadFrom(), ana::Spectrum::Mean(), ana::Spectrum::SaveTo(), ana::Spectrum::Spectrum(), ana::Spectrum::ToTH1(), and ana::ReweightableSpectrum::ToTH2().

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  }
std::optional< Binning > fBins1D
Definition: LabelsAndBins.h:79
std::vector< Binning > fBins
Definition: LabelsAndBins.h:77
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
const std::string & ana::LabelsAndBins::GetLabel1D ( ) const
inherited

Definition at line 43 of file LabelsAndBins.cxx.

References ana::LabelsAndBins::fLabel1D, ana::LabelsAndBins::fLabels, submit_hadd::l, and string.

Referenced by ana::LabelsAndBins::GetBinnings(), ana::Spectrum::ToTH1(), and ana::ReweightableSpectrum::ToTH2().

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  }
std::optional< std::string > fLabel1D
Definition: LabelsAndBins.h:80
std::vector< std::string > fLabels
Definition: LabelsAndBins.h:76
enum BeamMode string
const std::vector<std::string>& ana::LabelsAndBins::GetLabels ( ) const
inlineinherited
template<class T >
T ana::_HistAxis< T >::GetVar1D ( ) const

A variable "flattening" all the dimensions into one 1D value. Use sparingly.

Definition at line 43 of file HistAxis.cxx.

References om::cout, allTimeWatchdog::endl, ana::LabelsAndBins::fBins, ana::_HistAxis< T >::fVars, ana::MultiVar2D(), ana::Var2D(), and ana::Var3D().

Referenced by ana::FluxReweight::FluxReweight(), ana::_HistAxis< Var >::GetVars(), ana::Multiverse::Multiverse(), ana::NoReweight::NoReweight(), ana::RecoReweight::RecoReweight(), and ana::TrivialExtrap::TrivialExtrap().

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  }
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
_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
if(dump)
OStream cout
Definition: OStream.cxx:6
_MultiVar< caf::SRProxy > MultiVar
Definition: MultiVar.h:52
double T
Definition: Xdiff_gwt.C:5
T GetVar1D() const
Definition: HistAxis.cxx:43
template<class T>
const std::vector<T>& ana::_HistAxis< T >::GetVars ( ) const
inline
template<class T>
bool ana::_HistAxis< T >::HasVars ( ) const
inline

Definition at line 90 of file HistAxis.h.

90 {return !fVars.empty();}
std::vector< T > fVars
Definition: HistAxis.h:99
unsigned int ana::LabelsAndBins::NDimensions ( ) const
inlineinherited

Member Data Documentation

std::vector<Binning> ana::LabelsAndBins::fBins
protectedinherited
std::optional<Binning> ana::LabelsAndBins::fBins1D
mutableprotectedinherited

Definition at line 79 of file LabelsAndBins.h.

Referenced by ana::LabelsAndBins::GetBins1D().

std::optional<std::string> ana::LabelsAndBins::fLabel1D
mutableprotectedinherited

Definition at line 80 of file LabelsAndBins.h.

Referenced by ana::LabelsAndBins::GetLabel1D().

std::vector<std::string> ana::LabelsAndBins::fLabels
protectedinherited
template<class T>
std::vector<T> ana::_HistAxis< T >::fVars
protected

The documentation for this class was generated from the following files: