ATLAS Offline Software
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
13 namespace xAOD {
14 
15  // Default ctor
17  : SG::AuxElement(),m_binWidthX(0),m_binWidthY(0) {
18  }
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
48 
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 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
xAOD::AUXSTORE_PRIMITIVE_SETTER_AND_GETTER
AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(BTagging_v1, float, IP2D_pb, setIP2D_pb) AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(BTagging_v1
xAOD::TrigHistoCutType::BELOW_X_BELOW_Y
@ BELOW_X_BELOW_Y
Definition: TrigHisto2D_v1.h:16
xAOD::TrigHisto2D_v1::m_binWidthX
float m_binWidthX
Definition: TrigHisto2D_v1.h:111
xAOD::TrigHistoCutType::ABOVE_X_ABOVE_Y
@ ABOVE_X_ABOVE_Y
Definition: TrigHisto2D_v1.h:19
xAOD::TrigHisto2D_v1::TrigHisto2D_v1
TrigHisto2D_v1()
Definition: TrigHisto2D_v1.cxx:16
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
xAOD::TrigHisto2D_v1::findBinX
unsigned int findBinX(float val) const
returns x bin index
Definition: TrigHisto2D_v1.cxx:171
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
AuxStoreAccessorMacros.h
xAOD::TrigHisto2D_v1::profileY
std::vector< float > profileY() const
Collapse the x-axis and return a profile from the y-axis.
Definition: TrigHisto2D_v1.cxx:98
xAOD::TrigHisto2D_v1::maxX
float maxX() const
Return the maximum along the x-axis.
initialize
void initialize()
Definition: run_EoverP.cxx:894
xAOD::TrigHisto2D_v1::nbinsX
unsigned int nbinsX() const
xAOD::TrigHisto2D_v1::findBinY
unsigned int findBinY(float val) const
returns y bin index
Definition: TrigHisto2D_v1.cxx:189
athena.value
value
Definition: athena.py:124
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::TrigHisto2D_v1::sumEntries
double sumEntries(float value_x, float value_y, int cutType) const
Sum the number of entries within the cut range.
Definition: TrigHisto2D_v1.cxx:111
TrigHisto2D_v1.h
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
xAOD::TrigHisto2D_v1::initialize
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
Definition: TrigHisto2D_v1.cxx:37
xAOD::TrigHistoCutType::BELOW_X_ABOVE_Y
@ BELOW_X_ABOVE_Y
Definition: TrigHisto2D_v1.h:18
lumiFormat.i
int i
Definition: lumiFormat.py:85
xAOD::TrigHisto2D_v1::~TrigHisto2D_v1
~TrigHisto2D_v1()
Destructor.
Definition: TrigHisto2D_v1.cxx:25
xAOD::TrigHisto2D_v1::nbinsY
unsigned int nbinsY() const
Return the number of bins along the y-axis, not including the under and overflow.
xAOD::TrigHisto2D_v1::minY
float minY() const
Return the minimum along the y-axis.
xAOD::TrigHisto2D_v1::m_binWidthY
float m_binWidthY
Definition: TrigHisto2D_v1.h:114
xAOD::TrigHisto2D_v1::minX
float minX() const
Return the minimum along the x-axis.
xAOD::TrigHistoCutType::ABOVE_X_BELOW_Y
@ ABOVE_X_BELOW_Y
Definition: TrigHisto2D_v1.h:17
xAOD::TrigHisto2D_v1::dump
void dump()
dump() function, for testing
Definition: TrigHisto2D_v1.cxx:214
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
xAOD::TrigHisto2D_v1::profileX
std::vector< float > profileX() const
Sum the number of entries within the cut range.
Definition: TrigHisto2D_v1.cxx:85
xAOD::TrigHisto2D_v1::fill
void fill(float value_x, float value_y, float weight)
fill histogram
Definition: TrigHisto2D_v1.cxx:73
xAOD::TrigHisto2D_v1::maxY
float maxY() const
Return the maximum along the y-axis.
xAOD::TrigHisto2D_v1::EXTRA_BINS
static const int EXTRA_BINS
additional bins for underflow and overflow bins
Definition: TrigHisto2D_v1.h:108
entries
double entries
Definition: listroot.cxx:49
xAOD::TrigHisto2D_v1::clear
void clear()
clear m_contents vector
Definition: TrigHisto2D_v1.cxx:207
xAOD::TrigHisto2D_v1
Definition: TrigHisto2D_v1.h:23
xAOD::AUXSTORE_OBJECT_SETTER_AND_GETTER
AUXSTORE_OBJECT_SETTER_AND_GETTER(CaloRings_v1, RingSetLinks, ringSetLinks, setRingSetLinks) unsigned CaloRings_v1
Definition: CaloRings_v1.cxx:27