ATLAS Offline Software
TrigHisto1D.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 }
13 
14 //---------------------------------------------------------------
15 
16 TrigHisto1D::TrigHisto1D(unsigned int nbins_x,
17  float min_x,
18  float max_x): TrigHisto() {
19 
21  m_min_x = min_x;
22  m_max_x = max_x;
23 
24  m_contents.clear();
25  m_contents.resize(m_nbins_x+2, 0); // Two additional bins for under and overflow.
26 
27  if(m_nbins_x != 0) {
28  m_binSize_x = (m_max_x - m_min_x)/((float)m_nbins_x); // Calculate bin size.
29  }
30  else {
31  m_binSize_x = 0.;
32  }
33 
34  m_underflowBin_x = 0; // Cache this to make the code more readable.
35  m_overflowBin_x = m_nbins_x+1; // Cache this to make the code more readable and faster.
36 }
37 
38 //---------------------------------------------------------------
39 
40 TrigHisto1D::TrigHisto1D(unsigned int nbins_x,
41  float min_x,
42  float max_x,
43  const std::vector<float>& contents) {
45  m_min_x = min_x;
46  m_max_x = max_x;
47 
49  m_contents.resize(m_nbins_x+2, 0); // Resize if it not the correct size.
50 
51  m_binSize_x = (m_max_x - m_min_x)/((float)m_nbins_x); // Calculate bin size.
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 }
56 
57 //---------------------------------------------------------------
58 
60 }
61 
62 //---------------------------------------------------------------
63 
65  m_nbins_x = trigHisto.m_nbins_x;
66  m_min_x = trigHisto.m_min_x;
67  m_max_x = trigHisto.m_max_x;
68  m_contents = trigHisto.m_contents;
69  m_binSize_x = trigHisto.m_binSize_x;
71  m_overflowBin_x = trigHisto.m_overflowBin_x;
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  m_contents = std::move(trigHisto.m_contents);
81  m_binSize_x = trigHisto.m_binSize_x;
82  m_underflowBin_x = trigHisto.m_underflowBin_x;
83  m_overflowBin_x = trigHisto.m_overflowBin_x;
84 }
85 
86 //---------------------------------------------------------------
87 
89  if (this != &trigHisto) {
90  m_nbins_x = trigHisto.m_nbins_x;
91  m_min_x = trigHisto.m_min_x;
92  m_max_x = trigHisto.m_max_x;
93  m_contents = trigHisto.m_contents;
94  m_binSize_x = trigHisto.m_binSize_x;
96  m_overflowBin_x = trigHisto.m_overflowBin_x;
97  }
98  return *this;
99 }
100 
101 //---------------------------------------------------------------
102 
104  if (this != &trigHisto) {
105  m_nbins_x = trigHisto.m_nbins_x;
106  m_min_x = trigHisto.m_min_x;
107  m_max_x = trigHisto.m_max_x;
108  m_contents = std::move(trigHisto.m_contents);
109  m_binSize_x = trigHisto.m_binSize_x;
110  m_underflowBin_x = trigHisto.m_underflowBin_x;
111  m_overflowBin_x = trigHisto.m_overflowBin_x;
112  }
113  return *this;
114 }
115 
116 //---------------------------------------------------------------
117 
118 void TrigHisto1D::fill(float value_x, float weight) {
119  const unsigned int ibin = findBin(m_nbins_x, m_min_x, m_max_x, m_binSize_x, value_x);
120 
121  m_contents[ibin] += weight; // Append the weight to this bin.
122 }
123 
124 //---------------------------------------------------------------
125 
126 double TrigHisto1D::sumEntries(float value_x, int cutType) const {
127  // Find which bin contains the value_x.
128  const unsigned int ibin_x_selected = findBin(m_nbins_x, m_min_x, m_max_x, m_binSize_x, value_x);
129 
130  double entries = 0.;
131 
132  if( m_nbins_x==0 ){
133  return 0;
134  }
135  else{
136 
137  if (cutType == BELOW_X) {
138  for(unsigned int ibin_x = m_underflowBin_x; ibin_x <= ibin_x_selected; ibin_x++) {
139  entries += m_contents[ibin_x];
140  }
141  }
142  else if(cutType == ABOVE_X) {
143  for(unsigned int ibin_x = ibin_x_selected; ibin_x <= m_overflowBin_x; ibin_x++) {
144  entries += m_contents[ibin_x];
145  }
146  }
147  else {
148  return 0; //<! Should report error message.
149  }
150  }
151 
152  return entries;
153 }
154 
155 //---------------------------------------------------------------
156 
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
TrigHisto::m_nbins_x
unsigned int m_nbins_x
Definition: TrigHisto.h:76
TrigHisto1D.h
xAOD::TrigHistoCutType::ABOVE_X
@ ABOVE_X
Definition: TrigHisto2D_v1.h:15
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
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
TrigHisto::m_min_x
float m_min_x
Definition: TrigHisto.h:79
TrigHistoCutType
Definition: TrigHisto.h:12
TrigHisto1D::operator=
TrigHisto1D & operator=(const TrigHisto1D &trigHisto)
Assignment operator.
Definition: TrigHisto1D.cxx:88
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:319
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
TrigHisto1D::fill
void fill(float value_x, float weight)
Fill a 1D histogram.
Definition: TrigHisto1D.cxx:118
TrigHisto::findBin
unsigned int findBin(unsigned int nbins, float h_min, float h_max, float binSize, float value) const
Definition: TrigHisto.cxx:33
TrigHisto1D::sumEntries
double sumEntries(float value_x, int cutType) const
Sum the number of entries within the cut range.
Definition: TrigHisto1D.cxx:126
xAOD::TrigHistoCutType::BELOW_X
@ BELOW_X
Definition: TrigHisto2D_v1.h:14
entries
double entries
Definition: listroot.cxx:49
TrigHisto::m_binSize_x
float m_binSize_x
Definition: TrigHisto.h:81
TrigHisto1D::~TrigHisto1D
virtual ~TrigHisto1D(void)
Destructor.
Definition: TrigHisto1D.cxx:59
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
TrigHisto1D::TrigHisto1D
TrigHisto1D(void)
Default constructor used by T/P converters.
Definition: TrigHisto1D.cxx:11
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