CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <boost/shared_ptr.hpp>
9 
10 #include <TH2F.h>
11 #include <TH2I.h>
12 
13 class XHistogram
14 {
15 public:
16  typedef TH2I ColorMap;
17  typedef TH2F Histogram;
18  typedef std::pair<double, double> Range;
19 
20 protected:
21  double m_minDl;
24  size_t m_xBins;
25  size_t m_yBins;
26  size_t m_size;
27 
28  std::vector< boost::shared_ptr<Histogram> > m_histograms;
29  boost::shared_ptr<Histogram> m_normalization;
30  boost::shared_ptr<ColorMap> m_colormap;
31  boost::shared_ptr<Histogram> m_dummy;
32 
33 public:
35  XHistogram(void) :
36  m_minDl( 0.000001 ),
37  m_xRange(),
38  m_yRange(),
39  m_xBins(),
40  m_yBins(),
41  m_size(),
42  m_histograms(),
44  m_colormap(),
45  m_dummy()
46  { }
47 
48  // explicit CTOR
49  XHistogram( size_t size, size_t bins_x, size_t bins_y, Range x, Range y, size_t zones, std::vector<double> max ) :
50  m_minDl( 0.000001 ),
51  m_xRange( x ),
52  m_yRange( y ),
53  m_xBins( bins_x ),
54  m_yBins( bins_y ),
55  m_size( size ),
58  m_colormap()
59  {
60  // setup unnamed ROOT histograms
61  for (size_t i = 0; i < m_size; ++i) {
62  m_histograms[i].reset(new Histogram( 0, 0, bins_x, x.first, x.second, bins_y, y.first, y.second ));
63  m_histograms[i]->SetMinimum( 0. );
64  m_histograms[i]->SetMaximum( max[i] );
65  }
66  m_normalization.reset(new Histogram( 0, 0, bins_x, x.first, x.second, bins_y, y.first, y.second ));
67  m_colormap.reset(new ColorMap( 0, 0, bins_x, x.first, x.second, bins_y, y.first, y.second ));
68  m_colormap->SetMinimum( 0 );
69  m_colormap->SetMaximum( zones );
70  Histogram( 0, 0, 0, 0., 0., 0, 0., 0. ); // make ROOT "forget" about unnamed histograms
71  }
72 
74  void fill( double x, double y, const std::vector<double> & weight, double norm );
75 
77  void fill( double x, double y, const std::vector<double> & weight, double norm, unsigned int colour );
78 
80  void fill( const Range& x, const Range& y, const std::vector<double> & weight, double norm );
81 
83  void fill( const Range& x, const Range& y, const std::vector<double> & weight, double norm, unsigned int colour );
84 
86  void normalize(void);
87 
89  Histogram * get(size_t h = 0) const
90  {
91  if (h < m_size)
92  return (Histogram *) m_histograms[h]->Clone(0);
93  else
94  return 0;
95  }
96 
98  Histogram * normalization(void) const
99  {
100  return (Histogram *) m_normalization->Clone(0);
101  }
102 
104  ColorMap * colormap(void) const
105  {
106  return (ColorMap *) m_colormap->Clone(0);
107  }
108 
111  void setMinDl( double dl )
112  {
113  m_minDl = dl;
114  }
115 
116 protected:
117  struct position {
118  double f;
119  double x;
120  double y;
121 
122  position() : f(0), x(0), y(0) { }
123 
124  position(double f_, double x_, double y_) : f(f_), x(x_), y(y_) { }
125 
126  bool operator<(const position& other) const {
127  return f < other.f;
128  }
129  };
130 
132  std::vector<position> splitSegment( Range x, Range y ) const;
133 
135  void check_weight(const std::vector<double> & weight) throw (std::invalid_argument)
136  {
137  // run time check for vector size
138  if (weight.size() != m_size)
139  throw std::invalid_argument("weight: wrong number of elements");
140  }
141 
142 };
143 
144 #endif // XHistogram_h
int i
Definition: DBlmapReader.cc:9
double m_minDl
Definition: XHistogram.h:21
ColorMap * colormap(void) const
access the colormap
Definition: XHistogram.h:104
boost::shared_ptr< Histogram > m_dummy
Definition: XHistogram.h:31
Range m_xRange
Definition: XHistogram.h:22
TH2F Histogram
Definition: XHistogram.h:17
size_t m_size
Definition: XHistogram.h:26
boost::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:30
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: XHistogram.cc:7
XHistogram(size_t size, size_t bins_x, size_t bins_y, Range x, Range y, size_t zones, std::vector< double > max)
Definition: XHistogram.h:49
const T & max(const T &a, const T &b)
void check_weight(const std::vector< double > &weight)
check the weights passed as an std::vector have the correct size
Definition: XHistogram.h:135
tuple norm
Definition: lumiNorm.py:78
position(double f_, double x_, double y_)
Definition: XHistogram.h:124
bool operator<(const position &other) const
Definition: XHistogram.h:126
void setMinDl(double dl)
Definition: XHistogram.h:111
XHistogram(void)
default CTOR
Definition: XHistogram.h:35
std::vector< boost::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:28
boost::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:29
size_t m_xBins
Definition: XHistogram.h:24
TH2I ColorMap
Definition: XHistogram.h:16
size_t m_yBins
Definition: XHistogram.h:25
void fill(double x, double y, const std::vector< double > &weight, double norm)
fill one point
Definition: XHistogram.cc:71
void normalize(void)
normalize the histograms
Definition: XHistogram.cc:119
Range m_yRange
Definition: XHistogram.h:23
std::pair< double, double > Range
Definition: XHistogram.h:18
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Histogram * normalization(void) const
access the normalization
Definition: XHistogram.h:98
tuple size
Write out results.