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 
73  void reset( void )
74  {
75  // reset all ROOT histograms
76  for (size_t i = 0; i < m_size; ++i)
77  m_histograms[i]->Reset("ICES");
78  m_normalization->Reset();
79  m_colormap->Reset("ICES");
80  }
81 
83  void fill( double x, double y, const std::vector<double> & weight, double norm );
84 
86  void fill( double x, double y, const std::vector<double> & weight, double norm, unsigned int colour );
87 
89  void fill( const Range& x, const Range& y, const std::vector<double> & weight, double norm );
90 
92  void fill( const Range& x, const Range& y, const std::vector<double> & weight, double norm, unsigned int colour );
93 
95  void normalize(void);
96 
98  Histogram * get(size_t h = 0) const
99  {
100  if (h < m_size)
101  return (Histogram *) m_histograms[h]->Clone(0);
102  else
103  return 0;
104  }
105 
107  Histogram * normalization(void) const
108  {
109  return (Histogram *) m_normalization->Clone(0);
110  }
111 
113  ColorMap * colormap(void) const
114  {
115  return (ColorMap *) m_colormap->Clone(0);
116  }
117 
120  void setMinDl( double dl )
121  {
122  m_minDl = dl;
123  }
124 
125 protected:
126  struct position {
127  double f;
128  double x;
129  double y;
130 
131  position() : f(0), x(0), y(0) { }
132 
133  position(double f_, double x_, double y_) : f(f_), x(x_), y(y_) { }
134 
135  bool operator<(const position& other) const {
136  return f < other.f;
137  }
138  };
139 
141  std::vector<position> splitSegment( Range x, Range y ) const;
142 
144  void check_weight(const std::vector<double> & weight) throw (std::invalid_argument)
145  {
146  // run time check for vector size
147  if (weight.size() != m_size)
148  throw std::invalid_argument("weight: wrong number of elements");
149  }
150 
151 };
152 
153 #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:113
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:144
position(double f_, double x_, double y_)
Definition: XHistogram.h:133
bool operator<(const position &other) const
Definition: XHistogram.h:135
void setMinDl(double dl)
Definition: XHistogram.h:120
XHistogram(void)
default CTOR
Definition: XHistogram.h:35
std::vector< boost::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:28
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
boost::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:29
size_t m_xBins
Definition: XHistogram.h:24
TH2I ColorMap
Definition: XHistogram.h:16
void reset(void)
Definition: XHistogram.h:73
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
void Reset(std::vector< TH2F > &depth)
Definition: DDAxes.h:10
int weight
Definition: histoStyle.py:50
std::pair< double, double > Range
Definition: XHistogram.h:18
Histogram * normalization(void) const
access the normalization
Definition: XHistogram.h:107
tuple size
Write out results.