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
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:428
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:121
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:87
DD4hep_XHistogram::position::x
double x
Definition: DD4hep_XHistogram.h:107
DD4hep_XHistogram
Definition: DD4hep_XHistogram.h:13
trackingPlots.other
other
Definition: trackingPlots.py:1460
h
DD4hep_XHistogram::position::f
double f
Definition: DD4hep_XHistogram.h:106
DD4hep_XHistogram::position::operator<
bool operator<(const position &other) const
Definition: DD4hep_XHistogram.h:114
DD4hep_XHistogram::position::position
position()
Definition: DD4hep_XHistogram.h:110
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:105
DD4hep_XHistogram::setMinDl
void setMinDl(double dl)
Definition: DD4hep_XHistogram.h:102
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:98
DD4hep_XHistogram::normalization
Histogram * normalization(void) const
access the normalization
Definition: DD4hep_XHistogram.h:95
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:108
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
DD4hep_XHistogram::position::position
position(const double &f_, const double &x_, const double &y_)
Definition: DD4hep_XHistogram.h:112