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
XHistogram::m_histograms
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
XHistogram::position::position
position()
Definition: XHistogram.h:109
DDAxes::y
XHistogram::m_size
size_t m_size
Definition: XHistogram.h:25
mps_fire.i
i
Definition: mps_fire.py:428
XHistogram::Range
std::pair< double, double > Range
Definition: XHistogram.h:17
XHistogram::get
Histogram * get(size_t h=0) const
access one of the histograms
Definition: XHistogram.h:86
XHistogram::m_minDl
double m_minDl
Definition: XHistogram.h:20
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
XHistogram::m_xBins
size_t m_xBins
Definition: XHistogram.h:23
XHistogram::position
Definition: XHistogram.h:104
XHistogram::XHistogram
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
XHistogram::position::x
double x
Definition: XHistogram.h:106
DDAxes::x
XHistogram::colormap
ColorMap * colormap(void) const
access the colormap
Definition: XHistogram.h:97
XHistogram::setMinDl
void setMinDl(double dl)
Definition: XHistogram.h:101
XHistogram
Definition: XHistogram.h:13
XHistogram::normalization
Histogram * normalization(void) const
access the normalization
Definition: XHistogram.h:94
XHistogram::position::position
position(double f_, double x_, double y_)
Definition: XHistogram.h:111
XHistogram::fill
void fill(double x, double y, const std::vector< double > &weight, double norm)
fill one point
Definition: XHistogram.cc:70
XHistogram::m_normalization
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
trackingPlots.other
other
Definition: trackingPlots.py:1467
h
XHistogram::XHistogram
XHistogram(void)
default CTOR
Definition: XHistogram.h:34
XHistogram::m_yBins
size_t m_yBins
Definition: XHistogram.h:24
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
XHistogram::check_weight
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
XHistogram::m_xRange
Range m_xRange
Definition: XHistogram.h:21
XHistogram::m_colormap
std::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:29
XHistogram::position::operator<
bool operator<(const position &other) const
Definition: XHistogram.h:113
XHistogram::m_yRange
Range m_yRange
Definition: XHistogram.h:22
XHistogram::ColorMap
TH2I ColorMap
Definition: XHistogram.h:15
XHistogram::position::f
double f
Definition: XHistogram.h:105
XHistogram::normalize
void normalize(void)
normalize the histograms
Definition: XHistogram.cc:115
XHistogram::m_dummy
std::shared_ptr< Histogram > m_dummy
Definition: XHistogram.h:30
weight
Definition: weight.py:1
XHistogram::position::y
double y
Definition: XHistogram.h:107
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
XHistogram::splitSegment
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: XHistogram.cc:7
XHistogram::Histogram
TH2F Histogram
Definition: XHistogram.h:16