ATLAS Offline Software
Loading...
Searching...
No Matches
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
7using namespace TrigHistoCutType;
8
9//---------------------------------------------------------------
10
13
14//---------------------------------------------------------------
15
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
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
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;
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;
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
118void 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
126double 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
void fill(float value_x, float weight)
Fill a 1D histogram.
TrigHisto1D & operator=(const TrigHisto1D &trigHisto)
Assignment operator.
virtual ~TrigHisto1D(void)
Destructor.
double sumEntries(float value_x, int cutType) const
Sum the number of entries within the cut range.
TrigHisto1D(void)
Default constructor used by T/P converters.
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