ATLAS Offline Software
xAODTrigMinBiasHelperFunc_v1.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 #include <iostream>
7 
8 namespace xAOD{
9  double sumEntries(const std::vector<float> &cont,
10  unsigned int nbins_x,
11  float min_x,
12  float max_x,
13  unsigned int nbins_y,
14  float min_y,
15  float max_y,
16  float value_x,
17  float value_y,
18  int cutType){
19 
20 
21  const unsigned int nbins_x_widened = nbins_x + 2;
22  const unsigned int nbins_y_widened = nbins_y + 2;
23 
24  if((nbins_x_widened*nbins_y_widened) != cont.size()){
25  std::cout<<"ERROR in xAOD::sumEntries: nbins and container size don't match!!"<<std::endl;
26  return -1.;
27  }
28  if(nbins_x*nbins_y == 0 ){
29  std::cout<<"ERROR in xAOD::sumEntries: nbins_x * nbins_y = 0"<<std::endl;
30  }
31  unsigned int ibin(0), ibin_x(0), ibin_y(0), ibin_x_selected(0), ibin_y_selected(0);
32  const float binWidth_x = (max_x - min_x)/((float)nbins_x);
33  const float binWidth_y = (max_y - min_y)/((float)nbins_y);
34 
35  double entries(0.);
36 
37  if(value_x < min_x) { // Underflow
38  ibin_x = 0;
39  }
40  else if( !(value_x < max_x) ) { // Overflow (catches NaN)
41  ibin_x = nbins_x+1;
42  }
43  else {
44  while(value_x > (ibin_x*binWidth_x+min_x) && ibin_x <= nbins_x) { // None under/overflow from 1 to nbins
45  ibin_x++;
46  }
47  }
48 
49  //and for y bind
50  if(value_y < min_y) { // Underflow
51  ibin_y = 0;
52  }
53  else if( !(value_y < max_y) ) { // Overflow (catches NaN)
54  ibin_y = nbins_y+1;
55  }
56  else {
57  while(value_y > (ibin_y*binWidth_y+min_y) && ibin_y <= nbins_y) { // None under/overflow from 1 to nbins
58  ibin_y++;
59  }
60  }
61 
62  // Find the x bin index that the cut corresponds to.
63  ibin_x_selected = ibin_x;
64 
65  // Find the y bin index that the cut corresponds to.
66  ibin_y_selected = ibin_y;
67 
68  if(cutType == TrigHistoCutType::BELOW_X_BELOW_Y) {
69  for(ibin_x = 0; ibin_x <= ibin_x_selected; ibin_x++) {
70  for(ibin_y = 0; ibin_y <= ibin_y_selected; ibin_y++) {
71  ibin = ibin_y*(nbins_x_widened) + ibin_x; // Find position in 1d data array
72  entries += cont.at(ibin);
73  }
74  }
75  }
76  else if(cutType == TrigHistoCutType::ABOVE_X_BELOW_Y) {
77  for(ibin_x = ibin_x_selected; ibin_x < nbins_x_widened; ibin_x++) {
78  for(ibin_y = 0; ibin_y <= ibin_y_selected; ibin_y++) {
79  ibin = ibin_y*(nbins_x_widened) + ibin_x; // Find position in 1d data array
80  entries += cont.at(ibin);
81  }
82  }
83  }
84  else if(cutType == TrigHistoCutType::BELOW_X_ABOVE_Y) {
85  for(ibin_x = 0; ibin_x <= ibin_x_selected; ibin_x++) {
86  for(ibin_y = ibin_y_selected; ibin_y < nbins_y_widened; ibin_y++) {
87  ibin = ibin_y*(nbins_x_widened) + ibin_x; // Find position in 1d data array
88  entries += cont.at(ibin);
89  }
90  }
91  }
92  else if(cutType == TrigHistoCutType::ABOVE_X_ABOVE_Y) {
93  for(ibin_x = ibin_x_selected; ibin_x < nbins_x_widened; ibin_x++) {
94  for(ibin_y = ibin_y_selected; ibin_y < nbins_y_widened; ibin_y++) {
95  ibin = ibin_y*(nbins_x_widened) + ibin_x; // Find position in 1d data array
96  entries += cont.at(ibin);
97  }
98  }
99  }
100  else {
101  return 0;
102  }
103  return entries;
104  } //end function
105 } //xAOD namespace
xAOD::TrigHistoCutType::BELOW_X_BELOW_Y
@ BELOW_X_BELOW_Y
Definition: TrigHisto2D_v1.h:16
xAOD::TrigHistoCutType::ABOVE_X_ABOVE_Y
@ ABOVE_X_ABOVE_Y
Definition: TrigHisto2D_v1.h:19
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::TrigHistoCutType::BELOW_X_ABOVE_Y
@ BELOW_X_ABOVE_Y
Definition: TrigHisto2D_v1.h:18
xAOD::TrigHistoCutType::ABOVE_X_BELOW_Y
@ ABOVE_X_BELOW_Y
Definition: TrigHisto2D_v1.h:17
xAOD::sumEntries
double sumEntries(const std::vector< float > &cont, unsigned int nbins_x, float min_x, float max_x, unsigned int nbins_y, float min_y, float max_y, float value_x, float value_y, int cutType)
Definition: xAODTrigMinBiasHelperFunc_v1.cxx:9
xAODTrigMinBiasHelperFunc.h
entries
double entries
Definition: listroot.cxx:49