ATLAS Offline Software
Loading...
Searching...
No Matches
TrigHisto2D_v1.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
9
10#include <iostream>
11
12//#define DBG
13namespace xAOD {
14
15 // Default ctor
19
20 TrigHisto2D_v1::TrigHisto2D_v1(unsigned int nbins_x, float min_x, float max_x, unsigned int nbins_y, float min_y, float max_y)
21 : SG::AuxElement() {
22 initialize(nbins_x, min_x, max_x, nbins_y, min_y, max_y);
23 }
24
26
27 AUXSTORE_OBJECT_SETTER_AND_GETTER(TrigHisto2D_v1, std::vector<float>, contents, setContents)
28
29 AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(TrigHisto2D_v1, unsigned int, nbinsX, setNbinsX)
32
33 AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(TrigHisto2D_v1, unsigned int, nbinsY, setNbinsY)
36
37 void TrigHisto2D_v1::initialize(unsigned int nbins_x, float min_x, float max_x, unsigned int nbins_y, float min_y, float max_y){
38
39 //the aux store has to exist if we wont to write anything there
40 if(!this->hasStore())
41 this->makePrivateStore();
42
44 unsigned int contents_size = (nbins_x+TrigHisto2D_v1::EXTRA_BINS)*(nbins_y+TrigHisto2D_v1::EXTRA_BINS);
45#ifdef DBG
46 std::cout<<"Creating Thist2D with :"<<contents_size<< " elements"<<std::endl<<"nbins_x+2="<< nbins_x+TrigHisto2D_v1::EXTRA_BINS<<std::endl<<"nbins_y+2="<<nbins_y+TrigHisto2D_v1::EXTRA_BINS<<std::endl;
47#endif
49 setContents(std::vector<float>(contents_size,0.));
50 setMinX(min_x);
51 setMaxX(max_x);
52 setNbinsX(nbins_x);
53 setMinY(min_y);
54 setMaxY(max_y);
55 setNbinsY(nbins_y);
56
58 if(nbins_x != 0) {
59 m_binWidthX = (max_x - min_x)/((float)nbins_x); // Calculate bin size.
60 }
61 else {
62 m_binWidthX = 0.;
63 }
64
65 if(nbins_y != 0) {
66 m_binWidthY = (max_y - min_y)/((float)nbins_y); // Calculate bin size.
67 }
68 else {
69 m_binWidthY = 0.;
70 }
71 }
72
73 void TrigHisto2D_v1::fill(float value_x, float value_y, float weight=1.){
74
75 unsigned int ibin_x = findBinX(value_x);
76 unsigned int ibin_y = findBinY(value_y);
77
78 unsigned int ibin = ibin_y*(nbinsX()+TrigHisto2D_v1::EXTRA_BINS) + ibin_x;
79
80 static const Accessor< std::vector<float> > acc_contents( "contents" );
81
82 acc_contents(*this).at(ibin)+= weight;
83 }
84
85 std::vector<float> TrigHisto2D_v1::profileX() const {
86 std::vector<float> contentsX(nbinsX()+TrigHisto2D_v1::EXTRA_BINS,0.);
87
88 static const Accessor< std::vector<float> > acc_contents( "contents" );
89
90 for(unsigned int ix = 0 ; ix < nbinsX() + TrigHisto2D_v1::EXTRA_BINS; ix++){
91 for(unsigned int iy = 0; iy < nbinsY() + TrigHisto2D_v1::EXTRA_BINS; iy++){
92 contentsX.at(ix) += acc_contents(*this).at(ix + iy*(nbinsX() + TrigHisto2D_v1::EXTRA_BINS));
93 }
94 }
95 return contentsX;
96 }
97
98 std::vector<float> TrigHisto2D_v1::profileY() const {
99 std::vector<float> contentsY(nbinsY()+TrigHisto2D_v1::EXTRA_BINS);
100
101 static const Accessor< std::vector<float> > acc_contents( "contents" );
102
103 for(unsigned int iy = 0 ; iy < nbinsY() + TrigHisto2D_v1::EXTRA_BINS; iy++){
104 for(unsigned int ix = 0; ix < nbinsX() + TrigHisto2D_v1::EXTRA_BINS; ix++){
105 contentsY.at(iy) += acc_contents(*this).at(ix + iy*(nbinsX() + TrigHisto2D_v1::EXTRA_BINS));
106 }
107 }
108 return contentsY;
109 }
110
111 double TrigHisto2D_v1::sumEntries(float value_x, float value_y, int cutType) const {
112
113 unsigned int ibin, ibin_x, ibin_y, ibin_x_selected, ibin_y_selected;
114 double entries;
115
116 static const Accessor< std::vector<float> > acc_contents( "contents" );
117
118 // Find the x bin index that the cut corresponds to.
119 ibin_x_selected = findBinX(value_x);
120
121 // Find the y bin index that the cut corresponds to.
122 ibin_y_selected = findBinY(value_y);
123 entries = 0.;
124
125
126 if( nbinsX()==0 || nbinsY()==0 ){
127 return 0;
128 }
129 else{
130
131 if(cutType == TrigHistoCutType::BELOW_X_BELOW_Y) {
132 for(ibin_x = 0; ibin_x <= ibin_x_selected; ibin_x++) {
133 for(ibin_y = 0; ibin_y <= ibin_y_selected; ibin_y++) {
134 ibin = ibin_y*(nbinsX()+2) + ibin_x; // Find position in 1d data array
135 entries += acc_contents(*this).at(ibin);
136 }
137 }
138 }
139 else if(cutType == TrigHistoCutType::ABOVE_X_BELOW_Y) {
140 for(ibin_x = ibin_x_selected; ibin_x < nbinsX()+ TrigHisto2D_v1::EXTRA_BINS; ibin_x++) {
141 for(ibin_y = 0; ibin_y <= ibin_y_selected; ibin_y++) {
142 ibin = ibin_y*(nbinsX()+ TrigHisto2D_v1::EXTRA_BINS) + ibin_x; // Find position in 1d data array
143 entries += acc_contents(*this).at(ibin);
144 }
145 }
146 }
147 else if(cutType == TrigHistoCutType::BELOW_X_ABOVE_Y) {
148 for(ibin_x = 0; ibin_x <= ibin_x_selected; ibin_x++) {
149 for(ibin_y = ibin_y_selected; ibin_y < nbinsY()+ TrigHisto2D_v1::EXTRA_BINS; ibin_y++) {
150 ibin = ibin_y*(nbinsX()+ TrigHisto2D_v1::EXTRA_BINS) + ibin_x; // Find position in 1d data array
151 entries += acc_contents(*this).at(ibin);
152 }
153 }
154 }
155 else if(cutType == TrigHistoCutType::ABOVE_X_ABOVE_Y) {
156 for(ibin_x = ibin_x_selected; ibin_x < nbinsX()+ TrigHisto2D_v1::EXTRA_BINS; ibin_x++) {
157 for(ibin_y = ibin_y_selected; ibin_y < nbinsY()+ TrigHisto2D_v1::EXTRA_BINS; ibin_y++) {
158 ibin = ibin_y*(nbinsX()+ TrigHisto2D_v1::EXTRA_BINS) + ibin_x; // Find position in 1d data array
159 entries += acc_contents(*this).at(ibin);
160 }
161 }
162 }
163 else {
164 return 0;
165 }
166 }// else of m_nbins!=0
167
168 return entries;
169 }
170
171 unsigned int TrigHisto2D_v1::findBinX(float value) const {
172
173 unsigned int ibin = 0;
174
175 if(value < minX()) { // Underflow
176 ibin = 0;
177 }
178 else if( !(value < maxX()) ) { // Overflow (catches NaN)
179 ibin = nbinsX()+1;
180 }
181 else {
182 while(value > (ibin*m_binWidthX+minX()) && ibin <= nbinsX()) { // None under/overflow from 1 to nbins
183 ibin++;
184 }
185 }
186 return ibin;
187 }
188
189 unsigned int TrigHisto2D_v1::findBinY(float value) const{
190
191 unsigned int ibin = 0;
192
193 if(value < minY()) { // Underflow
194 ibin = 0;
195 }
196 else if( !(value < maxY()) ) { // Overflow (catches NaN)
197 ibin = nbinsY()+1;
198 }
199 else {
200 while(value > (ibin*m_binWidthY+minY()) && ibin <= nbinsY()) { // None under/overflow from 1 to nbins
201 ibin++;
202 }
203 }
204 return ibin;
205 }
206
208 static const Accessor< std::vector<float> > acc_contents( "contents" );
209
210 for(std::vector<float>::iterator contents_iter = acc_contents(*this).begin(); contents_iter !=acc_contents(*this).end(); ++contents_iter)
211 *contents_iter = 0;
212 }
213
215 static const Accessor< std::vector<float> > acc_contents( "contents" );
216
217 std::cout<<"Dump contets vector of size:: "<<acc_contents(*this).size()<<std::endl;
218 for( unsigned int i = 0 ; i < acc_contents(*this).size(); i++)
219 std::cout<<acc_contents(*this).at(i)<<" ";
220 std::cout<<std::endl;
221
222 std::cout<<"NbinX:: "<< nbinsX()<<"\tRangeX:: ["<<minX()<<","<<maxX()<<"]"<<std::endl;
223 std::cout<<"NbinY:: "<< nbinsY()<<"\tRangeY:: ["<<minY()<<","<<maxY()<<"]"<<std::endl;
224
225
226 for(unsigned int iy = 0 ; iy < nbinsY() + TrigHisto2D_v1::EXTRA_BINS; iy++){
227 std::cout<<std::endl;
228 for(unsigned int ix = 0; ix < nbinsX() + TrigHisto2D_v1::EXTRA_BINS; ix++){
229 std::cout<< acc_contents(*this).at(ix + iy*(nbinsX() + TrigHisto2D_v1::EXTRA_BINS))<<"\t";
230 }
231 }
232 std::cout<<std::endl;
233 }
234}
#define AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(CL, TYPE, NAME, SETTER)
Macro creating the accessors of primitive auxiliary properties.
#define AUXSTORE_OBJECT_SETTER_AND_GETTER(CL, TYPE, NAME, SETTER)
Macro creating the accessors of complex auxiliary properties.
void makePrivateStore()
Create a new (empty) private store for this object.
bool hasStore() const
Return true if this object has an associated store.
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
AuxElement()
Default constructor.
void setNbinsX(unsigned int nx)
NbinsX setter.
double sumEntries(float value_x, float value_y, int cutType) const
Sum the number of entries within the cut range.
unsigned int findBinY(float val) const
returns y bin index
float maxY() const
Return the maximum along the y-axis.
unsigned int nbinsY() const
Return the number of bins along the y-axis, not including the under and overflow.
void setMaxY(float val)
float maxX() const
Return the maximum along the x-axis.
void fill(float value_x, float value_y, float weight)
fill histogram
std::vector< float > profileY() const
Collapse the x-axis and return a profile from the y-axis.
~TrigHisto2D_v1()
Destructor.
void setContents(const std::vector< float > &cont)
contents setter
void clear()
clear m_contents vector
void dump()
dump() function, for testing
void setMinY(float val)
static const int EXTRA_BINS
additional bins for underflow and overflow bins
unsigned int findBinX(float val) const
returns x bin index
void setMaxX(float val)
float minX() const
Return the minimum along the x-axis.
std::vector< float > profileX() const
Sum the number of entries within the cut range.
float minY() const
Return the minimum along the y-axis.
void setMinX(float val)
void setNbinsY(unsigned int ny)
NbinsY setter.
void initialize(unsigned int nbins_x, float min_x, float max_x, unsigned int nbins_y, float min_y, float max_y)
creates empty histogram
unsigned int nbinsX() const
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
double entries
Definition listroot.cxx:49
Forward declaration.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
void initialize()