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 (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...
 
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...
 
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 (size_t size, size_t bins_x, size_t bins_y, Range x, Range y, size_t zones, const std::vector< double > &max)
 
 XHistogram (void)
 default CTOR More...
 

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

◆ ColorMap

typedef TH2I XHistogram::ColorMap

Definition at line 15 of file XHistogram.h.

◆ Histogram

typedef TH2F XHistogram::Histogram

Definition at line 16 of file XHistogram.h.

◆ Range

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

Definition at line 17 of file XHistogram.h.

Constructor & Destructor Documentation

◆ XHistogram() [1/2]

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() {}

◆ XHistogram() [2/2]

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.

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  }

References mps_fire::i, m_colormap, m_histograms, m_normalization, m_size, SiStripPI::max, x, and y.

Member Function Documentation

◆ check_weight()

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.

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  }

References m_size.

Referenced by fill().

◆ colormap()

ColorMap* XHistogram::colormap ( void  ) const
inline

access the colormap

Definition at line 97 of file XHistogram.h.

97 { return (ColorMap*)m_colormap->Clone(nullptr); }

References m_colormap.

Referenced by TrackingMaterialPlotter::draw().

◆ fill() [1/4]

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.

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 }

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

◆ fill() [2/4]

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.

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 }

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

◆ fill() [3/4]

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.

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 }

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

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

◆ fill() [4/4]

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.

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 }

References check_weight(), HcalObjRepresent::Fill(), dqmMemoryStats::float, h, m_colormap, m_histograms, m_normalization, m_size, x, and y.

◆ get()

Histogram* XHistogram::get ( size_t  h = 0) const
inline

◆ normalization()

Histogram* XHistogram::normalization ( void  ) const
inline

access the normalization

Definition at line 94 of file XHistogram.h.

94 { return (Histogram*)m_normalization->Clone(nullptr); }

References m_normalization.

◆ normalize()

void XHistogram::normalize ( void  )

normalize the histograms

Definition at line 115 of file XHistogram.cc.

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 }

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

Referenced by TrackingMaterialPlotter::normalize().

◆ setMinDl()

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; }

References m_minDl.

◆ splitSegment()

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.

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 }

References reco::ceil(), hgcalPerformanceValidation::df, 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().

Member Data Documentation

◆ m_colormap

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

Definition at line 29 of file XHistogram.h.

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

◆ m_dummy

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

Definition at line 30 of file XHistogram.h.

◆ m_histograms

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

Definition at line 27 of file XHistogram.h.

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

◆ m_minDl

double XHistogram::m_minDl
protected

Definition at line 20 of file XHistogram.h.

Referenced by setMinDl(), and splitSegment().

◆ m_normalization

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

Definition at line 28 of file XHistogram.h.

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

◆ m_size

size_t XHistogram::m_size
protected

Definition at line 25 of file XHistogram.h.

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

◆ m_xBins

size_t XHistogram::m_xBins
protected

Definition at line 23 of file XHistogram.h.

Referenced by splitSegment().

◆ m_xRange

Range XHistogram::m_xRange
protected

Definition at line 21 of file XHistogram.h.

Referenced by splitSegment().

◆ m_yBins

size_t XHistogram::m_yBins
protected

Definition at line 24 of file XHistogram.h.

Referenced by splitSegment().

◆ m_yRange

Range XHistogram::m_yRange
protected

Definition at line 22 of file XHistogram.h.

Referenced by splitSegment().

XHistogram::m_histograms
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: XHistogram.h:27
DDAxes::y
XHistogram::m_size
size_t m_size
Definition: XHistogram.h:25
mps_fire.i
i
Definition: mps_fire.py:428
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
XHistogram::m_minDl
double m_minDl
Definition: XHistogram.h:20
XHistogram::m_xBins
size_t m_xBins
Definition: XHistogram.h:23
DDAxes::x
findQualityFiles.v
v
Definition: findQualityFiles.py:179
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
alignCSCRings.s
s
Definition: alignCSCRings.py:92
reco::ceil
constexpr int32_t ceil(float num)
Definition: constexpr_cmath.h:7
XHistogram::m_normalization
std::shared_ptr< Histogram > m_normalization
Definition: XHistogram.h:28
h
XHistogram::m_yBins
size_t m_yBins
Definition: XHistogram.h:24
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
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: XHistogram.h:120
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
createfilelist.int
int
Definition: createfilelist.py:10
XHistogram::m_xRange
Range m_xRange
Definition: XHistogram.h:21
XHistogram::m_colormap
std::shared_ptr< ColorMap > m_colormap
Definition: XHistogram.h:29
XHistogram::m_yRange
Range m_yRange
Definition: XHistogram.h:22
HcalObjRepresent::Fill
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Definition: HcalObjRepresent.h:1053
XHistogram::ColorMap
TH2I ColorMap
Definition: XHistogram.h:15
hgcalPerformanceValidation.df
df
Definition: hgcalPerformanceValidation.py:733
customisers.steps
steps
Definition: customisers.py:39
mps_fire.result
result
Definition: mps_fire.py:311
XHistogram::m_dummy
std::shared_ptr< Histogram > m_dummy
Definition: XHistogram.h:30
weight
Definition: weight.py:1
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
XHistogram::splitSegment
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: XHistogram.cc:7
XHistogram::Histogram
TH2F Histogram
Definition: XHistogram.h:16