ATLAS Offline Software
VariableBinwidthHistogramBin.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef VARIABLEBINWIDTHHISTOGRAMBIN_H
6 #define VARIABLEBINWIDTHHISTOGRAMBIN_H
7 
8 #include <TString.h> // for Form
9 
10 #include <cstdlib>
11 #include <iostream>
12 #include <vector>
13 
14 namespace MuonCalib {
15 
23  public:
24  //----------------------------------constructor---------------------------------
25 
28 
35  inline VariableBinwidthHistogramBin(double center, double width, unsigned int content) :
36  m_center(center), m_width(width), m_content(content) {}
37 
38  //-----------------------------------public member functions--------------------
39 
46  inline void Set(double center, double width, unsigned int content) {
47  m_center = center;
48  m_width = width;
50  }
51 
56  inline void SetContent(unsigned int n) { m_content = n; }
57 
62  inline VariableBinwidthHistogramBin operator+=(unsigned int n) {
63  m_content += n;
64  return *this;
65  }
70  inline VariableBinwidthHistogramBin operator+(unsigned int n) {
72  ret += n;
73  return ret;
74  }
75 
80  void MoveRight(double new_right) {
81  double left = Left();
82  if (new_right < left) {
83  throw std::runtime_error(
84  Form("File: %s, Line: %d\nVariableBinwidthHistogramBin::MoveRight() - new right is too small!", __FILE__, __LINE__));
85  }
86  m_width = new_right - left;
87  m_center = 0.5 * (left + new_right);
88  }
89 
94  void MoveLeft(double new_left) {
95  double right = Right();
96  if (new_left > right) {
97  throw std::runtime_error(
98  Form("File: %s, Line: %d\nVariableBinwidthHistogramBin::MoveRight() - new left is too small!", __FILE__, __LINE__));
99  }
100  m_width = right - new_left;
101  m_center = 0.5 * (new_left + right);
102  }
103 
105  inline double Center() const { return m_center; }
106 
108  inline double Width() const { return m_width; }
109 
111  inline double Left() const { return m_center - 0.5 * m_width; }
112 
114  inline double Right() const { return m_center + 0.5 * m_width; }
115 
117  inline unsigned int Entries() const { return m_content; }
118 
120  inline double Density() const { return static_cast<double>(m_content) / m_width; }
121 
122  private:
123  //-----------------------------------------private data members-----------------
124 
125  double m_center, m_width;
126  unsigned int m_content;
127  };
128 
135  class VBHBinPtrSrt {
136  public:
137  //-----------------------------------constructor--------------------------------
139  inline VBHBinPtrSrt() {}
140 
146 
147  //--------------------------------------public member functions-----------------
148 
154 
158  inline VariableBinwidthHistogramBin &Bin() { return *m_bin; }
159 
164  inline bool operator>(const VBHBinPtrSrt &other) const { return m_bin->Width() > other.m_bin->Width(); }
165 
170  inline bool operator<(const VBHBinPtrSrt &other) const { return m_bin->Width() < other.m_bin->Width(); }
171 
172  private:
173  //------------------------------private data members----------------------------
174 
177  };
178 
179 } // namespace MuonCalib
180 
181 #endif
MuonCalib::VBHBinPtrSrt::m_bin
VariableBinwidthHistogramBin * m_bin
pointer to bin
Definition: VariableBinwidthHistogramBin.h:176
MuonCalib::VariableBinwidthHistogramBin::SetContent
void SetContent(unsigned int n)
set content
Definition: VariableBinwidthHistogramBin.h:56
MuonCalib::VBHBinPtrSrt::operator<
bool operator<(const VBHBinPtrSrt &other) const
Operator < for sorting bins by content.
Definition: VariableBinwidthHistogramBin.h:170
MuonCalib::VariableBinwidthHistogramBin::MoveRight
void MoveRight(double new_right)
move right bin boarder
Definition: VariableBinwidthHistogramBin.h:80
MuonCalib::VBHBinPtrSrt
Definition: VariableBinwidthHistogramBin.h:135
bin
Definition: BinsDiffFromStripMedian.h:43
MuonCalib::VariableBinwidthHistogramBin::operator+=
VariableBinwidthHistogramBin operator+=(unsigned int n)
add to bin content
Definition: VariableBinwidthHistogramBin.h:62
MuonCalib::VBHBinPtrSrt::operator>
bool operator>(const VBHBinPtrSrt &other) const
Operator > for sorting bins by content.
Definition: VariableBinwidthHistogramBin.h:164
grepfile.content
string content
Definition: grepfile.py:56
MuonCalib::VBHBinPtrSrt::VBHBinPtrSrt
VBHBinPtrSrt(VariableBinwidthHistogramBin *bin)
initializing constructor
Definition: VariableBinwidthHistogramBin.h:145
MuonCalib::VariableBinwidthHistogramBin::operator+
VariableBinwidthHistogramBin operator+(unsigned int n)
add to bin content
Definition: VariableBinwidthHistogramBin.h:70
MuonCalib::VBHBinPtrSrt::Initialize
void Initialize(VariableBinwidthHistogramBin *bin)
initialize
Definition: VariableBinwidthHistogramBin.h:153
MuonCalib::VariableBinwidthHistogramBin::m_content
unsigned int m_content
Definition: VariableBinwidthHistogramBin.h:126
MuonCalib::VariableBinwidthHistogramBin::Center
double Center() const
Get bin center.
Definition: VariableBinwidthHistogramBin.h:105
MuonCalib::VariableBinwidthHistogramBin::m_width
double m_width
Definition: VariableBinwidthHistogramBin.h:125
MuonCalib::VariableBinwidthHistogramBin::MoveLeft
void MoveLeft(double new_left)
move left bin boarder
Definition: VariableBinwidthHistogramBin.h:94
beamspotman.n
n
Definition: beamspotman.py:731
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::VariableBinwidthHistogramBin::Entries
unsigned int Entries() const
Get number of entries in the bin.
Definition: VariableBinwidthHistogramBin.h:117
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
MuonCalib::VariableBinwidthHistogramBin
Definition: VariableBinwidthHistogramBin.h:22
MuonCalib::VariableBinwidthHistogramBin::Left
double Left() const
Get left (lower) bin border.
Definition: VariableBinwidthHistogramBin.h:111
MuonCalib::VariableBinwidthHistogramBin::VariableBinwidthHistogramBin
VariableBinwidthHistogramBin(double center, double width, unsigned int content)
Initializing constructor.
Definition: VariableBinwidthHistogramBin.h:35
MuonCalib::VBHBinPtrSrt::VBHBinPtrSrt
VBHBinPtrSrt()
default constructor
Definition: VariableBinwidthHistogramBin.h:139
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
MuonCalib::VariableBinwidthHistogramBin::m_center
double m_center
Definition: VariableBinwidthHistogramBin.h:125
MuonCalib::VariableBinwidthHistogramBin::Right
double Right() const
Get right (upper) bin border.
Definition: VariableBinwidthHistogramBin.h:114
MuonCalib::VariableBinwidthHistogramBin::Set
void Set(double center, double width, unsigned int content)
Set bin.
Definition: VariableBinwidthHistogramBin.h:46
MuonCalib::VBHBinPtrSrt::Bin
VariableBinwidthHistogramBin & Bin()
Get reference to bin.
Definition: VariableBinwidthHistogramBin.h:158
MuonCalib::VariableBinwidthHistogramBin::Width
double Width() const
Get width of the bin.
Definition: VariableBinwidthHistogramBin.h:108
MuonCalib::VariableBinwidthHistogramBin::VariableBinwidthHistogramBin
VariableBinwidthHistogramBin()
Default constructor.
Definition: VariableBinwidthHistogramBin.h:27
MuonCalib::VariableBinwidthHistogramBin::Density
double Density() const
Get density=Entries()/Width()
Definition: VariableBinwidthHistogramBin.h:120