CMS 3D CMS Logo

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) noexcept(false)
 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

std::shared_ptr< ColorMapm_colormap
 
std::shared_ptr< Histogramm_dummy
 
std::vector< std::shared_ptr< Histogram > > m_histograms
 
double m_minDl
 
std::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 15 of file XHistogram.h.

typedef TH2F XHistogram::Histogram

Definition at line 16 of file XHistogram.h.

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

Definition at line 17 of file XHistogram.h.

Constructor & Destructor Documentation

XHistogram::XHistogram ( void  )
inline

default CTOR

Definition at line 34 of file XHistogram.h.

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() {}
double m_minDl
Definition: XHistogram.h:20
Range m_xRange
Definition: XHistogram.h:21
size_t m_size
Definition: XHistogram.h:25
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
std::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:29
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
std::shared_ptr< Histogram > m_dummy
Definition: XHistogram.h:30
size_t m_xBins
Definition: XHistogram.h:23
size_t m_yBins
Definition: XHistogram.h:24
Range m_yRange
Definition: XHistogram.h:22
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 47 of file XHistogram.h.

References fill(), mps_fire::i, m_size, normalize(), x, and y.

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  }
size
Write out results.
double m_minDl
Definition: XHistogram.h:20
Range m_xRange
Definition: XHistogram.h:21
TH2F Histogram
Definition: XHistogram.h:16
size_t m_size
Definition: XHistogram.h:25
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
std::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:29
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
size_t m_xBins
Definition: XHistogram.h:23
TH2I ColorMap
Definition: XHistogram.h:15
size_t m_yBins
Definition: XHistogram.h:24
Range m_yRange
Definition: XHistogram.h:22

Member Function Documentation

void XHistogram::check_weight ( const std::vector< double > &  weight)
inlineprotectednoexcept

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

Definition at line 120 of file XHistogram.h.

References m_size.

Referenced by fill().

120  {
121  // run time check for vector size
122  if (weight.size() != m_size)
123  throw std::invalid_argument("weight: wrong number of elements");
124  }
Definition: weight.py:1
size_t m_size
Definition: XHistogram.h:25
ColorMap* XHistogram::colormap ( void  ) const
inline

access the colormap

Definition at line 97 of file XHistogram.h.

Referenced by TrackingMaterialPlotter::draw().

97 { return (ColorMap*)m_colormap->Clone(nullptr); }
std::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:29
TH2I ColorMap
Definition: XHistogram.h:15
void XHistogram::fill ( double  x,
double  y,
const std::vector< double > &  weight,
double  norm 
)

fill one point

Definition at line 70 of file XHistogram.cc.

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

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

70  {
72 
73  for (size_t h = 0; h < m_size; ++h)
74  m_histograms[h]->Fill(x, y, weight[h]);
75  m_normalization->Fill(x, y, norm);
76 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: weight.py:1
size_t m_size
Definition: XHistogram.h:25
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void check_weight(const std::vector< double > &weight) noexcept(false)
check the weights passed as an std::vector have the correct size
Definition: XHistogram.h:120
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
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 79 of file XHistogram.cc.

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

79  {
81 
82  for (size_t h = 0; h < m_size; ++h)
83  m_histograms[h]->Fill(x, y, weight[h]);
84  m_normalization->Fill(x, y, norm);
85  m_colormap->SetBinContent(m_colormap->FindBin(x, y), (float)colour);
86 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: weight.py:1
size_t m_size
Definition: XHistogram.h:25
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void check_weight(const std::vector< double > &weight) noexcept(false)
check the weights passed as an std::vector have the correct size
Definition: XHistogram.h:120
std::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:29
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
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 89 of file XHistogram.cc.

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

89  {
91 
92  std::vector<position> v = splitSegment(x, y);
93  for (size_t i = 0, s = v.size(); i < s; ++i) {
94  for (size_t h = 0; h < m_size; ++h)
95  m_histograms[h]->Fill(v[i].x, v[i].y, v[i].f * weight[h]);
96  m_normalization->Fill(v[i].x, v[i].y, v[i].f * norm);
97  }
98 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: weight.py:1
size_t m_size
Definition: XHistogram.h:25
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: XHistogram.cc:7
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void check_weight(const std::vector< double > &weight) noexcept(false)
check the weights passed as an std::vector have the correct size
Definition: XHistogram.h:120
double f[11][100]
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
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 101 of file XHistogram.cc.

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

102  {
104 
105  std::vector<position> v = splitSegment(x, y);
106  for (size_t i = 0, s = v.size(); i < s; ++i) {
107  for (size_t h = 0; h < m_size; ++h)
108  m_histograms[h]->Fill(v[i].x, v[i].y, v[i].f * weight[h]);
109  m_normalization->Fill(v[i].x, v[i].y, v[i].f * norm);
110  m_colormap->SetBinContent(m_colormap->FindBin(v[i].x, v[i].y), (float)colour);
111  }
112 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: weight.py:1
size_t m_size
Definition: XHistogram.h:25
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: XHistogram.cc:7
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void check_weight(const std::vector< double > &weight) noexcept(false)
check the weights passed as an std::vector have the correct size
Definition: XHistogram.h:120
std::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:29
double f[11][100]
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
Histogram* XHistogram::get ( size_t  h = 0) const
inline

access one of the histograms

Definition at line 86 of file XHistogram.h.

References h.

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

86  {
87  if (h < m_size)
88  return (Histogram*)m_histograms[h]->Clone(nullptr);
89  else
90  return nullptr;
91  }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
TH2F Histogram
Definition: XHistogram.h:16
size_t m_size
Definition: XHistogram.h:25
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
Histogram* XHistogram::normalization ( void  ) const
inline

access the normalization

Definition at line 94 of file XHistogram.h.

94 { return (Histogram*)m_normalization->Clone(nullptr); }
TH2F Histogram
Definition: XHistogram.h:16
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
void XHistogram::normalize ( void  )

normalize the histograms

Definition at line 115 of file XHistogram.cc.

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

Referenced by TrackingMaterialPlotter::normalize(), and XHistogram().

115  {
116  for (int i = 0; i < m_normalization->GetSize(); ++i) {
117  if ((*m_normalization)[i] > 0.) {
118  for (size_t h = 0; h < m_size; ++h)
119  (*m_histograms[h])[i] /= (*m_normalization)[i];
120  (*m_normalization)[i] = 1.;
121  }
122  }
123 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
size_t m_size
Definition: XHistogram.h:25
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
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 101 of file XHistogram.h.

101 { m_minDl = dl; }
double m_minDl
Definition: XHistogram.h:20
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, mps_fire::i, createfilelist::int, m_minDl, m_xBins, m_xRange, m_yBins, m_yRange, position, mps_fire::result, alignCSCRings::s, jetUpdater_cfi::sort, customisers::steps, findQualityFiles::v, x, and y.

Referenced by fill(), and XHistogram::position::operator<().

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

Member Data Documentation

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

Definition at line 29 of file XHistogram.h.

Referenced by fill().

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

Definition at line 30 of file XHistogram.h.

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

Definition at line 27 of file XHistogram.h.

Referenced by fill(), and normalize().

double XHistogram::m_minDl
protected

Definition at line 20 of file XHistogram.h.

Referenced by splitSegment().

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

Definition at line 28 of file XHistogram.h.

Referenced by fill(), and normalize().

size_t XHistogram::m_size
protected

Definition at line 25 of file XHistogram.h.

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

size_t XHistogram::m_xBins
protected

Definition at line 23 of file XHistogram.h.

Referenced by splitSegment().

Range XHistogram::m_xRange
protected

Definition at line 21 of file XHistogram.h.

Referenced by splitSegment().

size_t XHistogram::m_yBins
protected

Definition at line 24 of file XHistogram.h.

Referenced by splitSegment().

Range XHistogram::m_yRange
protected

Definition at line 22 of file XHistogram.h.

Referenced by splitSegment().