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