CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
XHistogram Class Reference

#include <XHistogram.h>

Classes

struct  position
 

Public Types

typedef TH2I ColorMap
 
typedef TH2F Histogram
 
typedef std::pair< double, double > Range
 

Public Member Functions

ColorMapcolormap (void) const
 access the colormap More...
 
void fill (double x, double y, const std::vector< double > &weight, double norm)
 fill one point More...
 
void fill (double x, double y, const std::vector< double > &weight, double norm, unsigned int colour)
 fill one point and set its color More...
 
void fill (const Range &x, const Range &y, const std::vector< double > &weight, double norm)
 fill one segment, normalizing each bin's weight to the fraction of the segment it contains More...
 
void fill (const Range &x, const Range &y, const std::vector< double > &weight, double norm, unsigned int colour)
 fill one segment and set its color, normalizing each bin's weight to the fraction of the segment it contains More...
 
Histogramget (size_t h=0) const
 access one of the histograms More...
 
Histogramnormalization (void) const
 access the normalization More...
 
void normalize (void)
 normalize the histograms More...
 
void setMinDl (double dl)
 
 XHistogram (void)
 default CTOR More...
 
 XHistogram (size_t size, size_t bins_x, size_t bins_y, Range x, Range y, size_t zones, const std::vector< double > &max)
 

Protected Member Functions

void check_weight (const std::vector< double > &weight) throw (std::invalid_argument)
 check the weights passed as an std::vector have the correct size More...
 
std::vector< positionsplitSegment (Range x, Range y) const
 split a segment into a vector of points More...
 

Protected Attributes

boost::shared_ptr< ColorMapm_colormap
 
boost::shared_ptr< Histogramm_dummy
 
std::vector< boost::shared_ptr
< Histogram > > 
m_histograms
 
double m_minDl
 
boost::shared_ptr< Histogramm_normalization
 
size_t m_size
 
size_t m_xBins
 
Range m_xRange
 
size_t m_yBins
 
Range m_yRange
 

Detailed Description

Definition at line 13 of file XHistogram.h.

Member Typedef Documentation

typedef TH2I XHistogram::ColorMap

Definition at line 16 of file XHistogram.h.

typedef TH2F XHistogram::Histogram

Definition at line 17 of file XHistogram.h.

typedef std::pair<double, double> XHistogram::Range

Definition at line 18 of file XHistogram.h.

Constructor & Destructor Documentation

XHistogram::XHistogram ( void  )
inline

default CTOR

Definition at line 35 of file XHistogram.h.

35  :
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  { }
double m_minDl
Definition: XHistogram.h:21
boost::shared_ptr< Histogram > m_dummy
Definition: XHistogram.h:31
Range m_xRange
Definition: XHistogram.h:22
size_t m_size
Definition: XHistogram.h:26
boost::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:30
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
size_t m_yBins
Definition: XHistogram.h:25
Range m_yRange
Definition: XHistogram.h:23
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 
)
inline

Definition at line 49 of file XHistogram.h.

References i, m_colormap, m_histograms, m_normalization, and m_size.

49  :
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  }
int i
Definition: DBlmapReader.cc:9
double m_minDl
Definition: XHistogram.h:21
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
const T & max(const T &a, const T &b)
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
Range m_yRange
Definition: XHistogram.h:23
Definition: DDAxes.h:10
tuple size
Write out results.

Member Function Documentation

void XHistogram::check_weight ( const std::vector< double > &  weight)
throw (std::invalid_argument
)
inlineprotected

check the weights passed as an std::vector have the correct size

Definition at line 135 of file XHistogram.h.

References m_size, and histoStyle::weight.

Referenced by fill().

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  }
size_t m_size
Definition: XHistogram.h:26
int weight
Definition: histoStyle.py:50
ColorMap* XHistogram::colormap ( void  ) const
inline

access the colormap

Definition at line 104 of file XHistogram.h.

References m_colormap.

Referenced by TrackingMaterialPlotter::draw().

105  {
106  return (ColorMap *) m_colormap->Clone(0);
107  }
boost::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:30
TH2I ColorMap
Definition: XHistogram.h:16
void XHistogram::fill ( double  x,
double  y,
const std::vector< double > &  weight,
double  norm 
)

fill one point

Definition at line 71 of file XHistogram.cc.

References check_weight(), HcalObjRepresent::Fill(), h, m_histograms, m_normalization, and m_size.

Referenced by TrackingMaterialPlotter::plotSegmentInLayer(), and TrackingMaterialPlotter::plotSegmentUnassigned().

72 {
74 
75  for (size_t h = 0; h < m_size; ++h)
76  m_histograms[h]->Fill( x, y, weight[h] );
77  m_normalization->Fill( x, y, norm );
78 }
size_t m_size
Definition: XHistogram.h:26
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void check_weight(const std::vector< double > &weight)
check the weights passed as an std::vector have the correct size
Definition: XHistogram.h:135
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
Definition: DDAxes.h:10
int weight
Definition: histoStyle.py:50
void XHistogram::fill ( double  x,
double  y,
const std::vector< double > &  weight,
double  norm,
unsigned int  colour 
)

fill one point and set its color

Definition at line 81 of file XHistogram.cc.

References check_weight(), HcalObjRepresent::Fill(), h, m_colormap, m_histograms, m_normalization, and m_size.

82 {
84 
85  for (size_t h = 0; h < m_size; ++h)
86  m_histograms[h]->Fill( x, y, weight[h] );
87  m_normalization->Fill( x, y, norm );
88  m_colormap->SetBinContent( m_colormap->FindBin(x, y), (float) colour );
89 }
size_t m_size
Definition: XHistogram.h:26
boost::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:30
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void check_weight(const std::vector< double > &weight)
check the weights passed as an std::vector have the correct size
Definition: XHistogram.h:135
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
Definition: DDAxes.h:10
int weight
Definition: histoStyle.py:50
void XHistogram::fill ( const Range x,
const Range y,
const std::vector< double > &  weight,
double  norm 
)

fill one segment, normalizing each bin's weight to the fraction of the segment it contains

Definition at line 92 of file XHistogram.cc.

References check_weight(), f, HcalObjRepresent::Fill(), h, i, m_histograms, m_normalization, m_size, alignCSCRings::s, splitSegment(), and findQualityFiles::v.

93 {
95 
96  std::vector<position> v = splitSegment( x, y );
97  for (size_t i = 0, s = v.size(); i < s; ++i) {
98  for (size_t h = 0; h < m_size; ++h)
99  m_histograms[h]->Fill( v[i].x, v[i].y, v[i].f * weight[h] );
100  m_normalization->Fill( v[i].x, v[i].y, v[i].f * norm );
101  }
102 }
int i
Definition: DBlmapReader.cc:9
size_t m_size
Definition: XHistogram.h:26
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: XHistogram.cc:7
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void check_weight(const std::vector< double > &weight)
check the weights passed as an std::vector have the correct size
Definition: XHistogram.h:135
double f[11][100]
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
Definition: DDAxes.h:10
int weight
Definition: histoStyle.py:50
void XHistogram::fill ( const Range x,
const Range y,
const std::vector< double > &  weight,
double  norm,
unsigned int  colour 
)

fill one segment and set its color, normalizing each bin's weight to the fraction of the segment it contains

Definition at line 105 of file XHistogram.cc.

References check_weight(), f, HcalObjRepresent::Fill(), h, i, m_colormap, m_histograms, m_normalization, m_size, alignCSCRings::s, splitSegment(), and findQualityFiles::v.

106 {
107  check_weight( weight );
108 
109  std::vector<position> v = splitSegment( x, y );
110  for (size_t i = 0, s = v.size(); i < s; ++i) {
111  for (size_t h = 0; h < m_size; ++h)
112  m_histograms[h]->Fill( v[i].x, v[i].y, v[i].f * weight[h] );
113  m_normalization->Fill( v[i].x, v[i].y, v[i].f * norm );
114  m_colormap->SetBinContent( m_colormap->FindBin(v[i].x, v[i].y), (float) colour );
115  }
116 }
int i
Definition: DBlmapReader.cc:9
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
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void check_weight(const std::vector< double > &weight)
check the weights passed as an std::vector have the correct size
Definition: XHistogram.h:135
double f[11][100]
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
Definition: DDAxes.h:10
int weight
Definition: histoStyle.py:50
Histogram* XHistogram::get ( size_t  h = 0) const
inline

access one of the histograms

Definition at line 89 of file XHistogram.h.

References h, m_histograms, and m_size.

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), TrackingMaterialPlotter::draw(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), and betterConfigParser.BetterConfigParser::getResultingSection().

90  {
91  if (h < m_size)
92  return (Histogram *) m_histograms[h]->Clone(0);
93  else
94  return 0;
95  }
TH2F Histogram
Definition: XHistogram.h:17
size_t m_size
Definition: XHistogram.h:26
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
Histogram* XHistogram::normalization ( void  ) const
inline

access the normalization

Definition at line 98 of file XHistogram.h.

References m_normalization.

99  {
100  return (Histogram *) m_normalization->Clone(0);
101  }
TH2F Histogram
Definition: XHistogram.h:17
boost::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:29
void XHistogram::normalize ( void  )

normalize the histograms

Definition at line 119 of file XHistogram.cc.

References h, i, m_histograms, m_normalization, and m_size.

Referenced by TrackingMaterialPlotter::normalize().

120 {
121  for (int i = 0; i < m_normalization->GetSize(); ++i) {
122  if ((*m_normalization)[i] > 0.) {
123  for (size_t h = 0; h < m_size; ++h)
124  (*m_histograms[h])[i] /= (*m_normalization)[i];
125  (*m_normalization)[i] = 1.;
126  }
127  }
128 }
int i
Definition: DBlmapReader.cc:9
size_t m_size
Definition: XHistogram.h:26
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
void XHistogram::setMinDl ( double  dl)
inline

set the minimum length of sub-segment a segment should be split into: when splitting across bin boundaries with splitSegment(...), sub-segments shorter than this are skipped

Definition at line 111 of file XHistogram.h.

References m_minDl.

112  {
113  m_minDl = dl;
114  }
double m_minDl
Definition: XHistogram.h:21
std::vector< XHistogram::position > XHistogram::splitSegment ( Range  x,
Range  y 
) const
protected

split a segment into a vector of points

Definition at line 7 of file XHistogram.cc.

References f, i, m_minDl, m_xBins, m_xRange, m_yBins, m_yRange, position, query::result, alignCSCRings::s, python.multivaluedict::sort(), relval_steps::steps, findQualityFiles::v, x, and detailsBasic3DVector::y.

Referenced by fill().

8 {
9  double deltaX = rangeX.second - rangeX.first;
10  double deltaY = rangeY.second - rangeY.first;
11  double length = hypot(deltaX, deltaY);
12  double stepX = (m_xRange.second - m_xRange.first) / m_xBins;
13  double stepY = (m_yRange.second - m_yRange.first) / m_yBins;
14 
15  int min_i, max_i, min_j, max_j;
16  if (rangeX.first < rangeX.second) {
17  min_i = (int) ceil(rangeX.first / stepX); // included
18  max_i = (int) floor(rangeX.second / stepX) + 1; // excluded
19  } else {
20  min_i = (int) ceil(rangeX.second / stepX);
21  max_i = (int) floor(rangeX.first / stepX) + 1;
22  }
23  if (rangeY.first < rangeY.second) {
24  min_j = (int) ceil(rangeY.first / stepY);
25  max_j = (int) floor(rangeY.second / stepY) + 1;
26  } else {
27  min_j = (int) ceil(rangeY.second / stepY);
28  max_j = (int) floor(rangeY.first / stepY) + 1;
29  }
30 
31  int steps = max_i-min_i + max_j-min_j + 2;
32  std::vector<position> v;
33  v.clear();
34  v.reserve(steps);
35 
36  v.push_back( position(0., rangeX.first, rangeY.first) );
37  double x, y, f;
38  for (int i = min_i; i < max_i; ++i) {
39  x = i * stepX;
40  y = rangeY.first + (x - rangeX.first) * deltaY / deltaX;
41  f = std::fabs( (x - rangeX.first) / deltaX );
42  v.push_back( position(f, x, y) );
43  }
44  for (int i = min_j; i < max_j; ++i) {
45  y = i * stepY;
46  x = rangeX.first + (y - rangeY.first) * deltaX / deltaY;
47  f = std::fabs( (y - rangeY.first) / deltaY );
48  v.push_back( position(f, x, y) );
49  }
50  v.push_back( position(1., rangeX.second, rangeY.second) );
51 
52  // sort by distance from the start of the segment
53  std::sort(v.begin(), v.end());
54 
55  // filter away the fragments shorter than m_minDl, and save the center of each fragment along with its fractionary length
56  std::vector<position> result;
57  result.push_back( v.front() );
58  for (int i = 1, s = v.size(); i < s; ++i) {
59  double mx = (v[i].x + v[i-1].x) / 2.;
60  double my = (v[i].y + v[i-1].y) / 2.;
61  double df = (v[i].f - v[i-1].f);
62  if (df * length < m_minDl)
63  continue;
64  result.push_back( position( df, mx, my ) );
65  }
66 
67  return result;
68 }
int i
Definition: DBlmapReader.cc:9
double m_minDl
Definition: XHistogram.h:21
Range m_xRange
Definition: XHistogram.h:22
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
tuple result
Definition: query.py:137
double f[11][100]
size_t m_xBins
Definition: XHistogram.h:24
size_t m_yBins
Definition: XHistogram.h:25
Range m_yRange
Definition: XHistogram.h:23
Definition: DDAxes.h:10

Member Data Documentation

boost::shared_ptr<ColorMap> XHistogram::m_colormap
protected

Definition at line 30 of file XHistogram.h.

Referenced by colormap(), fill(), and XHistogram().

boost::shared_ptr<Histogram> XHistogram::m_dummy
protected

Definition at line 31 of file XHistogram.h.

std::vector< boost::shared_ptr<Histogram> > XHistogram::m_histograms
protected

Definition at line 28 of file XHistogram.h.

Referenced by fill(), get(), normalize(), and XHistogram().

double XHistogram::m_minDl
protected

Definition at line 21 of file XHistogram.h.

Referenced by setMinDl(), and splitSegment().

boost::shared_ptr<Histogram> XHistogram::m_normalization
protected

Definition at line 29 of file XHistogram.h.

Referenced by fill(), normalization(), normalize(), and XHistogram().

size_t XHistogram::m_size
protected

Definition at line 26 of file XHistogram.h.

Referenced by check_weight(), fill(), get(), normalize(), and XHistogram().

size_t XHistogram::m_xBins
protected

Definition at line 24 of file XHistogram.h.

Referenced by splitSegment().

Range XHistogram::m_xRange
protected

Definition at line 22 of file XHistogram.h.

Referenced by splitSegment().

size_t XHistogram::m_yBins
protected

Definition at line 25 of file XHistogram.h.

Referenced by splitSegment().

Range XHistogram::m_yRange
protected

Definition at line 23 of file XHistogram.h.

Referenced by splitSegment().