CMS 3D CMS Logo

DD4hep_XHistogram.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cmath>
3 #include <vector>
4 
5 #include "DD4hep_XHistogram.h"
6 
7 std::vector<DD4hep_XHistogram::position> DD4hep_XHistogram::splitSegment(Range rangeX, Range rangeY) const {
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 }
68 
70 void DD4hep_XHistogram::fill(double x, double y, const std::vector<double>& weight, double norm) {
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 }
77 
79 void DD4hep_XHistogram::fill(double x, double y, const std::vector<double>& weight, double norm, unsigned int colour) {
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 }
87 
89 void DD4hep_XHistogram::fill(const Range& x, const Range& y, const std::vector<double>& weight, double norm) {
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 }
99 
102  const Range& x, const Range& y, const std::vector<double>& weight, double norm, unsigned int colour) {
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 }
113 
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 }
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:428
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:121
DD4hep_XHistogram::m_xBins
size_t m_xBins
Definition: DD4hep_XHistogram.h:23
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
DD4hep_XHistogram.h
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
DD4hep_XHistogram::Range
std::pair< double, double > Range
Definition: DD4hep_XHistogram.h:17
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
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
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
DD4hep_XHistogram::fill
void fill(double x, double y, const std::vector< double > &weight, double norm)
fill one point
Definition: DD4hep_XHistogram.cc:70
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
hgcalPerformanceValidation.df
df
Definition: hgcalPerformanceValidation.py:733
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
genVertex_cff.x
x
Definition: genVertex_cff.py:12
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
customisers.steps
steps
Definition: customisers.py:40
mps_fire.result
result
Definition: mps_fire.py:311
DD4hep_XHistogram::normalize
void normalize(void)
normalize the histograms
Definition: DD4hep_XHistogram.cc:115
weight
Definition: weight.py:1