Binning.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <memory>
5 #include <vector>
6 #include <string>
7 
8 class TAxis;
9 class TDirectory;
10 
11 namespace ana
12 {
13  /// \brief Represent the binning of a Spectrum's x-axis
14  ///
15  /// May be "Simple" (equally spaced) or "Custom" (arbitrary binning)
16  class Binning
17  {
18  public:
19  static Binning Simple(int n, double lo, double hi,
20  const std::vector<std::string>& labels = {});
21  static Binning LogUniform(int n, double lo, double hi);
22  static Binning Custom(const std::vector<double>& edges);
23  static Binning FromTAxis(const TAxis* ax);
24 
25  Binning(const Binning& b);
26  Binning& operator=(const Binning& b);
27  ~Binning();
28 
29  int NBins() const {return fNBins;}
30  double Min() const {return fMin;}
31  double Max() const {return fMax;}
32  int FindBin(double x) const;
33  bool IsSimple() const {return fIsSimple;}
34  const std::vector<double>& Edges() const
35  {
36  return fEdges;
37  }
38 
39  const std::vector<std::string>& Labels() const {return fLabels;}
40 
41  void SaveTo(TDirectory* dir, const std::string& name) const;
42  static std::unique_ptr<Binning> LoadFrom(TDirectory* dir, const std::string& name);
43 
44  bool operator==(const Binning& rhs) const;
45  bool operator<(const Binning& rhs) const;
46 
47  protected:
48  Binning();
49 
50  static Binning SimpleHelper(int n, double lo, double hi,
51  const std::vector<std::string>& labels = {});
52 
53  static Binning CustomHelper(const std::vector<double>& edges);
54 
55  std::vector<double> fEdges;
56  std::vector<std::string> fLabels;
57  int fNBins;
58  double fMin, fMax;
59  bool fIsSimple;
60  };
61 
62 }
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Binning.cxx:230
Binning & operator=(const Binning &b)
Definition: Binning.cxx:58
const XML_Char * name
Definition: expat.h:151
TSpline3 lo("lo", xlo, ylo, 12,"0")
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
bool operator<(const Binning &rhs) const
Definition: Binning.cxx:282
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:173
int FindBin(double x) const
Definition: Binning.cxx:155
std::vector< std::string > fLabels
Definition: Binning.h:56
static Binning CustomHelper(const std::vector< double > &edges)
Definition: Binning.cxx:130
std::vector< double > fEdges
Definition: Binning.h:55
bool fIsSimple
Definition: Binning.h:59
bool IsSimple() const
Definition: Binning.h:33
TSpline3 hi("hi", xhi, yhi, 18,"0")
bool operator==(const Binning &rhs) const
Definition: Binning.cxx:270
double Min() const
Definition: Binning.h:30
static Binning Custom(const std::vector< double > &edges)
Definition: Binning.cxx:145
const std::vector< double > & Edges() const
Definition: Binning.h:34
double Max() const
Definition: Binning.h:31
double fMax
Definition: Binning.h:58
static Binning LogUniform(int n, double lo, double hi)
Definition: Binning.cxx:118
TDirectory * dir
Definition: macro.C:5
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Binning.cxx:193
int NBins() const
Definition: Binning.h:29
const std::vector< std::string > & Labels() const
Definition: Binning.h:39
const hit & b
Definition: hits.cxx:21
double fMin
Definition: Binning.h:58
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
int fNBins
Definition: Binning.h:57
static Binning SimpleHelper(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:88
enum BeamMode string