ATLAS Offline Software
Loading...
Searching...
No Matches
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
7using namespace TrigHistoCutType;
8
9//---------------------------------------------------------------
10
19
20//---------------------------------------------------------------
21
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(),
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
60 float min_x, float max_x,
61 unsigned int nbins_y,
62 float min_y, float max_y)
64 std::vector<float>())
65{
66}
67
68
69//---------------------------------------------------------------
70
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
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;
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
170void 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
181double 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//---------------------------------------------------------------
A very basic one dimensional histogram to provide storage of HLT distributions, allowing constraints ...
Definition TrigHisto1D.h:23
TrigHisto2D(void)
Default constructor used by T/P converters.
float min_y(void) const
Return the minimum along the y-axis.
unsigned int nbins_y(void) const
Return the number of bins along the y-axis, not including the under and overflow.
TrigHisto1D profileY(void) const
Collapse the x-axis and return a profile from the y-axis.
double sumEntries(float value_x, float value_y, int cutType) const
Sum the number of entries within the cut range.
TrigHisto1D profileX(void) const
Collapse the y-axis and return a profile from the x-axis.
void fill(float value_x, float value_y, float weight)
Fill a 2D histogram.
TrigHisto2D & operator=(const TrigHisto2D &trigHisto)
Assignment operator.
float max_y(void) const
Return the maximum along the y-axis.
virtual ~TrigHisto2D(void)
Destructor.
TrigHisto(void)
Definition TrigHisto.cxx:9
unsigned int m_nbins_x
Definition TrigHisto.h:76
unsigned int m_underflowBin_x
Definition TrigHisto.h:77
unsigned int m_overflowBin_x
Definition TrigHisto.h:78
float max_x(void) const
Return the maximum along the x-axis.
Definition TrigHisto.h:52
float m_binSize_x
Definition TrigHisto.h:81
unsigned int findBin(unsigned int nbins, float h_min, float h_max, float binSize, float value) const
Definition TrigHisto.cxx:33
float m_min_x
Definition TrigHisto.h:79
float min_x(void) const
Return the minimum along the x-axis.
Definition TrigHisto.h:47
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
const std::vector< float > & contents(void) const
Return the bin contents of the histogram, including the under and overflow bins.
Definition TrigHisto.h:58
float m_max_x
Definition TrigHisto.h:80
std::vector< float > m_contents
Definition TrigHisto.h:71
double entries
Definition listroot.cxx:49
STL namespace.