CMS 3D CMS Logo

XHistogram.h
Go to the documentation of this file.
1 #ifndef XHistogram_h
2 #define XHistogram_h
3 
4 #include <algorithm>
5 #include <vector>
6 #include <iostream>
7 #include <stdexcept>
8 #include <memory>
9 
10 #include <TH2F.h>
11 #include <TH2I.h>
12 
13 class XHistogram {
14 public:
15  typedef TH2I ColorMap;
16  typedef TH2F Histogram;
17  typedef std::pair<double, double> Range;
18 
19 protected:
20  double m_minDl;
23  size_t m_xBins;
24  size_t m_yBins;
25  size_t m_size;
26 
27  std::vector<std::shared_ptr<Histogram> > m_histograms;
28  std::shared_ptr<Histogram> m_normalization;
29  std::shared_ptr<ColorMap> m_colormap;
30  std::shared_ptr<Histogram> m_dummy;
31 
32 public:
34  XHistogram(void)
35  : m_minDl(0.000001),
36  m_xRange(),
37  m_yRange(),
38  m_xBins(),
39  m_yBins(),
40  m_size(),
41  m_histograms(),
43  m_colormap(),
44  m_dummy() {}
45 
46  // explicit CTOR
47  XHistogram(size_t size, size_t bins_x, size_t bins_y, Range x, Range y, size_t zones, const std::vector<double>& max)
48  : m_minDl(0.000001),
49  m_xRange(x),
50  m_yRange(y),
51  m_xBins(bins_x),
52  m_yBins(bins_y),
53  m_size(size),
56  m_colormap() {
57  // setup unnamed ROOT histograms
58  for (size_t i = 0; i < m_size; ++i) {
59  m_histograms[i].reset(new Histogram(nullptr, nullptr, bins_x, x.first, x.second, bins_y, y.first, y.second));
60  m_histograms[i]->SetMinimum(0.);
61  m_histograms[i]->SetMaximum(max[i]);
62  }
63  m_normalization.reset(new Histogram(nullptr, nullptr, bins_x, x.first, x.second, bins_y, y.first, y.second));
64  m_colormap.reset(new ColorMap(nullptr, nullptr, bins_x, x.first, x.second, bins_y, y.first, y.second));
65  m_colormap->SetMinimum(0);
66  m_colormap->SetMaximum(zones);
67  Histogram(nullptr, nullptr, 0, 0., 0., 0, 0., 0.); // make ROOT "forget" about unnamed histograms
68  }
69 
71  void fill(double x, double y, const std::vector<double>& weight, double norm);
72 
74  void fill(double x, double y, const std::vector<double>& weight, double norm, unsigned int colour);
75 
77  void fill(const Range& x, const Range& y, const std::vector<double>& weight, double norm);
78 
80  void fill(const Range& x, const Range& y, const std::vector<double>& weight, double norm, unsigned int colour);
81 
83  void normalize(void);
84 
86  Histogram* get(size_t h = 0) const {
87  if (h < m_size)
88  return (Histogram*)m_histograms[h]->Clone(nullptr);
89  else
90  return nullptr;
91  }
92 
94  Histogram* normalization(void) const { return (Histogram*)m_normalization->Clone(nullptr); }
95 
97  ColorMap* colormap(void) const { return (ColorMap*)m_colormap->Clone(nullptr); }
98 
101  void setMinDl(double dl) { m_minDl = dl; }
102 
103 protected:
104  struct position {
105  double f;
106  double x;
107  double y;
108 
109  position() : f(0), x(0), y(0) {}
110 
111  position(double f_, double x_, double y_) : f(f_), x(x_), y(y_) {}
112 
113  bool operator<(const position& other) const { return f < other.f; }
114  };
115 
117  std::vector<position> splitSegment(Range x, Range y) const;
118 
120  void check_weight(const std::vector<double>& weight) noexcept(false) {
121  // run time check for vector size
122  if (weight.size() != m_size)
123  throw std::invalid_argument("weight: wrong number of elements");
124  }
125 };
126 
127 #endif // XHistogram_h
size
Write out results.
double m_minDl
Definition: XHistogram.h:20
Range m_xRange
Definition: XHistogram.h:21
TH2F Histogram
Definition: XHistogram.h:16
Definition: weight.py:1
size_t m_size
Definition: XHistogram.h:25
XHistogram(size_t size, size_t bins_x, size_t bins_y, Range x, Range y, size_t zones, const std::vector< double > &max)
Definition: XHistogram.h:47
Histogram * normalization(void) const
access the normalization
Definition: XHistogram.h:94
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: XHistogram.cc:7
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
ColorMap * colormap(void) const
access the colormap
Definition: XHistogram.h:97
void check_weight(const std::vector< double > &weight) noexcept(false)
check the weights passed as an std::vector have the correct size
Definition: XHistogram.h:120
position(double f_, double x_, double y_)
Definition: XHistogram.h:111
std::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:29
bool operator<(const position &other) const
Definition: XHistogram.h:113
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
void setMinDl(double dl)
Definition: XHistogram.h:101
XHistogram(void)
default CTOR
Definition: XHistogram.h:34
std::shared_ptr< Histogram > m_dummy
Definition: XHistogram.h:30
size_t m_xBins
Definition: XHistogram.h:23
TH2I ColorMap
Definition: XHistogram.h:15
size_t m_yBins
Definition: XHistogram.h:24
void fill(double x, double y, const std::vector< double > &weight, double norm)
fill one point
Definition: XHistogram.cc:70
void normalize(void)
normalize the histograms
Definition: XHistogram.cc:115
Range m_yRange
Definition: XHistogram.h:22
std::pair< double, double > Range
Definition: XHistogram.h:17
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4