All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Binning.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cassert>
4 #include <map>
5 #include <memory>
6 #include <vector>
7 #include <string>
8 #include <unordered_map>
9 
10 class TAxis;
11 class TDirectory;
12 
13 namespace ana
14 {
15  /// \brief Represent the binning of a Spectrum's x-axis
16  ///
17  /// May be "Simple" (equally spaced) or "Custom" (arbitrary binning)
18  class Binning
19  {
20  public:
21  static Binning Simple(int n, double lo, double hi,
22  const std::vector<std::string>& labels = {});
23  static Binning LogUniform(int n, double lo, double hi);
24  static Binning Custom(const std::vector<double>& edges);
25  static Binning FromTAxis(const TAxis* ax);
26 
27  int NBins() const {return fNBins;}
28  double Min() const {return fMin;}
29  double Max() const {return fMax;}
30  int FindBin(float x) const;
31  bool IsSimple() const {return fIsSimple;}
32  const std::vector<double>& Edges() const
33  {
34  return fEdges;
35  }
36 
37  const std::vector<std::string>& Labels() const {return fLabels;}
38 
39  void SaveTo(TDirectory* dir) const;
40  static std::unique_ptr<Binning> LoadFrom(TDirectory* dir);
41 
42  int ID() const {return fID;}
43  static int MaxID() {return fgNextID-1;}
44 
45  bool operator==(const Binning& rhs) const;
46  bool operator<(const Binning& rhs) const;
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  int fID;
62  /// The next ID that hasn't yet been assigned
63  static int fgNextID;
64 
65  static std::map<Binning, int>& IDMap();
66  };
67 
68  /// Default true-energy bin edges
70  /// Default true-energy bin edges
72 
73  // 2km/GeV is the empirical largest L/E at Icarus
75 }
* labels
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:18
bool operator<(const Binning &rhs) const
Definition: Binning.cxx:278
process_name opflash particleana ie x
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
static std::map< Binning, int > & IDMap()
Definition: Binning.cxx:290
std::vector< std::string > fLabels
Definition: Binning.h:56
static Binning CustomHelper(const std::vector< double > &edges)
Definition: Binning.cxx:68
const Binning kTrueLOverEBins
Definition: Binning.h:74
process_name opflashCryoW ana
static int MaxID()
Definition: Binning.h:43
std::vector< double > fEdges
Definition: Binning.h:55
bool fIsSimple
Definition: Binning.h:59
bool IsSimple() const
Definition: Binning.h:31
static int fgNextID
The next ID that hasn&#39;t yet been assigned.
Definition: Binning.h:63
bool operator==(const Binning &rhs) const
Definition: Binning.cxx:264
double Min() const
Definition: Binning.h:28
void SaveTo(TDirectory *dir) const
Definition: Binning.cxx:197
int FindBin(float x) const
Definition: Binning.cxx:100
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:71
static Binning Custom(const std::vector< double > &edges)
Definition: Binning.cxx:83
const std::vector< double > & Edges() const
Definition: Binning.h:32
tuple dir
Definition: dropbox.py:28
double Max() const
Definition: Binning.h:29
double fMax
Definition: Binning.h:58
Binning TrueEnergyBins()
Default true-energy bin edges.
Definition: Binning.cxx:152
static Binning LogUniform(int n, double lo, double hi)
Definition: Binning.cxx:56
int NBins() const
Definition: Binning.h:27
const std::vector< std::string > & Labels() const
Definition: Binning.h:37
int ID() const
Definition: Binning.h:42
double fMin
Definition: Binning.h:58
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:38
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir)
Definition: Binning.cxx:229
int fNBins
Definition: Binning.h:57
static Binning SimpleHelper(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:19