CMS 3D CMS Logo

Histogram3D.h
Go to the documentation of this file.
1 #ifndef CondFormats_PhysicsToolsObjects_Histogram3D_h
2 #define CondFormats_PhysicsToolsObjects_Histogram3D_h
3 
5 
6 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
7 #include <atomic>
8 #endif
9 
10 #include <utility>
11 #include <vector>
12 #include <cmath>
13 
15 
16 namespace PhysicsTools {
17  namespace Calibration {
18 
19  //template<typename Value_t, typename AxisX_t = Value_t,
20  // typename AxisY_t = AxisX_t>
21 
22  template <typename Value_t, typename AxisX_t = Value_t, typename AxisY_t = AxisX_t, typename AxisZ_t = AxisX_t>
23 
24  class Histogram3D {
25  public:
29 
30  Histogram3D();
31 
32  Histogram3D(const Histogram3D &orig);
33 
34  template <typename OValue_t, typename OAxisX_t, typename OAxisY_t, typename OAxisZ_t>
36 
37  Histogram3D(const std::vector<AxisX_t> &binULimitsX,
38  const std::vector<AxisY_t> &binULimitsY,
39  const std::vector<AxisZ_t> &binULimitsZ);
40 
41  template <typename OAxisX_t, typename OAxisY_t, typename OAxisZ_t>
42  Histogram3D(const std::vector<OAxisX_t> &binULimitsX,
43  const std::vector<OAxisY_t> &binULimitsY,
44  const std::vector<OAxisZ_t> &binULimitsZ);
45 
46  /*
47  //TO BE CONVERTED FROM HISTO2D TO HISTO3D
48  template<typename OAxisX_t, typename OAxisY_t>
49  Histogram3D(const std::vector<OAxisX_t> &binULimitsX,
50  unsigned int nBinsY,
51  const PhysicsTools::Calibration::Range<OAxisY_t> &rangeY);
52 
53  template<typename OAxisX_t, typename OAxisY_t>
54  Histogram3D(unsigned int nBinsX,
55  const PhysicsTools::Calibration::Range<OAxisX_t> &rangeX,
56  const std::vector<OAxisY_t> &binULimitsY);
57 
58  template<typename OAxisX_t, typename OAxisY_t>
59  Histogram3D(unsigned int nBinsX,
60  const PhysicsTools::Calibration::Range<OAxisX_t> &rangeX,
61  unsigned int nBinsY,
62  const PhysicsTools::Calibration::Range<OAxisY_t> &rangeY);
63 */
64  Histogram3D(unsigned int nBinsX,
65  AxisX_t minX,
66  AxisX_t maxX,
67  unsigned int nBinsY,
68  AxisY_t minY,
69  AxisY_t maxY,
70  unsigned int nBinsZ,
71  AxisZ_t minZ,
72  AxisZ_t maxZ);
73 
74  ~Histogram3D();
75 
76  Histogram3D &operator=(const Histogram3D &orig);
77 
78  template <typename OValue_t, typename OAxisX_t, typename OAxisY_t, typename OAxisZ_t>
80 
81  void reset();
82 
83  const std::vector<AxisX_t> upperLimitsX() const { return binULimitsX; }
84  const std::vector<AxisY_t> upperLimitsY() const { return binULimitsY; }
85  const std::vector<AxisZ_t> upperLimitsZ() const { return binULimitsZ; }
86 
87  inline int bin3D(int binX, int binY, int binZ) const
88  // { return (((binY * strideY) + binX) * strideX) + binZ; }
89  {
90  return binZ * strideX * strideY + binY * strideX + binX;
91  }
92 
93  Value_t binContent(int bin) const { return binValues[bin]; }
94  Value_t binContent(int binX, int binY, int binZ) const { return binValues[bin3D(binX, binY, binZ)]; }
95  Value_t value(AxisX_t x, AxisY_t y, AxisY_t z) const { return binContent(findBin(x, y, z)); }
96  Value_t normalizedValue(AxisX_t x, AxisY_t y, AxisZ_t z) const {
97  return binContent(findBin(x, y, z)) / normalization();
98  }
99 
100  //TO BE CONVERTED FROM HISTO2D TO HISTO3D
101  // Value_t normalizedXValue(AxisX_t x, AxisY_t y, AxisZ_t z) const;
102  // Value_t normalizedYValue(AxisX_t x, AxisY_t y, AxisZ_t z) const;
103  // Value_t normalizedZValue(AxisX_t x, AxisY_t y, AxisZ_t z) const;
104 
105  Value_t binError(int bin) const { return std::sqrt(binContent(bin)); }
106  Value_t binError(int binX, int binY, int binZ) const { return binError(bin3D(binX, binY, binZ)); }
107  Value_t error(AxisX_t x, AxisY_t y, AxisZ_t z) const { return binError(findBin(x, y, z)); }
108  Value_t normalizedError(AxisX_t x, AxisY_t y, AxisY_t z) const {
109  return std::sqrt(binContent(findBin(x, y, z))) / normalization();
110  }
111 
112  //TO BE CONVERTED FROM HISTO2D TO HISTO3D
113  // Value_t normalizedXError(AxisX_t x, AxisY_t y, AxisZ_t z) const;
114  // Value_t normalizedYError(AxisX_t x, AxisY_t y, AxisZ_t z) const;
115 
116  void setBinContent(int bin, Value_t value);
117  void setBinContent(int binX, int binY, int binZ, Value_t value) { setBinContent(bin3D(binX, binY, binZ), value); }
118  void fill(AxisX_t x, AxisY_t y, AxisZ_t z, Value_t weight = 1.0);
119 
120  bool empty() const { return binValues.empty(); }
121  bool hasEquidistantBinsX() const { return binULimitsX.empty(); }
122  bool hasEquidistantBinsY() const { return binULimitsY.empty(); }
123  bool hasEquidistantBinsZ() const { return binULimitsZ.empty(); }
124  int numberOfBinsX() const { return strideX - 2; }
125  int numberOfBinsY() const { return strideY - 2; }
126  int numberOfBinsZ() const { return binValues.size() / (strideX * strideY) - 2; }
127  int numberOfBins() const { return numberOfBinsX() * numberOfBinsY() * numberOfBinsZ(); }
128 
129  inline const std::vector<Value_t> &values() const { return binValues; }
130 
131  void setValues(const std::vector<Value_t> &values);
132 
133  template <typename OValue_t>
134  void setValues(const std::vector<OValue_t> &values);
135 
136  inline RangeX rangeX() const { return limitsX; }
137  inline RangeY rangeY() const { return limitsY; }
138  inline RangeZ rangeZ() const { return limitsZ; }
139  RangeX binRangeX(int binX) const;
140  RangeY binRangeY(int binY) const;
141  RangeZ binRangeZ(int binZ) const;
142 
143  //TO BE CONVERTED FROM HISTO2D TO HISTO3D
144  /* std::pair<RangeX, RangeY> binRange(int bin) const;
145  std::pair<RangeX, RangeY> binRange(int binX, int binY) const
146  { return binRange(bin2D(binX, binY)); }
147 */
148  int findBinX(AxisX_t x) const;
149  int findBinY(AxisY_t y) const;
150  int findBinZ(AxisZ_t z) const;
151  int findBin(AxisX_t x, AxisY_t y, AxisZ_t z) const { return bin3D(findBinX(x), findBinY(y), findBinZ(z)); }
152  Value_t normalization() const;
153 
154  //TO BE CONVERTED FROM HISTO2D TO HISTO3D
155  // Value_t normalizationX(int binY) const;
156  // Value_t normalizationY(int binX) const;
157 
158  protected:
159  unsigned int strideX;
160  unsigned int strideY;
161  std::vector<AxisX_t> binULimitsX;
162  std::vector<AxisY_t> binULimitsY;
163  std::vector<AxisZ_t> binULimitsZ;
164  std::vector<Value_t> binValues;
168 
169  // transient cache variables
170  mutable Value_t total COND_TRANSIENT; //CMS-THREADING protected by totalValid
171 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
172  mutable std::atomic<bool> totalValid COND_TRANSIENT;
173 #else
174  mutable bool totalValid COND_TRANSIENT;
175 #endif
176  mutable std::vector<Value_t> sliceTotal COND_TRANSIENT;
177  mutable std::vector<Value_t> rowTotal COND_TRANSIENT;
178  mutable std::vector<Value_t> columnTotal COND_TRANSIENT;
179 
181  };
182 
185 
186  } // namespace Calibration
187 } // namespace PhysicsTools
188 
189 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
190 #include "CondFormats/PhysicsToolsObjects/interface/Histogram3D.icc"
191 #endif
192 
193 #endif // CondFormats_PhysicsToolsObjects_Histogram3D_h
PhysicsTools::Calibration::Histogram3D::numberOfBinsZ
int numberOfBinsZ() const
Definition: Histogram3D.h:126
PhysicsTools::Calibration::Histogram3D::~Histogram3D
~Histogram3D()
PhysicsTools::Calibration::Histogram3D::hasEquidistantBinsZ
bool hasEquidistantBinsZ() const
Definition: Histogram3D.h:123
PhysicsTools::Calibration::Histogram3D::reset
void reset()
PhysicsTools::Calibration::Histogram3D::error
Value_t error(AxisX_t x, AxisY_t y, AxisZ_t z) const
Definition: Histogram3D.h:107
PhysicsTools::Calibration::Histogram3D::limitsY
RangeY limitsY
Definition: Histogram3D.h:166
PhysicsTools::Calibration::Histogram3D::strideX
unsigned int strideX
Definition: Histogram3D.h:159
PhysicsTools::Calibration::Histogram3D::binULimitsX
std::vector< AxisX_t > binULimitsX
Definition: Histogram3D.h:161
PhysicsTools::Calibration::Histogram3D::binULimitsY
std::vector< AxisY_t > binULimitsY
Definition: Histogram3D.h:162
PhysicsTools::Calibration::Histogram3D::findBinY
int findBinY(AxisY_t y) const
PhysicsTools::Calibration::Histogram3D::empty
bool empty() const
Definition: Histogram3D.h:120
COND_SERIALIZABLE
#define COND_SERIALIZABLE
Definition: Serializable.h:39
PhysicsTools::Calibration::Histogram3D::upperLimitsX
const std::vector< AxisX_t > upperLimitsX() const
Definition: Histogram3D.h:83
COND_TRANSIENT
#define COND_TRANSIENT
Definition: Serializable.h:63
PhysicsTools::Calibration::Histogram3D::binError
Value_t binError(int bin) const
Definition: Histogram3D.h:105
PhysicsTools::Calibration::Histogram3D::findBinX
int findBinX(AxisX_t x) const
PhysicsTools::Calibration::Histogram3D::rangeY
RangeY rangeY() const
Definition: Histogram3D.h:137
PhysicsTools::Calibration::Histogram3D::findBin
int findBin(AxisX_t x, AxisY_t y, AxisZ_t z) const
Definition: Histogram3D.h:151
HGVHistoProducerAlgoBlock_cfi.minX
minX
Definition: HGVHistoProducerAlgoBlock_cfi.py:169
PhysicsTools::Calibration::Histogram3D::strideY
unsigned int strideY
Definition: Histogram3D.h:160
PhysicsTools::Calibration::Histogram3D::setValues
void setValues(const std::vector< Value_t > &values)
CosmicsPD_Skims.maxZ
maxZ
Definition: CosmicsPD_Skims.py:136
PhysicsTools::Calibration::Histogram3D::columnTotal
std::vector< Value_t > columnTotal
Definition: Histogram3D.h:178
PhysicsTools::Calibration::Histogram3D::RangeY
Range< AxisY_t > RangeY
Definition: Histogram3D.h:27
PhysicsTools::Calibration::Histogram3D::sliceTotal
std::vector< Value_t > sliceTotal
Definition: Histogram3D.h:176
PhysicsTools::Calibration::Histogram3D::binRangeY
RangeY binRangeY(int binY) const
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
PhysicsTools::Calibration::Histogram3D::binULimitsZ
std::vector< AxisZ_t > binULimitsZ
Definition: Histogram3D.h:163
PhysicsTools::Calibration::Histogram3D::limitsX
RangeX limitsX
Definition: Histogram3D.h:165
PhysicsTools::Calibration::Histogram3D::totalValid
std::atomic< bool > totalValid
Definition: Histogram3D.h:172
PhysicsTools::Calibration::Histogram3D::rangeX
RangeX rangeX() const
Definition: Histogram3D.h:136
PhysicsTools::Calibration::Histogram3D::operator=
Histogram3D & operator=(const Histogram3D &orig)
PhysicsTools::Calibration::Histogram3D::binValues
std::vector< Value_t > binValues
Definition: Histogram3D.h:164
PhysicsTools::Calibration::Histogram3D::value
Value_t value(AxisX_t x, AxisY_t y, AxisY_t z) const
Definition: Histogram3D.h:95
PhysicsTools::Calibration::Range< AxisX_t >
PhysicsTools::Calibration::Histogram3D::RangeX
Range< AxisX_t > RangeX
Definition: Histogram3D.h:26
PhysicsTools::Calibration::Histogram3D::binRangeZ
RangeZ binRangeZ(int binZ) const
HGVHistoProducerAlgoBlock_cfi.minY
minY
Definition: HGVHistoProducerAlgoBlock_cfi.py:174
PhysicsTools
Definition: Histogram.h:13
PhysicsTools::Calibration::Histogram3D::normalization
Value_t normalization() const
Serializable.h
PhysicsTools::Calibration::Histogram3D::findBinZ
int findBinZ(AxisZ_t z) const
value
Definition: value.py:1
PhysicsTools::Calibration::Histogram3D::numberOfBinsY
int numberOfBinsY() const
Definition: Histogram3D.h:125
PhysicsTools::Calibration::Histogram3D::binContent
Value_t binContent(int bin) const
Definition: Histogram3D.h:93
PhysicsTools::Calibration::Histogram3D::fill
void fill(AxisX_t x, AxisY_t y, AxisZ_t z, Value_t weight=1.0)
PhysicsTools::Calibration::Histogram3D::normalizedValue
Value_t normalizedValue(AxisX_t x, AxisY_t y, AxisZ_t z) const
Definition: Histogram3D.h:96
PhysicsTools::Calibration::Histogram3D::binContent
Value_t binContent(int binX, int binY, int binZ) const
Definition: Histogram3D.h:94
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
PhysicsTools::Calibration::Histogram3D::hasEquidistantBinsX
bool hasEquidistantBinsX() const
Definition: Histogram3D.h:121
PhysicsTools::Calibration::Histogram3D::numberOfBins
int numberOfBins() const
Definition: Histogram3D.h:127
Histogram2D.h
PhysicsTools::Calibration::Histogram3D::setBinContent
void setBinContent(int bin, Value_t value)
HGVHistoProducerAlgoBlock_cfi.maxY
maxY
Definition: HGVHistoProducerAlgoBlock_cfi.py:175
PhysicsTools::Calibration::Histogram3D::binRangeX
RangeX binRangeX(int binX) const
PhysicsTools::Calibration::Histogram3D::normalizedError
Value_t normalizedError(AxisX_t x, AxisY_t y, AxisY_t z) const
Definition: Histogram3D.h:108
PhysicsTools::Calibration::Histogram3D::upperLimitsZ
const std::vector< AxisZ_t > upperLimitsZ() const
Definition: Histogram3D.h:85
PhysicsTools::Calibration::Histogram3D::values
const std::vector< Value_t > & values() const
Definition: Histogram3D.h:129
PhysicsTools::Calibration::Histogram3D
Definition: Histogram3D.h:24
PhysicsTools::Calibration::HistogramD3D
Histogram3D< double > HistogramD3D
Definition: Histogram3D.h:184
HLT_FULL_cff.Calibration
Calibration
Definition: HLT_FULL_cff.py:3579
PhysicsTools::Calibration::Histogram3D::numberOfBinsX
int numberOfBinsX() const
Definition: Histogram3D.h:124
PhysicsTools::Calibration::Histogram3D::rangeZ
RangeZ rangeZ() const
Definition: Histogram3D.h:138
PhysicsTools::Calibration::Histogram3D::total
Value_t total
Definition: Histogram3D.h:170
PhysicsTools::Calibration::Histogram3D::hasEquidistantBinsY
bool hasEquidistantBinsY() const
Definition: Histogram3D.h:122
PhysicsTools::Calibration::Histogram3D::upperLimitsY
const std::vector< AxisY_t > upperLimitsY() const
Definition: Histogram3D.h:84
PhysicsTools::Calibration::Histogram3D::bin3D
int bin3D(int binX, int binY, int binZ) const
Definition: Histogram3D.h:87
PhysicsTools::Calibration::Histogram3D::RangeZ
Range< AxisZ_t > RangeZ
Definition: Histogram3D.h:28
PhysicsTools::Calibration::Histogram3D::Histogram3D
Histogram3D()
PhysicsTools::Calibration::Histogram3D::rowTotal
std::vector< Value_t > rowTotal
Definition: Histogram3D.h:177
PhysicsTools::Calibration::Histogram3D::limitsZ
RangeY limitsZ
Definition: Histogram3D.h:167
weight
Definition: weight.py:1
HGVHistoProducerAlgoBlock_cfi.maxX
maxX
Definition: HGVHistoProducerAlgoBlock_cfi.py:170
PhysicsTools::Calibration::Histogram3D::setBinContent
void setBinContent(int binX, int binY, int binZ, Value_t value)
Definition: Histogram3D.h:117
CosmicGenFilterHelix_cff.minZ
minZ
i.e.
Definition: CosmicGenFilterHelix_cff.py:9
PhysicsTools::Calibration::HistogramF3D
Histogram3D< float > HistogramF3D
Definition: Histogram3D.h:183
PhysicsTools::Calibration::Histogram3D::binError
Value_t binError(int binX, int binY, int binZ) const
Definition: Histogram3D.h:106