ATLAS Offline Software
TrigHisto2D.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 using namespace TrigHistoCutType;
8 
9 //---------------------------------------------------------------
10 
12  m_nbins_y(0),
13  m_underflowBin_y(0),
14  m_overflowBin_y(0),
15  m_min_y(0.),
16  m_max_y(0.),
17  m_binSize_y(0.) {
18 }
19 
20 //---------------------------------------------------------------
21 
22 TrigHisto2D::TrigHisto2D(unsigned int nbins_x,
23  float min_x, float max_x,
24  unsigned int nbins_y,
25  float min_y, float max_y,
26  const std::vector<float>& contents)
27  : TrigHisto(),
28  m_nbins_y(nbins_y),
29  m_min_y(min_y),
30  m_max_y(max_y) {
32  m_min_x = min_x;
33  m_max_x = max_x;
34 
35  unsigned int nbins = (nbins_x+2)*(nbins_y+2); // Two additional bins for under and overflow per 1d profile.
36 
38  m_contents.resize(nbins, 0.); // Two additional bins for under and overflow per 1d profile.
39 
40  if(m_nbins_x != 0) {
41  m_binSize_x = (m_max_x - m_min_x)/((float)m_nbins_x); // Calculate bin size.
42  }
43  else {
44  m_binSize_x = 0.;
45  }
46  if(m_nbins_y != 0) {
47  m_binSize_y = (m_max_y - m_min_y)/((float)m_nbins_y); // Calculate bin size.
48  }
49  else {
50  m_binSize_y = 0.;
51  }
52 
53  m_underflowBin_x = 0; // Cache this to make the code more readable.
54  m_overflowBin_x = m_nbins_x+1; // Cache this to make the code more readable and faster.
55  m_underflowBin_y = 0; // Cache this to make the code more readable.
56  m_overflowBin_y = m_nbins_y+1; // Cache this to make the code more readable and faster.
57 }
58 
59 TrigHisto2D::TrigHisto2D(unsigned int nbins_x,
60  float min_x, float max_x,
61  unsigned int nbins_y,
62  float min_y, float max_y)
63  : TrigHisto2D (nbins_x, min_x, max_x, nbins_y, min_y, max_y,
64  std::vector<float>())
65 {
66 }
67 
68 
69 //---------------------------------------------------------------
70 
72 }
73 
74 //---------------------------------------------------------------
75 
77  m_nbins_x = trigHisto.m_nbins_x;
78  m_min_x = trigHisto.m_min_x;
79  m_max_x = trigHisto.m_max_x;
80 
81  m_nbins_y = trigHisto.m_nbins_y;
82  m_min_y = trigHisto.m_min_y;
83  m_max_y = trigHisto.m_max_y;
84 
85  m_contents = trigHisto.m_contents;
86 
87  m_binSize_x = trigHisto.m_binSize_x;
88  m_binSize_y = trigHisto.m_binSize_y;
89 
91  m_overflowBin_x = trigHisto.m_overflowBin_x;
93  m_overflowBin_y = trigHisto.m_overflowBin_y;
94 }
95 
96 //---------------------------------------------------------------
97 
99  m_nbins_x = trigHisto.m_nbins_x;
100  m_min_x = trigHisto.m_min_x;
101  m_max_x = trigHisto.m_max_x;
102 
103  m_nbins_y = trigHisto.m_nbins_y;
104  m_min_y = trigHisto.m_min_y;
105  m_max_y = trigHisto.m_max_y;
106 
107  m_contents = std::move(trigHisto.m_contents);
108 
109  m_binSize_x = trigHisto.m_binSize_x;
110  m_binSize_y = trigHisto.m_binSize_y;
111 
112  m_underflowBin_x = trigHisto.m_underflowBin_x;
113  m_overflowBin_x = trigHisto.m_overflowBin_x;
114  m_underflowBin_y = trigHisto.m_underflowBin_y;
115  m_overflowBin_y = trigHisto.m_overflowBin_y;
116 }
117 
118 //---------------------------------------------------------------
119 
121  if (this != &trigHisto) {
122  m_nbins_x = trigHisto.m_nbins_x;
123  m_min_x = trigHisto.m_min_x;
124  m_max_x = trigHisto.m_max_x;
125 
126  m_nbins_y = trigHisto.m_nbins_y;
127  m_min_y = trigHisto.m_min_y;
128  m_max_y = trigHisto.m_max_y;
129 
130  m_contents = trigHisto.m_contents;
131 
132  m_binSize_x = trigHisto.m_binSize_x;
133  m_binSize_y = trigHisto.m_binSize_y;
134 
136  m_overflowBin_x = trigHisto.m_overflowBin_x;
138  m_overflowBin_y = trigHisto.m_overflowBin_y;
139  }
140  return *this;
141 }
142 
143 //---------------------------------------------------------------
144 
146  if (this != &trigHisto) {
147  m_nbins_x = trigHisto.m_nbins_x;
148  m_min_x = trigHisto.m_min_x;
149  m_max_x = trigHisto.m_max_x;
150 
151  m_nbins_y = trigHisto.m_nbins_y;
152  m_min_y = trigHisto.m_min_y;
153  m_max_y = trigHisto.m_max_y;
154 
155  m_contents = std::move(trigHisto.m_contents);
156 
157  m_binSize_x = trigHisto.m_binSize_x;
158  m_binSize_y = trigHisto.m_binSize_y;
159 
160  m_underflowBin_x = trigHisto.m_underflowBin_x;
161  m_overflowBin_x = trigHisto.m_overflowBin_x;
162  m_underflowBin_y = trigHisto.m_underflowBin_y;
163  m_overflowBin_y = trigHisto.m_overflowBin_y;
164  }
165  return *this;
166 }
167 
168 //---------------------------------------------------------------
169 
170 void TrigHisto2D::fill(float value_x, float value_y, float weight) {
171  const unsigned int ibin_x = findBin(m_nbins_x, m_min_x, m_max_x, m_binSize_x, value_x);
172  const unsigned int ibin_y = findBin(m_nbins_y, m_min_y, m_max_y, m_binSize_y, value_y);
173 
174  const unsigned int ibin = ibin_y*(m_nbins_x+2) + ibin_x; // Find position in 1d data array
175 
176  m_contents[ibin] += weight; // Append the weight to this bin
177 }
178 
179 //---------------------------------------------------------------
180 
181 double TrigHisto2D::sumEntries(float value_x, float value_y, int cutType) const {
182  // Find the x bin index that the cut corresponds to.
183  const unsigned int ibin_x_selected = findBin(m_nbins_x, m_min_x, m_max_x, m_binSize_x, value_x);
184 
185  // Find the y bin index that the cut corresponds to.
186  const unsigned int ibin_y_selected = findBin(m_nbins_y, m_min_y, m_max_y, m_binSize_y, value_y);
187 
188  double entries = 0.;
189 
190 
191  if( m_nbins_x==0 || m_nbins_y==0 ){
192  return 0;
193  }
194  else{
195 
196  if(cutType == BELOW_X_BELOW_Y) {
197  for(unsigned int ibin_x = m_underflowBin_x; ibin_x <= ibin_x_selected; ibin_x++) {
198  for(unsigned int ibin_y = m_underflowBin_y; ibin_y <= ibin_y_selected; ibin_y++) {
199  const unsigned int ibin = ibin_y*(m_nbins_x+2) + ibin_x; // Find position in 1d data array
200  entries += m_contents[ibin];
201  }
202  }
203  }
204  else if(cutType == ABOVE_X_BELOW_Y) {
205  for(unsigned int ibin_x = ibin_x_selected; ibin_x <= m_overflowBin_x; ibin_x++) {
206  for(unsigned int ibin_y = m_underflowBin_y; ibin_y <= ibin_y_selected; ibin_y++) {
207  const unsigned int ibin = ibin_y*(m_nbins_x+2) + ibin_x; // Find position in 1d data array
208  entries += m_contents[ibin];
209  }
210  }
211  }
212  else if(cutType == BELOW_X_ABOVE_Y) {
213  for(unsigned int ibin_x = m_underflowBin_x; ibin_x <= ibin_x_selected; ibin_x++) {
214  for(unsigned int ibin_y = ibin_y_selected; ibin_y <= m_overflowBin_y; ibin_y++) {
215  const unsigned int ibin = ibin_y*(m_nbins_x+2) + ibin_x; // Find position in 1d data array
216  entries += m_contents[ibin];
217  }
218  }
219  }
220  else if(cutType == ABOVE_X_ABOVE_Y) {
221  for(unsigned int ibin_x = ibin_x_selected; ibin_x <= m_overflowBin_x; ibin_x++) {
222  for(unsigned int ibin_y = ibin_y_selected; ibin_y <= m_overflowBin_y; ibin_y++) {
223  const unsigned int ibin = ibin_y*(m_nbins_x+2) + ibin_x; // Find position in 1d data array
224  entries += m_contents[ibin];
225  }
226  }
227  }
228  else {
229  return 0;
230  }
231  }// else of m_nbins!=0
232 
233  return entries;
234 }
235 
236 //---------------------------------------------------------------
237 
239  unsigned int ibin, ibin_x, ibin_y;
240 
241  // Define size carefully to avoid memory problems in for loop.
242  std::vector<float> contents((m_overflowBin_x-m_underflowBin_x+1),0.);
243 
244  // Sum all y bins for each x bin.
245  for(ibin_x = m_underflowBin_x; ibin_x <= m_overflowBin_x; ibin_x++) {
246  for(ibin_y = m_underflowBin_y; ibin_y <= m_overflowBin_y; ibin_y++) {
247  ibin = ibin_y*(m_nbins_x+2) + ibin_x; // Find position in 1d data array
248  contents[ibin_x] += m_contents[ibin];
249  }
250  }
251 
252  // Return a 1D histogram containing the profile contents.
254 }
255 
256 //---------------------------------------------------------------
257 
259  // Define size carefully to avoid memory problems in for loop.
260  std::vector<float> contents((m_overflowBin_y-m_underflowBin_y+1),0.);
261 
262  // Sum all x bins for each y bin.
263  for(unsigned int ibin_y = m_underflowBin_y; ibin_y <= m_overflowBin_y; ibin_y++) {
264  for(unsigned int ibin_x = m_underflowBin_x; ibin_x <= m_overflowBin_x; ibin_x++) {
265  const unsigned int ibin = ibin_y*(m_nbins_x+2) + ibin_x; // Find position in 1d data array
266  contents[ibin_y] += m_contents[ibin];
267  }
268  }
269 
270  // Return a 1D histogram containing the profile contents.
272 }
273 
274 //---------------------------------------------------------------
xAOD::TrigHistoCutType::BELOW_X_BELOW_Y
@ BELOW_X_BELOW_Y
Definition: TrigHisto2D_v1.h:16
TrigHisto::m_overflowBin_x
unsigned int m_overflowBin_x
Definition: TrigHisto.h:78
TrigHisto::min_x
float min_x(void) const
Return the minimum along the x-axis.
Definition: TrigHisto.h:47
xAOD::TrigHistoCutType::ABOVE_X_ABOVE_Y
@ ABOVE_X_ABOVE_Y
Definition: TrigHisto2D_v1.h:19
TrigHisto::m_nbins_x
unsigned int m_nbins_x
Definition: TrigHisto.h:76
TrigHisto2D::m_max_y
float m_max_y
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:84
TrigHisto2D.h
TrigHisto
The base class for TrigHisto1D and TrigHisto2D. This class should never be stored or used directly.
Definition: TrigHisto.h:32
TrigHisto1D
A very basic one dimensional histogram to provide storage of HLT distributions, allowing constraints ...
Definition: TrigHisto1D.h:23
TrigHisto2D::operator=
TrigHisto2D & operator=(const TrigHisto2D &trigHisto)
Assignment operator.
Definition: TrigHisto2D.cxx:120
TrigHisto2D::nbins_y
unsigned int nbins_y(void) const
Return the number of bins along the y-axis, not including the under and overflow.
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:63
TrigHisto::max_x
float max_x(void) const
Return the maximum along the x-axis.
Definition: TrigHisto.h:52
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
TrigHisto::m_contents
std::vector< float > m_contents
Definition: TrigHisto.h:71
TrigHisto2D::m_overflowBin_y
unsigned int m_overflowBin_y
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:82
TrigHisto::m_min_x
float m_min_x
Definition: TrigHisto.h:79
TrigHisto2D::sumEntries
double sumEntries(float value_x, float value_y, int cutType) const
Sum the number of entries within the cut range.
Definition: TrigHisto2D.cxx:181
TrigHisto2D::profileY
TrigHisto1D profileY(void) const
Collapse the x-axis and return a profile from the y-axis.
Definition: TrigHisto2D.cxx:258
xAOD::TrigHistoCutType::BELOW_X_ABOVE_Y
@ BELOW_X_ABOVE_Y
Definition: TrigHisto2D_v1.h:18
TrigHisto2D::m_nbins_y
unsigned int m_nbins_y
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:80
TrigHisto2D::profileX
TrigHisto1D profileX(void) const
Collapse the y-axis and return a profile from the x-axis.
Definition: TrigHisto2D.cxx:238
TrigHistoCutType
Definition: TrigHisto.h:12
TrigHisto2D::m_min_y
float m_min_y
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:83
TrigHisto2D::fill
void fill(float value_x, float value_y, float weight)
Fill a 2D histogram.
Definition: TrigHisto2D.cxx:170
xAOD::TrigHistoCutType::ABOVE_X_BELOW_Y
@ ABOVE_X_BELOW_Y
Definition: TrigHisto2D_v1.h:17
contents
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
Definition: computils.cxx:320
TrigHisto::contents
const std::vector< float > & contents(void) const
Return the bin contents of the histogram, including the under and overflow bins.
Definition: TrigHisto.h:58
TrigHisto2D::m_binSize_y
float m_binSize_y
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:85
TrigHisto::findBin
unsigned int findBin(unsigned int nbins, float h_min, float h_max, float binSize, float value) const
Definition: TrigHisto.cxx:33
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
TrigHisto2D
A very basic two dimensional histogram to provide storage of HLT distributions, allowing constraints ...
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:24
entries
double entries
Definition: listroot.cxx:49
TrigHisto2D::m_underflowBin_y
unsigned int m_underflowBin_y
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:81
TrigHisto2D::TrigHisto2D
TrigHisto2D(void)
Default constructor used by T/P converters.
Definition: TrigHisto2D.cxx:11
TrigHisto::m_binSize_x
float m_binSize_x
Definition: TrigHisto.h:81
readCCLHist.float
float
Definition: readCCLHist.py:83
TrigHisto2D::~TrigHisto2D
virtual ~TrigHisto2D(void)
Destructor.
Definition: TrigHisto2D.cxx:71
TrigHisto::m_underflowBin_x
unsigned int m_underflowBin_x
Definition: TrigHisto.h:77
TrigHisto::m_max_x
float m_max_x
Definition: TrigHisto.h:80
TrigHisto::nbins_x
unsigned int nbins_x(void) const
Return the number of bins along the y-axis, not including the under and overflow.
Definition: TrigHisto.h:42