CMS 3D CMS Logo

DD4hep_XHistogram.h
Go to the documentation of this file.
1 #ifndef DD4hep_XHistogram_h
2 #define DD4hep_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 
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:
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
48  size_t size, size_t bins_x, size_t bins_y, Range x, Range y, size_t zones, const std::vector<double>& max)
49  : m_minDl(0.000001),
50  m_xRange(x),
51  m_yRange(y),
52  m_xBins(bins_x),
53  m_yBins(bins_y),
54  m_size(size),
57  m_colormap() {
58  // setup unnamed ROOT histograms
59  for (size_t i = 0; i < m_size; ++i) {
60  m_histograms[i].reset(new Histogram(nullptr, nullptr, bins_x, x.first, x.second, bins_y, y.first, y.second));
61  m_histograms[i]->SetMinimum(0.);
62  m_histograms[i]->SetMaximum(max[i]);
63  }
64  m_normalization.reset(new Histogram(nullptr, nullptr, bins_x, x.first, x.second, bins_y, y.first, y.second));
65  m_colormap.reset(new ColorMap(nullptr, nullptr, bins_x, x.first, x.second, bins_y, y.first, y.second));
66  m_colormap->SetMinimum(0);
67  m_colormap->SetMaximum(zones);
68  Histogram(nullptr, nullptr, 0, 0., 0., 0, 0., 0.); // make ROOT "forget" about unnamed histograms
69  }
70 
72  void fill(double x, double y, const std::vector<double>& weight, double norm);
73 
75  void fill(double x, double y, const std::vector<double>& weight, double norm, unsigned int colour);
76 
78  void fill(const Range& x, const Range& y, const std::vector<double>& weight, double norm);
79 
81  void fill(const Range& x, const Range& y, const std::vector<double>& weight, double norm, unsigned int colour);
82 
84  void normalize(void);
85 
87  Histogram* get(size_t h = 0) const {
88  if (h < m_size)
89  return (Histogram*)m_histograms[h]->Clone(nullptr);
90  else
91  return nullptr;
92  }
93 
95  Histogram* normalization(void) const { return (Histogram*)m_normalization->Clone(nullptr); }
96 
98  ColorMap* colormap(void) const { return (ColorMap*)m_colormap->Clone(nullptr); }
99 
102  void setMinDl(double dl) { m_minDl = dl; }
103 
104 protected:
105  struct position {
106  double f;
107  double x;
108  double y;
109 
110  position() : f(0), x(0), y(0) {}
111 
112  position(const double& f_, const double& x_, const double& y_) : f(f_), x(x_), y(y_) {}
113 
114  bool operator<(const position& other) const { return f < other.f; }
115  };
116 
118  std::vector<position> splitSegment(Range x, Range y) const;
119 
121  void check_weight(const std::vector<double>& weight) noexcept(false) {
122  // run time check for vector size
123  if (weight.size() != m_size)
124  throw std::invalid_argument("weight: wrong number of elements");
125  }
126 };
127 
128 #endif // DD4hep_XHistogram_h
size
Write out results.
DD4hep_XHistogram(void)
default CTOR
Histogram * normalization(void) const
access the normalization
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: weight.py:1
void check_weight(const std::vector< double > &weight) noexcept(false)
check the weights passed as an std::vector have the correct size
std::vector< std::shared_ptr< Histogram > > m_histograms
std::shared_ptr< Histogram > m_dummy
std::pair< double, double > Range
void fill(double x, double y, const std::vector< double > &weight, double norm)
fill one point
ColorMap * colormap(void) const
access the colormap
void setMinDl(double dl)
std::shared_ptr< Histogram > m_normalization
position(const double &f_, const double &x_, const double &y_)
DD4hep_XHistogram(size_t size, size_t bins_x, size_t bins_y, Range x, Range y, size_t zones, const std::vector< double > &max)
std::shared_ptr< ColorMap > m_colormap
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bool operator<(const position &other) const
void normalize(void)
normalize the histograms