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

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

◆ 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.

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 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 120 of file DD4hep_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* DD4hep_XHistogram::colormap ( void  ) const
inline

access the colormap

Definition at line 97 of file DD4hep_XHistogram.h.

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

References m_colormap.

Referenced by DD4hep_TrackingMaterialPlotter::draw().

◆ fill() [1/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.

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

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

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 DD4hep_TrackingMaterialPlotter::plotSegmentInLayer(), and DD4hep_TrackingMaterialPlotter::plotSegmentUnassigned().

◆ fill() [4/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.

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* DD4hep_XHistogram::get ( size_t  h = 0) const
inline

◆ normalization()

Histogram* DD4hep_XHistogram::normalization ( void  ) const
inline

access the normalization

Definition at line 94 of file DD4hep_XHistogram.h.

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

References m_normalization.

◆ normalize()

void DD4hep_XHistogram::normalize ( void  )

normalize the histograms

Definition at line 115 of file DD4hep_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 DD4hep_TrackingMaterialPlotter::normalize().

◆ 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 101 of file DD4hep_XHistogram.h.

101 { m_minDl = dl; }

References m_minDl.

◆ 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.

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(), f, mps_fire::i, createfilelist::int, m_minDl, m_xBins, m_xRange, m_yBins, m_yRange, position, mps_fire::result, alignCSCRings::s, customisers::steps, findQualityFiles::v, x, and y.

Referenced by fill().

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

DD4hep_XHistogram::m_colormap
std::shared_ptr< ColorMap > m_colormap
Definition: DD4hep_XHistogram.h:29
DD4hep_XHistogram::m_xRange
Range m_xRange
Definition: DD4hep_XHistogram.h:21
DDAxes::y
DD4hep_XHistogram::m_yBins
size_t m_yBins
Definition: DD4hep_XHistogram.h:24
mps_fire.i
i
Definition: mps_fire.py:355
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
DD4hep_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: DD4hep_XHistogram.h:120
DD4hep_XHistogram::Histogram
TH2F Histogram
Definition: DD4hep_XHistogram.h:16
DD4hep_XHistogram::m_xBins
size_t m_xBins
Definition: DD4hep_XHistogram.h:23
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
DD4hep_XHistogram::ColorMap
TH2I ColorMap
Definition: DD4hep_XHistogram.h:15
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
DD4hep_XHistogram::m_histograms
std::vector< std::shared_ptr< Histogram > > m_histograms
Definition: DD4hep_XHistogram.h:27
DDAxes::x
findQualityFiles.v
v
Definition: findQualityFiles.py:179
alignCSCRings.s
s
Definition: alignCSCRings.py:92
reco::ceil
constexpr int32_t ceil(float num)
Definition: constexpr_cmath.h:7
h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
DD4hep_XHistogram::m_yRange
Range m_yRange
Definition: DD4hep_XHistogram.h:22
createfilelist.int
int
Definition: createfilelist.py:10
DD4hep_XHistogram::m_minDl
double m_minDl
Definition: DD4hep_XHistogram.h:20
HcalObjRepresent::Fill
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Definition: HcalObjRepresent.h:1053
DD4hep_XHistogram::m_normalization
std::shared_ptr< Histogram > m_normalization
Definition: DD4hep_XHistogram.h:28
DD4hep_XHistogram::m_size
size_t m_size
Definition: DD4hep_XHistogram.h:25
DD4hep_XHistogram::m_dummy
std::shared_ptr< Histogram > m_dummy
Definition: DD4hep_XHistogram.h:30
DD4hep_XHistogram::splitSegment
std::vector< position > splitSegment(Range x, Range y) const
split a segment into a vector of points
Definition: DD4hep_XHistogram.cc:7
customisers.steps
steps
Definition: customisers.py:41
mps_fire.result
result
Definition: mps_fire.py:303
weight
Definition: weight.py:1
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443