ATLAS Offline Software
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
TrigHisto2D Class Reference

A very basic two dimensional histogram to provide storage of HLT distributions, allowing constraints but preventing excessive memory usage for busy events. The histogram data is compressed during persistification according to the type of template instantiated. More...

#include <TrigHisto2D.h>

Inheritance diagram for TrigHisto2D:
Collaboration diagram for TrigHisto2D:

Public Member Functions

 TrigHisto2D (void)
 Default constructor used by T/P converters. More...
 
 TrigHisto2D (unsigned int nbins_x, float min_x, float max_x, unsigned int nbins_y, float min_y, float max_y)
 Standard constructor used by FEX algorithms. More...
 
 TrigHisto2D (unsigned int nbins_x, float min_x, float max_x, unsigned int nbins_y, float min_y, float max_y, const std::vector< float > &contents)
 
virtual ~TrigHisto2D (void)
 Destructor. More...
 
 TrigHisto2D (const TrigHisto2D &trigHisto)
 Copy Constructor. More...
 
 TrigHisto2D (TrigHisto2D &&trigHisto)
 
TrigHisto2Doperator= (const TrigHisto2D &trigHisto)
 Assignment operator. More...
 
TrigHisto2Doperator= (TrigHisto2D &&trigHisto)
 
void fill (float value_x, float value_y, float weight)
 Fill a 2D histogram. More...
 
double sumEntries (float value_x, float value_y, int cutType) const
 Sum the number of entries within the cut range. More...
 
TrigHisto1D profileX (void) const
 Collapse the y-axis and return a profile from the x-axis. More...
 
TrigHisto1D profileY (void) const
 Collapse the x-axis and return a profile from the y-axis. More...
 
unsigned int nbins_y (void) const
 Return the number of bins along the y-axis, not including the under and overflow. More...
 
float min_y (void) const
 Return the minimum along the y-axis. More...
 
float max_y (void) const
 Return the maximum along the y-axis. More...
 
void clear (void)
 Zero all histogram bins. More...
 
unsigned int nbins_x (void) const
 Return the number of bins along the y-axis, not including the under and overflow. More...
 
float min_x (void) const
 Return the minimum along the x-axis. More...
 
float max_x (void) const
 Return the maximum along the x-axis. More...
 
const std::vector< float > & contents (void) const
 Return the bin contents of the histogram, including the under and overflow bins. More...
 

Protected Member Functions

unsigned int findBin (unsigned int nbins, float h_min, float h_max, float binSize, float value) const
 

Protected Attributes

unsigned int m_nbins_y
 
unsigned int m_underflowBin_y
 
unsigned int m_overflowBin_y
 
float m_min_y
 
float m_max_y
 
float m_binSize_y
 
std::vector< float > m_contents
 
std::vector< float >::iterator m_itr
 
std::vector< float >::iterator m_itr_end
 
unsigned int m_nbins_x
 
unsigned int m_underflowBin_x
 
unsigned int m_overflowBin_x
 
float m_min_x
 
float m_max_x
 
float m_binSize_x
 

Detailed Description

A very basic two dimensional histogram to provide storage of HLT distributions, allowing constraints but preventing excessive memory usage for busy events. The histogram data is compressed during persistification according to the type of template instantiated.

Author
W. H. Bell W.Bel.nosp@m.l@ce.nosp@m.rn.ch

Definition at line 24 of file Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h.

Constructor & Destructor Documentation

◆ TrigHisto2D() [1/5]

TrigHisto2D::TrigHisto2D ( void  )

Default constructor used by T/P converters.

Definition at line 11 of file TrigHisto2D.cxx.

11  : TrigHisto(),
12  m_nbins_y(0),
14  m_overflowBin_y(0),
15  m_min_y(0.),
16  m_max_y(0.),
17  m_binSize_y(0.) {
18 }

◆ TrigHisto2D() [2/5]

TrigHisto2D::TrigHisto2D ( unsigned int  nbins_x,
float  min_x,
float  max_x,
unsigned int  nbins_y,
float  min_y,
float  max_y 
)

Standard constructor used by FEX algorithms.

Definition at line 59 of file TrigHisto2D.cxx.

64  std::vector<float>())
65 {
66 }

◆ TrigHisto2D() [3/5]

TrigHisto2D::TrigHisto2D ( unsigned int  nbins_x,
float  min_x,
float  max_x,
unsigned int  nbins_y,
float  min_y,
float  max_y,
const std::vector< float > &  contents 
)

Definition at line 22 of file TrigHisto2D.cxx.

27  : TrigHisto(),
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 }

◆ ~TrigHisto2D()

TrigHisto2D::~TrigHisto2D ( void  )
virtual

Destructor.

Definition at line 71 of file TrigHisto2D.cxx.

71  {
72 }

◆ TrigHisto2D() [4/5]

TrigHisto2D::TrigHisto2D ( const TrigHisto2D trigHisto)

Copy Constructor.

Definition at line 76 of file TrigHisto2D.cxx.

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

◆ TrigHisto2D() [5/5]

TrigHisto2D::TrigHisto2D ( TrigHisto2D &&  trigHisto)

Definition at line 98 of file TrigHisto2D.cxx.

98  : TrigHisto() {
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 
113  m_overflowBin_x = trigHisto.m_overflowBin_x;
115  m_overflowBin_y = trigHisto.m_overflowBin_y;
116 }

Member Function Documentation

◆ clear()

void TrigHisto::clear ( void  )
inherited

Zero all histogram bins.

Definition at line 24 of file TrigHisto.cxx.

24  {
25  m_itr = m_contents.begin();
26  m_itr_end = m_contents.end();
27  for(; m_itr != m_itr_end; ++m_itr) (*m_itr) = 0.;
28 }

◆ contents()

const std::vector<float>& TrigHisto::contents ( void  ) const
inlineinherited

Return the bin contents of the histogram, including the under and overflow bins.

Definition at line 58 of file TrigHisto.h.

58  {
59  return m_contents;
60  }

◆ fill()

void TrigHisto2D::fill ( float  value_x,
float  value_y,
float  weight 
)

Fill a 2D histogram.

Definition at line 170 of file TrigHisto2D.cxx.

170  {
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 }

◆ findBin()

unsigned int TrigHisto::findBin ( unsigned int  nbins,
float  h_min,
float  h_max,
float  binSize,
float  value 
) const
protectedinherited
Returns
which bin this value corresponds to. (Supply bin limits such that it might be used for 1D or 2D derived class.)

Definition at line 33 of file TrigHisto.cxx.

37  {
38  unsigned int ibin = 0;
39 
40  if(value < h_min) { // Underflow
41  ibin = 0;
42  }
43  else if( !(value < h_max)) { // Overflow (catches NaN)
44  ibin = nbins+1;
45  }
46  else {
47  while(value > (ibin*binSize+h_min) && ibin <= nbins) { // None under/overflow from 1 to nbins
48  ibin++;
49  }
50  }
51 
52  return ibin;
53 }

◆ max_x()

float TrigHisto::max_x ( void  ) const
inlineinherited

Return the maximum along the x-axis.

Definition at line 52 of file TrigHisto.h.

52  {
53  return m_max_x;
54  }

◆ max_y()

float TrigHisto2D::max_y ( void  ) const
inline

Return the maximum along the y-axis.

Definition at line 73 of file Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h.

73  {
74  return m_max_y;
75  }

◆ min_x()

float TrigHisto::min_x ( void  ) const
inlineinherited

Return the minimum along the x-axis.

Definition at line 47 of file TrigHisto.h.

47  {
48  return m_min_x;
49  }

◆ min_y()

float TrigHisto2D::min_y ( void  ) const
inline

Return the minimum along the y-axis.

Definition at line 68 of file Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h.

68  {
69  return m_min_y;
70  }

◆ nbins_x()

unsigned int TrigHisto::nbins_x ( void  ) const
inlineinherited

Return the number of bins along the y-axis, not including the under and overflow.

Definition at line 42 of file TrigHisto.h.

42  {
43  return m_nbins_x;
44  }

◆ nbins_y()

unsigned int TrigHisto2D::nbins_y ( void  ) const
inline

Return the number of bins along the y-axis, not including the under and overflow.

Definition at line 63 of file Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h.

63  {
64  return m_nbins_y;
65  }

◆ operator=() [1/2]

TrigHisto2D & TrigHisto2D::operator= ( const TrigHisto2D trigHisto)

Assignment operator.

Definition at line 120 of file TrigHisto2D.cxx.

120  {
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 }

◆ operator=() [2/2]

TrigHisto2D & TrigHisto2D::operator= ( TrigHisto2D &&  trigHisto)

Definition at line 145 of file TrigHisto2D.cxx.

145  {
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 
161  m_overflowBin_x = trigHisto.m_overflowBin_x;
163  m_overflowBin_y = trigHisto.m_overflowBin_y;
164  }
165  return *this;
166 }

◆ profileX()

TrigHisto1D TrigHisto2D::profileX ( void  ) const

Collapse the y-axis and return a profile from the x-axis.

Definition at line 238 of file TrigHisto2D.cxx.

238  {
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 }

◆ profileY()

TrigHisto1D TrigHisto2D::profileY ( void  ) const

Collapse the x-axis and return a profile from the y-axis.

Definition at line 258 of file TrigHisto2D.cxx.

258  {
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 }

◆ sumEntries()

double TrigHisto2D::sumEntries ( float  value_x,
float  value_y,
int  cutType 
) const

Sum the number of entries within the cut range.

Definition at line 181 of file TrigHisto2D.cxx.

181  {
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 }

Member Data Documentation

◆ m_binSize_x

float TrigHisto::m_binSize_x
protectedinherited

Definition at line 81 of file TrigHisto.h.

◆ m_binSize_y

float TrigHisto2D::m_binSize_y
protected

◆ m_contents

std::vector<float> TrigHisto::m_contents
protectedinherited

Definition at line 71 of file TrigHisto.h.

◆ m_itr

std::vector<float>::iterator TrigHisto::m_itr
protectedinherited

Definition at line 72 of file TrigHisto.h.

◆ m_itr_end

std::vector<float>::iterator TrigHisto::m_itr_end
protectedinherited

Definition at line 73 of file TrigHisto.h.

◆ m_max_x

float TrigHisto::m_max_x
protectedinherited

Definition at line 80 of file TrigHisto.h.

◆ m_max_y

float TrigHisto2D::m_max_y
protected

◆ m_min_x

float TrigHisto::m_min_x
protectedinherited

Definition at line 79 of file TrigHisto.h.

◆ m_min_y

float TrigHisto2D::m_min_y
protected

◆ m_nbins_x

unsigned int TrigHisto::m_nbins_x
protectedinherited

Definition at line 76 of file TrigHisto.h.

◆ m_nbins_y

unsigned int TrigHisto2D::m_nbins_y
protected

◆ m_overflowBin_x

unsigned int TrigHisto::m_overflowBin_x
protectedinherited

Definition at line 78 of file TrigHisto.h.

◆ m_overflowBin_y

unsigned int TrigHisto2D::m_overflowBin_y
protected

◆ m_underflowBin_x

unsigned int TrigHisto::m_underflowBin_x
protectedinherited

Definition at line 77 of file TrigHisto.h.

◆ m_underflowBin_y

unsigned int TrigHisto2D::m_underflowBin_y
protected

The documentation for this class was generated from the following files:
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
athena.value
value
Definition: athena.py:122
TrigHisto::m_itr_end
std::vector< float >::iterator m_itr_end
Definition: TrigHisto.h:73
TrigHisto::TrigHisto
TrigHisto(void)
Definition: TrigHisto.cxx:9
TrigHisto1D
A very basic one dimensional histogram to provide storage of HLT distributions, allowing constraints ...
Definition: TrigHisto1D.h:23
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:200
TrigHisto::m_contents
std::vector< float > m_contents
Definition: TrigHisto.h:71
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
TrigHisto::m_itr
std::vector< float >::iterator m_itr
Definition: TrigHisto.h:72
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::min_y
float min_y(void) const
Return the minimum along the y-axis.
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:68
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::m_min_y
float m_min_y
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:83
xAOD::TrigHistoCutType::ABOVE_X_BELOW_Y
@ ABOVE_X_BELOW_Y
Definition: TrigHisto2D_v1.h:17
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
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
TrigHisto2D::max_y
float max_y(void) const
Return the maximum along the y-axis.
Definition: Trigger/TrigEvent/TrigInDetEvent/TrigInDetEvent/TrigHisto2D.h:73
TrigHisto::m_binSize_x
float m_binSize_x
Definition: TrigHisto.h:81
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