CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
DD4hep_XHistogram Class Reference

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

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 DD4hep_XHistogram.h.

Member Typedef Documentation

◆ ColorMap

Definition at line 15 of file DD4hep_XHistogram.h.

◆ Histogram

Definition at line 16 of file DD4hep_XHistogram.h.

◆ Range

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

Definition at line 17 of file DD4hep_XHistogram.h.

Constructor & Destructor Documentation

◆ DD4hep_XHistogram() [1/2]

DD4hep_XHistogram::DD4hep_XHistogram ( void  )
inline

default CTOR

Definition at line 34 of file DD4hep_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() {}
std::vector< std::shared_ptr< Histogram > > m_histograms
std::shared_ptr< Histogram > m_dummy
std::shared_ptr< Histogram > m_normalization
std::shared_ptr< ColorMap > m_colormap

◆ DD4hep_XHistogram() [2/2]

DD4hep_XHistogram::DD4hep_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 DD4hep_XHistogram.h.

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

49  : m_minDl(0.000001),
50  m_xRange(x),
51  m_yRange(y),
52  m_xBins(bins_x),
53  m_yBins(bins_y),
54  m_size(size),
57  m_colormap() {
58  // setup unnamed ROOT histograms
59  for (size_t i = 0; i < m_size; ++i) {
60  m_histograms[i].reset(new Histogram(nullptr, nullptr, bins_x, x.first, x.second, bins_y, y.first, y.second));
61  m_histograms[i]->SetMinimum(0.);
62  m_histograms[i]->SetMaximum(max[i]);
63  }
64  m_normalization.reset(new Histogram(nullptr, nullptr, bins_x, x.first, x.second, bins_y, y.first, y.second));
65  m_colormap.reset(new ColorMap(nullptr, nullptr, bins_x, x.first, x.second, bins_y, y.first, y.second));
66  m_colormap->SetMinimum(0);
67  m_colormap->SetMaximum(zones);
68  Histogram(nullptr, nullptr, 0, 0., 0., 0, 0., 0.); // make ROOT "forget" about unnamed histograms
69  }
size
Write out results.
std::vector< std::shared_ptr< Histogram > > m_histograms
std::shared_ptr< Histogram > m_normalization
std::shared_ptr< ColorMap > m_colormap

Member Function Documentation

◆ check_weight()

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

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

Definition at line 121 of file DD4hep_XHistogram.h.

References m_size.

Referenced by fill().

121  {
122  // run time check for vector size
123  if (weight.size() != m_size)
124  throw std::invalid_argument("weight: wrong number of elements");
125  }
Definition: weight.py:1

◆ colormap()

ColorMap* DD4hep_XHistogram::colormap ( void  ) const
inline

access the colormap

Definition at line 98 of file DD4hep_XHistogram.h.

References m_colormap.

Referenced by DD4hep_TrackingMaterialPlotter::draw().

98 { return (ColorMap*)m_colormap->Clone(nullptr); }
std::shared_ptr< ColorMap > m_colormap

◆ fill() [1/4]

void DD4hep_XHistogram::fill ( double  x,
double  y,
const std::vector< double > &  weight,
double  norm 
)

fill one point

Definition at line 70 of file DD4hep_XHistogram.cc.

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

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

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 }
Definition: weight.py:1
void check_weight(const std::vector< double > &weight) noexcept(false)
check the weights passed as an std::vector have the correct size
std::vector< std::shared_ptr< Histogram > > m_histograms
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
std::shared_ptr< Histogram > m_normalization
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ fill() [2/4]

void DD4hep_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 DD4hep_XHistogram.cc.

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

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 }
Definition: weight.py:1
void check_weight(const std::vector< double > &weight) noexcept(false)
check the weights passed as an std::vector have the correct size
std::vector< std::shared_ptr< Histogram > > m_histograms
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
std::shared_ptr< Histogram > m_normalization
std::shared_ptr< ColorMap > m_colormap
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ fill() [3/4]

void DD4hep_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 DD4hep_XHistogram.cc.

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

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 }
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: weight.py:1
void check_weight(const std::vector< double > &weight) noexcept(false)
check the weights passed as an std::vector have the correct size
std::vector< std::shared_ptr< Histogram > > m_histograms
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
double f[11][100]
std::shared_ptr< Histogram > m_normalization
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ fill() [4/4]

void DD4hep_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 DD4hep_XHistogram.cc.

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.

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 }
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: weight.py:1
void check_weight(const std::vector< double > &weight) noexcept(false)
check the weights passed as an std::vector have the correct size
std::vector< std::shared_ptr< Histogram > > m_histograms
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
double f[11][100]
std::shared_ptr< Histogram > m_normalization
std::shared_ptr< ColorMap > m_colormap
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ get()

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

access one of the histograms

Definition at line 87 of file DD4hep_XHistogram.h.

References h, m_histograms, and m_size.

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

87  {
88  if (h < m_size)
89  return (Histogram*)m_histograms[h]->Clone(nullptr);
90  else
91  return nullptr;
92  }
std::vector< std::shared_ptr< Histogram > > m_histograms
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ normalization()

Histogram* DD4hep_XHistogram::normalization ( void  ) const
inline

access the normalization

Definition at line 95 of file DD4hep_XHistogram.h.

References m_normalization.

95 { return (Histogram*)m_normalization->Clone(nullptr); }
std::shared_ptr< Histogram > m_normalization

◆ normalize()

void DD4hep_XHistogram::normalize ( void  )

normalize the histograms

Definition at line 115 of file DD4hep_XHistogram.cc.

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

Referenced by DD4hep_TrackingMaterialPlotter::normalize().

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 }
std::vector< std::shared_ptr< Histogram > > m_histograms
std::shared_ptr< Histogram > m_normalization
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ setMinDl()

void DD4hep_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 102 of file DD4hep_XHistogram.h.

References m_minDl.

102 { m_minDl = dl; }

◆ splitSegment()

std::vector< DD4hep_XHistogram::position > DD4hep_XHistogram::splitSegment ( Range  x,
Range  y 
) const
protected

split a segment into a vector of points

Definition at line 7 of file DD4hep_XHistogram.cc.

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().

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.emplace_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.emplace_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.emplace_back(position(f, x, y));
48  }
49  v.emplace_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.emplace_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.emplace_back(position(df, mx, my));
64  }
65 
66  return result;
67 }
constexpr int32_t ceil(float num)
double f[11][100]
static int position[264][3]
Definition: ReadPGInfo.cc:289

Member Data Documentation

◆ m_colormap

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

Definition at line 29 of file DD4hep_XHistogram.h.

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

◆ m_dummy

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

Definition at line 30 of file DD4hep_XHistogram.h.

◆ m_histograms

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

Definition at line 27 of file DD4hep_XHistogram.h.

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

◆ m_minDl

double DD4hep_XHistogram::m_minDl
protected

Definition at line 20 of file DD4hep_XHistogram.h.

Referenced by setMinDl(), and splitSegment().

◆ m_normalization

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

Definition at line 28 of file DD4hep_XHistogram.h.

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

◆ m_size

size_t DD4hep_XHistogram::m_size
protected

Definition at line 25 of file DD4hep_XHistogram.h.

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

◆ m_xBins

size_t DD4hep_XHistogram::m_xBins
protected

Definition at line 23 of file DD4hep_XHistogram.h.

Referenced by splitSegment().

◆ m_xRange

Range DD4hep_XHistogram::m_xRange
protected

Definition at line 21 of file DD4hep_XHistogram.h.

Referenced by splitSegment().

◆ m_yBins

size_t DD4hep_XHistogram::m_yBins
protected

Definition at line 24 of file DD4hep_XHistogram.h.

Referenced by splitSegment().

◆ m_yRange

Range DD4hep_XHistogram::m_yRange
protected

Definition at line 22 of file DD4hep_XHistogram.h.

Referenced by splitSegment().